|
|
@@ -14,9 +14,9 @@ definePage({
|
|
|
disableScroll: true,
|
|
|
},
|
|
|
})
|
|
|
-const { cartList, isAddingCart } = storeToRefs(useSmqjhCartStore())
|
|
|
+const { cartList, isCartAllChecked, totalProduct } = storeToRefs(useSmqjhCartStore())
|
|
|
const { smqjhSelectedAddress, token } = storeToRefs(useUserStore())
|
|
|
-const isAll = ref(false)
|
|
|
+const cartStore = useSmqjhCartStore()
|
|
|
const tab = ref(0)
|
|
|
const selectAddress = ref(false)
|
|
|
const navList = ref([
|
|
|
@@ -29,128 +29,13 @@ const navList = ref([
|
|
|
{ title: '酒店民宿', id: 7 },
|
|
|
{ title: '代驾', id: 8 },
|
|
|
])
|
|
|
-const totalProduct = ref<Api.shoppingCartOrderConfirm>()
|
|
|
-async function handleChangeAllShop(e: { value: boolean }, shop: Api.myShoppingCart) {
|
|
|
- if (e.value) {
|
|
|
- shop.allGoods = shop.skuList.filter(it => it.shopSkuStocks !== '0' && it.isDelete !== '1').map(it => Number(it.id))
|
|
|
- }
|
|
|
- else {
|
|
|
- shop.allGoods = []
|
|
|
- totalProduct.value = undefined
|
|
|
- }
|
|
|
-}
|
|
|
+
|
|
|
watch(() => cartList.value, async () => {
|
|
|
- const ids = cartList.value.filter(it => it.allGoods.length)
|
|
|
- if (ids.length) {
|
|
|
- const shopIds = ids.map(it => it.allGoods).flat()
|
|
|
- const id = shopIds.join(',')
|
|
|
- const res = await useSmqjhCartStore().getCartAddGoodsPrice(id)
|
|
|
- totalProduct.value = res
|
|
|
- }
|
|
|
- if (ids.length === cartList.value.length) {
|
|
|
- const goodsindex = ids.filter(it => it.allGoods.length === it.skuList.length)
|
|
|
- if (goodsindex.length === cartList.value.length) {
|
|
|
- isAll.value = true
|
|
|
- }
|
|
|
- else {
|
|
|
- isAll.value = false
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- isAll.value = false
|
|
|
- }
|
|
|
+ cartStore.getCartTotalPrice()
|
|
|
}, {
|
|
|
deep: true,
|
|
|
})
|
|
|
-onMounted(() => {
|
|
|
- totalProduct.value = undefined
|
|
|
-})
|
|
|
|
|
|
-async function handleChangShopGoods(e: { value: number[] }, shop: Api.myShoppingCart) {
|
|
|
- if (e.value.length === shop.skuList.length) {
|
|
|
- shop.AllShopGoods = true
|
|
|
- }
|
|
|
- else {
|
|
|
- shop.AllShopGoods = false
|
|
|
- totalProduct.value = undefined
|
|
|
- }
|
|
|
-}
|
|
|
-function handleAllShopGoods(e: { value: boolean }) {
|
|
|
- if (e.value) {
|
|
|
- cartList.value = cartList.value.map((it) => {
|
|
|
- return {
|
|
|
- ...it,
|
|
|
- AllShopGoods: true,
|
|
|
- allGoods: it.skuList.map(it => Number(it.id)),
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- else {
|
|
|
- cartList.value = cartList.value.map((it) => {
|
|
|
- return {
|
|
|
- ...it,
|
|
|
- AllShopGoods: false,
|
|
|
- allGoods: [],
|
|
|
- }
|
|
|
- })
|
|
|
- totalProduct.value = undefined
|
|
|
- }
|
|
|
-}
|
|
|
-async function handleDel() {
|
|
|
- const delGoods = cartList.value.filter(it => it.allGoods?.length > 0)
|
|
|
- if (delGoods.length) {
|
|
|
- await Apis.common.deleteShoppingCart({
|
|
|
- pathParams: {
|
|
|
- ids: delGoods.map(it => it.allGoods).join(','),
|
|
|
- },
|
|
|
- })
|
|
|
- await useSmqjhCartStore().getCartList('XSB')
|
|
|
- useGlobalToast().show({ msg: '删除成功!' })
|
|
|
- }
|
|
|
- else {
|
|
|
- useGlobalToast().show({ msg: '请选择要删除的商品' })
|
|
|
- }
|
|
|
-}
|
|
|
-async function handleSub(item: Api.CartSkuVo) {
|
|
|
- if (unref(isAddingCart)) {
|
|
|
- useGlobalToast().show({ msg: '移除商品中,请稍后' })
|
|
|
- return
|
|
|
- }
|
|
|
- if (item.num === 1) {
|
|
|
- useGlobalMessage().confirm({
|
|
|
- msg: '是否删除该商品?',
|
|
|
- success: async () => {
|
|
|
- await useSmqjhCartStore().addCart(item.skuId, -1, item.shopId, 'XSB')
|
|
|
- },
|
|
|
- })
|
|
|
- }
|
|
|
- else {
|
|
|
- await useSmqjhCartStore().addCart(item.skuId, -1, item.shopId, 'XSB')
|
|
|
- }
|
|
|
-}
|
|
|
-async function handleAdd(item: Api.CartSkuVo) {
|
|
|
- if (unref(isAddingCart)) {
|
|
|
- useGlobalToast().show({ msg: '添加商品中,请稍后' })
|
|
|
- return
|
|
|
- }
|
|
|
- await useSmqjhCartStore().addCart(item.skuId, 1, item.shopId, 'XSB')
|
|
|
-}
|
|
|
-function handelPay() {
|
|
|
- if (!unref(totalProduct)) {
|
|
|
- useGlobalToast().show({ msg: '请选择商品' })
|
|
|
- return
|
|
|
- }
|
|
|
- const list = cartList.value.filter(it => it.allGoods.length)
|
|
|
- if (list.length > 1) {
|
|
|
- useGlobalToast().show({ msg: '不能同时选中两个店铺的商品' })
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- router.push({
|
|
|
- name: 'xsb-confirmOrder',
|
|
|
- params: { data: JSON.stringify(unref(totalProduct)) },
|
|
|
- })
|
|
|
-}
|
|
|
function handleSelectAddress() {
|
|
|
if (!token.value) {
|
|
|
useGlobalToast().show({ msg: '请先登录!' })
|
|
|
@@ -194,13 +79,13 @@ function handleSelectAddress() {
|
|
|
</view>
|
|
|
<scroll-view scroll-y class="content box-border px24rpx">
|
|
|
<view v-for="shop in cartList" :key="shop.shopId" class="mb24rpx rounded-16rpx bg-white px24rpx pb18rpx pt28rpx">
|
|
|
- <wd-checkbox v-model="shop.AllShopGoods" size="large" @change="handleChangeAllShop($event, shop)">
|
|
|
+ <wd-checkbox v-model="shop.AllShopGoods" size="large" @change="cartStore.cartStoreAllChecked($event, shop)">
|
|
|
<view class="text-28rpx font-semibold">
|
|
|
{{ shop.shopName }}
|
|
|
</view>
|
|
|
</wd-checkbox>
|
|
|
<view class="mt20rpx h2rpx w-full bg-#F0F0F0" />
|
|
|
- <wd-checkbox-group v-model="shop.allGoods" size="large" @change="handleChangShopGoods($event, shop)">
|
|
|
+ <wd-checkbox-group v-model="shop.allGoods" size="large" @change="cartStore.cartGoodsChecked($event, shop)">
|
|
|
<view
|
|
|
v-for="item in shop.skuList" :key="item.id" class="relative mt20rpx flex items-center"
|
|
|
>
|
|
|
@@ -234,7 +119,7 @@ function handleSelectAddress() {
|
|
|
<image
|
|
|
:src="` ${StaticUrl}/sub-cart.png`"
|
|
|
class="h44rpx w44rpx"
|
|
|
- @click.stop="handleSub(item)"
|
|
|
+ @click.stop="cartStore.cartSubGoods(item)"
|
|
|
/>
|
|
|
<view class="box-border h44rpx w84rpx flex items-center justify-center border border-#F0F0F0 border-solid text-24rpx text-#AAAAAA">
|
|
|
{{ item.num }}
|
|
|
@@ -242,7 +127,7 @@ function handleSelectAddress() {
|
|
|
<image
|
|
|
:src="` ${StaticUrl}/add-cart.png`"
|
|
|
class="h44rpx w44rpx"
|
|
|
- @click.stop="handleAdd(item)"
|
|
|
+ @click.stop="cartStore.cartAddGoods(item)"
|
|
|
/>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -268,7 +153,7 @@ function handleSelectAddress() {
|
|
|
<view class="mb20rpx mt20rpx text-24rpx">
|
|
|
你还没有添加商品哦~
|
|
|
</view>
|
|
|
- <wd-button plain @click="router.pushTab({ name: 'smqjh-home' })">
|
|
|
+ <wd-button plain @click=" useTabbar().setTabbarItemActive('smqjh-home'), router.pushTab({ name: 'smqjh-home' })">
|
|
|
去逛逛
|
|
|
</wd-button>
|
|
|
</view>
|
|
|
@@ -284,10 +169,10 @@ function handleSelectAddress() {
|
|
|
class="h100rpx w100rpx"
|
|
|
/>
|
|
|
<view class="ml16rpx flex items-center">
|
|
|
- <wd-checkbox v-model="isAll" size="large" @change="handleAllShopGoods">
|
|
|
+ <wd-checkbox v-model="isCartAllChecked" size="large" @change="cartStore.cartAllChecked">
|
|
|
全选
|
|
|
</wd-checkbox>
|
|
|
- <view class="ml10rpx text-24rpx text-#FF4A39" @click="handleDel">
|
|
|
+ <view class="ml10rpx text-24rpx text-#FF4A39" @click="cartStore.cartDeleteGoods">
|
|
|
删除
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -305,7 +190,7 @@ function handleSelectAddress() {
|
|
|
</view>
|
|
|
</view>
|
|
|
<view class="ml20rpx w160rpx">
|
|
|
- <wd-button block size="large" @click="handelPay">
|
|
|
+ <wd-button block size="large" @click="cartStore.cartOrderConfirm">
|
|
|
结算
|
|
|
</wd-button>
|
|
|
</view>
|