fix:修复bug

This commit is contained in:
2026-03-03 09:42:22 +08:00
parent e9655643d6
commit 9f2d2f8764
17 changed files with 1232 additions and 210 deletions
+109 -12
View File
@@ -8,6 +8,7 @@ import { useScrollThreshold } from '@/hooks/useScrollThreshold'
import {
appCollectCollectPost, appMerchantCartCalculateSavingsPost, appMerchantCartListByMerchantIdPost,
appMerchantDetailMerchantIdGet,
appMerchantDishDishIdGet,
appMerchantMenuMenuListByUserPost, type MerchantCartVo,
type MerchantVo
} from "@/service";
@@ -138,7 +139,7 @@ function getStoreDetail() {
console.log('商家详情', res)
storeDetail.value = res.data as MerchantVo
getMerchantCouponReceiveList()
// getMerchantCouponReceiveList()
// 解析营业时间并判断闭店提示
if (res.data.businessHours) {
@@ -149,13 +150,19 @@ function getStoreDetail() {
}
}
if(res.data.merchantMenuVoList && res.data.merchantMenuVoList.length > 0) {
tabs.value = res.data.merchantMenuVoList.map((item) => {
return {
title: item.menuName,
key: item.id
}
})
if(res.data.merchantCategoryIds && res.data.merchantCategoryIds.length > 0) {
tabs.value = [
{
title: t('pages.store.all'),
key: ''
},
...res.data.merchantCategoryIds.map((item) => {
return {
title: item.menuName,
key: item.id
}
})
]
}
// 商户的经纬度存在,并且用户的经纬度也存在
@@ -283,7 +290,90 @@ function handleClickSegmented(index: number) {
}
const activeTab = ref(0);
const tabs = ref([]);
const tabs = ref<any[]>([]);
// 分页相关状态
const pageNum = ref(1);
const pageSize = ref(10);
const hasMore = ref(true);
const isLoadingMore = ref(false);
const dishListByQuery = ref<any[]>([]);
// 计算当前显示的商品列表
const currentDishList = computed(() => {
if(tabs.value[activeTab.value].key==''&&pageNum.value===1){
return storeDetail.value?.dishPage?.records
}
console.log(tabs.value[activeTab.value].key=='');
// 使用 dishListByQuery 作为数据源
return dishListByQuery.value || []
})
// 加载菜品列表
async function loadDishList(isLoadMore = false) {
if (isLoadingMore.value) return;
const currentTab = tabs.value[activeTab.value];
if (!currentTab) return;
try {
isLoadingMore.value = true;
// 构建请求参数
const body: any = {
merchantId: storeID.value,
pageNum: isLoadMore ? pageNum.value : 1,
pageSize: pageSize.value
};
// 如果选中的tab的key不为空,则传递menuId
if (currentTab.key !== '') {
body.menuId = currentTab.key;
}
console.log('加载菜品列表参数', body);
const res = await appMerchantDishDishIdGet({ body });
if (res.data && res.data.rows) {
if (isLoadMore) {
// 加载更多,追加数据
dishListByQuery.value = [
...dishListByQuery.value,
...res.data.rows
];
} else {
// 首次加载或刷新
dishListByQuery.value = res.data.rows;
}
// 更新分页信息
hasMore.value = res.data.rows.length >= pageSize.value;
if (isLoadMore) {
pageNum.value++;
}
}
} catch (error) {
console.error('加载菜品列表失败:', error);
} finally {
isLoadingMore.value = false;
}
}
// 监听tab切换,重置分页并加载数据
watch(activeTab, () => {
pageNum.value = 1;
hasMore.value = true;
loadDishList(false);
});
// 触底加载更多
onReachBottom(() => {
if (hasMore.value && !isLoadingMore.value) {
loadDishList(true);
}
});
const showStatusBar = useScrollThreshold()
onPageScroll((e) => {
@@ -540,9 +630,9 @@ function handleShare() {
<view class="box mt--6px"></view>
<view v-if="tabs.length > 0" class="px-30rpx pb-120rpx">
<view v-if="storeDetail?.merchantMenuVoList[activeTab]?.dishList.length > 0" class="text-40rpx lh-40rpx font-500 my-36rpx">{{ t('pages-store.store.recommend') }}</view>
<view v-if="storeDetail?.merchantMenuVoList[activeTab]?.dishList.length > 0" class="grid grid-cols-2 gap-30rpx">
<template v-for="item in storeDetail?.merchantMenuVoList[activeTab]?.dishList">
<view v-if="currentDishList.length > 0" class="text-40rpx lh-40rpx font-500 my-36rpx">{{ t('pages-store.store.recommend') }}</view>
<view v-if="currentDishList.length > 0" class="grid grid-cols-2 gap-30rpx">
<template v-for="item in currentDishList">
<view @click="navigateToDishes(item)" class="w-100% mb-10rpx">
<view class="relative h-248rpx rounded-24rpx mb-28rpx">
<view @click.stop="handleDishCollectionClick(item)" class="w-68rpx h-68rpx absolute z-2 top-0 right-0">
@@ -563,6 +653,13 @@ function handleShare() {
:src="item?.dishImage?.split(',')[0]"
mode="aspectFill"
class="w-full h-full rounded-24rpx bg-common"
v-if="item.dishImage.split(',').length > 0"
/>
<image
:src="item?.dishImage"
mode="aspectFill"
class="w-full h-full rounded-24rpx bg-common"
v-else
/>
</view>
<view class="line-clamp-1 text-30rpx text-#333 font-500">