place-order.vue 7.2 KB

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