From 195749ad6e30321fac4f30a27538bea16ff1a14f Mon Sep 17 00:00:00 2001 From: dzq Date: Tue, 10 Jun 2025 17:13:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(router):=20=E6=81=A2=E5=A4=8D=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E8=B7=AF=E7=94=B1=E5=AE=88=E5=8D=AB=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(api): 为余额查询接口添加corpid参数 refactor(product): 优化商品获取逻辑并移除URL参数依赖 feat(product): 添加机柜地址选择功能并重构商品列表页面 fix(wx): 修复余额获取逻辑并启用相关用户信息更新 --- src/common/apis/shop/index.ts | 4 +- src/pages/product/ProductList.vue | 166 ++++++++++++++++++---- src/pages/product/components/checkout.vue | 4 +- src/pinia/stores/product.ts | 7 +- src/pinia/stores/wx.ts | 6 +- src/router/guard.ts | 4 +- 6 files changed, 150 insertions(+), 41 deletions(-) diff --git a/src/common/apis/shop/index.ts b/src/common/apis/shop/index.ts index 342db5d..21d083b 100644 --- a/src/common/apis/shop/index.ts +++ b/src/common/apis/shop/index.ts @@ -59,11 +59,11 @@ export function openCabinetApi(orderId: number, orderGoodsId: number, data: Open } /** 获取用户余额接口 */ -export function getBalanceApi(openid: string) { +export function getBalanceApi(corpid: string, openid: string) { return request>({ url: "payment/getBalance", method: "get", - params: { openid } + params: { corpid, openid } }) } export function getBalanceByQyUserid(corpid: string, userid: string) { diff --git a/src/pages/product/ProductList.vue b/src/pages/product/ProductList.vue index e1dd1e4..a711864 100644 --- a/src/pages/product/ProductList.vue +++ b/src/pages/product/ProductList.vue @@ -11,6 +11,8 @@ import Detail from "./components/detail.vue" import { useRoute } from 'vue-router' import { useWxStore } from "@/pinia/stores/wx" import { bindQyUserApi } from "@/common/apis/ab98" +import { getShopListApi } from "@/common/apis/shop" +import { ShopEntity } from "@/common/apis/shop/type" const router = useRouter() const route = useRoute() @@ -33,6 +35,11 @@ const headerHeight = ref(150) // 滚动事件监听器存储数组 let scrollListener: any[] = [] +// 显示选择商店列表 +const showShopList = ref(true); +const shopList = ref([]); +const shopId = ref(0); + // 商品详情弹窗控制 const showDetailPopup = ref(false) // 当前查看的商品ID @@ -51,6 +58,18 @@ const idNum = ref(''); const showAb98BindPopup = ref(false); // 点击分类导航 +function handleShopSelect(selectedShopId: number) { + shopId.value = selectedShopId; + showShopList.value = false; + productStore.getGoods(selectedShopId); + cartStore.clearCart(); +} +function handleBackToShopList() { + showShopList.value = true; + shopId.value = 0; + cartStore.clearCart(); +} + function handleCategoryClick(index: number) { activeCategory.value = index } @@ -105,7 +124,7 @@ function getCartItemCount(cellId: number) { function filterProductsByName(products: Product[], query: string) { if (!query) return products - return products.filter(p => + return products.filter(p => p.name.toLowerCase().includes(query.toLowerCase()) ) } @@ -117,7 +136,15 @@ const currentProducts = computed(() => { // 组件挂载时添加滚动监听 onMounted(() => { - productStore.getGoods(); + if (showShopList.value) { + getShopListApi(wxStore.corpid).then((res) => { + if (res?.code === 0 && res?.data?.length > 0) { + shopList.value = res.data; + } + }); + } else { + productStore.getGoods(shopId.value); + } scrollListener.push(scrollContainer.value?.addEventListener("scroll", throttledScroll)) // scrollListener.push(scrollContainer.value?.addEventListener("scroll", throttledUpdate)) }) @@ -137,14 +164,22 @@ function handleCheckout() { // 路由更新时刷新数据 watch(() => route.path, (newPath) => { if (newPath === '/') { - productStore.getGoods() + if (showShopList.value) { + getShopListApi(wxStore.corpid).then((res) => { + if (res?.code === 0 && res?.data?.length > 0) { + shopList.value = res.data; + } + }); + } else { + productStore.getGoods(shopId.value); + } } -}); +}, { immediate: true }); let showAb98BindPopupOnce = false; watch(openid, async () => { - if (openid.value && corpidLogin.value && !ab98User.value - && !showAb98BindPopup.value && !showAb98BindPopupOnce) { + if (openid.value && corpidLogin.value && !ab98User.value + && !showAb98BindPopup.value && !showAb98BindPopupOnce) { // 显示绑定弹窗 showAb98BindPopup.value = true; showAb98BindPopupOnce = true; @@ -174,24 +209,49 @@ async function handleAb98Bind() {