import React, { useCallback, useEffect, useRef, useState } from 'react' import styles from './index.module.scss' import { useParams } from 'react-router-dom' import ZexhiBtn from '@/components/ZexhiBtn' import { Button, Form, FormInstance, Input, InputNumber, Select } from 'antd' import ZinfoPop from '@/components/ZinfoPop' import history from '@/utils/history' import classNames from 'classnames' import { MessageFu } from '@/utils/message' import delImg from '@/assets/img/exhibit/del.png' import MyPopconfirm from '@/components/MyPopconfirm' import { B3_APIgetList, B4_APIsave } from '@/store/action/all' import { B3ListApiType } from '../B3start/type' import ZselectCity from '@/components/ZselectCity' import TextArea from 'antd/es/input/TextArea' import { papersSelArr } from './data' function B4form() { // useEffect(() => { // FormBoxRef.current?.setFieldsValue({ // name1: '王大锤', // phone1: '18702025091', // identity1: '421083199504071212' // }) // }, []) // 获取路由参数 const [urlObj, setUrlObj] = useState({ bookDate: '', bookId: 0, time: '' }) // 路由参数key,1:个人/2:团体 const urlObjTemp: any = useParams() const getInfoFu = useCallback(async () => { const res = await B3_APIgetList() if (res.code === 0) { const list: B3ListApiType[] = res.data const index = Number(urlObjTemp.index) setUrlObj({ bookDate: urlObjTemp.bookDate.replaceAll('_', '-'), bookId: list[index].id, time: list[index].time }) } }, [urlObjTemp]) useEffect(() => { getInfoFu() }, [getInfoFu]) // 表单的ref const FormBoxRef = useRef(null) const [formArr, setFormArr] = useState([{ id: 1 }]) const formArrNumRef = useRef(1) // 点击新增 参观人 const addFormFu = useCallback(() => { if (formArr.length >= 5) return MessageFu.warning('最多5位!') setFormArr([...formArr, { id: formArrNumRef.current + 1 }]) formArrNumRef.current += 1 }, [formArr]) // 点击删除 参观人 const delFormFu = useCallback( (id: number) => { setFormArr(formArr.filter(v => v.id !== id)) }, [formArr] ) // 选择地区的ref const selectCityRef = useRef(null) // 没有通过校验 const onFinishFailed = useCallback(() => {}, []) // 打开提示弹窗 const [titPop, setTitPop] = useState('') // 通过校验点击确定 const onFinish = useCallback( async (values: any) => { if (values.teamPcs && values.teamPcs > 20) return MessageFu.warning('参团人数最多20人!') const cityArr = selectCityRef.current.getValue() if (cityArr.length < 2) return MessageFu.warning('请选择地区!') const arr: any = [] formArr.forEach(v => { arr.push({ bookDate: urlObj.bookDate, bookId: urlObj.bookId, time: urlObj.time, name: values[`name${v.id}`], phone: values[`phone${v.id}`], identity: values[`identity${v.id}`], papers: values[`papers${v.id}`], province: cityArr[0], city: cityArr[1] }) }) const obj = { info: arr, teamDesc: values.teamDesc, teamPcs: values.teamPcs, type: urlObjTemp.key === '1' ? 'person' : 'team' } // if (1 + 1 === 2) { // console.log(123, obj) // return // } const res = await B4_APIsave(obj) if (res.code === 0) setTitPop('succ') }, [formArr, urlObj.bookDate, urlObj.bookId, urlObj.time, urlObjTemp.key] ) return (

预约日期: {urlObj.bookDate}

入馆时间: {urlObj.time}

预约类型: {urlObjTemp.key === '1' ? '个人预约' : '团队预约'}

{/* 按钮 */} {/* 个人预约才有 */} {urlObjTemp.key === '1' ? (
= 5 ? 'myBtnNo' : '')} onClick={addFormFu} > 新增参观人(最多5位)
) : null} {/* 地区选择 */}
* 来自地区
{/* 卡片 */} {formArr.map((item, index) => (
{urlObjTemp.key === '1' ? `参观人信息${index + 1}` : '负责人信息'}
{formArr.length <= 1 ? (
) : ( delFormFu(item.id)} Dom={
删除
} /> )}
e.target.value.replace(/\s+/g, '')} >
))} {/* 团体才有的,团队信息 */} {urlObjTemp.key === '2' ? (
团队信息