cart.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <script setup lang="ts">
  2. import { StaticUrl } from '@/config'
  3. import router from '@/router'
  4. import { useSmqjhCartStore } from '@/store/cart'
  5. const emit = defineEmits(['changeTab'])
  6. const { cartList, isCartAllChecked, totalProduct } = storeToRefs(useSmqjhCartStore())
  7. const cartStore = useSmqjhCartStore()
  8. watch(() => cartList.value, async () => {
  9. cartStore.getCartTotalPrice()
  10. }, {
  11. deep: true,
  12. })
  13. onMounted(async () => {
  14. if (isCartAllChecked.value) {
  15. const ids = cartList.value.filter(it => it.allGoods.length)
  16. if (ids.length) {
  17. const id = ids[0].allGoods.join(',')
  18. const res = await useSmqjhCartStore().getCartAddGoodsPrice(id)
  19. totalProduct.value = res
  20. }
  21. }
  22. })
  23. </script>
  24. <template>
  25. <view class="page-xsb">
  26. <wd-navbar
  27. title="购物车" custom-style="background-color:transparent !important" :bordered="false" :z-index="99"
  28. safe-area-inset-top fixed
  29. />
  30. <view class="xsb-linear h406rpx" />
  31. <view class="-mt220rpx">
  32. <view class="content px24rpx">
  33. <scroll-view scroll-y class="content">
  34. <view v-for="shop in cartList" :key="shop.shopId" class="mb24rpx rounded-16rpx bg-white px24rpx pb18rpx pt28rpx">
  35. <wd-checkbox v-model="shop.AllShopGoods" size="large" @change="cartStore.cartStoreAllChecked($event, shop)">
  36. <view class="text-28rpx font-semibold">
  37. {{ shop.shopName }}
  38. </view>
  39. </wd-checkbox>
  40. <view class="mt20rpx h2rpx w-full bg-#F0F0F0" />
  41. <wd-checkbox-group v-model="shop.allGoods" size="large" @change="cartStore.cartGoodsChecked($event, shop)">
  42. <view
  43. v-for="item in shop.skuList" :key="item.id" class="relative mt20rpx flex items-center"
  44. >
  45. <view class="mr20rpx h32rpx w32rpx">
  46. <wd-checkbox :model-value="item.id" />
  47. </view>
  48. <view class="flex flex-1">
  49. <view class="relative">
  50. <image
  51. :src="item.pic"
  52. class="h206rpx w200rpx flex-shrink-0"
  53. @click.stop="router.push({ name: 'xsb-goods', params: { id: String(item.prodId) } })"
  54. />
  55. <image
  56. :src="`${StaticUrl}/xbs-shui-cart.png`"
  57. class="absolute left-0 top-0 h206rpx w200rpx flex-shrink-0"
  58. />
  59. </view>
  60. <view class="ml20rpx flex-1">
  61. <view class="text-left text-28rpx font-semibold">
  62. <!-- <view v-for="i in 2" :key="i" class="mr5px inline-block">
  63. <wd-tag type="danger">
  64. 惊喜回馈
  65. </wd-tag>
  66. </view> -->
  67. {{ item.skuName }}
  68. </view>
  69. <view class="mt14rpx text-24rpx text-#AAAAAA">
  70. 规格:{{ item.spec }}
  71. </view>
  72. <view class="mt14rpx flex items-center justify-between">
  73. <view class="text-36rpx text-#FF4A39 font-semibold">
  74. ¥{{ item.price }}
  75. </view>
  76. <!-- <wd-input-number v-model="item.num" disable-input @change="handleChangeNum($event, item)" /> -->
  77. <view class="flex items-center">
  78. <image
  79. :src="` ${StaticUrl}/sub-cart.png`"
  80. class="h44rpx w44rpx"
  81. @click.stop="cartStore.cartSubGoods(item)"
  82. />
  83. <view class="box-border h44rpx w84rpx flex items-center justify-center border border-#F0F0F0 border-solid text-24rpx text-#AAAAAA">
  84. {{ item.num }}
  85. </view>
  86. <image
  87. :src="` ${StaticUrl}/add-cart.png`"
  88. class="h44rpx w44rpx"
  89. @click.stop="cartStore.cartAddGoods(item)"
  90. />
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. <view v-if="item.shopSkuStocks == '0'" class="absolute left-0 top-0 z-1 h-full w-full flex items-center justify-center bg-[rgba(255,255,255,.6)]">
  96. <view class="rounded-16rpx bg-[rgba(0,0,0,.5)] p20rpx text-white">
  97. 商品已售罄
  98. </view>
  99. </view>
  100. <view v-if="item.isDelete == '1'" class="absolute left-0 top-0 z-1 h-full w-full flex items-center justify-center bg-[rgba(255,255,255,.6)]">
  101. <view class="rounded-16rpx bg-[rgba(0,0,0,.5)] p20rpx text-white">
  102. 商品已删除
  103. </view>
  104. </view>
  105. </view>
  106. </wd-checkbox-group>
  107. </view>
  108. <view v-if="!cartList.length" class="box-border w-full flex items-center justify-center">
  109. <view class="mt220rpx flex flex-col items-center">
  110. <image :src="`${StaticUrl}/cart.png`" class="h110rpx w110rpx" />
  111. <view class="mb20rpx mt20rpx text-24rpx">
  112. 你还没有添加商品哦~
  113. </view>
  114. <wd-button plain @click="emit('changeTab')">
  115. 去逛逛
  116. </wd-button>
  117. </view>
  118. </view>
  119. <view class="h100rpx" />
  120. </scroll-view>
  121. </view>
  122. </view>
  123. <view v-if="cartList.length" class="fixedShadow fixed bottom-60rpx left-0 z-99 box-border w-full flex items-center justify-between rounded-t-16rpx bg-white px24rpx pb60rpx pt10rpx">
  124. <view class="ios w-full flex items-center justify-between">
  125. <view class="flex items-center">
  126. <image
  127. :src="`${StaticUrl}/cart-lanzi.png`"
  128. class="h100rpx w100rpx"
  129. />
  130. <view class="ml16rpx flex items-center">
  131. <wd-checkbox v-model="isCartAllChecked" size="large" @change="cartStore.cartAllChecked">
  132. 全选
  133. </wd-checkbox>
  134. <view class="ml10rpx text-24rpx text-#FF4A39" @click="cartStore.cartDeleteGoods">
  135. 删除
  136. </view>
  137. </view>
  138. </view>
  139. <view class="flex items-center">
  140. <view class="flex items-center font-semibold">
  141. <view class="text-22rpx text-#222">
  142. 总计:
  143. </view>
  144. <view class="flex items-baseline text-24rpx text-#FF4A39">
  145. <text class="text-36rpx">
  146. {{ totalProduct?.price || '0.00' }}
  147. </text>
  148. </view>
  149. </view>
  150. <view class="ml20rpx w160rpx">
  151. <wd-button block size="large" @click="cartStore.cartOrderConfirm">
  152. 结算
  153. </wd-button>
  154. </view>
  155. </view>
  156. </view>
  157. </view>
  158. </view>
  159. </template>
  160. <style scoped lang="scss">
  161. .content {
  162. height: calc(100vh - var(--window-top) - 400rpx);
  163. height: calc(100vh - var(--window-top) - constant(safe-area-inset-bottom) - 400rpx);
  164. height: calc(100vh - var(--window-top) - env(safe-area-inset-bottom) - 400rpx);
  165. }
  166. .fixedShadow{
  167. box-shadow: 0rpx -6rpx 12rpx 2rpx rgba(0,0,0,0.05);
  168. }
  169. </style>