import React, { useState, useCallback } from 'react'
import Taro from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'
import images from '@/config/images'
import './StadiumDetail.scss'
import TextareaTag from '@/components/TextareaTag'
import CoverImageUpload, { type CoverImage } from '@/components/ImageUpload'
export interface Stadium {
id?: string
name: string
address?: string
longitude?: number
latitude?: number
istance?: string
}
interface StadiumDetailProps {
stadium: Stadium
onBack: () => void
onConfirm: (stadium: Stadium, venueType: string, groundMaterial: string, additionalInfo: string) => void
}
const stadiumInfo = [
{
label: '场地类型',
options: ['室内', '室外', '室外雨棚'],
prop: 'venueType',
type: 'tags'
},
{
label: '地面材质',
options: ['硬地', '红土', '草地'],
prop: 'groundMaterial',
type: 'tags'
},
{
label: '场地信息补充',
options: ['1号场', '2号场', '3号场', '4号场', '有空调', '6号场','6号场'],
prop: 'additionalInfo',
type: 'textareaTag'
},
{
label: '场地预定截图',
options: ['有其他场地信息可备注'],
prop: 'imagesList',
type: 'image'
}
]
// 公共的标题组件
const SectionTitle: React.FC<{ title: string,prop: string }> = ({ title, prop }) => {
console.log(prop,'propprop');
if (prop === 'imagesList') {
return (
{title}
添加截图,平台会优先推荐
)
}
return (
{title}
)
}
// 公共的容器组件
const SectionContainer: React.FC<{ title: string; children: React.ReactNode, prop: string }> = ({ title, children, prop }) => (
{children}
)
const StadiumDetail: React.FC = ({
stadium,
}) => {
const [formData, setFormData] = useState({
stadiumName: stadium.name,
stadiumAddress: stadium.address,
stadiumLongitude: stadium.longitude,
stadiumLatitude: stadium.latitude,
istance: stadium.istance,
venueType: '室内',
groundMaterial: '硬地',
additionalInfo: '',
imagesList: [] as CoverImage[]
})
const handleMapLocation = () => {
Taro.chooseLocation({
success: (res) => {
console.log(res,'resres');
setFormData({
...formData,
stadiumName: res.name,
stadiumAddress: res.address,
stadiumLongitude: res.longitude,
stadiumLatitude: res.latitude
})
},
fail: (err) => {
console.error('选择位置失败:', err)
Taro.showToast({
title: '位置选择失败',
icon: 'error'
})
}
})
}
const updateFormData = useCallback((prop: string, value: any) => {
setFormData(prev => ({ ...prev, [prop]: value }))
}, [])
const getSelectedByLabel = useCallback((label: string) => {
if (label === '场地类型') return formData.venueType
if (label === '地面材质') return formData.groundMaterial
return ''
}, [formData.venueType, formData.groundMaterial])
console.log(stadium,'stadiumstadium');
return (
{/* 已选球场 */}
handleMapLocation()}
>
{formData.stadiumName}
{formData.istance} ·
{formData.stadiumAddress}
{stadiumInfo.map((item) => {
if (item.type === 'tags') {
const selected = getSelectedByLabel(item.label)
return (
{item.options.map((opt) => (
updateFormData(item.prop, opt)}
>
{opt}
))}
)
}
if (item.type === 'textareaTag') {
return (
updateFormData(item.prop, value)}
placeholder='有其他场地信息可备注'
options={(item.options || []).map((o) => ({ label: o, value: o }))}
/>
)
}
if (item.type === 'image') {
return (
updateFormData(item.prop, images)}
/>
)
}
return null
})}
)
}
export default StadiumDetail