修复日期选择问题
This commit is contained in:
@@ -21,7 +21,7 @@ interface IProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CityPicker(props) {
|
function CityPicker(props) {
|
||||||
const { visible, setVisible, cities, area, setArea } = props;
|
const { visible, setVisible, cities, area, setArea, onCityChange } = props;
|
||||||
console.log(cities, "cities");
|
console.log(cities, "cities");
|
||||||
const [value, setValue] = useState(area);
|
const [value, setValue] = useState(area);
|
||||||
|
|
||||||
@@ -29,6 +29,10 @@ function CityPicker(props) {
|
|||||||
console.log(value, "value");
|
console.log(value, "value");
|
||||||
setValue(value);
|
setValue(value);
|
||||||
setArea(value);
|
setArea(value);
|
||||||
|
// 切换城市时触发接口调用
|
||||||
|
if (onCityChange) {
|
||||||
|
onCityChange(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
visible && (
|
visible && (
|
||||||
@@ -48,7 +52,7 @@ const ListHeader = (props: IProps) => {
|
|||||||
const { config } = props;
|
const { config } = props;
|
||||||
const { showInput = false, inputLeftIcon, leftIconClick } = config || {};
|
const { showInput = false, inputLeftIcon, leftIconClick } = config || {};
|
||||||
const { getLocationLoading, statusNavbarHeightInfo } = useGlobalState();
|
const { getLocationLoading, statusNavbarHeightInfo } = useGlobalState();
|
||||||
const { gamesNum, searchValue, cities, area, updateArea } = useListState();
|
const { gamesNum, searchValue, cities, area, updateArea, getMatchesData, fetchGetGamesCount, refreshBothLists } = useListState();
|
||||||
const { navBarHeight } = statusNavbarHeightInfo;
|
const { navBarHeight } = statusNavbarHeightInfo;
|
||||||
|
|
||||||
const [cityPopupVisible, setCityPopupVisible] = useState(false);
|
const [cityPopupVisible, setCityPopupVisible] = useState(false);
|
||||||
@@ -107,6 +111,18 @@ const ListHeader = (props: IProps) => {
|
|||||||
|
|
||||||
const area_city = area.at(-1);
|
const area_city = area.at(-1);
|
||||||
|
|
||||||
|
// 处理城市切换
|
||||||
|
const handleCityChange = async (newArea: any) => {
|
||||||
|
// 切换城市后,同时更新两个列表接口获取数据
|
||||||
|
if (refreshBothLists) {
|
||||||
|
await refreshBothLists();
|
||||||
|
}
|
||||||
|
// 更新球局数量
|
||||||
|
if (fetchGetGamesCount) {
|
||||||
|
await fetchGetGamesCount();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CustomNavbar>
|
<CustomNavbar>
|
||||||
<View className="listNavWrapper">
|
<View className="listNavWrapper">
|
||||||
@@ -176,6 +192,7 @@ const ListHeader = (props: IProps) => {
|
|||||||
cities={cities}
|
cities={cities}
|
||||||
area={area}
|
area={area}
|
||||||
setArea={updateArea}
|
setArea={updateArea}
|
||||||
|
onCityChange={handleCityChange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</CustomNavbar>
|
</CustomNavbar>
|
||||||
|
|||||||
@@ -177,6 +177,28 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
|||||||
// 全城和快捷筛选
|
// 全城和快捷筛选
|
||||||
const distanceQuickFilter = currentPageState?.distanceQuickFilter || {};
|
const distanceQuickFilter = currentPageState?.distanceQuickFilter || {};
|
||||||
const { distanceFilter, order } = 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 = {
|
const params = {
|
||||||
pageOption: currentPageState?.pageOption,
|
pageOption: currentPageState?.pageOption,
|
||||||
@@ -185,8 +207,10 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
|||||||
title: state.searchValue,
|
title: state.searchValue,
|
||||||
ntrpMin: filterOptions?.ntrp?.[0],
|
ntrpMin: filterOptions?.ntrp?.[0],
|
||||||
ntrpMax: filterOptions?.ntrp?.[1],
|
ntrpMax: filterOptions?.ntrp?.[1],
|
||||||
dateRange: filterOptions?.dateRange,
|
dateRange: dateRange, // 确保始终是两个值的数组
|
||||||
distanceFilter: distanceFilter,
|
distanceFilter: distanceFilter,
|
||||||
|
province: province, // 添加省份参数
|
||||||
|
city: city, // 添加区县参数(虽然叫 city,但实际是区县)
|
||||||
},
|
},
|
||||||
order: order,
|
order: order,
|
||||||
lat: state?.location?.latitude,
|
lat: state?.location?.latitude,
|
||||||
@@ -289,6 +313,77 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
|||||||
return await fetchMatches({}, true); // 第一次进入页面,传入 isFirstLoad = true
|
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 () => {
|
fetchGetGamesCount: async () => {
|
||||||
const { getSearchParams } = get();
|
const { getSearchParams } = get();
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ export interface ListActions {
|
|||||||
getCities: () => Promise<void>;
|
getCities: () => Promise<void>;
|
||||||
getCityQrCode: () => Promise<void>;
|
getCityQrCode: () => Promise<void>;
|
||||||
updateArea: (payload: [string, string, string]) => void;
|
updateArea: (payload: [string, string, string]) => void;
|
||||||
|
refreshBothLists: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPayload {
|
export interface IPayload {
|
||||||
|
|||||||
Reference in New Issue
Block a user