import React, { useCallback, useEffect, useRef, useState } from 'react' import styles from './index.module.scss' import { Button, DatePicker, Form, FormInstance, Input, InputNumber, Radio, Select } from 'antd' import { A1EditInfoType } from '@/pages/A1event/data' import { A2_APIgetInfo, A2_APIsave } from '@/store/action/A2exhibition' import dayjs from 'dayjs' import { MessageFu } from '@/utils/message' import classNames from 'classnames' import ZupAudio from '@/components/ZupAudio' import ZupOne from '@/components/ZupOne' import MyPopconfirm from '@/components/MyPopconfirm' import ZRichTexts from '@/components/ZRichTexts' import TextArea from 'antd/es/input/TextArea' import ZupTypes from '@/components/ZupTypes' const { RangePicker } = DatePicker type Props = { editInfo: A1EditInfoType closeFu: () => void editTableFu: () => void addTableFu: () => void } function A2add({ editInfo, closeFu, editTableFu, addTableFu }: Props) { const [dirCode, setDirCode] = useState('') // 表单的ref const FormBoxRef = useRef(null) // 封面图的ref const ZupThumbRef = useRef(null) // PC海报图的ref const ZupPcImgRef = useRef(null) // 富文本的ref const ZRichTextRef = useRef(null) // 展品的ref const ZupFilesRef1 = useRef(null) // 展馆的ref const ZupFilesRef2 = useRef(null) // 标题的音频 const [nameAudio, setNameAudio] = useState({ fileName: '', filePath: '' }) // 编辑/查看 进入页面 获取信息 const getInfoFu = useCallback(async (id: number) => { const res = await A2_APIgetInfo(id) if (res.code === 0) { const data = res.data setDirCode(data.dirCode) // 展示展品 ZupFilesRef1.current?.setFileComFileFu({ type: 'img', fileList: data.exhibitsFile || [] }) // 展示展馆 ZupFilesRef2.current?.setFileComFileFu({ type: 'img', fileList: data.exhibitionFile || [] }) // 设置 临时展览 / 常设展览 setTimeType(data.type) // 设置 常设展览描述 setTimeVal(data.typeRemark) // 设置 临时展览 时间 if (data.dateStart && data.dateEnd) { setTimeArr([dayjs(data.dateStart), dayjs(data.dateEnd)]) } // 设置地址 setAddrType({ key: data.addrType, txt: data.address }) // 设置标题的 音频 if (data.fileName && data.filePath) { setNameAudio({ fileName: data.fileName, filePath: data.filePath }) } // 设置富文本 ZRichTextRef.current?.ritxtShowFu(JSON.parse(data.rtf)) const obj = { ...data, myTime: dayjs(data.datePublish) } FormBoxRef.current?.setFieldsValue(obj) // 设置封面图 ZupThumbRef.current?.setFileComFileFu({ fileName: '', filePath: data.thumb }) // 设置Pc海报 ZupPcImgRef.current?.setFileComFileFu({ fileName: '', filePath: data.thumbPc }) } }, []) // 临时展览 常设展览的切换 const [timeType, setTimeType] = useState('long') const [timeVal, setTimeVal] = useState('') // 格式为dayjs的格式,需要转换 const [timeArr, setTimeArr] = useState(null) // 地址 const [addrType, setAddrType] = useState({ key: 'inland', txt: '' }) const addrTypeChangeFu = useCallback( (key: 'key' | 'txt', val: string) => { setAddrType({ ...addrType, [key]: val }) }, [addrType] ) // 附件 是否 已经点击过确定 const [fileCheck, setFileCheck] = useState(false) // 没有通过校验 const onFinishFailed = useCallback(() => { setFileCheck(true) }, []) // 通过校验点击确定 const onFinish = useCallback( async (values: any) => { setFileCheck(true) const coverUrl1 = ZupThumbRef.current?.fileComFileResFu() // 没有传 封面图 if (!coverUrl1.filePath) return MessageFu.warning('请上传封面图!') // 发布日期 const datePublish = dayjs(values.myTime).format('YYYY-MM-DD') // 临时展览的时候要判断 if (timeType === 'temp') { if (!timeArr || !timeArr[0]) return MessageFu.warning('请选择临时展览时间!') } // 地址校验 if (!addrType.txt) return MessageFu.warning('请输入地址!') let dateStart = '' let dateEnd = '' if (timeArr && timeArr[0] && timeArr[1]) { dateStart = dayjs(timeArr[0]).format('YYYY-MM-DD') dateEnd = dayjs(timeArr[1]).format('YYYY-MM-DD') } // 富文本校验不通过 const rtf = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true } if (rtf.flag) return MessageFu.warning('请输入完整正文!') // 展品的校验 const { sonFileIds: exhibitsFileIds } = ZupFilesRef1.current?.fileComFileResFu() if (exhibitsFileIds.length <= 0) { return MessageFu.warning('请最少上传一个展品!') } // 展馆的校验 const { sonFileIds: exhibitionFileIds } = ZupFilesRef2.current?.fileComFileResFu() if (exhibitionFileIds.length <= 0) { return MessageFu.warning('请最少上传一个展馆!') } // pc海报 const coverUrl2 = ZupPcImgRef.current?.fileComFileResFu() // 富文本标题集合 let rtfNameArr: string[] = [] if (rtf.val && rtf.val.txtArr && rtf.val.txtArr.length) { rtfNameArr = rtf.val.txtArr.map((v: any) => v.name) } const obj = { ...values, id: editInfo.id > 0 ? editInfo.id : null, datePublish, thumb: coverUrl1.filePath, thumbPc: coverUrl2.filePath, rtf: JSON.stringify(rtf.val || ''), fileName: nameAudio.fileName, filePath: nameAudio.filePath, type: timeType, dateStart, dateEnd, addrType: addrType.key, address: addrType.txt, exhibitsFileIds: exhibitsFileIds.join(','), exhibitionFileIds: exhibitionFileIds.join(','), dirCode, typeRemark: timeVal, rtfTitle: JSON.stringify(rtfNameArr) } // if (obj) { // console.log(123, obj); // return; // } const res = await A2_APIsave(obj) if (res.code === 0) { MessageFu.success(`${editInfo.txt}成功!`) editInfo.id > 0 ? editTableFu() : addTableFu() closeFu() } }, [ timeVal, dirCode, addTableFu, addrType.key, addrType.txt, closeFu, editInfo.id, editInfo.txt, editTableFu, nameAudio.fileName, nameAudio.filePath, timeArr, timeType ] ) useEffect(() => { if (editInfo.id > 0) { getInfoFu(editInfo.id) } else { setDirCode(Date.now() + '') FormBoxRef.current?.setFieldsValue({ myTime: dayjs(Date.now()), sort: 999, display: 1 }) } }, [editInfo.id, getInfoFu]) return (
e.target.value.replace(/\s+/g, "")} >