Преглед на файлове

feat(cart): 购物车功能重构和优化

- 将购物车相关逻辑统一迁移到store中管理
- 添加购物车全选、商品选中、删除、加减数量等功能方法
- 优化购物车价格计算和商品状态同步逻辑
- 在个人中心页面添加disableScroll配置
- 修复订单页面取消订单参数传递问题
- 优化商品详情页立即购买和加入购物车逻辑

fix(config): 更新开发环境API地址

- 将开发环境API地址从旧域名切换到新域名

style(my): 个人中心页面样式优化

- 添加disableScroll配置以禁用页面滚动
- 调整页面高度计算以适配安全区域
zhangtao преди 1 седмица
родител
ревизия
e922487a36

+ 1 - 1
src/config/index.ts

@@ -17,7 +17,7 @@ const mapEnvVersion = {
   // develop: 'http://192.168.1.253:8080',
   // develop: 'http://192.168.1.89:8080', // 田
   develop: 'http://47.109.84.152:8081',
-  // develop: 'https://smqjh.admin.zswlgz.com:433',
+  // develop: 'https://smqjh.api.zswlgz.com:88',
   /**
    * 体验版
    */

+ 2 - 1
src/pages.json

@@ -54,7 +54,8 @@
       "islogin": false,
       "style": {
         "navigationBarTitleText": "个人中心",
-        "navigationStyle": "custom"
+        "navigationStyle": "custom",
+        "disableScroll": true
       }
     }
   ],

+ 12 - 127
src/pages/cart/index.vue

@@ -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>

+ 2 - 0
src/pages/my/index.vue

@@ -9,6 +9,7 @@ definePage({
   style: {
     navigationBarTitleText: '个人中心',
     navigationStyle: 'custom',
+    disableScroll: true,
   },
 })
 const tabList = ref([
@@ -160,6 +161,7 @@ function handleGo(item: { name: string }) {
 }
 
 .page-class {
+  height: calc(100vh - var(--window-top) - 150rpx);
   :deep() {
     .login-btn {
       min-width: 0 !important;

+ 148 - 0
src/store/cart.ts

@@ -11,12 +11,14 @@ interface cartState {
    * 星闪豹购物车全选按钮状态
    */
   isCartAllChecked: boolean
+  totalProduct: Api.shoppingCartOrderConfirm | null
 }
 export const useSmqjhCartStore = defineStore('smqjh-cart', {
   state: (): cartState => ({
     cartList: [],
     isAddingCart: false,
     isCartAllChecked: false,
+    totalProduct: null,
   }),
   getters: {
     /**
@@ -87,6 +89,8 @@ export const useSmqjhCartStore = defineStore('smqjh-cart', {
         }
       })
       this.isCartAllChecked = false
+      this.totalProduct = null
+      useTabbar().setTabbarItem('smqjh-cart', this.getTotalNum)
     },
     /**
      *
@@ -105,6 +109,150 @@ export const useSmqjhCartStore = defineStore('smqjh-cart', {
         }).catch(err => reject(err)).finally(() => uni.hideLoading())
       })
     },
+    /**
+     * 购物车店铺全选按钮点击逻辑
+     */
+    async cartStoreAllChecked(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 = []
+        this.totalProduct = null
+      }
+    },
+    /**
+     * 购物车商品选中逻辑
+     */
+    cartGoodsChecked(e: { value: number[] }, shop: Api.myShoppingCart) {
+      if (e.value.length === shop.skuList.length) {
+        shop.AllShopGoods = true
+      }
+      else {
+        shop.AllShopGoods = false
+        this.totalProduct = null
+      }
+    },
+    /**
+     * 购物车底部全选
+     */
+    cartAllChecked(e: { value: boolean }) {
+      if (e.value) {
+        this.cartList = this.cartList.map((it) => {
+          return {
+            ...it,
+            AllShopGoods: true,
+            allGoods: it.skuList.map(it => Number(it.id)),
+          }
+        })
+      }
+      else {
+        this.cartList = this.cartList.map((it) => {
+          return {
+            ...it,
+            AllShopGoods: false,
+            allGoods: [],
+          }
+        })
+        this.totalProduct = null
+      }
+    },
+    /**
+     * 购物车删除商品逻辑
+     */
+    cartDeleteGoods() {
+      useGlobalMessage().confirm({
+        title: '删除商品',
+        msg: '是否删除选中的商品?',
+        success: async () => {
+          const delGoods = this.cartList.filter(it => it.allGoods?.length > 0)
+          if (delGoods.length) {
+            await Apis.common.deleteShoppingCart({
+              pathParams: {
+                ids: delGoods.map(it => it.allGoods).join(','),
+              },
+            })
+            this.getCartList('XSB')
+            useGlobalToast().show({ msg: '删除成功!' })
+          }
+          else {
+            useGlobalToast().show({ msg: '请选择要删除的商品' })
+          }
+        },
+      })
+    },
+    /**
+     * 购物车减按钮逻辑
+     */
+    async cartSubGoods(item: Api.CartSkuVo) {
+      if (this.isAddingCart) {
+        useGlobalToast().show({ msg: '移除商品中,请稍后' })
+        return
+      }
+      if (item.num === 1) {
+        useGlobalMessage().confirm({
+          msg: '是否删除该商品?',
+          success: async () => {
+            await this.addCart(item.skuId, -1, item.shopId, 'XSB')
+          },
+        })
+      }
+      else {
+        await this.addCart(item.skuId, -1, item.shopId, 'XSB')
+      }
+    },
+    /**
+     * 购物车加按钮逻辑
+     */
+    async cartAddGoods(item: Api.CartSkuVo) {
+      if (this.isAddingCart) {
+        useGlobalToast().show({ msg: '加入购物车中,请稍后' })
+        return
+      }
+      await this.addCart(item.skuId, 1, item.shopId, 'XSB')
+    },
+    /**
+     * 统一结算按钮逻辑
+     */
+    async cartOrderConfirm() {
+      if (!this.totalProduct) {
+        useGlobalToast().show({ msg: '请选择商品' })
+        return
+      }
+      const list = this.cartList.filter(it => it.allGoods.length)
+      if (list.length > 1) {
+        useGlobalToast().show({ msg: '不能同时选中两个店铺的商品' })
+        return
+      }
+      router.push({
+        name: 'xsb-confirmOrder',
+        params: { data: JSON.stringify(this.totalProduct) },
+      })
+    },
+    /**
+     * 统一获取价格逻辑
+     */
+    async getCartTotalPrice() {
+      const ids = this.cartList.filter(it => it.allGoods.length)
+      if (ids.length) {
+        const shopIds = ids.map(it => it.allGoods).flat()
+        const id = shopIds.join(',')
+        const res = await this.getCartAddGoodsPrice(id)
+        this.totalProduct = res
+      }
+      if (ids.length === this.cartList.length) {
+        const goodsindex = ids.filter(it => it.allGoods.length === it.skuList.length)
+        if (goodsindex.length === this.cartList.length) {
+          this.isCartAllChecked = true
+        }
+        else {
+          this.isCartAllChecked = false
+        }
+      }
+      else {
+        this.isCartAllChecked = false
+      }
+    },
 
   },
 })

+ 1 - 1
src/subPack-smqjh/order/index.vue

@@ -172,7 +172,7 @@ async function handleSubmitOrder(order: Api.xsbOrderList) {
         </view>
         <view class="my24rpx flex items-center justify-end">
           <template v-if="item.hbOrderStatus === subPackOrder?.OrderStatus.PaddingPay">
-            <wd-button size="small" plain type="info" @click.stop="handleCancel">
+            <wd-button size="small" plain type="info" @click.stop="handleCancel(item)">
               取消订单
             </wd-button>
             <view class="ml20rpx">

+ 11 - 126
src/subPack-xsb/commonTab/components/cart.vue

@@ -13,39 +13,11 @@ definePage({
     disableScroll: true,
   },
 })
-const { cartList, isAddingCart, isCartAllChecked } = storeToRefs(useSmqjhCartStore())
-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)
-  console.log(ids, '测试')
+const { cartList, isCartAllChecked, totalProduct } = storeToRefs(useSmqjhCartStore())
+const cartStore = useSmqjhCartStore()
 
-  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) {
-      isCartAllChecked.value = true
-    }
-    else {
-      isCartAllChecked.value = false
-    }
-  }
-  else {
-    isCartAllChecked.value = false
-  }
+watch(() => cartList.value, async () => {
+  cartStore.getCartTotalPrice()
 }, {
   deep: true,
 })
@@ -59,93 +31,6 @@ onMounted(async () => {
     }
   }
 })
-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) {
-  totalProduct.value = undefined
-  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) {
-  totalProduct.value = undefined
-  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)) },
-  })
-}
 </script>
 
 <template>
@@ -159,13 +44,13 @@ function handelPay() {
       <view class="content px24rpx">
         <scroll-view scroll-y class="content">
           <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"
               >
@@ -199,7 +84,7 @@ function handelPay() {
                         <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 }}
@@ -207,7 +92,7 @@ function handelPay() {
                         <image
                           :src="` ${StaticUrl}/add-cart.png`"
                           class="h44rpx w44rpx"
-                          @click.stop="handleAdd(item)"
+                          @click.stop="cartStore.cartAddGoods(item)"
                         />
                       </view>
                     </view>
@@ -250,10 +135,10 @@ function handelPay() {
             class="h100rpx w100rpx"
           />
           <view class="ml16rpx flex items-center">
-            <wd-checkbox v-model="isCartAllChecked" 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>
@@ -271,7 +156,7 @@ function handelPay() {
             </view>
           </view>
           <view class="ml20rpx w160rpx">
-            <wd-button block size="large" @click="handelPay">
+            <wd-button block size="large" @click="cartStore.cartOrderConfirm">
               结算
             </wd-button>
           </view>

+ 5 - 4
src/subPack-xsb/confirmOrder/index.vue

@@ -12,6 +12,7 @@ definePage({
 const { selectedAddress, userInfo } = storeToRefs(useUserStore())
 const { SelectShopInfo } = storeToRefs(useSysXsbStore())
 const orderInfo = ref<Api.shoppingCartOrderConfirm>()
+const { totalProduct } = storeToRefs(useSmqjhCartStore())
 const isPay = ref(false)
 const remarks = ref('')
 
@@ -57,10 +58,10 @@ async function handlePay() {
         skuId: it.skuId,
       }
     })
-
-    const orderNumber = await getOrderPayMent(orderInfo.value.transfee, 'XSB', deliveryType.value, Number(orderInfo.value?.skuList[0].shopId), orderItemList, unref(remarks))
-    const res = await handleCommonPayMent(orderNumber)
     await clearCart(orderInfo.value.skuList)
+    totalProduct.value = null
+    const orderNumber = await getOrderPayMent(orderInfo.value.transfee, 'XSB', deliveryType.value, Number(orderInfo.value?.skuList[0].shopId || SelectShopInfo.value.shopId), orderItemList, unref(remarks))
+    const res = await handleCommonPayMent(orderNumber)
     if (res.payType !== 1) {
       await getWxCommonPayment(res)
       paySuccess()
@@ -137,7 +138,7 @@ async function handlePay() {
               规格:{{ item.spec }}
             </view>
             <view class="text-24rpx text-#AAAAAA">
-              ×{{ item.num }}
+              ×{{ item.num || 1 }}
             </view>
           </view>
         </view>

+ 10 - 7
src/subPack-xsb/goods/index.vue

@@ -41,6 +41,7 @@ onLoad((option: any) => {
 })
 
 const goodsInfo = ref<Api.xsbProductDetail>()
+const isLoging = ref(false)
 
 const swiperList = computed(() => {
   if (goodsInfo.value) {
@@ -96,7 +97,7 @@ async function handleConfimOrder() {
   if (Number(unref(goodsInfo)?.spuStock) < unref(SelectGoodsNum)) {
     useGlobalToast().show('库存不足,请调整购买数量')
   }
-
+  isLoging.value = true
   const res = await Apis.xsb.skuOrderConfirm({
     data: {
       skuId: specId.value,
@@ -107,16 +108,18 @@ async function handleConfimOrder() {
   })
   router.push({
     name: 'xsb-confirmOrder',
-    params: { data: JSON.stringify(res.data) },
+    params: { data: JSON.stringify({ ...res.data, skuList: [{ ...res.data.sku, num: SelectGoodsNum.value }] }) },
   })
-
+  isLoging.value = false
   console.log(res, '数据')
 }
 async function handleAddCart() {
+  isLoging.value = true
   try {
     await useSmqjhCartStore().addCart(specId.value, unref(SelectGoodsNum), unref(SelectShopInfo.value.shopId), 'XSB')
     selectGoods.value = false
     useGlobalToast().show('添加成功')
+    isLoging.value = false
   }
   catch (error) {
     console.log(error)
@@ -140,7 +143,7 @@ async function handleAddCart() {
           </view>
         </template>
       </wd-swiper>
-      <view class="view-0 header relative z-3 rounded-t-32rpx px24rpx pt24rpx -mt30rpx">
+      <view class="header view-0 relative z-3 rounded-t-32rpx px24rpx pt24rpx -mt30rpx">
         <view class="flex items-center justify-between">
           <view class="flex items-end text-#FF4D3A font-semibold">
             <view class="text-24rpx">
@@ -341,7 +344,7 @@ async function handleAddCart() {
 
           <view class="flex items-center">
             <view class="w220rpx">
-              <wd-button hairline plain block @click="selectGoods = true">
+              <wd-button plain hairline block @click="selectGoods = true">
                 加入购物车
               </wd-button>
             </view>
@@ -357,12 +360,12 @@ async function handleAddCart() {
         <template #footer>
           <view class="box-border w-full flex items-center justify-between py20rpx">
             <view class="w-48%">
-              <wd-button plain hairline block @click="handleAddCart">
+              <wd-button plain hairline block :loading="isLoging" @click="handleAddCart">
                 加入购物车
               </wd-button>
             </view>
             <view class="w-48%">
-              <wd-button block @click="handleConfimOrder">
+              <wd-button block :loading="isLoging" @click="handleConfimOrder">
                 立即购买
               </wd-button>
             </view>

+ 25 - 10
src/subPack-xsb/utils/confirm-order.ts

@@ -11,7 +11,11 @@ export function handleCommonPayMent(orderNumber: string): Promise<wxpay> {
     uni.showLoading({ mask: true })
     Apis.common.hybridPayment({ data: { orderNumber } }).then((res) => {
       resolve(res.data)
-    }).finally(() => uni.hideLoading()).catch(err => reject(err))
+      uni.hideLoading()
+    }).catch((err) => {
+      uni.hideLoading()
+      reject(err)
+    })
   })
 }
 const { selectedAddress, userInfo } = storeToRefs(useUserStore())
@@ -46,7 +50,13 @@ export function getOrderPayMent(freightFee: number, businessType: string, dvyTyp
         orderItemList,
         remarks,
       },
-    }).then(res => resolve(res.data)).catch(err => reject(err)).finally(() => uni.hideLoading())
+    }).then((res) => {
+      resolve(res.data)
+      uni.hideLoading()
+    }).catch((err) => {
+      uni.hideLoading()
+      reject(err)
+    })
   })
 }
 /**
@@ -113,13 +123,18 @@ export function payError() {
 export async function clearCart(skuList: Api.CartSkuVo[]) {
   return new Promise((resolve) => {
     const skuids = skuList.map(item => item.id).join(',')
-    Apis.common.deleteShoppingCart({
-      pathParams: {
-        ids: skuids,
-      },
-    }).then(async (res) => {
-      resolve(res)
-      await useSmqjhCartStore().getCartList('XSB')
-    }).finally(() => resolve(1))
+    if (skuids.length) {
+      Apis.common.deleteShoppingCart({
+        pathParams: {
+          ids: skuids,
+        },
+      }).then(async (res) => {
+        resolve(res)
+        await useSmqjhCartStore().getCartList('XSB')
+      }).finally(() => resolve(1))
+    }
+    else {
+      resolve(1)
+    }
   })
 }