place-order.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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" style="font-size: 20rpx;">
  15. {{ item.cart.reduce((t, e) => t + e, 0) }}
  16. </view>
  17. <text v-else class="cuIcon-cart"></text>
  18. </view>
  19. </view>
  20. </view>
  21. <!-- <view v-if="!goodsList.length" class="loading">{{ status }}</view> -->
  22. </scroll-view>
  23. <navigator open-type="navigate" url="../shop-car1/shop-car1" class="cart">
  24. 购物车
  25. <text v-if="cartNum" class="sizeNum">{{ cartNum }}</text>
  26. </navigator>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import {
  32. deepClone
  33. } from '@/common/util/index.js'
  34. import {
  35. _API_GoodList
  36. } from '@/apis/good.js'
  37. import AddCart from '@/components/public/add-cart.vue'
  38. export default {
  39. components: {
  40. AddCart
  41. },
  42. data() {
  43. return {
  44. image: [
  45. 'http://look.qiniuyun.jiuweiyun.cn/daweiboshi-app/18afbb463c7e9a8aefa4883e726900f.jpg?imageMogr2/thumbnail/!40p',
  46. ],
  47. title: '订货下单',
  48. mode: 'square',
  49. goodsList: [],
  50. scrollviewHeight: 0,
  51. status: '加载中...'
  52. }
  53. },
  54. computed: {
  55. userinfo() {
  56. return this.$store.state.userinfo
  57. },
  58. list() {
  59. const temp = deepClone(this.goodsList)
  60. temp.forEach(goodItem => {
  61. goodItem.cart = Array(goodItem.size.length).fill(0)
  62. const itemInCart = this.$store.state.cart.list.find(e => e.attr_id === goodItem.attr_id)
  63. if (itemInCart) {
  64. Object.assign(goodItem, itemInCart)
  65. }
  66. })
  67. return temp
  68. },
  69. cartNum() {
  70. return this.$store.getters['cart/shopcarNum']
  71. }
  72. },
  73. mounted() { // 获取商品列表
  74. this.$offset('.content').then(res => this.scrollviewHeight = res.height - uni.upx2px(98)) // 设置scrollview 高
  75. if (this.$store.state.userinfo.user_type !== 3) {
  76. uni.navigateBack()
  77. setTimeout(() => uni.$emit('noopening'))
  78. return
  79. }
  80. //测试账号
  81. if (this.$store.state.userinfo.mobile != 15866666666) {
  82. this.request()
  83. }
  84. },
  85. onPullDownRefresh() {
  86. //测试账号
  87. if (this.$store.state.userinfo.mobile != 15866666666) {
  88. this.request()
  89. } else {
  90. uni.stopPullDownRefresh()
  91. }
  92. // this.request()
  93. },
  94. methods: {
  95. gosoap(type) {
  96. uni.navigateTo({
  97. url: '../soap/index?type=' + type
  98. })
  99. },
  100. request() {
  101. uni.showLoading({
  102. mask: true
  103. })
  104. _API_GoodList().then(res => {
  105. if (res.code === 200) {
  106. this.goodsList = res.data.list
  107. console.log(this.goodsList)
  108. if (!this.goodsList.length) {
  109. this.status = '暂无商品'
  110. }
  111. } else {
  112. uni.toast('网络好像出了点问题,下拉刷新试试')
  113. }
  114. uni.stopPullDownRefresh()
  115. }).catch(() => setTimeout(() => {
  116. uni.toast('网络好像出了点问题,下拉刷新试试')
  117. uni.stopPullDownRefresh()
  118. }, 123))
  119. },
  120. tap(index) { // 查看商品详情
  121. uni.setStorageSync('ggg', JSON.stringify(this.goodsList[index]))
  122. uni.navigateTo({
  123. url: `../good-detail1/good-detail1`
  124. })
  125. },
  126. tapShopCar(item) {
  127. this.$refs.addCart.show(deepClone(item))
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss">
  133. .place-order {
  134. @include page();
  135. .soapNav {
  136. background-color: #fff;
  137. display: flex;
  138. align-items: center;
  139. padding: 24rpx;
  140. margin-bottom: 30rpx;
  141. &_flex {
  142. height: 150rpx;
  143. display: flex;
  144. justify-content: space-between;
  145. flex-direction: column;
  146. .text1 {
  147. font-size: 30rpx;
  148. font-weight: bold;
  149. }
  150. .text2 {
  151. display: block;
  152. width: 92rpx;
  153. height: 44rpx;
  154. color: #333333;
  155. line-height: 44rpx;
  156. text-align: center;
  157. background: #F5F5F5;
  158. border-radius: 4rpx 4rpx 4rpx 4rpx;
  159. }
  160. .text3 {
  161. font-size: 28rpx;
  162. color: #FB231F;
  163. }
  164. .text4 {
  165. font-size: 44rpx;
  166. font-weight: bold;
  167. color: #FB231F;
  168. }
  169. }
  170. }
  171. .content {
  172. .cart {
  173. height: 98rpx;
  174. @include flex();
  175. color: $app-base-color;
  176. font-size: 36rpx;
  177. // background: $app-base-color;
  178. border-top: 1rpx solid #C0C0C0;
  179. background: #FFFFFF;
  180. position: relative;
  181. .sizeNum {
  182. @include flex();
  183. position: absolute;
  184. font-size: 20rpx;
  185. left: 50%;
  186. margin-left: 48rpx;
  187. height: 32rpx;
  188. color: #FFFFFF;
  189. top: 24rpx;
  190. padding: 2rpx 8rpx;
  191. border-radius: 32rpx;
  192. background: #FF0000;
  193. }
  194. }
  195. .loading {
  196. text-align: center;
  197. margin-top: 567rpx;
  198. }
  199. .item {
  200. float: left;
  201. width: 100%;
  202. padding: 30rpx;
  203. box-sizing: border-box;
  204. background: #FFFFFF;
  205. margin-bottom: 20rpx;
  206. display: flex;
  207. justify-content: space-between;
  208. .img {
  209. height: 240rpx !important;
  210. width: 300rpx !important;
  211. margin-right: 23rpx;
  212. }
  213. .info {
  214. flex: 1;
  215. width: 100%;
  216. position: relative;
  217. @include flex(column);
  218. border-radius: 8rpx;
  219. align-items: flex-start;
  220. justify-content: space-around;
  221. .top {
  222. width: 100%;
  223. color: #181818;
  224. font-size: 28rpx;
  225. overflow: hidden;
  226. white-space: nowrap;
  227. text-overflow: ellipsis;
  228. }
  229. .mid {
  230. font-size: 32rpx;
  231. color: $app-base-color;
  232. font-weight: bold;
  233. }
  234. .bot {
  235. font-size: 28rpx;
  236. color: #666666;
  237. }
  238. .shopCar {
  239. right: 0;
  240. bottom: 13rpx;
  241. width: 60rpx;
  242. height: 60rpx;
  243. color: #FFFFFF;
  244. @include flex();
  245. font-size: 42rpx;
  246. position: absolute;
  247. border-radius: 50%;
  248. background: $app-base-color;
  249. }
  250. }
  251. }
  252. }
  253. }
  254. </style>