| | |
| | | const [siteList, setSiteList] = useState([]) //推荐站点列表 |
| | | const [historySite, setHistorySite] = useState([]) //历史记录列表 |
| | | const [nonOperationalSite, setNonOperationalSite] = useState([]) // 非运营区域站点 |
| | | const [nearbySiteList, setNearbySiteList] = useState([]) // 附近站点列表 |
| | | const [searchValue, setSearchValue] = useState('') //搜索值 |
| | | const [pageType, setPageType] = useState('') //出发地 start 目的地 end |
| | | const [showAllHistory, setShowAllHistory] = useState(false) // 是否展示全部历史记录 |
| | |
| | | |
| | | const router = Taro.useRouter(); |
| | | |
| | | const fetchNearbySites = async (lat: number, lon: number, electronicAreaId?: string | number) => { |
| | | const selectedCity = Taro.getStorageSync('selectedCity'); |
| | | const payload = { |
| | | cityCode: selectedCity?.code || '', |
| | | electronicAreaId: electronicAreaId ? Number(electronicAreaId) : 0, |
| | | lat: Number(lat), |
| | | lon: Number(lon) |
| | | }; |
| | | |
| | | try { |
| | | const res = await queryPointByName(payload); |
| | | const { availablePoints } = res; |
| | | if (Array.isArray(availablePoints)) { |
| | | const list = availablePoints.map(item => ({ |
| | | ...item, |
| | | distance: formatDistance(item.distance) |
| | | })); |
| | | setNearbySiteList(list); |
| | | } else { |
| | | setNearbySiteList([]); |
| | | } |
| | | } catch (error) { |
| | | console.error('fetch nearby error', error); |
| | | setNearbySiteList([]); |
| | | } |
| | | } |
| | | |
| | | useEffect(() => { |
| | | const { pageType: type, latitude: lat, longitude: lon } = router.params; |
| | | const { pageType: type, latitude: lat, longitude: lon, electronicAreaId } = router.params; |
| | | |
| | | if (type) { |
| | | setPageType(type); |
| | | } |
| | | |
| | | if (lat && lon) { |
| | | fetchNearbySites(Number(lat), Number(lon), electronicAreaId); |
| | | const payload = { |
| | | lat: Number(lat), |
| | | lon: Number(lon) |
| | |
| | | } |
| | | |
| | | |
| | | const recommendList = siteList.length > 0 ? siteList : nearbySiteList; |
| | | |
| | | return ( |
| | | <View className='search-page'> |
| | | {/* 搜索区域 */} |
| | |
| | | } |
| | | {/* 推荐站点 */} |
| | | { |
| | | siteList.length > 0 && |
| | | recommendList.length > 0 && |
| | | <View className='recommend-card'> |
| | | <View className='card-header'>推荐站点</View> |
| | | <View className='card-header'>{siteList.length > 0 ? '推荐站点' : '附近站点'}</View> |
| | | <View className='card-content'> |
| | | { |
| | | siteList.map((item, index) => { |
| | | recommendList.map((item, index) => { |
| | | return <View onClick={() => onChangeSelectSite(item)} className='history-item' key={item.id || index}> |
| | | <Image className='history-icon' src={address}></Image> |
| | | <View className='history-info'> |
| | |
| | | }) |
| | | } |
| | | </View> |
| | | {siteList.length > MAX_SHOW_COUNT && ( |
| | | {recommendList.length > MAX_SHOW_COUNT && ( |
| | | <View className='show-more' onClick={toggleRecommendShow}> |
| | | <Text className='more-text'>{showAllRecommend ? '收起' : '展示更多'}</Text> |
| | | <Image className={`more-icon ${showAllRecommend ? 'rotate-up' : ''}`} src={arrow}></Image> |
| | |
| | | </View> |
| | | } |
| | | { |
| | | (!siteList.length && !nonOperationalSite.length && !historySite.length) && |
| | | (!siteList.length && !nearbySiteList.length && !nonOperationalSite.length && !historySite.length) && |
| | | <View className='no-data-box'> |
| | | <Image className='no-data-image' src={require('../../assets/no-data-city.png')} /> |
| | | <View>暂无站点</View> |