import { useEffect, useState } from "react"; import { View, Text, Image } from "@tarojs/components"; import img from "@/config/images"; import { useGlobalState } from "@/store/global"; import { useUserInfo } from "@/store/userStore"; import { useListState } from "@/store/listStore"; import CustomNavbar from "@/components/CustomNavbar"; import { Input } from "@nutui/nutui-react-taro"; import Taro from "@tarojs/taro"; import "./index.scss"; import { getCurrentFullPath } from "@/utils"; import { CityPicker as PopupPicker } from "@/components/Picker"; interface IProps { config?: { showInput: boolean; inputLeftIcon?: string; iconPath?: string; leftIconClick?: () => void; }; } function CityPicker(props) { const { visible, setVisible, cities, area, setArea, onCityChange } = props; console.log(cities, "cities"); const [value, setValue] = useState(area); function onChange(value: any) { console.log(value, "value"); setValue(value); setArea(value); // 切换城市时触发接口调用 if (onCityChange) { onCityChange(value); } } return ( visible && ( ) ); } const ListHeader = (props: IProps) => { const { config } = props; const { showInput = false, inputLeftIcon, leftIconClick } = config || {}; const { getLocationLoading, statusNavbarHeightInfo } = useGlobalState(); const { gamesNum, searchValue, cities, area, updateArea, getMatchesData, fetchGetGamesCount, refreshBothLists } = useListState(); const { navBarHeight } = statusNavbarHeightInfo; const [cityPopupVisible, setCityPopupVisible] = useState(false); const userInfo = useUserInfo(); const province = (userInfo as any)?.province || ""; const city = (userInfo as any)?.city || ""; // const district = (userInfo as any)?.district || ""; useEffect(() => { updateArea(["中国", province, city]); }, [province, city]); // const currentAddress = city + district; const handleInputClick = () => { const currentPagePath = getCurrentFullPath(); if (currentPagePath === "/game_pages/searchResult/index") { Taro.navigateBack(); } else { Taro.navigateTo({ url: "/game_pages/search/index", }); } }; // 点击logo const handleLogoClick = () => { // 如果当前在列表页,点击后页面回到顶部 if (getCurrentFullPath() === "/game_pages/list/index") { Taro.pageScrollTo({ scrollTop: 0, duration: 300, }); } Taro.redirectTo({ url: "game_pages/list/index", // 列表页 }); }; const handleInputLeftIconClick = () => { if (leftIconClick) { leftIconClick(); } else { handleLogoClick(); } }; const navbarStyle = { height: `${navBarHeight}px`, }; function handleToggleCity() { setCityPopupVisible(true); } const area_city = area.at(-1); // 处理城市切换 const handleCityChange = async (newArea: any) => { // 切换城市后,同时更新两个列表接口获取数据 if (refreshBothLists) { await refreshBothLists(); } // 更新球局数量 if (fetchGetGamesCount) { await fetchGetGamesCount(); } }; return ( {/* 首页logo 导航*/} {cityPopupVisible && ( )} ); }; export default ListHeader;