Explorar el Código

feat(cart): 添加市民请集合购物车地址选择功能

- 在用户store中添加smqjhSelectedAddress字段用于管理市民请集合购物车的收货地址
- 实现getSmqjhSelectedAddress和updateSmqjhSelectedAddress方法
- 在支付成功后清空已购买商品的购物车

fix(address): 修复地址选择组件显示和更新问题

- 修改selectAddress组件使用真实的地址数据而非模拟数据
- 添加地址选中状态显示和设为默认地址功能
- 修复地址更新后未重新获取列表的问题

fix(api): 修复渠道ID参数传递错误

- 将channelTopId替换为channelId以使用正确的渠道ID参数
- 更新购物车、商品分类、商品详情等接口的参数传递

fix(popup): 优化弹窗组件层级和样式

- 添加zindex属性支持自定义弹窗层级
- 修复radio组件背景色样式问题

fix(payment): 修复支付结果页面标题错误

- 将支付失败页面的标题从"支付成功"更正为"支付失败"

refactor(commonTab): 优化分类组件逻辑和交互

- 修复分类组件初始激活状态的判断逻辑
- 添加组件卸载时的状态清理
- 优化购物车弹窗的关闭和数据更新流程
zhangtao hace 2 días
padre
commit
4c96382b38

+ 5 - 1
src/App.vue

@@ -61,7 +61,11 @@ onLaunch(() => { })
         margin: 20rpx 0 20rpx 0 !important;
       }
     }
-
+    .custom-radio{
+      .wd-radio-group {
+        background-color: unset !important;
+      }
+    }
     .wd-sort-button {
       height: 100% !important;
       line-height: 0 !important;

+ 1 - 0
src/api/core/handlers.ts

@@ -36,6 +36,7 @@ export async function handleAlovaResponse(
     const { redirectName, token } = storeToRefs(useUserStore())
     // 如果是未授权错误,清除用户信息并跳转到登录页
     token.value = ''
+    useSmqjhCartStore().$reset()
     globalToast.error({ msg: '登录已过期,请重新登录!', duration: 2000 })
     redirectName.value = getCurrentPath()
     const timer = setTimeout(() => {

+ 3 - 1
src/components/Zpopup.vue

@@ -2,15 +2,17 @@
 withDefaults(defineProps<{
   bg?: string
   showfooter?: boolean
+  zindex?: number
 }>(), {
   bg: '#f6f6f6',
   showfooter: true,
+  zindex: 999,
 })
 const show = defineModel({ default: false })
 </script>
 
 <template>
-  <wd-popup v-model="show" lock-scroll custom-style="border-radius:32rpx;32rpx 0rpx 0rpx" :z-index="99" position="bottom">
+  <wd-popup v-model="show" lock-scroll custom-style="border-radius:32rpx;32rpx 0rpx 0rpx" :z-index="zindex" position="bottom">
     <view :style="{ background: bg }">
       <slot />
       <view class="h150rpx" />

+ 2 - 2
src/pages/cart/index.vue

@@ -14,8 +14,8 @@ definePage({
     disableScroll: true,
   },
 })
-const { name } = storeToRefs(useAddressStore())
 const { cartList, isAddingCart } = storeToRefs(useSmqjhCartStore())
+const { smqjhSelectedAddress } = storeToRefs(useUserStore())
 const isAll = ref(false)
 const tab = ref(0)
 const selectAddress = ref(false)
@@ -166,7 +166,7 @@ function handelPay() {
           </view>
           <image :src="`${StaticUrl}/location-green.png`" class="h33.8rpx w29rpx" />
           <view class="ml10rpx max-w-280rpx truncate text-32rpx text-#222 font-semibold">
-            {{ name }}
+            {{ smqjhSelectedAddress?.city }}
           </view>
         </view>
       </template>

+ 2 - 2
src/store/cart.ts

@@ -56,7 +56,7 @@ export const useSmqjhCartStore = defineStore('smqjh-cart', {
             skuId,
             num,
             shopId,
-            channelId: Number(userInfo.value.channelTopId),
+            channelId: Number(userInfo.value.channelId),
           },
         }).then((res) => {
           this.getCartList('XSB')
@@ -76,7 +76,7 @@ export const useSmqjhCartStore = defineStore('smqjh-cart', {
       }
       const res = await Apis.common.myShoppingCart({
         data: {
-          channelId: unref(userInfo).channelTopId as number,
+          channelId: unref(userInfo).channelId,
           businessType,
         },
       })

+ 21 - 1
src/store/user.ts

@@ -16,10 +16,14 @@ interface userStroe {
    */
   addresses: Api.addressList[]
   /**
-   * 用户选择的收货地址
+   * 星闪爆用户选择的收货地址
    *
    */
   selectedAddress: Api.addressList | null
+  /**
+   * 市民请集合购物车用户选中的收货地址
+   */
+  smqjhSelectedAddress: Api.addressList | null
 }
 export const useUserStore = defineStore('user', {
   state: (): userStroe => ({
@@ -32,6 +36,7 @@ export const useUserStore = defineStore('user', {
     },
     addresses: [],
     selectedAddress: null,
+    smqjhSelectedAddress: null,
   }),
   getters: {
     getUserAvatar(): string {
@@ -73,6 +78,7 @@ export const useUserStore = defineStore('user', {
       })
     },
     /**
+     *
      * 更新用户选择的收货地址
      */
     updateSelectedAddress(address: Api.addressList) {
@@ -85,5 +91,19 @@ export const useUserStore = defineStore('user', {
     getSelectedAddress() {
       this.selectedAddress = this.addresses.find(it => it.defaulted === 1) ?? null
     },
+    /**
+     * 获取市民请集合购物车用户选择的收货地址
+     * @description 默认选择默认地址,如无默认地址则不选择
+     */
+    getSmqjhSelectedAddress() {
+      this.smqjhSelectedAddress = this.addresses.find(it => it.defaulted === 1) ?? null
+    },
+    /**
+     * 更新市民请集合购物车用户选择的收货地址
+     */
+    updateSmqjhSelectedAddress(address: Api.addressList) {
+      this.smqjhSelectedAddress = address
+    },
+
   },
 })

+ 1 - 1
src/subPack-common/editAddress/index.vue

@@ -69,11 +69,11 @@ async function handleSubmit() {
   }
   if (Number(route.query?.type) === 1) {
     await Apis.sys.Addaddresses({ data: modelForm.value })
-
     useGlobalToast().show({ msg: '添加成功' })
   }
   else {
     await Apis.sys.updateAddresses({ pathParams: modelForm.value.id, data: modelForm.value })
+    await useUserStore().getuserAddresslist()
     useGlobalToast().show({ msg: '修改成功' })
   }
   setTimeout(() => {

+ 1 - 1
src/subPack-common/payError/index.vue

@@ -31,7 +31,7 @@ function handleBackIndex() {
 <template>
   <view class="pages">
     <wd-navbar
-      title="支付成功" custom-style="background-color:transparent !important" :bordered="false" :z-index="99"
+      title="支付失败" custom-style="background-color:transparent !important" :bordered="false" :z-index="99"
 
       safe-area-inset-top left-arrow fixed
       @click-left="router.back()"

+ 51 - 32
src/subPack-smqjh/components/selectAddress/index.vue

@@ -3,50 +3,69 @@ import { StaticUrl } from '@/config'
 import router from '@/router'
 
 const selectAddress = defineModel({ default: false })
+const { addresses, smqjhSelectedAddress } = storeToRefs(useUserStore())
+const defultId = ref()
+onMounted(() => {
+  useUserStore().getSmqjhSelectedAddress()
+  defultId.value = addresses.value.find(it => it.defaulted)?.id
+})
+function handleSelect(item: Api.addressList) {
+  useUserStore().updateSmqjhSelectedAddress(item)
+  selectAddress.value = false
+}
 </script>
 
 <template>
   <Zpopup v-model="selectAddress" :showfooter="false">
-    <view class="px24rpx py28rpx">
-      <view class="pb20rpx text-center text-32rpx font-semibold">
-        选择地址
-      </view>
-      <scroll-view scroll-y class="h800rpx">
-        <view v-for="item in 10" :key="item" class="mb24rpx flex rounded-16rpx bg-white px24rpx py28rpx">
-          <image :src="`${StaticUrl}/checked.png`" class="h32rpx w32rpx flex-shrink-0" />
-          <view class="ml20rpx flex-1">
-            <view class="flex items-center justify-between">
-              <view class="line-clamp-1 text-32rpx font-semibold">
-                杨先生 18456252489
-              </view>
-              <view class="text-24rpx">
-                编辑
-              </view>
-            </view>
-            <view class="line-clamp-2 mt20rpx text-24rpx text-#AAAAAA">
-              贵州省贵阳市  观山湖区  富力中心A7座  3410
-            </view>
-            <view class="mt20rpx">
-              <wd-checkbox>
-                <view class="text-24rpx text-#AAAAAA">
-                  设为默认地址
+    <view class="page-xsb">
+      <view class="custom-radio px24rpx py28rpx">
+        <view class="pb20rpx text-center text-32rpx font-semibold">
+          选择地址
+        </view>
+        <wd-radio-group v-model="defultId" inline shape="dot">
+          <scroll-view scroll-y class="h800rpx">
+            <view v-for="item in addresses" :key="item.id" class="mb24rpx flex rounded-16rpx bg-white px24rpx py28rpx">
+              <image
+                v-if="smqjhSelectedAddress?.id === item.id" :src="`${StaticUrl}/checked.png`"
+                class="h32rpx w32rpx flex-shrink-0"
+              />
+              <view class="ml20rpx flex-1">
+                <view @click="handleSelect(item)">
+                  <view class="flex items-center justify-between">
+                    <view class="line-clamp-1 text-32rpx font-semibold">
+                      {{ item.consigneeName }} {{ item.consigneeMobile }}
+                    </view>
+                    <view class="text-24rpx" @click.stop="router.push({ name: 'common-editAddress', params: { type: '2', id: `${item.id}` } })">
+                      编辑
+                    </view>
+                  </view>
+                  <view class="line-clamp-2 mt20rpx text-24rpx text-#AAAAAA">
+                    {{ item.province }} {{ item.city }} {{ item.detailAddress }}
+                  </view>
+                </view>
+                <view class="mt20rpx">
+                  <wd-radio :value="item.id">
+                    <view class="text-24rpx text-#AAAAAA">
+                      设为默认地址
+                    </view>
+                  </wd-radio>
                 </view>
-              </wd-checkbox>
+              </view>
             </view>
+          </scroll-view>
+        </wd-radio-group>
+        <view class="ios fixed bottom-0 left-0 box-border w-full px24rpx">
+          <view class="pb20rpx">
+            <wd-button block size="large" @click="router.push({ name: 'common-addressList' })">
+              新增收货地址
+            </wd-button>
           </view>
         </view>
-      </scroll-view>
-      <view class="ios fixed bottom-0 left-0 box-border w-full px24rpx">
-        <view class="pb20rpx">
-          <wd-button block size="large" @click="router.push({ name: 'common-addressList' })">
-            新增收货地址
-          </wd-button>
-        </view>
       </view>
     </view>
   </Zpopup>
 </template>
 
-<style scoped>
+<style scoped lang="scss">
 
 </style>

+ 15 - 5
src/subPack-xsb/commonTab/components/classfiy.vue

@@ -75,7 +75,7 @@ async function getCartCategorList() {
     Apis.xsb.myShoppingCartCategory({
       data: {
         businessType: 'XSB',
-        channelId: unref(userInfo).channelTopId,
+        channelId: unref(userInfo).channelId,
         shopId: unref(SelectShopInfo).shopId,
       },
     }).then((res) => {
@@ -98,7 +98,7 @@ async function getProductList() {
     data: {
       categoryId: Number(categoriesId.value),
       shopId: Number(SelectShopInfo.value?.shopId) || 1,
-      channelId: unref(userInfo).channelTopId || 1,
+      channelId: unref(userInfo).channelId || 1,
     },
   })
   productList.value = res.data
@@ -144,8 +144,11 @@ async function handleAddCart(event: WechatMiniprogram.TouchEvent, item: Api.xsbC
   getCartCategorList()
 }
 onMounted(async () => {
-  topNavActive.value = props.categoryList[0].code || ''
-  leftActive.value = props.categoryList[0].children[0].code || ''
+  if (!topNavActive.value || !leftActive.value) {
+    topNavActive.value = props.categoryList[0].code || ''
+    leftActive.value = props.categoryList[0].children[0].code || ''
+  }
+
   if (leftActive.value) {
     handleChange({ value: leftActive.value })
   }
@@ -191,7 +194,9 @@ async function handleSub(item: Api.xsbCategoriesCartList) {
     useGlobalMessage().confirm({
       msg: '是否删除该商品?',
       success: async () => {
+        cartPopup.value = false
         await useSmqjhCartStore().addCart(item.skuId, -1, item.shopId, 'XSB')
+        await getCartCategorList()
       },
     })
   }
@@ -206,6 +211,11 @@ async function handleAdd(item: Api.xsbCategoriesCartList) {
   getGoodsPrice()
   await getCartCategorList()
 }
+onUnmounted(() => {
+  console.log('组件卸载')
+  topNavActive.value = ''
+  leftActive.value = ''
+})
 </script>
 
 <template>
@@ -417,7 +427,7 @@ async function handleAdd(item: Api.xsbCategoriesCartList) {
         </view>
       </view>
     </view>
-    <Zpopup v-model="cartPopup">
+    <Zpopup v-model="cartPopup" :zindex="99">
       <view class="ios h800rpx overflow-y-scroll">
         <view class="p24rpx">
           <view

+ 2 - 0
src/subPack-xsb/commonTab/components/index.vue

@@ -44,6 +44,8 @@ onMounted(() => {
 })
 
 function handleCommonClass(item: Api.xsbCategories) {
+  console.log(item, '===================')
+
   topNavActive.value = item.code
   leftActive.value = item.children[0].code
   emit('changeNav')

+ 16 - 3
src/subPack-xsb/commonTab/index.vue

@@ -26,7 +26,7 @@ const { ScrollDown, backTop, SelectShopInfo } = storeToRefs(useSysXsbStore())
 const { userInfo } = storeToRefs(useUserStore())
 const commonCategoryData = ref<Api.xsbCategories[]>([])
 const { data: goodsList, isLastPage, page, error, refresh } = usePagination((pageNum, pageSize) =>
-  Apis.xsb.getSearchProductList({ data: { pageNum, pageSize, salesNum: 'DESC', shopId: Number(SelectShopInfo.value?.shopId) || 1, channelId: userInfo.value.channelTopId || 1 } }), {
+  Apis.xsb.getSearchProductList({ data: { pageNum, pageSize, salesNum: 'DESC', shopId: Number(SelectShopInfo.value?.shopId) || 1, channelId: userInfo.value.channelId || 1 } }), {
   data: resp => resp.data?.list,
   initialData: [],
   initialPage: 1,
@@ -113,6 +113,18 @@ function handleScrollBottom() {
     page.value++
   }
 }
+function handleChange() {
+  tabbarItems.value = tabbarItems.value.map((it) => {
+    if (it.name === 'xsb-classfiy') {
+      it.active = true
+    }
+    else {
+      it.active = false
+    }
+    return it
+  })
+  tabbarName.value = 'xsb-classfiy'
+}
 </script>
 
 <template>
@@ -126,14 +138,15 @@ function handleScrollBottom() {
       :goods-list="goodsList"
       :last-page="isLastPage"
       :error="error"
-      @change-nav="tabbarName = 'xsb-classfiy'"
+      @change-nav="handleChange"
       @scroll-bottom="handleScrollBottom"
     />
     <cart v-if="tabbarName == 'xsb-cart'" />
     <classfiy v-if="tabbarName == 'xsb-classfiy'" :category-list="commonCategoryData" :hot-text="hotText" />
     <my v-if="tabbarName == 'xsb-my'" />
     <wd-tabbar
-      :model-value="tabbarName" safe-area-inset-bottom placeholder fixed :bordered="false"
+      v-model="tabbarName"
+      placeholder safe-area-inset-bottom fixed :bordered="false"
       custom-class="custom-tab"
       :custom-style="`box-shadow:${tabbarName == 'xsb-cart' || tabbarName == 'xsb-classfiy' ? '' : ' 0rpx -6rpx 12rpx 2rpx rgba(0, 0, 0, 0.09)'}`"
       :z-index="99999"

+ 3 - 1
src/subPack-xsb/confirmOrder/index.vue

@@ -1,5 +1,5 @@
 <script setup lang="ts">
-import { getOrderPayMent, getWxCommonPayment, handleCommonPayMent, payError, paySuccess } from '../utils/confirm-order'
+import { clearCart, getOrderPayMent, getWxCommonPayment, handleCommonPayMent, payError, paySuccess } from '../utils/confirm-order'
 import router from '@/router'
 
 definePage({
@@ -63,6 +63,7 @@ async function handlePay() {
 
     const orderNumber = await getOrderPayMent('XSB', deliveryType.value, Number(orderInfo.value?.skuList[0].shopId), orderItemList, unref(remarks))
     const res = await handleCommonPayMent(orderNumber)
+    await clearCart(orderInfo.value.skuList)
     if (res.payType !== 1) {
       await getWxCommonPayment(res)
       paySuccess()
@@ -70,6 +71,7 @@ async function handlePay() {
     else {
       paySuccess()
     }
+
     isPay.value = false
   }
   catch {

+ 1 - 1
src/subPack-xsb/goods/index.vue

@@ -86,7 +86,7 @@ function handleGoCurren(id: number) {
 }
 
 async function getGoodsDetaile() {
-  const res = await Apis.xsb.getProductDetail({ data: { id: goodsId.value, shopId: Number(SelectShopInfo.value?.shopId), channelId: userInfo.value.channelTopId || 1 } })
+  const res = await Apis.xsb.getProductDetail({ data: { id: goodsId.value, shopId: Number(SelectShopInfo.value?.shopId), channelId: userInfo.value.channelId || 1 } })
   console.log(res, '请求')
   goodsInfo.value = res.data
   specId.value = res.data.skuList?.[0].skuId

+ 1 - 1
src/subPack-xsb/search/index.vue

@@ -26,7 +26,7 @@ const { data, send, isLastPage, page, error } = usePagination((pageNum, pageSize
   priceSort: activeTab.value === 2 ? 'DESC' : '',
   salesNum: activeTab.value === 1 ? 'DESC' : '',
   shopId: 1,
-  channelId: userInfo.value.channelTopId || 1,
+  channelId: userInfo.value.channelId || 1,
 } }), {
   immediate: false,
   data: resp => resp.data?.list,

+ 5 - 3
src/subPack-xsb/selectAddress/index.vue

@@ -24,10 +24,13 @@ const allShopList = computed(() => {
 
 function handleClick(item: Api.xsbShopList) {
   SelectShopInfo.value = item
-  router.back()
 }
+watch(() => SelectShopInfo.value, () => {
+  router.back()
+})
 
-function handelChange() {
+function handelChange(e: { value: number }) {
+  console.log(e.value, selectAddressId.value)
   const address = addresses.value.find(it => it.id === selectAddressId.value)
   if (!address)
     return
@@ -45,7 +48,6 @@ function handelChange() {
       if (distance < minDistance) {
         minDistance = distance
         handleClick({ ...shop, distance: Number(distance.toFixed(2)) })
-        // SelectShopInfo.value = { ...shop, distance: Number(distance.toFixed(2)) }
       }
     }
   }

+ 19 - 1
src/subPack-xsb/utils/confirm-order.ts

@@ -37,7 +37,7 @@ export function getOrderPayMent(businessType: string, dvyType: number, shopId: n
     }
     Apis.common.addOrder({
       data: {
-        channelId: Number(unref(userInfo).channelTopId),
+        channelId: Number(unref(userInfo).channelId),
         businessType,
         addressId: selectedAddress.value.id,
         dvyType,
@@ -105,3 +105,21 @@ export function payError() {
   payBackIndexPath.value = 'subPack-xsb/commonTab/index'
   router.replace({ name: 'common-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))
+  })
+}