import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import styles from './index.module.scss' import { Button, Cascader, DatePicker, Form, FormInstance, Input, InputNumber, Select } from 'antd' import MyPopconfirm from '@/components/MyPopconfirm' import TextArea from 'antd/es/input/TextArea' import ZRichTexts from '@/components/ZRichTexts' import MyTable from '@/components/MyTable' import { Y33tableC } from '@/utils/tableData' import ImageLazy from '@/components/ImageLazy' import YtableVideo from '@/components/YtableVideo' import { selectObj } from '@/utils/select' import dayjs from 'dayjs' import { getTokenInfo } from '@/utils/storage' import Z3upFiles from '@/components/Z3upFiles' import { GoodFileType } from './type' import { baseURL } from '@/utils/http' import { fileImgArr, fileVideoArr } from '@/store/action/layout' import { API_C2dels } from '@/store/action/C2files' import { API_goodsAdd, API_goodsInfo } from '@/store/action/C1ledger' import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type' import { MessageFu } from '@/utils/message' import history, { cascaderObjFu } from '@/utils/history' import ZGaddNow from '@/components/ZGaddNow' // 级联的数据转换成字符串 export const cascaderChArr = [ 'dictType', 'dictAge', 'pcsUnit', 'dictTexture1', 'dictTexture2', 'dictTexture3', 'dictTorn', 'sizeUnit', 'qualityDictScope', 'qualityUnit', 'inDictDateScope', 'source', 'dictHouse1', 'dictHouse2', // 其他模块有的级联字段 'dictAgeFirst' ] // 下拉框为空的时候转变成null export const addZiSelectChArr = ['numName', 'dictLevel', 'accountType'] type Props = { closeFu: () => void nowSta: { key: string; id: string } isEdit: boolean //藏品编辑模块 editSnap?: C1GoodType //藏品模块属于新增还是编辑 succFu: ( obj: C1GoodType, type: '新增' | '编辑', sta: '存草稿' | '提交', flieNew?: GoodFileType[], fileOld?: GoodFileType[], oldInfo?: C1GoodType ) => void } function AddGoods({ nowSta, closeFu, succFu, isEdit, editSnap }: Props) { // 制档日期 / 制档人 const [txtArr, setTxtArr] = useState([getTokenInfo().user.realName, dayjs().format('YYYY-MM-DD')]) // 藏品编辑模块用来对比 const objOld = useRef({}) // 编辑进来获取详情 const getInfo = useCallback( async (id: number) => { const res = await API_goodsInfo(id) if (res.code === 0) { // 藏品编辑信息保存 objOld.current = { ...res.data } // dateMaking inGoodsDate 2个日期需要格式处理一下 const obj = editSnap && editSnap.id ? { ...editSnap } : { ...res.data } if (obj.dateMaking) obj.dateMaking = dayjs(obj.dateMaking) // if (obj.inGoodsDate) obj.inGoodsDate = dayjs(obj.inGoodsDate) setTxtArr([obj.creatorName, dayjs(obj.createTime).format('YYYY-MM-DD')]) cascaderChArr.forEach(v => { if (obj[v]) obj[v] = obj[v].split(',') }) addZiSelectChArr.forEach(v => { if (!obj[v]) obj[v] = null }) FormBoxRef.current?.setFieldsValue(obj) // 设置封面图 // ZupThumbRef.current?.setFileComFileFu({ // fileName: '', // filePath: obj.thumbPc, // thumb: obj.thumb // }) // 设置富文本 if (obj.rtf) ZRichTextRef.current?.ritxtShowFu(JSON.parse(obj.rtf)) // 设置附件 setTable(obj.file || []) } }, [editSnap] ) useEffect(() => { if (nowSta.id !== 'null') { getInfo(Number(nowSta.id)) } }, [getInfo, nowSta.id]) // 设置表单ref const FormBoxRef = useRef(null) // 年代是否选择了其他 const [ageAc, setAgeAc] = useState(false) // 封面图的ref // const ZupThumbRef = useRef(null) // 富文本的ref const ZRichTextRef = useRef(null) // 上传附件的ref const filesRef = useRef(null) // 附件表格 const [table, setTable] = useState([]) // 附件删除记录id const fileDelIdArr = useRef([]) const tableFu = useCallback( (key: 'type' | 'effect', id: number, val: any) => { setTable( table.map(v => ({ ...v, [key]: id === v.id ? val : v[key] })) ) }, [table] ) // 附件类型和附件用途是否禁用 const disabledSelect = useCallback( (id: number) => { let flag = false if (isEdit) { if (objOld.current && objOld.current.file && objOld.current.file.length) { const oldFileIds: number[] = objOld.current.file.map((v: any) => v.id) if (oldFileIds.includes(id)) flag = true } } return flag }, [isEdit] ) // 相关附件的操作 const startBtn = useMemo(() => { return [ { width: 100, title: '缩略图/视频', render: (item: GoodFileType) => { const fileNameArr = item.fileName.split('.') const fileNameLast = fileNameArr[fileNameArr.length - 1] return fileImgArr.includes(fileNameLast) ? (
) : fileVideoArr.includes(fileNameLast) ? ( ) : ( ' - ' ) } }, { title: '附件类型', render: (item: GoodFileType) => (
制档人:
{txtArr[0]}
制档日期:
{txtArr[1]}
藏品基本信息