列表搜索页面
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import { create } from 'zustand'
|
||||
import { getTennisMatches, getSearchHistory, clearHistory, searchSuggestion } from '../services/listApi'
|
||||
import { getGamesList, getGamesIntegrateList, getSearchHistory, clearHistory, searchSuggestion } from '../services/listApi'
|
||||
import { ListActions, IFilterOptions, ListState } from '../../types/list/types'
|
||||
|
||||
// 完整的 Store 类型
|
||||
type TennisStore = ListState & ListActions
|
||||
|
||||
const defaultFilterOptions: IFilterOptions = {
|
||||
location: '', // 位置
|
||||
time: '', // 时间
|
||||
ntrp: [1.0, 5.0], // NTRP 水平区间
|
||||
court_type: '', // 场地类型
|
||||
game_play: '', // 玩法
|
||||
dateRange: [], // 日期区间
|
||||
timeSlot: '', // 时间段
|
||||
ntrp: [1, 5], // NTRP 水平区间
|
||||
venueType: '', // 场地类型
|
||||
playType: '', // 玩法
|
||||
};
|
||||
|
||||
const defaultDistance = 'all'; // 默认距离
|
||||
@@ -21,6 +21,10 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
matches: [],
|
||||
// 推荐列表
|
||||
recommendList: [],
|
||||
location: {
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
}, // 位置
|
||||
// 是否加载中
|
||||
loading: false,
|
||||
error: null,
|
||||
@@ -38,10 +42,10 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
quickFilter: 1, // 1: 默认 2: 好评 3: 销量
|
||||
// 距离筛选数据
|
||||
distanceData: [
|
||||
{ id: 0, label: "全城", value: "全城" },
|
||||
{ id: 1, label: "3km", value: "3km" },
|
||||
{ id: 2, label: "5km", value: "5km" },
|
||||
{ id: 3, label: "10km", value: "10km" },
|
||||
{ id: 0, label: "全城", value: "0" },
|
||||
{ id: 1, label: "3km", value: "3" },
|
||||
{ id: 2, label: "5km", value: "5" },
|
||||
{ id: 3, label: "10km", value: "10" },
|
||||
],
|
||||
// 快捷筛选数据
|
||||
quickFilterData: [
|
||||
@@ -100,13 +104,42 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
isOpenDistancePopup: false,
|
||||
// 打开快捷筛选框
|
||||
isOpenQuickFilterPopup: false,
|
||||
// 分页
|
||||
pageOption: {
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
},
|
||||
|
||||
// 获取比赛数据
|
||||
// 组装搜索数据
|
||||
getSearchParams: () => {
|
||||
const state = get()
|
||||
const filterOptions = state?.filterOptions || {};
|
||||
const params = {
|
||||
pageOption: state.pageOption,
|
||||
seachOption: {
|
||||
...filterOptions,
|
||||
title: state.searchValue,
|
||||
},
|
||||
order: '',
|
||||
lat: state?.location?.latitude,
|
||||
lng: state?.location?.longitude,
|
||||
}
|
||||
return params;
|
||||
},
|
||||
|
||||
// 初始化获取比赛数据
|
||||
fetchMatches: async (params) => {
|
||||
set({ loading: true, error: null })
|
||||
|
||||
try {
|
||||
const resData = await getTennisMatches(params) || {};
|
||||
const { getSearchParams } = get();
|
||||
const searchParams = getSearchParams() || {};
|
||||
const reqParams = {
|
||||
...(searchParams || {}),
|
||||
...params,
|
||||
}
|
||||
const resData = await getGamesList(reqParams) || {};
|
||||
console.log('===resData', resData)
|
||||
const { data = {}, code } = resData;
|
||||
if (code !== 0) {
|
||||
set({
|
||||
@@ -116,25 +149,25 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
})
|
||||
}
|
||||
const { count, rows } = data;
|
||||
const list = (rows || []).map(() => {
|
||||
return {
|
||||
id: "3",
|
||||
title: "黄浦区双打约球",
|
||||
dateTime: "7月20日(周日)下午6点 2小时",
|
||||
location: "仁恒河滨花园网球场",
|
||||
distance: "3.5km",
|
||||
registeredCount: 3,
|
||||
maxCount: 4,
|
||||
skillLevel: "2.0 至 2.5",
|
||||
matchType: "双打",
|
||||
images: [
|
||||
"https://images.unsplash.com/photo-1554068865-24cecd4e34b8?w=200&h=200&fit=crop&crop=center",
|
||||
],
|
||||
}
|
||||
})
|
||||
// const list = (rows || []).map(() => {
|
||||
// return {
|
||||
// id: "3",
|
||||
// title: "黄浦区双打约球",
|
||||
// dateTime: "7月20日(周日)下午6点 2小时",
|
||||
// location: "仁恒河滨花园网球场",
|
||||
// distance: "3.5km",
|
||||
// registeredCount: 3,
|
||||
// maxCount: 4,
|
||||
// skillLevel: "2.0 至 2.5",
|
||||
// matchType: "双打",
|
||||
// images: [
|
||||
// "https://images.unsplash.com/photo-1554068865-24cecd4e34b8?w=200&h=200&fit=crop&crop=center",
|
||||
// ],
|
||||
// }
|
||||
// })
|
||||
set({
|
||||
matches: list || rows || [],
|
||||
recommendList: list || rows || [],
|
||||
matches: rows || [],
|
||||
recommendList: rows || [],
|
||||
error: null,
|
||||
loading: false,
|
||||
gamesNum: count,
|
||||
@@ -149,22 +182,6 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
}
|
||||
},
|
||||
|
||||
// 刷新比赛数据
|
||||
refreshMatches: async () => {
|
||||
set({ loading: true, error: null })
|
||||
|
||||
try {
|
||||
const resData = await getTennisMatches() || {};
|
||||
const { data = {}, code } = resData;
|
||||
const { count, rows } = data;
|
||||
set({
|
||||
matches: rows,
|
||||
loading: false,
|
||||
})
|
||||
} catch (error) {
|
||||
}
|
||||
},
|
||||
|
||||
// 获取历史搜索数据
|
||||
getSearchHistory: async () => {
|
||||
try {
|
||||
@@ -212,10 +229,10 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
|
||||
// 更新综合筛选项
|
||||
updateFilterOptions: (payload: Record<string, any>) => {
|
||||
console.log('===更新综合筛选项', payload)
|
||||
const preFilterOptions = get()?.filterOptions || {}
|
||||
const filterOptions = { ...preFilterOptions, ...payload }
|
||||
const filterCount = Object.values(filterOptions).filter(Boolean).length
|
||||
console.log('===更新综合筛选项', filterOptions, filterCount)
|
||||
set({
|
||||
filterOptions,
|
||||
filterCount
|
||||
|
||||
Reference in New Issue
Block a user