|
|
@@ -1,61 +1,82 @@
|
|
|
-import React, { useState, useEffect } from 'react'
|
|
|
+import React from 'react'
|
|
|
import { View, Text, Image, ScrollView } from '@tarojs/components'
|
|
|
import { useRouter, navigateTo } from '@tarojs/taro'
|
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
import { routeClient } from '../../api'
|
|
|
-import { LocationSearch } from '../../components/LocationSearch'
|
|
|
|
|
|
interface Activity {
|
|
|
id: number
|
|
|
name: string
|
|
|
description?: string
|
|
|
+ type: 'departure' | 'return'
|
|
|
+ startDate: string
|
|
|
+ endDate: string
|
|
|
+ imageUrl?: string
|
|
|
venueLocationId: number
|
|
|
- venueLocation?: {
|
|
|
+ venueLocation: {
|
|
|
id: number
|
|
|
name: string
|
|
|
provinceId: number
|
|
|
cityId: number
|
|
|
districtId: number
|
|
|
address: string
|
|
|
+ latitude: string
|
|
|
+ longitude: string
|
|
|
+ province: {
|
|
|
+ id: number
|
|
|
+ name: string
|
|
|
+ level: number
|
|
|
+ code: string
|
|
|
+ isDisabled: number
|
|
|
+ isDeleted: number
|
|
|
+ createdBy?: any
|
|
|
+ updatedBy?: any
|
|
|
+ createdAt: string
|
|
|
+ updatedAt: string
|
|
|
+ }
|
|
|
+ city: {
|
|
|
+ id: number
|
|
|
+ name: string
|
|
|
+ level: number
|
|
|
+ code: string
|
|
|
+ isDisabled: number
|
|
|
+ isDeleted: number
|
|
|
+ createdBy?: any
|
|
|
+ updatedBy?: any
|
|
|
+ createdAt: string
|
|
|
+ updatedAt: string
|
|
|
+ }
|
|
|
+ district: {
|
|
|
+ id: number
|
|
|
+ name: string
|
|
|
+ level: number
|
|
|
+ code: string
|
|
|
+ isDisabled: number
|
|
|
+ isDeleted: number
|
|
|
+ createdBy?: any
|
|
|
+ updatedBy?: any
|
|
|
+ createdAt: string
|
|
|
+ updatedAt: string
|
|
|
+ }
|
|
|
+ isDisabled: number
|
|
|
+ isDeleted: number
|
|
|
+ createdBy?: any
|
|
|
+ updatedBy?: any
|
|
|
+ createdAt: string
|
|
|
+ updatedAt: string
|
|
|
}
|
|
|
- startDate: string
|
|
|
- endDate: string
|
|
|
- type: 'departure' | 'return'
|
|
|
- imageUrl?: string
|
|
|
+ isDisabled: number
|
|
|
+ isDeleted: number
|
|
|
+ createdBy?: any
|
|
|
+ updatedBy?: any
|
|
|
+ createdAt: string
|
|
|
+ updatedAt: string
|
|
|
}
|
|
|
|
|
|
-interface Route {
|
|
|
- id: number
|
|
|
- startLocation: {
|
|
|
- name: string
|
|
|
- province?: string
|
|
|
- city?: string
|
|
|
- district?: string
|
|
|
- }
|
|
|
- endLocation: {
|
|
|
- name: string
|
|
|
- province?: string
|
|
|
- city?: string
|
|
|
- district?: string
|
|
|
- }
|
|
|
- activities: Activity[]
|
|
|
- routeType: 'departure' | 'return'
|
|
|
-}
|
|
|
|
|
|
-interface Location {
|
|
|
- id: number
|
|
|
- name: string
|
|
|
- province?: string
|
|
|
- city?: string
|
|
|
- district?: string
|
|
|
- address?: string
|
|
|
-}
|
|
|
|
|
|
const ActivitySelectPage: React.FC = () => {
|
|
|
const router = useRouter()
|
|
|
- const [selectedActivity, setSelectedActivity] = useState<Activity | null>(null)
|
|
|
- const [startLocation, setStartLocation] = useState<Location | null>(null)
|
|
|
- const [endLocation, setEndLocation] = useState<Location | null>(null)
|
|
|
|
|
|
// 从路由参数获取查询条件
|
|
|
const searchParams = {
|
|
|
@@ -67,40 +88,35 @@ const ActivitySelectPage: React.FC = () => {
|
|
|
|
|
|
// 查询路线和关联活动
|
|
|
const { data: routeData, isLoading } = useQuery({
|
|
|
- queryKey: ['routes', 'search', searchParams, startLocation, endLocation],
|
|
|
+ queryKey: ['routes', 'search', searchParams],
|
|
|
queryFn: async () => {
|
|
|
- if (!startLocation?.id || !endLocation?.id) {
|
|
|
- return { routes: [], activities: [] }
|
|
|
- }
|
|
|
-
|
|
|
+ // 根据省市区查询该地区的路线和活动
|
|
|
const res = await routeClient.search.$get({
|
|
|
query: {
|
|
|
- startLocationId: startLocation.id,
|
|
|
- endLocationId: endLocation.id,
|
|
|
+ startAreaIds: JSON.stringify(searchParams.startAreaIds),
|
|
|
+ endAreaIds: JSON.stringify(searchParams.endAreaIds),
|
|
|
date: searchParams.date,
|
|
|
- routeType: 'all',
|
|
|
sortBy: 'departureTime',
|
|
|
- sortOrder: 'asc'
|
|
|
+ sortOrder: 'ASC'
|
|
|
}
|
|
|
})
|
|
|
if (res.status !== 200) throw new Error('查询路线失败')
|
|
|
const data = await res.json()
|
|
|
return data.data || { routes: [], activities: [] }
|
|
|
},
|
|
|
- enabled: !!startLocation?.id && !!endLocation?.id
|
|
|
+ enabled: searchParams.startAreaIds?.length > 0 && searchParams.endAreaIds?.length > 0
|
|
|
})
|
|
|
|
|
|
- const routes = routeData?.routes || []
|
|
|
const activities = routeData?.activities || []
|
|
|
|
|
|
// 分离去程和返程活动
|
|
|
- const departureActivities = activities
|
|
|
+ const departureActivities = (activities as Activity[])
|
|
|
.filter((activity: Activity) => activity.type === 'departure')
|
|
|
.filter((activity, index, self) =>
|
|
|
index === self.findIndex(a => a.id === activity.id)
|
|
|
)
|
|
|
|
|
|
- const returnActivities = activities
|
|
|
+ const returnActivities = (activities as Activity[])
|
|
|
.filter((activity: Activity) => activity.type === 'return')
|
|
|
.filter((activity, index, self) =>
|
|
|
index === self.findIndex(a => a.id === activity.id)
|
|
|
@@ -108,18 +124,11 @@ const ActivitySelectPage: React.FC = () => {
|
|
|
|
|
|
// 选择活动
|
|
|
const handleSelectActivity = (activity: Activity, routeType: 'departure' | 'return') => {
|
|
|
- setSelectedActivity(activity)
|
|
|
-
|
|
|
- if (!startLocation?.id || !endLocation?.id) {
|
|
|
- console.log('请先选择出发地和目的地')
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
// 导航到班次列表页面
|
|
|
navigateTo({
|
|
|
url: `/pages/schedule-list/ScheduleListPage?` +
|
|
|
- `startLocationId=${startLocation.id}&` +
|
|
|
- `endLocationId=${endLocation.id}&` +
|
|
|
+ `startAreaIds=${JSON.stringify(searchParams.startAreaIds)}&` +
|
|
|
+ `endAreaIds=${JSON.stringify(searchParams.endAreaIds)}&` +
|
|
|
`date=${searchParams.date}&` +
|
|
|
`vehicleType=${searchParams.vehicleType}&` +
|
|
|
`activityId=${activity.id}&` +
|
|
|
@@ -130,23 +139,24 @@ const ActivitySelectPage: React.FC = () => {
|
|
|
// 获取活动显示信息
|
|
|
const getActivityDisplayInfo = (activity: Activity) => {
|
|
|
const venue = activity.venueLocation
|
|
|
- const locationParts = []
|
|
|
- if (venue?.district) locationParts.push(venue.district)
|
|
|
- if (venue?.city) locationParts.push(venue.city)
|
|
|
- if (venue?.province) locationParts.push(venue.province)
|
|
|
+ const locationParts: string[] = []
|
|
|
+ if (venue.district?.name) locationParts.push(venue.district.name)
|
|
|
+ if (venue.city?.name) locationParts.push(venue.city.name)
|
|
|
+ if (venue.province?.name) locationParts.push(venue.province.name)
|
|
|
|
|
|
return {
|
|
|
location: locationParts.join(' · '),
|
|
|
- address: venue?.address,
|
|
|
+ address: venue.address,
|
|
|
date: new Date(activity.startDate).toLocaleDateString('zh-CN')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取路线信息显示
|
|
|
const getRouteInfo = () => {
|
|
|
+ // 这里可以根据省市区ID获取地区名称,暂时使用默认值
|
|
|
return {
|
|
|
- fromCity: startLocation?.name || '出发地',
|
|
|
- toCity: endLocation?.name || '目的地'
|
|
|
+ fromCity: '出发地',
|
|
|
+ toCity: '目的地'
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -172,62 +182,15 @@ const ActivitySelectPage: React.FC = () => {
|
|
|
</Text>
|
|
|
</View>
|
|
|
|
|
|
- {/* 地点选择区域 */}
|
|
|
- <View className="bg-white p-4 border-b border-gray-200">
|
|
|
- <Text className="text-sm font-medium text-gray-700 mb-2 block">
|
|
|
- 请选择具体地点
|
|
|
- </Text>
|
|
|
- <View className="space-y-3">
|
|
|
- {/* 出发地点选择 */}
|
|
|
- <View>
|
|
|
- <Text className="text-sm text-gray-600 mb-1 block">出发地点</Text>
|
|
|
- <LocationSearch
|
|
|
- value={startLocation}
|
|
|
- onChange={setStartLocation}
|
|
|
- placeholder="搜索出发地点"
|
|
|
- areaFilter={{
|
|
|
- provinceId: searchParams.startAreaIds?.[0],
|
|
|
- cityId: searchParams.startAreaIds?.[1],
|
|
|
- districtId: searchParams.startAreaIds?.[2]
|
|
|
- }}
|
|
|
- />
|
|
|
- </View>
|
|
|
-
|
|
|
- {/* 目的地点选择 */}
|
|
|
- <View>
|
|
|
- <Text className="text-sm text-gray-600 mb-1 block">目的地点</Text>
|
|
|
- <LocationSearch
|
|
|
- value={endLocation}
|
|
|
- onChange={setEndLocation}
|
|
|
- placeholder="搜索目的地点"
|
|
|
- areaFilter={{
|
|
|
- provinceId: searchParams.endAreaIds?.[0],
|
|
|
- cityId: searchParams.endAreaIds?.[1],
|
|
|
- districtId: searchParams.endAreaIds?.[2]
|
|
|
- }}
|
|
|
- />
|
|
|
- </View>
|
|
|
- </View>
|
|
|
- </View>
|
|
|
|
|
|
<ScrollView className="flex-1">
|
|
|
<View className="p-4">
|
|
|
- {!startLocation?.id || !endLocation?.id ? (
|
|
|
- <View className="bg-white rounded-lg border border-gray-200 p-8 text-center">
|
|
|
- <Text className="text-4xl mb-4">📍</Text>
|
|
|
- <Text className="text-lg text-gray-600 block mb-2">请先选择出发地和目的地</Text>
|
|
|
- <Text className="text-sm text-gray-500">
|
|
|
- 在上方搜索框中选择具体的出发地和目的地
|
|
|
- </Text>
|
|
|
- </View>
|
|
|
- ) : (
|
|
|
- <>
|
|
|
- <Text className="text-lg font-bold text-gray-800 mb-2 block">
|
|
|
- 选择观看活动
|
|
|
- </Text>
|
|
|
- <Text className="text-sm text-gray-500 mb-4 block">
|
|
|
- 系统已为您自动匹配出发地和目的地的热门活动
|
|
|
- </Text>
|
|
|
+ <Text className="text-lg font-bold text-gray-800 mb-2 block">
|
|
|
+ 选择观看活动
|
|
|
+ </Text>
|
|
|
+ <Text className="text-sm text-gray-500 mb-4 block">
|
|
|
+ 系统已为您自动匹配出发地和目的地的热门活动
|
|
|
+ </Text>
|
|
|
|
|
|
{/* 去程活动区域 */}
|
|
|
<View className="mb-6">
|
|
|
@@ -363,8 +326,6 @@ const ActivitySelectPage: React.FC = () => {
|
|
|
</Text>
|
|
|
</View>
|
|
|
)}
|
|
|
- </>
|
|
|
- )}
|
|
|
</View>
|
|
|
</ScrollView>
|
|
|
</View>
|