修复日期选择问题

This commit is contained in:
张成
2025-11-09 00:48:49 +08:00
parent db9a4a2c83
commit 712ebe6463
3 changed files with 116 additions and 3 deletions

View File

@@ -177,6 +177,28 @@ export const useListStore = create<TennisStore>()((set, get) => ({
// 全城和快捷筛选
const distanceQuickFilter = currentPageState?.distanceQuickFilter || {};
const { distanceFilter, order } = distanceQuickFilter || {};
// 从 area 中获取省份和城市名称area 格式: ["中国", 省份, 城市]
const province = state.area?.[1] || ""; // area[1] 是省份
const city = state.area?.at(-1) || ""; // area[2] 是城市(虽然参数名是 city但实际是城市名称
// 处理 dateRange确保始终有两个值
let dateRange: [string, string] = defaultDateRange;
const filterDateRange = filterOptions?.dateRange;
if (Array.isArray(filterDateRange)) {
if (filterDateRange.length === 0) {
// 如果没有选择日期,使用默认值
dateRange = defaultDateRange;
} else if (filterDateRange.length === 1) {
// 如果只选择了一个日期,转换为两个相同的值
const singleDate = filterDateRange[0] as string;
dateRange = [singleDate, singleDate];
} else if (filterDateRange.length >= 2) {
// 如果选择了两个或更多日期,取前两个
// 如果两个日期相同,保持两个相同的值
dateRange = [filterDateRange[0] as string, filterDateRange[1] as string];
}
}
const params = {
pageOption: currentPageState?.pageOption,
@@ -185,8 +207,10 @@ export const useListStore = create<TennisStore>()((set, get) => ({
title: state.searchValue,
ntrpMin: filterOptions?.ntrp?.[0],
ntrpMax: filterOptions?.ntrp?.[1],
dateRange: filterOptions?.dateRange,
dateRange: dateRange, // 确保始终是两个值的数组
distanceFilter: distanceFilter,
province: province, // 添加省份参数
city: city, // 添加区县参数(虽然叫 city但实际是区县
},
order: order,
lat: state?.location?.latitude,
@@ -289,6 +313,77 @@ export const useListStore = create<TennisStore>()((set, get) => ({
return await fetchMatches({}, true); // 第一次进入页面,传入 isFirstLoad = true
},
// 同时更新两个列表接口(常规列表和智能排序列表)
refreshBothLists: async () => {
const state = get();
const { getSearchParams, setListData } = state;
const { getGamesList, getGamesIntegrateList } = await import("../services/listApi");
try {
const searchParams = getSearchParams() || {};
// 调用常规列表接口
const listParams = {
...searchParams,
order: searchParams.order || "distance",
};
const listRes = await getGamesList(listParams);
// 调用智能排序列表接口
const integrateParams = {
...searchParams,
order: "",
seachOption: {
...searchParams.seachOption,
isRefresh: true,
},
};
const integrateRes = await getGamesIntegrateList(integrateParams);
// 根据当前排序方式更新对应的数据
const currentPageState = state.isSearchResult ? state.searchPageState : state.listPageState;
const distanceQuickFilter = currentPageState?.distanceQuickFilter || {};
const isIntegrate = distanceQuickFilter?.order === "0";
if (listRes?.code === 0 && listRes?.data) {
const { count, rows } = listRes.data;
if (!isIntegrate) {
// 如果当前是常规排序,更新常规列表数据
setListData({
error: '',
data: rows || [],
loading: false,
count,
isAppend: false,
});
}
}
if (integrateRes?.code === 0 && integrateRes?.data) {
const { count, rows, recommendList } = integrateRes.data;
if (isIntegrate) {
// 如果当前是智能排序,更新智能排序列表数据
setListData({
error: '',
data: rows || [],
loading: false,
count,
isAppend: false,
});
}
// 无论当前排序方式如何,都更新推荐列表
state.updateCurrentPageState({
recommendList: recommendList || [],
});
}
return Promise.resolve();
} catch (error) {
console.error("更新列表数据失败:", error);
return Promise.reject(error);
}
},
// 获取球局数量
fetchGetGamesCount: async () => {
const { getSearchParams } = get();