cart.vue 11 KB

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