place-order.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="place-order">
  3. <custom-nav noback="noback" transparent="transparent" ref="ltm" title=" " />
  4. <AddCart ref="addCart" />
  5. <view class="content">
  6. <scroll-view scroll-y :style="{ height: scrollviewHeight + 'px' }">
  7. <view class="item" v-for="(item, index) in list" :key="index" @tap="tap(index)">
  8. <image class="img" :src="item.main_img" mode="aspectFill"></image>
  9. <view class="info">
  10. <view class="top ellipsis">{{ item.name }}</view>
  11. <view class="mid">¥{{ item.money }}/{{ item.unit }}</view>
  12. <view class="bot">{{ item.size.length }}个尺码可选</view>
  13. <view class="shopCar" @tap.stop="tapShopCar(item)">
  14. <view v-if="item.cart.reduce((t, e) => t + e, 0)" class="sizeNum">{{ item.cart.reduce((t, e) => t + e, 0) }}</view>
  15. <text class="cuIcon-cart"></text>
  16. </view>
  17. </view>
  18. </view>
  19. <view v-if="!goodsList.length" class="loading">{{ status }}</view>
  20. </scroll-view>
  21. <navigator open-type="switchTab" url="../shop-car1/shop-car1" class="cart">
  22. 购物车
  23. <text v-if="cartNum" class="sizeNum">{{ cartNum }}</text>
  24. </navigator>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { deepClone } from '@/common/util/index.js'
  30. import { _API_GoodList } from '@/apis/good.js'
  31. import AddCart from '@/components/public/add-cart.vue'
  32. export default {
  33. components: { AddCart },
  34. data() {
  35. return {
  36. title: '订货下单',
  37. mode: 'square',
  38. goodsList: [],
  39. scrollviewHeight: 0,
  40. status: '加载中...'
  41. }
  42. },
  43. computed: {
  44. list() {
  45. const temp = deepClone(this.goodsList)
  46. temp.forEach(goodItem => {
  47. goodItem.cart = Array(goodItem.size.length).fill(0)
  48. const itemInCart = this.$store.state.cart.list.find(e => e.attr_id === goodItem.attr_id)
  49. if (itemInCart) {
  50. Object.assign(goodItem, itemInCart)
  51. }
  52. })
  53. return temp
  54. },
  55. cartNum() {
  56. return this.$store.getters['cart/shopcarNum']
  57. }
  58. },
  59. mounted() { // 获取商品列表
  60. this.$offset('.content').then(res => this.scrollviewHeight = res.height - uni.upx2px(98)) // 设置scrollview 高
  61. if (this.$store.state.userinfo.level !== '代理公司') {
  62. uni.navigateBack()
  63. setTimeout(() => uni.$emit('noopening'))
  64. return
  65. }
  66. this.request()
  67. },
  68. onPullDownRefresh() {
  69. this.request()
  70. },
  71. methods: {
  72. request() {
  73. uni.showLoading({ mask: true })
  74. _API_GoodList().then(res => {
  75. if (res.code === 200) {
  76. this.goodsList = res.data.list
  77. console.log(this.goodsList)
  78. if (!this.goodsList.length) {
  79. this.status = '暂无商品'
  80. }
  81. } else {
  82. uni.toast('网络好像出了点问题,下拉刷新试试')
  83. }
  84. uni.stopPullDownRefresh()
  85. }).catch(() => setTimeout(() => {
  86. uni.toast('网络好像出了点问题,下拉刷新试试')
  87. uni.stopPullDownRefresh()
  88. }, 123))
  89. },
  90. tap(index) { // 查看商品详情
  91. uni.setStorageSync('ggg', JSON.stringify(this.goodsList[index]))
  92. uni.navigateTo({ url: `../good-detail1/good-detail1` })
  93. },
  94. tapShopCar(item) {
  95. this.$refs.addCart.show(deepClone(item))
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. .place-order {
  102. @include page();
  103. .content {
  104. .cart {
  105. height: 98rpx;
  106. @include flex();
  107. color: $app-base-color;
  108. font-size: 36rpx;
  109. // background: $app-base-color;
  110. border-top: 1rpx solid #C0C0C0;
  111. background: #FFFFFF;
  112. position: relative;
  113. .sizeNum {
  114. @include flex();
  115. position: absolute;
  116. font-size: 20rpx;
  117. left: 50%;
  118. margin-left: 48rpx;
  119. height: 32rpx;
  120. color: #FFFFFF;
  121. top: 24rpx;
  122. padding: 2rpx 8rpx;
  123. border-radius: 32rpx;
  124. background: #FF0000;
  125. }
  126. }
  127. .loading {
  128. text-align: center;
  129. margin-top: 567rpx;
  130. }
  131. .item {
  132. float: left;
  133. width: 330rpx;
  134. height: 380rpx;
  135. margin-top: 20rpx;
  136. margin-left: 30rpx;
  137. background: #FFFFFF;
  138. align-items: flex-end;
  139. @include flex(column);
  140. .img {
  141. height: 220rpx;
  142. width: 100%;
  143. }
  144. .info {
  145. flex: 1;
  146. width: 100%;
  147. margin-left: 12rpx;
  148. position: relative;
  149. @include flex(column);
  150. border-radius: 8rpx;
  151. align-items: flex-start;
  152. justify-content: space-around;
  153. .top {
  154. width: 100%;
  155. color: #181818;
  156. font-size: 28rpx;
  157. overflow: hidden;
  158. white-space: nowrap;
  159. text-overflow: ellipsis;
  160. }
  161. .mid {
  162. font-size: 32rpx;
  163. color: $app-base-color;
  164. font-weight: bold;
  165. }
  166. .bot {
  167. font-size: 28rpx;
  168. color: #666666;
  169. }
  170. .shopCar {
  171. right: 24rpx;
  172. bottom: 13rpx;
  173. width: 60rpx;
  174. height: 60rpx;
  175. color: #FFFFFF;
  176. @include flex();
  177. font-size: 42rpx;
  178. position: absolute;
  179. border-radius: 50%;
  180. background: $app-base-color;
  181. }
  182. }
  183. }
  184. }
  185. }
  186. </style>