import React, { useCallback, useEffect, useRef, useState } from 'react' import styles from './index.module.scss' import { A1EditInfoType } from '@/pages/A1goods/data' import { Button, Form, FormInstance, Input, InputNumber } from 'antd' import { A4_APIgetInfo, A4_APIsave } from '@/store/action/A4video' import { MessageFu } from '@/utils/message' import classNames from 'classnames' import ZupOne from '@/components/ZupOne' import TextArea from 'antd/es/input/TextArea' import MyPopconfirm from '@/components/MyPopconfirm' type Props = { editInfo: A1EditInfoType closeFu: () => void addTableFu: () => void editTableFu: () => void } function A4add({ editInfo, closeFu, addTableFu, editTableFu }: Props) { // 表单的ref const FormBoxRef = useRef(null) // 封面图的ref const ZupThumbRef = useRef(null) // 附件的ref const ZupVideoRef = useRef(null) // 编辑/查看 进入页面 获取信息 const getInfoFu = useCallback(async (id: number) => { const res = await A4_APIgetInfo(id) if (res.code === 0) { const info = res.data const obj = { ...info } FormBoxRef.current?.setFieldsValue(obj) // 设置封面图 ZupThumbRef.current?.setFileComFileFu({ fileName: '', filePath: info.thumb }) // 设置附件 ZupVideoRef.current?.setFileComFileFu({ fileName: info.fileName, filePath: info.filePath }) } }, []) // 附件 是否 已经点击过确定 const [fileCheck, setFileCheck] = useState(false) useEffect(() => { if (editInfo.id > 0) { getInfoFu(editInfo.id) } else { FormBoxRef.current?.setFieldsValue({ sort: 999 }) } }, [editInfo.id, getInfoFu]) // 没有通过校验 const onFinishFailed = useCallback(() => { setFileCheck(true) }, []) // 通过校验点击确定 const onFinish = useCallback( async (values: any) => { setFileCheck(true) const coverUrl1 = ZupThumbRef.current?.fileComFileResFu() // 没有传 封面图 if (!coverUrl1.filePath) return // 没有传视频附件 let fileName = '' let filePath = '' // txt附件 const ZupVideoRefObj = ZupVideoRef.current?.fileComFileResFu() fileName = ZupVideoRefObj.fileName filePath = ZupVideoRefObj.filePath if (!filePath) return MessageFu.warning('请上传附件!') const obj = { ...values, id: editInfo.id > 0 ? editInfo.id : null, thumb: coverUrl1.filePath, fileName, filePath } const res = await A4_APIsave(obj) if (res.code === 0) { MessageFu.success(editInfo.txt + '成功!') editInfo.id > 0 ? editTableFu() : addTableFu() closeFu() } }, [addTableFu, closeFu, editInfo.id, editInfo.txt, editTableFu] ) return (
{/* 封面 */}
* 封面:
{editInfo.txt === '查看' ?
: null} {/* 附件 */}
* 附件:
{editInfo.txt === '查看' ?
: null}