cart.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. const priceDetailPopup = ref(false)
  9. watch(() => cartList.value, async () => {
  10. cartStore.getCartTotalPrice()
  11. }, {
  12. deep: true,
  13. })
  14. onMounted(async () => {
  15. if (isCartAllChecked.value) {
  16. const ids = cartList.value.filter(it => it.allGoods.length)
  17. if (ids.length) {
  18. const id = ids[0].allGoods.join(',')
  19. const res = await useSmqjhCartStore().getCartAddGoodsPrice(id)
  20. totalProduct.value = res
  21. }
  22. }
  23. })
  24. </script>
  25. <template>
  26. <view class="page-xsb">
  27. <wd-navbar
  28. title="购物车" custom-style="background-color:transparent !important" :bordered="false" :z-index="99"
  29. safe-area-inset-top fixed
  30. />
  31. <view class="xsb-linear h406rpx" />
  32. <view class="-mt220rpx">
  33. <view class="content px24rpx">
  34. <scroll-view scroll-y class="content">
  35. <view v-for="shop in cartList" :key="shop.shopId" class="mb24rpx rounded-16rpx bg-white px24rpx pb18rpx pt28rpx">
  36. <wd-checkbox v-model="shop.AllShopGoods" size="large" @change="cartStore.cartStoreAllChecked($event, shop)">
  37. <view class="text-28rpx font-semibold">
  38. {{ shop.shopName }}
  39. </view>
  40. </wd-checkbox>
  41. <view class="mt20rpx h2rpx w-full bg-#F0F0F0" />
  42. <wd-checkbox-group v-model="shop.allGoods" size="large" @change="cartStore.cartGoodsChecked($event, shop)">
  43. <view
  44. v-for="item in shop.skuList" :key="item.id" class="relative mt20rpx flex items-center"
  45. >
  46. <view class="mr20rpx h32rpx w32rpx">
  47. <wd-checkbox :model-value="item.id" />
  48. </view>
  49. <view class="flex flex-1">
  50. <view class="relative">
  51. <image
  52. :src="item.pic"
  53. class="h206rpx w200rpx flex-shrink-0"
  54. @click.stop="router.push({ name: 'xsb-goods', params: { id: String(item.prodId) } })"
  55. />
  56. <image
  57. :src="`${StaticUrl}/xbs-shui-cart.png`"
  58. class="absolute left-0 top-0 h206rpx w200rpx flex-shrink-0"
  59. />
  60. </view>
  61. <view class="ml20rpx flex-1">
  62. <view class="text-left text-28rpx font-semibold">
  63. <!-- <view v-for="i in 2" :key="i" class="mr5px inline-block">
  64. <wd-tag type="danger">
  65. 惊喜回馈
  66. </wd-tag>
  67. </view> -->
  68. {{ item.skuName }}
  69. </view>
  70. <view class="mt14rpx text-24rpx text-#AAAAAA">
  71. 规格:{{ item.spec }}
  72. </view>
  73. <view class="mt14rpx flex items-center justify-between">
  74. <view class="text-36rpx text-#FF4A39 font-semibold">
  75. ¥{{ item.price }}
  76. </view>
  77. <!-- <wd-input-number v-model="item.num" disable-input @change="handleChangeNum($event, item)" /> -->
  78. <view class="flex items-center">
  79. <image
  80. :src="` ${StaticUrl}/sub-cart.png`"
  81. class="h44rpx w44rpx"
  82. @click.stop="cartStore.cartSubGoods(item)"
  83. />
  84. <view class="box-border h44rpx w84rpx flex items-center justify-center border border-#F0F0F0 border-solid text-24rpx text-#AAAAAA">
  85. {{ item.num }}
  86. </view>
  87. <image
  88. :src="` ${StaticUrl}/add-cart.png`"
  89. class="h44rpx w44rpx"
  90. @click.stop="cartStore.cartAddGoods(item)"
  91. />
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. <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)]">
  97. <view class="rounded-16rpx bg-[rgba(0,0,0,.5)] p20rpx text-white">
  98. 商品已售罄
  99. </view>
  100. </view>
  101. <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)]">
  102. <view class="rounded-16rpx bg-[rgba(0,0,0,.5)] p20rpx text-white">
  103. 商品已删除
  104. </view>
  105. </view>
  106. </view>
  107. </wd-checkbox-group>
  108. </view>
  109. <view v-if="!cartList.length" class="box-border w-full flex items-center justify-center">
  110. <view class="mt220rpx flex flex-col items-center">
  111. <image :src="`${StaticUrl}/cart.png`" class="h110rpx w110rpx" />
  112. <view class="mb20rpx mt20rpx text-24rpx">
  113. 你还没有添加商品哦~
  114. </view>
  115. <wd-button plain @click="emit('changeTab')">
  116. 去逛逛
  117. </wd-button>
  118. </view>
  119. </view>
  120. <view class="h100rpx" />
  121. </scroll-view>
  122. </view>
  123. </view>
  124. <view 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">
  125. <view class="ios w-full flex items-center justify-between">
  126. <view class="flex items-center">
  127. <view class="flex items-center">
  128. <!-- <wd-badge :model-value="getTotalNum" :top="20"> -->
  129. <image :src="`${StaticUrl}/cart-lanzi.png`" class="h100rpx w100rpx" />
  130. <!-- </wd-badge> -->
  131. </view>
  132. <view class="ml40rpx">
  133. <view class="flex items-center">
  134. <view class="font-semibold">
  135. ¥ {{ totalProduct?.amount || 0 }}
  136. </view>
  137. <view v-if="totalProduct?.coupon" class="ml10rpx text-24rpx text-#FF4A39">
  138. 共减¥{{ totalProduct?.coupon }}
  139. </view>
  140. <view v-if="totalProduct?.amount" class="ml10rpx text-24rpx text-gray" @click="priceDetailPopup = true">
  141. 明细 <wd-icon name="arrow-up" size="24rpx" color="#aaa" />
  142. </view>
  143. </view>
  144. <view class="mt10rpx text-24rpx text-gray">
  145. 配送费:¥{{ totalProduct?.transfee || 0 }}
  146. </view>
  147. </view>
  148. </view>
  149. <view class="flex items-center">
  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. <!-- 价格明细弹窗 -->
  159. <Zpopup v-model="priceDetailPopup" :zindex="10" bg="#fff">
  160. <view class="ios box-border w-full px-40rpx pb-60rpx pt-36rpx">
  161. <view class="mb-40rpx text-center text-32rpx font-semibold">
  162. 价格明细
  163. </view>
  164. <view class="flex items-center justify-between py-20rpx">
  165. <view class="text-30rpx font-semibold">
  166. 商品合计
  167. </view>
  168. <view class="text-30rpx font-semibold">
  169. ¥{{ totalProduct?.amount }}
  170. </view>
  171. </view>
  172. <view class="flex items-center justify-between py-20rpx">
  173. <view class="text-28rpx text-#333">
  174. 商品总价
  175. </view>
  176. <view class="text-28rpx text-#333">
  177. ¥{{ totalProduct?.price }}
  178. </view>
  179. </view>
  180. <template v-if="totalProduct?.coupon">
  181. <view class="flex items-center justify-between py-20rpx">
  182. <view class="text-28rpx text-#333">
  183. 下单用券共减
  184. </view>
  185. <view class="text-28rpx text-#FF4A39 font-semibold">
  186. -¥{{ totalProduct?.coupon }}
  187. </view>
  188. </view>
  189. <view v-if="totalProduct?.couponName" class="flex items-center justify-between pb-20rpx">
  190. <view class="text-24rpx text-#AAAAAA">
  191. {{ totalProduct?.couponName }}
  192. </view>
  193. <view class="text-24rpx text-#AAAAAA">
  194. -¥{{ totalProduct?.coupon }}
  195. </view>
  196. </view>
  197. </template>
  198. <view class="flex items-center justify-between py-20rpx">
  199. <view class="text-28rpx text-#333">
  200. 配送费
  201. </view>
  202. <view class="text-28rpx text-#333">
  203. ¥{{ totalProduct?.transfee }}
  204. </view>
  205. </view>
  206. </view>
  207. <view class="h200rpx" />
  208. </Zpopup>
  209. </view>
  210. </template>
  211. <style scoped lang="scss">
  212. .content {
  213. height: calc(100vh - var(--window-top) - 400rpx);
  214. height: calc(100vh - var(--window-top) - constant(safe-area-inset-bottom) - 400rpx);
  215. height: calc(100vh - var(--window-top) - env(safe-area-inset-bottom) - 400rpx);
  216. }
  217. .fixedShadow{
  218. box-shadow: 0rpx -6rpx 12rpx 2rpx rgba(0,0,0,0.05);
  219. }
  220. </style>