import React, { useState, useCallback, useEffect } from 'react' import { View, Text, Input, Image, Picker } from '@tarojs/components' import PopupGameplay from '../PopupGameplay' import img from '@/config/images'; import { FormFieldConfig } from '@/config/formSchema/publishBallFormSchema'; import SelectStadium from '../SelectStadium/SelectStadium' import { Stadium } from '../SelectStadium/StadiumDetail' import './FormBasicInfo.scss' type PlayGame = { play_type: string // 玩法类型 price: number | string // 价格 venue_id?: number | null // 场地id location_name?: string // 场地名称 location?: string // 场地地址 latitude?: string // 纬度 longitude?: string // 经度 court_type?: string // 场地类型 1: 室内 2: 室外 court_surface?: string // 场地表面 1: 硬地 2: 红土 3: 草地 venue_description_tag?: Array[] // 场地描述标签 venue_description?: string // 场地描述 venue_image_list?: Array[] // 场地图片 } interface FormBasicInfoProps { value: PlayGame onChange: (value: any) => void children: FormFieldConfig[] } const FormBasicInfo: React.FC = ({ value, onChange, children }) => { const [gameplayVisible, setGameplayVisible] = useState(false) const [showStadiumSelector, setShowStadiumSelector] = useState(false) const [playGame, setPlayGame] = useState<{label: string, value: string }[]>([]) const handleGameplaySelect = () => { setGameplayVisible(true) } const handleGameplayConfirm = (selectedGameplay: string) => { onChange({...value, [children[2].prop]: selectedGameplay}) setGameplayVisible(false) } const handleGameplayClose = () => { setGameplayVisible(false) } // 处理场馆选择 const handleStadiumSelect = (stadium: Stadium | null) => { console.log(stadium,'stadiumstadium'); const { address, name, latitude, longitude, court_type, court_surface, description, description_tag, venue_image_list} = stadium || {}; onChange({...value, venue_id: stadium?.id, location_name: name, location: address, latitude, longitude, court_type, court_surface, venue_description: description, venue_description_tag: description_tag, venue_image_list }) setShowStadiumSelector(false) } const handleChange = useCallback((key: string, value: any) => { onChange({...value, [key]: value}) }, [onChange]) useEffect(() => { if (children.length > 2) { const options = children[2]?.options || []; setPlayGame(options) } }, [children]) const renderChildren = () => { return children.map((child: any, index: number) => { return { index === 0 && ( {child.label} handleChange(child.prop, e.detail.value)} /> 元/每人 ) } { index === 1 && ( {child.label} setShowStadiumSelector(true)}> {value[child.prop] ? value[child.prop] : '请选择'} ) } { index === 2 && ( {child.label} {value[child.prop] ? value[child.prop] : '请选择'} ) } }) } return ( {/* 费用 */} {renderChildren()} {/* 玩法选择弹窗 */} {/* 场馆选择弹窗 */} setShowStadiumSelector(false)} onConfirm={handleStadiumSelect} /> ) } export default FormBasicInfo