import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import styles from './index.module.scss' import { useParams } from 'react-router-dom' import { FourTableType } from '@/pages/B_enterTibet/B1collect/type' import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type' import { D6_APIcreate, D6_APIdel, D6_APIgetInfo, D6_APIrevocation, D6_APIsaveApply, D6_APIsaveAudit, D6_APIsaveCreate, D6_APIsaveDraft } from '@/store/action/D6putsStor' import { API_goodsInfo } from '@/store/action/C1ledger' import { pageTitTxtObj } from '../../D4impStor/D4edit' import dayjs from 'dayjs' import { MessageFu } from '@/utils/message' import history, { btnFlagFu2, openGoodsInfoFu } from '@/utils/history' import classNames from 'classnames' import TextArea from 'antd/es/input/TextArea' import { Button, DatePicker, Input, Modal, Radio, Select } from 'antd' import MyPopconfirm from '@/components/MyPopconfirm' import { EXbtnFu } from '@/utils/EXBtn' import X3auditInfo from '@/pages/X_stock/X3auditInfo' import { D6tableCgoods, statusObj } from '@/utils/tableData' import { useDispatch, useSelector } from 'react-redux' import { D2_APIgetList } from '@/store/action/D2storSet' import { RootState } from '@/store' import MyTable from '@/components/MyTable' import ZflowTable from '@/components/ZflowTable' import ZupFileTable from '@/components/ZupFileTable' import Y1cathet from '@/pages/Y_goodsDetails/Y1cathet' import ZGaddNow from '@/components/ZGaddNow' import D6batchInput from './D6batchInput' function D6edit() { // 获取库房设置列表/入馆凭证号-用于分库缩写下拉 const dispatch = useDispatch() useEffect(() => { dispatch(D2_APIgetList({ pageNum: 1, pageSize: 99999 })) }, [dispatch]) const { list: storageIdArr } = useSelector((state: RootState) => state.D2storSet.tableInfo) const { key, id } = useParams() // key:1 新增 2编辑 3审批 4查看 // 滚到顶部 const sollrDom = useRef(null) // 顶部数据 const [topInfo, setTopInfo] = useState({} as FourTableType) // 藏品清单快照数据 const [snaps, setSnaps] = useState([]) const delSnapIdsRef = useRef([]) const snapsID2ref = useRef<{ goodsId: number; id: number }[]>([]) // 创建订单 const creatFu = useCallback(async () => { const res = await D6_APIcreate() if (res.code === 0) { // 从藏品详情点击按钮进来 const urlAll = window.location.href if (urlAll.includes('?id=')) { const urlId = urlAll.split('?id=')[1] const res2 = await API_goodsInfo(Number(urlId)) if (res2.code === 0) { setTopInfo({ ...res.data, storageId: res2.data.storageId, sonTypeName: '1' }) setSnaps([res2.data]) } } else setTopInfo({ ...res.data, sonTypeName: '1' }) } }, []) // 获取详情 const getInfoFu = useCallback(async () => { const res = await D6_APIgetInfo(id) if (res.code === 0) { const data = res.data setTopInfo(data) // 藏品清单快照信息id对比 const arrTemp: any = [] const snapsTemp = data.snaps || [] snapsTemp.forEach((v: any) => { snapsID2ref.current.push({ goodsId: v.goodsId, id: v.id }) const obj = JSON.parse(v.snap || '{}') if (obj.id) obj.id2 = v.id arrTemp.push(obj) }) setSnaps(arrTemp) } }, [id]) useEffect(() => { if (key === '1') creatFu() else getInfoFu() if (sollrDom.current) sollrDom.current.scrollTop = 0 }, [creatFu, getInfoFu, key]) const pageTitTxt = useMemo(() => { return Reflect.get(pageTitTxtObj, key) }, [key]) const timeChange = useCallback( (e: any, key: 'date' | 'returnDate') => { setTopInfo({ ...topInfo, [key]: dayjs(e).format('YYYY-MM-DD') }) }, [topInfo] ) // 审批意见的ref const ZAuditRef = useRef(null) // 审批的sta const [auditSta, setAuDitSta] = useState('') // 字段的校验 const checkFu = useCallback(() => { if (!topInfo.sonTypeName) { MessageFu.warning('请选择提退类型') return true } if (!topInfo.num) { MessageFu.warning('请输入提退单编号') return true } if (topInfo.sonTypeName === '3' && !topInfo.borrowInUnit) { MessageFu.warning('请输入借出单位') return true } if (!topInfo.sonUnit) { MessageFu.warning( `请输入${ topInfo.sonTypeName === '1' ? '提用单位(部门)' : topInfo.sonTypeName === '2' ? '提用部门' : '借入单位' }` ) return true } if (!topInfo.date) { MessageFu.warning(`请选择${topInfo.sonTypeName === '3' ? '借用日期' : '提用日期'}`) return true } if (topInfo.sonTypeName === '3') { if (!topInfo.returnDate) { MessageFu.warning('请选择归还日期') return true } if (!topInfo.receiveUnit) { MessageFu.warning('请输入接收单位') return true } if (!topInfo.returnUnit) { MessageFu.warning('请输入归还单位') return true } } else { if (!topInfo.effect) { MessageFu.warning(`请输入${topInfo.sonTypeName === '2' ? '提用原因' : '提用目的'}`) return true } } if (!topInfo.storageId) { MessageFu.warning('请输入请选择分库缩写') return true } }, [topInfo]) // 新增的底部按钮点击 const btnClickFu = useCallback( async (val: '草稿' | '创建' | '保存' | '审批') => { if (checkFu()) { if (sollrDom.current) sollrDom.current.scrollTop = 0 return } if (val !== '草稿') { if (snaps.length === 0) return MessageFu.warning('请添加藏品') } if (val === '审批') { // console.log('审批信息富文本', rtf2) if (!auditSta) { if (sollrDom.current) sollrDom.current.scrollTop = 0 return MessageFu.warning('请选择审批结果') } const rtf2 = ZAuditRef.current?.resData() const res: any = await D6_APIsaveAudit({ orderId: topInfo.id, rtfOpinion: rtf2, status: auditSta === '同意' ? 1 : 2 }) if (res.code === 0) { MessageFu.success('审批成功') // 跳详情页 history.push(`/putsStor_edit/4/${topInfo.id}`) } } else { const obj = { ...topInfo, goodsIds: snaps.map(v => v.id).join(','), delSnapIds: delSnapIdsRef.current.length ? delSnapIdsRef.current : '', snaps: snaps.map(v => ({ goodsId: v.id, id: v.id2 ? v.id2 : null, orderId: topInfo.id, snap: JSON.stringify(v) })) } // console.log(123, obj.snaps) // if (1 + 1 === 2) return if (val === '草稿') { // 存草稿 当前页保存 不跳转 const res = await D6_APIsaveDraft(obj) if (res.code === 0) { MessageFu.success('草稿保存成功') } } else { const res: any = val === '创建' ? await D6_APIsaveCreate(obj) : await D6_APIsaveApply(obj) if (res.code === 0) { MessageFu.success(`${val}成功`) // 跳到详情页 history.push(`/putsStor_edit/4/${topInfo.id}`) } } } }, [auditSta, checkFu, snaps, topInfo] ) // 打开侧边栏 const [cathet, setCathet] = useState(0) const startBtn = useMemo(() => { const arr: any[] = [ { title: '藏品编号', render: (item: C1GoodType) => { return ( setCathet(item.id)} className={classNames('D1GtNum', item.id === cathet ? 'D1GtNumAc' : '')} > {item.num || '(空)'} ) } }, { title: '编号类型', render: (item: C1GoodType) => item.numName || '(空)' } ] if (topInfo.sonTypeName === '1') { arr.push({ title: '藏品分库号', render: (item: C1GoodType) => item.siteNum }) } return arr }, [cathet, topInfo.sonTypeName]) const tableLastBtn = useMemo(() => { const arr: any[] = [] if (topInfo.sonTypeName !== '3') { arr.push({ title: `${topInfo.sonTypeName === '1' ? '退还人' : '退回者'}`, width: 150, render: (item: C1GoodType) => { const keyTxt = topInfo.sonTypeName === '1' ? 'txt1' : 'txt3' return (