import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import styles from './index.module.scss' import { pageTitTxtObj } from '../../D4impStor/D4edit' import { useParams } from 'react-router-dom' import { Button, Cascader, DatePicker, Input, Radio, Select } from 'antd' import { B3aForm1 } from '@/pages/B_enterTibet/B3_4page/B3edit/data' import dayjs from 'dayjs' import Z3upFiles from '@/components/Z3upFiles' import ZRichTexts from '@/components/ZRichTexts' import { MessageFu } from '@/utils/message' import history, { btnFlagFu2, cascaderObjFu, openGoodsInfoFu } from '@/utils/history' import B3GaddNow from '@/pages/B_enterTibet/B3goodsTable/B3GaddNow' import MyTable from '@/components/MyTable' import classNames from 'classnames' import MyPopconfirm from '@/components/MyPopconfirm' import { D4goodsTableC, statusObj } from '@/utils/tableData' import Y1cathet from '@/pages/Y_goodsDetails/Y1cathet' import X3auditInfo from '@/pages/X_stock/X3auditInfo' import B3flowTable from '@/pages/B_enterTibet/B3flowTable' import { FourTableType } from '@/pages/B_enterTibet/B3_4page/type' import { useDispatch, useSelector } from 'react-redux' import { D2_APIgetList } from '@/store/action/D2storSet' import { RootState } from '@/store' import { D6_APIcreate, D6_APIdel, D6_APIgetInfo, D6_APIrevocation, D6_APIsaveApply, D6_APIsaveAudit, D6_APIsaveCreate, D6_APIsaveDraft } from '@/store/action/D6putsStor' import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type' import { EXbtnFu } from '@/utils/EXBtn' import D6impRelation from '../D6impRelation' function D6edit() { const { key, id } = useParams() // key:1 新增 2编辑 3审批 4查看 // 滚到顶部 const sollrDom = useRef(null) // 顶部数据 const [topInfo, setTopInfo] = useState({} as FourTableType) // 出库库房数组信息 const dispatch = useDispatch() useEffect(() => { dispatch(D2_APIgetList({ pageNum: 1, pageSize: 99999 })) }, [dispatch]) const { list: storSetList } = useSelector((state: RootState) => state.D2storSet.tableInfo) // 库房负责人txt const managerUser = useMemo(() => { let txt = '' if (topInfo.storageId && storSetList.length) { let obj = storSetList.find(v => v.id === topInfo.storageId) if (obj) txt = obj.managerUser } return txt }, [storSetList, topInfo.storageId]) // 创建订单 const creatFu = useCallback(async () => { const res = await D6_APIcreate() if (res.code === 0) { setTopInfo({ ...res.data, isReturn: 0 }) } }, []) // 获取详情 const getInfoFu = useCallback(async () => { const res = await D6_APIgetInfo(id) if (res.code === 0) { setTopInfo(res.data) // 设置富文本 ZRichTextRef.current?.ritxtShowFu(JSON.parse(res.data.rtf) || '{}') } }, [id]) useEffect(() => { if (key === '1') creatFu() else getInfoFu() if (sollrDom.current) sollrDom.current.scrollTop = 0 }, [creatFu, getInfoFu, key]) // 上传附件的ref const filesRef = useRef(null) // const filesRes = filesRef.current.filesIdRes(); // 富文本的ref const ZRichTextRef = useRef(null) // 审批意见的ref const ZAuditRef = useRef(null) const pageTitTxt = useMemo(() => { return Reflect.get(pageTitTxtObj, key) }, [key]) const timeChange = useCallback( (e: any) => { setTopInfo({ ...topInfo, date: dayjs(e).format('YYYY-MM-DD') }) }, [topInfo] ) const checkDataFu = useCallback(() => { if (!topInfo.name) { MessageFu.warning('申请名称不能为空') return true } if (!topInfo.sonTypeName) { MessageFu.warning('请选择业务类型') return true } if (!topInfo.storageId) { MessageFu.warning('请选择出库库房') return true } return false }, [topInfo]) // 审批的sta const [auditSta, setAuDitSta] = useState('') // 新增的底部按钮点击 const btnClickFu = useCallback( async (val: '草稿' | '创建' | '保存' | '审批') => { if (checkDataFu()) return if (val !== '草稿') { if (!topInfo.goods || (topInfo.goods && topInfo.goods.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 = 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 rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true } // console.log('申请信息富文本', JSON.stringify(rtf1.val || '')) // 上传附件 const filesRes = filesRef.current.filesIdRes() const obj = { ...topInfo, fileIds: filesRes.join(','), rtf: JSON.stringify(rtf1.val || ''), goodsIds: topInfo.goods.map(v => v.id).join(',') } // console.log(123, obj) // if (1 + 1 === 2) return if (val === '草稿') { // 存草稿 当前页保存 不跳转 const res = await D6_APIsaveDraft(obj) if (res.code === 0) { MessageFu.success('草稿保存成功') } } else { const res = val === '创建' ? await D6_APIsaveCreate(obj) : await D6_APIsaveApply(obj) if (res.code === 0) { MessageFu.success(`${val}成功`) // 跳到详情页 history.push(`/putsStor_edit/4/${topInfo.id}`) } } } }, [auditSta, checkDataFu, topInfo] ) // 打开侧边栏 const [cathet, setCathet] = useState(0) const startBtn = useMemo(() => { return [ { title: '藏品编号', render: (item: C1GoodType) => { return ( setCathet(item.id)} className={classNames('D1GtNum', item.id === cathet ? 'D1GtNumAc' : '')} > {item.num} ) } } ] }, [cathet]) const tableLastBtn = useMemo(() => { return [ { title: '出库位置', width: 200, render: (item: C1GoodType) => { return item.siteStr ? item.siteStr.replaceAll(',', ' / ') : '(空)' } }, { title: '操作', render: (item: C1GoodType) => { return ( <> {['3', '4'].includes(key) ? null : ( setTopInfo({ ...topInfo, goods: topInfo.goods.filter(v => v.id !== item.id) }) } /> )} ) } } ] }, [key, topInfo]) // 点击新增 const [nowSta, setNowSta] = useState({ key: '', id: '' }) // 查看的按钮创建-提交-撤回 const lookBtnFu = useCallback( async (val: '创建' | '提交' | '撤回') => { if (val !== '撤回') { if (!topInfo.goods || (topInfo.goods && topInfo.goods.length === 0)) { return MessageFu.warning('请添加藏品') } } const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true } // console.log('申请信息富文本', JSON.stringify(rtf1.val || '')) // 上传附件 const filesRes = filesRef.current.filesIdRes() const obj = { ...topInfo, fileIds: filesRes.join(','), rtf: JSON.stringify(rtf1.val || ''), goodsIds: topInfo.goods.map(v => v.id).join(',') } const res = val === '创建' ? await D6_APIsaveCreate(obj) : val === '提交' ? await D6_APIsaveApply(obj) : await D6_APIrevocation(id) if (res.code === 0) { if (sollrDom.current) sollrDom.current.scrollTop = 0 MessageFu.success(val + '成功') getInfoFu() } }, [getInfoFu, id, topInfo] ) // 查看模式点击删除 const delFu = useCallback(async () => { const res = await D6_APIdel(id) if (res.code === 0) { MessageFu.success('删除成功') history.push('/putsStor') } }, [id]) // 查看模式点击审批 编辑 const lookJumpFu = useCallback( (val: '审批' | '编辑') => { history.push(`/putsStor_edit/${val === '审批' ? 3 : 2}/${id}`) MessageFu.success(`已跳转至${val}页面`) }, [id] ) // 查看模式下的按钮 const lookBtn = useMemo(() => { return ( <> {btnFlagFu2(topInfo)['创建'] ? ( ) : null} {btnFlagFu2(topInfo)['提交'] ? ( ) : null} {btnFlagFu2(topInfo)['撤回'] ? ( lookBtnFu('撤回')} Dom={ } /> ) : null} {btnFlagFu2(topInfo)['审批'] ? ( ) : null} {btnFlagFu2(topInfo)['编辑'] ? ( ) : null} {btnFlagFu2(topInfo)['重新提交'] ? ( ) : null} {EXbtnFu(topInfo)} {btnFlagFu2(topInfo)['删除'] ? ( delFu()} Dom={ } /> ) : null} ) }, [delFu, lookBtnFu, lookJumpFu, topInfo]) return (
藏品出库-{pageTitTxt}
{['3'].includes(key) ? ( setAuDitSta(val)} ref={ZAuditRef} /> ) : null} {/* 表单字段、附件等 */}
申请信息 {key === '1' ? null : ( )}
* 申请名称:
setTopInfo({ ...topInfo, name: e.target.value.trim() })} readOnly={['3', '4'].includes(key)} placeholder='请输入内容' maxLength={30} showCount />
* 业务类型:
setTopInfo({ ...topInfo, sonTypeName: e ? e.join(',') : '' })} disabled={['3', '4'].includes(key)} options={cascaderObjFu()['藏品出库']} changeOnSelect placeholder='请选择' fieldNames={{ label: 'name', value: 'id', children: 'children' }} allowClear={false} />
{B3aForm1.map(v => (
{v.name}:
{topInfo[v.key as 'name']} {['3', '4'].includes(key) && v.name === '发起人' ? ' - ' + topInfo.createTime || '' : ''}
))}
* 是否归还:
setTopInfo({ ...topInfo, isReturn: e.target.value, returnDate: e.target.value === 0 ? '' : topInfo.returnDate }) } options={[ { value: 1, label: '是' }, { value: 0, label: '否' } ]} />
预计归还日期:
setTopInfo({ ...topInfo, returnDate: e ? dayjs(e).format('YYYY-MM-DD') : '' }) } />
* 业务日期:
原因事由:
setTopInfo({ ...topInfo, reason: e.target.value })} readOnly={['3', '4'].includes(key)} placeholder='请输入内容' maxLength={30} showCount />
附件:
备注:
库房信息
* 出库库房: