123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550 |
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
- import styles from './index.module.scss'
- import { useParams } from 'react-router-dom'
- import { Button, Input } from 'antd'
- import MyPopconfirm from '@/components/MyPopconfirm'
- import {
- B2_APIcreate,
- B2_APIdel,
- B2_APIgetInfo,
- B2_APIrevocation,
- B2_APIsaveApply,
- B2_APIsaveAudit,
- B2_APIsaveCreate,
- B2_APIsaveDraft
- } from '@/store/action/B2identify'
- import { MessageFu } from '@/utils/message'
- import history, { btnFlagFu2 } from '@/utils/history'
- import { EXbtnFu } from '@/utils/EXBtn'
- import { pageTitTxtObj } from '@/pages/D_storeManage/D4impStor/D4edit'
- import X3auditInfo from '@/pages/X_stock/X3auditInfo'
- import { B2TableC2, statusObj } from '@/utils/tableData'
- import TextArea from 'antd/es/input/TextArea'
- import MyTable from '@/components/MyTable'
- import ZflowTable from '../../../../components/ZflowTable'
- import ZupFileTable from '@/components/ZupFileTable'
- import ZGaddNow from '../../../../components/ZGaddNow'
- import Y1cathet from '@/pages/Y_goodsDetails/Y1cathet'
- import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type'
- import classNames from 'classnames'
- import B2MoAdd from './B2MoAdd'
- import { B2keyFliterFu } from '../data'
- import { FourTableType } from '../../B1collect/type'
- function B2edit() {
- const { key, id } = useParams<any>()
- // key:1 新增 2编辑 3审批 4查看
- // 滚到顶部
- const sollrDom = useRef<HTMLDivElement>(null)
- // 顶部数据
- const [topInfo, setTopInfo] = useState({} as FourTableType)
- // 藏品清单快照数据
- const [snaps, setSnaps] = useState<C1GoodType[]>([])
- const delSnapIdsRef = useRef<number[]>([])
- const snapsID2ref = useRef<{ goodsId: number; id: number }[]>([])
- // -------新增藏品-新字段-------------
- const [openInfo, setOpenInfo] = useState({} as C1GoodType)
- // 打开侧边栏
- const [cathet, setCathet] = useState(0)
- const startBtn = useMemo(() => {
- return [
- {
- title: '藏品编号',
- render: (item: C1GoodType) => {
- return (
- <span
- onClick={() => setCathet(item.id)}
- className={classNames('D1GtNum', item.id === cathet ? 'D1GtNumAc' : '')}
- >
- {item.num || '(空)'}
- </span>
- )
- }
- }
- ]
- }, [cathet])
- const tableLastBtn = useMemo(() => {
- return [
- {
- title: '操作',
- render: (item: any) => {
- return (
- <>
- <Button size='small' type='text' onClick={() => setOpenInfo(item)}>
- {['3', '4'].includes(key) ? '查看' : '编辑'}
- </Button>
- {['3', '4'].includes(key) ? null : (
- <MyPopconfirm
- txtK='删除'
- onConfirm={() => {
- if (item.id2 && !delSnapIdsRef.current.includes(item.id2))
- delSnapIdsRef.current.push(item.id2)
- setSnaps(snaps.filter(v => v.id !== item.id))
- }}
- />
- )}
- </>
- )
- }
- }
- ]
- }, [snaps, key])
- // -------新增藏品-新字段-------------
- // 创建订单
- const creatFu = useCallback(async () => {
- const res = await B2_APIcreate()
- if (res.code === 0) {
- setTopInfo(res.data)
- }
- }, [])
- // 获取详情
- const getInfoFu = useCallback(async () => {
- const res = await B2_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])
- // 审批意见的ref
- const ZAuditRef = useRef<any>(null)
- // 审批的sta
- const [auditSta, setAuDitSta] = useState('')
- // 新增的底部按钮点击
- const btnClickFu = useCallback(
- async (val: '草稿' | '创建' | '保存' | '审批') => {
- 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 = await B2_APIsaveAudit({
- orderId: topInfo.id,
- rtfOpinion: rtf2,
- status: auditSta === '同意' ? 1 : 2
- })
- if (res.code === 0) {
- MessageFu.success('审批成功')
- // 跳详情页
- history.push(`/identify_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(B2keyFliterFu(v))
- }))
- }
- // console.log(123, obj)
- // if (1 + 1 === 2) return
- if (val === '草稿') {
- // 存草稿 当前页保存 不跳转
- const res = await B2_APIsaveDraft(obj)
- if (res.code === 0) {
- MessageFu.success('草稿保存成功')
- }
- } else {
- const res = val === '创建' ? await B2_APIsaveCreate(obj) : await B2_APIsaveApply(obj)
- if (res.code === 0) {
- MessageFu.success(`${val}成功`)
- // 跳到详情页
- history.push(`/identify_edit/4/${topInfo.id}`)
- }
- }
- }
- },
- [auditSta, snaps, topInfo]
- )
- // 查看的按钮创建-提交-撤回
- const lookBtnFu = useCallback(
- async (val: '创建' | '提交' | '撤回') => {
- if (val !== '撤回') {
- if (snaps.length === 0) return MessageFu.warning('请添加藏品')
- }
- 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(B2keyFliterFu(v))
- }))
- }
- const res =
- val === '创建'
- ? await B2_APIsaveCreate(obj)
- : val === '提交'
- ? await B2_APIsaveApply(obj)
- : await B2_APIrevocation(id)
- if (res.code === 0) {
- if (sollrDom.current) sollrDom.current.scrollTop = 0
- MessageFu.success(val + '成功')
- getInfoFu()
- }
- },
- [snaps, getInfoFu, id, topInfo]
- )
- // 查看模式点击删除
- const delFu = useCallback(async () => {
- const res = await B2_APIdel(id)
- if (res.code === 0) {
- MessageFu.success('删除成功')
- history.push('/identify')
- }
- }, [id])
- // 查看模式点击审批 编辑
- const lookJumpFu = useCallback(
- (val: '审批' | '编辑') => {
- history.push(`/identify_edit/${val === '审批' ? 3 : 2}/${id}`)
- MessageFu.success(`已跳转至${val}页面`)
- },
- [id]
- )
- // 查看模式下的按钮
- const lookBtn = useMemo(() => {
- return (
- <>
- {btnFlagFu2(topInfo)['创建'] ? (
- <Button type='primary' onClick={() => lookBtnFu('创建')}>
- 创建
- </Button>
- ) : null}
- {btnFlagFu2(topInfo)['提交'] ? (
- <Button type='primary' onClick={() => lookBtnFu('提交')}>
- 提交
- </Button>
- ) : null}
- {btnFlagFu2(topInfo)['撤回'] ? (
- <MyPopconfirm
- txtK='撤回'
- onConfirm={() => lookBtnFu('撤回')}
- Dom={
- <Button type='primary' danger>
- 撤回
- </Button>
- }
- />
- ) : null}
- {btnFlagFu2(topInfo)['审批'] ? (
- <Button type='primary' onClick={() => lookJumpFu('审批')}>
- 审批
- </Button>
- ) : null}
- {btnFlagFu2(topInfo)['编辑'] ? (
- <Button type='primary' onClick={() => lookJumpFu('编辑')}>
- 编辑
- </Button>
- ) : null}
- {btnFlagFu2(topInfo)['重新提交'] ? (
- <Button type='primary' onClick={() => lookBtnFu('提交')}>
- 重新提交
- </Button>
- ) : null}
- {EXbtnFu(topInfo)}
- {btnFlagFu2(topInfo)['删除'] ? (
- <MyPopconfirm
- txtK='删除'
- onConfirm={() => delFu()}
- Dom={
- <Button type='primary' danger>
- 删除
- </Button>
- }
- />
- ) : null}
- <Button onClick={() => history.push('/identify')}>返回</Button>
- </>
- )
- }, [delFu, lookBtnFu, lookJumpFu, topInfo])
- // 申请记录
- const [auditsShow, setAuditsShow] = useState(false)
- // 点击新增
- const [nowSta, setNowSta] = useState({ key: '', id: '' })
- return (
- <div className={styles.B2edit}>
- <div className='pageTitle'>藏品鉴定-{Reflect.get(pageTitTxtObj, key)}</div>
- <div className='B2main'>
- {['3'].includes(key) ? (
- <X3auditInfo
- dirCode='B2identify'
- myUrl='cms/goodsFile/upload'
- auditSta={auditSta}
- auditStaFu={val => setAuDitSta(val)}
- ref={ZAuditRef}
- />
- ) : null}
- {/* 表单字段、附件等 */}
- <div className='B2Tit'>
- 申请信息
- {key === '1' ? null : (
- <Button type='dashed'>{Reflect.get(statusObj, topInfo.status)}</Button>
- )}
- </div>
- <div className='B2rowAll'>
- <div className='B2row'>
- <div className='B2rowll'>业务单号:</div>
- <div className='B2rowrr'>{topInfo.num}</div>
- </div>
- <div className='B2row'>
- <div className='B2rowll'>业务名称:</div>
- <div className='B2rowrr'>{topInfo.name}</div>
- </div>
- <div className='B2row'>
- <div className='B2rowll'>发起人:</div>
- <div className='B2rowrr'>
- {topInfo.creatorName}
- {['3', '4'].includes(key) ? ' - ' + topInfo.createTime || '' : ''}
- </div>
- </div>
- <div className='B2row'>
- <div className='B2rowll'>发起部门:</div>
- <div className='B2rowrr'>{topInfo.deptName}</div>
- </div>
- <div className='B2row'>
- <div className='B2rowll'>鉴定单位:</div>
- <div className='B2rowrr'>
- <Input
- maxLength={30}
- showCount
- value={topInfo.authUnit}
- onChange={e => setTopInfo({ ...topInfo, authUnit: e.target.value })}
- placeholder={['3', '4'].includes(key) ? '(空)' : '请填入内容'}
- />
- </div>
- </div>
- <div className='B2row'>
- <div className='B2rowll'>核准单位:</div>
- <div className='B2rowrr'>
- <Input
- maxLength={30}
- showCount
- value={topInfo.confirmUnit}
- onChange={e => setTopInfo({ ...topInfo, confirmUnit: e.target.value })}
- placeholder={['3', '4'].includes(key) ? '(空)' : '请填入内容'}
- />
- </div>
- </div>
- <div className='B2row B2row2'>
- <div className='B2rowll'>鉴定人员:</div>
- <div className='B2rowrr'>
- <TextArea
- maxLength={50}
- showCount
- value={topInfo.authUser}
- onChange={e => setTopInfo({ ...topInfo, authUser: e.target.value })}
- placeholder={['3', '4'].includes(key) ? '(空)' : '请填入人员姓名,以逗号分隔'}
- />
- </div>
- </div>
- <div className='B2row B2row2'>
- <div className='B2rowll'>说明:</div>
- <div className='B2rowrr'>
- <TextArea
- maxLength={200}
- showCount
- value={topInfo.reason}
- onChange={e => setTopInfo({ ...topInfo, reason: e.target.value })}
- placeholder={['3', '4'].includes(key) ? '(空)' : '请填入内容'}
- />
- </div>
- </div>
- </div>
- {/* 藏品清单 */}
- <div className='B2goodsBox'>
- <div className='B2Tit2'>
- <div className='B2Tit2ll'>藏品清单</div>
- <div className='B2Tit2rr'>
- {['3', '4'].includes(key) ? null : (
- <Button
- type='primary'
- onClick={() => setNowSta({ key: '鉴定', id: 'cms/orderAuth/goods/getList' })}
- >
- 选择藏品
- </Button>
- )}
- </div>
- </div>
- {/* 表格 */}
- <MyTable
- list={snaps}
- columnsTemp={B2TableC2}
- startBtn={startBtn}
- lastBtn={tableLastBtn}
- pagingInfo={false}
- />
- </div>
- {/* 申请流程 */}
- {auditsShow ? (
- <ZflowTable tableArr={topInfo.audits || []} closeFu={() => setAuditsShow(false)} />
- ) : null}
- {/* 附件归档 */}
- {topInfo.status === 4 ? (
- <ZupFileTable
- listTemp={topInfo.filing || []}
- dirCode='B2identify'
- myUrl='cms/orderAuth/upload'
- fromData={{ moduleId: topInfo.id }}
- />
- ) : null}
- </div>
- {/* 底部按钮 */}
- <div className='B2btn'>
- {['3', '4'].includes(key) && topInfo.audits && topInfo.audits.length ? (
- <Button type='primary' onClick={() => setAuditsShow(true)}>
- 申请记录
- </Button>
- ) : null}
- {key === '4' ? (
- lookBtn
- ) : (
- <>
- {key === '3' ? (
- <Button type='primary' onClick={() => btnClickFu('审批')}>
- 审批
- </Button>
- ) : (
- <Button type='primary' onClick={() => btnClickFu(key === '1' ? '创建' : '保存')}>
- {key === '1' ? '创建' : '保存'}
- </Button>
- )}
- {key === '1' ? (
- <Button type='primary' onClick={() => btnClickFu('草稿')}>
- 存草稿
- </Button>
- ) : null}
- <MyPopconfirm txtK='取消' onConfirm={() => history.push('/identify')} />
- </>
- )}
- </div>
- {/* 打开侧边栏 */}
- <Y1cathet sId={cathet} closeFu={() => setCathet(0)} />
- {/* 新增弹窗 */}
- {nowSta.id ? (
- <ZGaddNow
- nowSta={nowSta}
- closeFu={() => setNowSta({ key: '', id: '' })}
- dataResFu={data => {
- //需要过滤掉已经有id的-不替换数据,没有id的替换数据 因为数据可能已经在另外一个弹窗更新了
- const nowIds = snaps.map(v => v.id)
- let dataRes = data.map((v, i) => {
- if (nowIds.includes(v.id)) return snaps[i]
- else return v
- })
- dataRes.forEach(v => {
- // id2表示的是自己这条数据的id id才是goodsId
- const obj = snapsID2ref.current.find(c => c.goodsId === v.id)
- if (obj) v.id2 = obj.id
- })
- setSnaps(dataRes)
- }}
- oldCheckArr={snaps}
- />
- ) : null}
- {openInfo.id ? (
- <B2MoAdd
- info={openInfo}
- closeFu={() => setOpenInfo({} as C1GoodType)}
- succFu={obj =>
- setSnaps(
- snaps.map(v => {
- if (v.id === obj.id) return obj
- else return v
- })
- )
- }
- look={['3', '4'].includes(key)}
- />
- ) : null}
- </div>
- )
- }
- const MemoB2edit = React.memo(B2edit)
- export default MemoB2edit
|