before.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <view class="shop-car1">
  3. <view v-if="list.length" class="list">
  4. <view class="shopcar-item" v-for="(item, index) in list" :key="index">
  5. <view class="name" @tap="chooseGood(!item.choosed, index)">
  6. <view class="left">
  7. <text v-if="item.choosed" class="cuIcon-roundcheckfill"></text>
  8. <text v-else class="cuIcon-round"></text>
  9. <view class="name ellipsis">{{ item.name }}</view>
  10. </view>
  11. <text class="cuIcon-delete" @click.stop="deleteGood(index)"></text>
  12. </view>
  13. <view class="sizeItem" v-for="(sizeItem, sizeIndex) in item.size" :key="sizeIndex" v-if="item.cart[sizeIndex]"
  14. @tap="chooseSize(!item.sizeChoosed[sizeIndex], index, sizeIndex)"
  15. >
  16. <text v-if="item.sizeChoosed[sizeIndex]" class="cuIcon-roundcheckfill"></text>
  17. <text v-else class="cuIcon-round"></text>
  18. <image :src="item.main_img"></image>
  19. <view class="info">
  20. <text>尺码:{{ sizeItem }}</text>
  21. <text class="basecolor">¥{{ item.money }}/{{ item.unit }}</text>
  22. </view>
  23. <NumInput :value="item.cart[sizeIndex]" :args="[index, sizeIndex]" @change="numChange" />
  24. </view>
  25. </view>
  26. <view class="gift_container" v-if="giftList.length > 0">
  27. <view class="fix_title">
  28. <text class="cuIcon-roundcheckfill"></text>
  29. <text class="title">赠品信息</text>
  30. </view>
  31. <div class="gift_list">
  32. <view class="gift_item" v-for="item in giftList" :key="item.id" v-show="Math.floor(giftNum / item.num) > 0">
  33. <template v-if="giftNum >= item.limit_num">
  34. <image :src="item.img" class="gift_img"></image>
  35. <view class="right">
  36. <view class="fixed">赠品名称:</view>
  37. <view class="bottom">
  38. <view class="name">{{item.name}}</view>
  39. <view class="num">数量:{{ Math.floor(giftNum / item.num) }}</view>
  40. </view>
  41. </view>
  42. </template>
  43. </view>
  44. </div>
  45. </view>
  46. </view>
  47. <view v-else class="none">
  48. <image src="../../static/icon/emptyshopcar.png"></image>
  49. <view class="big-btn" @tap="goToBuy">去下单</view>
  50. </view>
  51. <view class="buy">
  52. <view class="all" @tap="chooseAll(!choosedAll)">
  53. <text v-if="choosedAll" class="cuIcon-roundcheckfill"></text>
  54. <text v-else class="cuIcon-round"></text>
  55. <text>全选</text>
  56. </view>
  57. <view class="total">总计: <text>{{ '¥ ' + choosedPrice + '' }}</text></view>
  58. <view class="pay" @tap="confirm">结算({{ ' ' + choosedNum + ' ' }})</view>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import { deepClone } from '@/common/util/index.js'
  64. import { _API_GoodList } from '@/apis/good.js'
  65. import { _API_GetallGift } from '@/apis/order.js'
  66. import NumInput from '@/components/public/num-input.vue'
  67. export default {
  68. components: { NumInput },
  69. data() {
  70. return {
  71. giftList: []
  72. };
  73. },
  74. computed: {
  75. list() { return this.$store.state.cart.list },
  76. choosedAll() { return this.$store.getters['cart/choosedAll'] },
  77. choosedNum() { return this.$store.getters['cart/choosedNum'] },
  78. choosedPrice() { return this.$store.getters['cart/choosedPrice'] },
  79. giftNum() { return this.$store.getters['cart/giftNum'] }
  80. },
  81. // async onShow() {
  82. // uni.loading()
  83. // const { data: { list } } = await _API_GoodList()
  84. // for(let i = this.list.length - 1; i >= 0; i --) { // 遍历购物车
  85. // const inCartGood = list.find(listItem => listItem.attr_id == this.list[i].attr_id)
  86. // if (inCartGood) { // 如果购物车的商品存在于商品列表中
  87. // for(let j = this.list[i].size_id.length - 1; j >= 0; j --) {
  88. // const cartSize = this.list[i].size_id[j]
  89. // const inCartSize = inCartGood.size_id.find(e => e == cartSize)
  90. // console.log(inCartSize)
  91. // // // if (inCartSize) {
  92. // // // console.log(inCartSize)
  93. // // // } else {
  94. // // // console.log(inCartSize)
  95. // // // }
  96. // // console.log(inCartSize)
  97. // }
  98. // } else { // 不存直接删除
  99. // this.$store.commit('cart/DELETE', i)
  100. // }
  101. // }
  102. // },
  103. onShow() {
  104. // if (this.$store.getters['cart/shopcarNum']) {
  105. // uni.setTabBarBadge({ index: 1, text: this.$store.getters['cart/shopcarNum'] + '' })
  106. // } else {
  107. // uni.removeTabBarBadge({ index: 1 })
  108. // }
  109. this.getAllGift()
  110. },
  111. methods: {
  112. getAllGift() {
  113. this.giftList = []
  114. _API_GetallGift().then(res => {
  115. if(res.code === 200) {
  116. this.giftList = res.data.list
  117. }
  118. })
  119. },
  120. numChange(value, index, sizeIndex) { // 购物车数量发生变化
  121. if (value) {
  122. this.$store.commit('cart/COUNTCHANGE', { value, index, sizeIndex, del: true })
  123. } else {
  124. uni.showModal({
  125. title: '提示',
  126. content: '确定删除这个尺寸?',
  127. success: res => {
  128. if (res.confirm) {
  129. this.$store.commit('cart/COUNTCHANGE', { value, index, sizeIndex, del: true })
  130. }
  131. }
  132. })
  133. }
  134. },
  135. chooseAll(to) { // 点击全选
  136. this.$store.commit('cart/CHOOSEDCHANGE', [to])
  137. },
  138. chooseGood(to, index) { // 点击商品
  139. this.$store.commit('cart/CHOOSEDCHANGE', [to, index])
  140. },
  141. chooseSize(to, index, sizeIndex) { // 点击尺寸
  142. this.$store.commit('cart/CHOOSEDCHANGE', [to, index, sizeIndex])
  143. },
  144. goToBuy() { // 点击去下单
  145. uni.navigateTo({ url: '../place-order/place-order' })
  146. },
  147. deleteGood(index) { // 点击删除商品
  148. uni.showModal({
  149. title: '提示',
  150. content: '确定删除这件商品?',
  151. success: res => {
  152. if (res.confirm) {
  153. this.$store.commit('cart/DELETE', index)
  154. }
  155. }
  156. })
  157. },
  158. confirm() { // 点击结算
  159. if (this.choosedNum) {
  160. uni.navigateTo({ url: '../confirm-order1/confirm-order1' })
  161. }
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. .shop-car1 {
  168. height: 100vh;
  169. overflow: auto;
  170. background: $app-base-bg;
  171. border-bottom: calc(var(--window-bottom) + 100rpx) solid transparent;
  172. .gift_container {
  173. width: 100%;
  174. .fix_title {
  175. height: 90rpx;
  176. line-height: 90rpx;
  177. padding: 0 32rpx;
  178. display: flex;
  179. justify-content: flex-start;
  180. align-items: center;
  181. border-bottom: 1px solid $app-base-bg;
  182. .cuIcon-roundcheckfill {
  183. color: #F76454;
  184. font-size: 32rpx;
  185. }
  186. .title {
  187. margin-left: 30rpx;
  188. color: #181818;
  189. font-size: 32rpx;
  190. }
  191. }
  192. .gift_list {
  193. background-color: #FFFFFF;
  194. .gift_item {
  195. padding: 28rpx 30rpx;
  196. margin-bottom: 1px;
  197. background-color: #FFFFFF;
  198. display: flex;
  199. justify-content: space-between;
  200. align-items: center;
  201. .gift_img {
  202. display: block;
  203. width: 140rpx;
  204. height: 140rpx;
  205. }
  206. .right {
  207. width: calc(100% - 140rpx);
  208. height: 140rpx;
  209. padding: 0 50rpx 0 30rpx;
  210. display: flex;
  211. justify-content: space-between;
  212. flex-direction: column;
  213. .fixed {
  214. color: #181818;
  215. font-size: 32rpx;
  216. }
  217. .bottom {
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. .name {
  222. color: #F76454;
  223. font-size: 32rpx;
  224. }
  225. .num {
  226. color: #181818;
  227. font-size: 28rpx;
  228. }
  229. }
  230. }
  231. }
  232. }
  233. }
  234. .shopcar-item {
  235. margin-bottom: 10rpx;
  236. .name {
  237. height: 90rpx;
  238. @include flex();
  239. background: #FFFFFF;
  240. justify-content: space-between;
  241. .left {
  242. @include flex();
  243. > .name {
  244. color: #181818;
  245. font-size: 32rpx;
  246. font-weight: bold;
  247. }
  248. .cuIcon-round, .cuIcon-roundcheckfill {
  249. @include flex();
  250. width: 102rpx;
  251. height: 100%;
  252. font-size: 32rpx;
  253. &.cuIcon-roundcheckfill {
  254. color: $app-base-color;
  255. }
  256. }
  257. }
  258. .cuIcon-delete {
  259. font-size: 40rpx;
  260. margin-right: 30rpx;
  261. }
  262. }
  263. .sizeItem {
  264. @include flex();
  265. height: 200rpx;
  266. margin-top: 4rpx;
  267. background: #FFFFFF;
  268. box-sizing: border-box;
  269. padding-right: 39rpx;
  270. .cuIcon-round, .cuIcon-roundcheckfill {
  271. @include flex();
  272. width: 102rpx;
  273. height: 100%;
  274. font-size: 32rpx;
  275. &.cuIcon-roundcheckfill {
  276. color: $app-base-color;
  277. }
  278. }
  279. image {
  280. width: 140rpx;
  281. height: 140rpx;
  282. border-radius: 6rpx;
  283. }
  284. .info {
  285. flex: 1;
  286. height: 100%;
  287. @include flex(column);
  288. align-items: flex-start;
  289. padding: 43rpx 29rpx;
  290. box-sizing: border-box;
  291. justify-content: space-between;
  292. }
  293. }
  294. }
  295. .none {
  296. @include flex(column);
  297. height: 100%;
  298. image {
  299. width: 305rpx;
  300. height: 417rpx;
  301. }
  302. .big-btn {
  303. width: 280rpx;
  304. height: 80rpx;
  305. margin-top: 123rpx;
  306. border-radius: 40rpx;
  307. }
  308. }
  309. .buy {
  310. @include flex();
  311. position: fixed;
  312. left: 0;
  313. right: 0;
  314. bottom: var(--window-bottom);
  315. z-index: 1;
  316. height: 98rpx;
  317. font-size: 32rpx;
  318. background: #FFFFFF;
  319. justify-content: space-between;
  320. box-shadow: 0rpx -1rpx 0rpx 0rpx rgba(178,178,178,1);
  321. view {
  322. @include flex();
  323. height: 100%;
  324. &.all {
  325. font-size: 32rpx;
  326. text {
  327. margin-left: 30rpx;
  328. &.cuIcon-roundcheckfill {
  329. color: $app-base-color;
  330. }
  331. }
  332. }
  333. &.total {
  334. flex: 1;
  335. margin-right: 30rpx;
  336. justify-content: flex-end;
  337. text {
  338. color: $app-base-color;
  339. }
  340. }
  341. &.pay {
  342. width: 220rpx;
  343. color: #FFFFFF;
  344. background: $app-base-color;
  345. }
  346. }
  347. }
  348. }
  349. </style>