import { View, Text, Input, Button, Picker } from '@tarojs/components' import { useMemo, useState } from 'react' import Taro from '@tarojs/taro' import { DestCard } from './DestCard' import type { Destination } from '../services/api' const FILTERS = [ { key: 'all', label: '全部' }, { key: 'sea', label: '东南亚' }, { key: 'europe', label: '欧洲' }, { key: 'latam', label: '拉美' }, { key: 'asia', label: '东亚' }, ] const SORTS = [ { key: 'rating', label: '评分' }, { key: 'cost-asc', label: '费用低→高' }, { key: 'cost-desc', label: '费用高→低' }, { key: 'speed', label: '网速' }, ] const isH5 = process.env.TARO_ENV === 'h5' function goDestinations() { if (isH5) { Taro.navigateTo({ url: '/pages/destinations/index' }).catch(() => Taro.redirectTo({ url: '/pages/destinations/index' }) ) return } Taro.navigateTo({ url: '/pages/destinations/index' }).catch(() => Taro.redirectTo({ url: '/pages/destinations/index' }) ) } type Props = { list: Destination[] limit?: number } export function DestinationsSection({ list, limit }: Props) { const [filter, setFilter] = useState('all') const [search, setSearch] = useState('') const [sort, setSort] = useState('rating') const filtered = useMemo(() => { let rows = list.slice() if (filter !== 'all') rows = rows.filter((d) => d.region === filter) if (search.trim()) { const q = search.trim().toLowerCase() rows = rows.filter( (d) => String(d.name).toLowerCase().includes(q) || String(d.country || '').toLowerCase().includes(q), ) } if (sort === 'cost-asc') rows.sort((a, b) => (a.cost || 0) - (b.cost || 0)) else if (sort === 'cost-desc') rows.sort((a, b) => (b.cost || 0) - (a.cost || 0)) else if (sort === 'speed') rows.sort((a, b) => (b.speed || 0) - (a.speed || 0)) else rows.sort((a, b) => (b.rating || 0) - (a.rating || 0)) return rows }, [list, filter, search, sort]) const visible = typeof limit === 'number' ? filtered.slice(0, limit) : filtered const sortIdx = Math.max(0, SORTS.findIndex((s) => s.key === sort)) return ( 🌴 TOP DESTINATIONS 热门旅居目的地 按预算、网速与气候筛选,点进城市看详情 setSearch(e.detail.value)} /> {FILTERS.map((f) => ( ))} s.label)} value={sortIdx} onChange={(e) => setSort(SORTS[Number(e.detail.value)]?.key || 'rating')} > 排序:{SORTS[sortIdx]?.label} {visible.map((d) => ( ))} {typeof limit === 'number' && filtered.length > limit ? ( ) : null} {!visible.length ? 没有匹配的城市 : null} ) }