new_file.vue 4.1 KB

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