index.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { useParams } from 'react-router-dom'
  4. import { Button, Input } from 'antd'
  5. import MyPopconfirm from '@/components/MyPopconfirm'
  6. import {
  7. B2_APIcreate,
  8. B2_APIdel,
  9. B2_APIgetInfo,
  10. B2_APIrevocation,
  11. B2_APIsaveApply,
  12. B2_APIsaveAudit,
  13. B2_APIsaveCreate,
  14. B2_APIsaveDraft
  15. } from '@/store/action/B2identify'
  16. import { MessageFu } from '@/utils/message'
  17. import history, { btnFlagFu2 } from '@/utils/history'
  18. import { EXbtnFu } from '@/utils/EXBtn'
  19. import { pageTitTxtObj } from '@/pages/D_storeManage/D4impStor/D4edit'
  20. import X3auditInfo from '@/pages/X_stock/X3auditInfo'
  21. import { B2TableC2, statusObj } from '@/utils/tableData'
  22. import TextArea from 'antd/es/input/TextArea'
  23. import MyTable from '@/components/MyTable'
  24. import ZflowTable from '../../../../components/ZflowTable'
  25. import ZupFileTable from '@/components/ZupFileTable'
  26. import ZGaddNow from '../../../../components/ZGaddNow'
  27. import Y1cathet from '@/pages/Y_goodsDetails/Y1cathet'
  28. import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type'
  29. import classNames from 'classnames'
  30. import B2MoAdd from './B2MoAdd'
  31. import { B2keyFliterFu } from '../data'
  32. import { FourTableType } from '../../B1collect/type'
  33. function B2edit() {
  34. const { key, id } = useParams<any>()
  35. // key:1 新增 2编辑 3审批 4查看
  36. // 滚到顶部
  37. const sollrDom = useRef<HTMLDivElement>(null)
  38. // 顶部数据
  39. const [topInfo, setTopInfo] = useState({} as FourTableType)
  40. // 藏品清单快照数据
  41. const [snaps, setSnaps] = useState<C1GoodType[]>([])
  42. const delSnapIdsRef = useRef<number[]>([])
  43. const snapsID2ref = useRef<{ goodsId: number; id: number }[]>([])
  44. // -------新增藏品-新字段-------------
  45. const [openInfo, setOpenInfo] = useState({} as C1GoodType)
  46. // 打开侧边栏
  47. const [cathet, setCathet] = useState(0)
  48. const startBtn = useMemo(() => {
  49. return [
  50. {
  51. title: '藏品编号',
  52. render: (item: C1GoodType) => {
  53. return (
  54. <span
  55. onClick={() => setCathet(item.id)}
  56. className={classNames('D1GtNum', item.id === cathet ? 'D1GtNumAc' : '')}
  57. >
  58. {item.num || '(空)'}
  59. </span>
  60. )
  61. }
  62. }
  63. ]
  64. }, [cathet])
  65. const tableLastBtn = useMemo(() => {
  66. return [
  67. {
  68. title: '操作',
  69. render: (item: any) => {
  70. return (
  71. <>
  72. <Button size='small' type='text' onClick={() => setOpenInfo(item)}>
  73. {['3', '4'].includes(key) ? '查看' : '编辑'}
  74. </Button>
  75. {['3', '4'].includes(key) ? null : (
  76. <MyPopconfirm
  77. txtK='删除'
  78. onConfirm={() => {
  79. if (item.id2 && !delSnapIdsRef.current.includes(item.id2))
  80. delSnapIdsRef.current.push(item.id2)
  81. setSnaps(snaps.filter(v => v.id !== item.id))
  82. }}
  83. />
  84. )}
  85. </>
  86. )
  87. }
  88. }
  89. ]
  90. }, [snaps, key])
  91. // -------新增藏品-新字段-------------
  92. // 创建订单
  93. const creatFu = useCallback(async () => {
  94. const res = await B2_APIcreate()
  95. if (res.code === 0) {
  96. setTopInfo(res.data)
  97. }
  98. }, [])
  99. // 获取详情
  100. const getInfoFu = useCallback(async () => {
  101. const res = await B2_APIgetInfo(id)
  102. if (res.code === 0) {
  103. const data = res.data
  104. setTopInfo(data)
  105. // 藏品清单快照信息id对比
  106. const arrTemp: any = []
  107. const snapsTemp = data.snaps || []
  108. snapsTemp.forEach((v: any) => {
  109. snapsID2ref.current.push({ goodsId: v.goodsId, id: v.id })
  110. const obj = JSON.parse(v.snap || '{}')
  111. if (obj.id) obj.id2 = v.id
  112. arrTemp.push(obj)
  113. })
  114. setSnaps(arrTemp)
  115. }
  116. }, [id])
  117. useEffect(() => {
  118. if (key === '1') creatFu()
  119. else getInfoFu()
  120. if (sollrDom.current) sollrDom.current.scrollTop = 0
  121. }, [creatFu, getInfoFu, key])
  122. // 审批意见的ref
  123. const ZAuditRef = useRef<any>(null)
  124. // 审批的sta
  125. const [auditSta, setAuDitSta] = useState('')
  126. // 新增的底部按钮点击
  127. const btnClickFu = useCallback(
  128. async (val: '草稿' | '创建' | '保存' | '审批') => {
  129. if (val !== '草稿') {
  130. if (snaps.length === 0) return MessageFu.warning('请添加藏品')
  131. }
  132. if (val === '审批') {
  133. // console.log('审批信息富文本', rtf2)
  134. if (!auditSta) {
  135. if (sollrDom.current) sollrDom.current.scrollTop = 0
  136. return MessageFu.warning('请选择审批结果')
  137. }
  138. const rtf2 = ZAuditRef.current?.resData()
  139. const res = await B2_APIsaveAudit({
  140. orderId: topInfo.id,
  141. rtfOpinion: rtf2,
  142. status: auditSta === '同意' ? 1 : 2
  143. })
  144. if (res.code === 0) {
  145. MessageFu.success('审批成功')
  146. // 跳详情页
  147. history.push(`/identify_edit/4/${topInfo.id}`)
  148. }
  149. } else {
  150. const obj = {
  151. ...topInfo,
  152. goodsIds: snaps.map(v => v.id).join(','),
  153. delSnapIds: delSnapIdsRef.current.length ? delSnapIdsRef.current : '',
  154. snaps: snaps.map(v => ({
  155. goodsId: v.id,
  156. id: v.id2 ? v.id2 : null,
  157. orderId: topInfo.id,
  158. snap: JSON.stringify(B2keyFliterFu(v))
  159. }))
  160. }
  161. // console.log(123, obj)
  162. // if (1 + 1 === 2) return
  163. if (val === '草稿') {
  164. // 存草稿 当前页保存 不跳转
  165. const res = await B2_APIsaveDraft(obj)
  166. if (res.code === 0) {
  167. MessageFu.success('草稿保存成功')
  168. }
  169. } else {
  170. const res = val === '创建' ? await B2_APIsaveCreate(obj) : await B2_APIsaveApply(obj)
  171. if (res.code === 0) {
  172. MessageFu.success(`${val}成功`)
  173. // 跳到详情页
  174. history.push(`/identify_edit/4/${topInfo.id}`)
  175. }
  176. }
  177. }
  178. },
  179. [auditSta, snaps, topInfo]
  180. )
  181. // 查看的按钮创建-提交-撤回
  182. const lookBtnFu = useCallback(
  183. async (val: '创建' | '提交' | '撤回') => {
  184. if (val !== '撤回') {
  185. if (snaps.length === 0) return MessageFu.warning('请添加藏品')
  186. }
  187. const obj = {
  188. ...topInfo,
  189. goodsIds: snaps.map(v => v.id).join(','),
  190. delSnapIds: delSnapIdsRef.current.length ? delSnapIdsRef.current : '',
  191. snaps: snaps.map(v => ({
  192. goodsId: v.id,
  193. id: v.id2 ? v.id2 : null,
  194. orderId: topInfo.id,
  195. snap: JSON.stringify(B2keyFliterFu(v))
  196. }))
  197. }
  198. const res =
  199. val === '创建'
  200. ? await B2_APIsaveCreate(obj)
  201. : val === '提交'
  202. ? await B2_APIsaveApply(obj)
  203. : await B2_APIrevocation(id)
  204. if (res.code === 0) {
  205. if (sollrDom.current) sollrDom.current.scrollTop = 0
  206. MessageFu.success(val + '成功')
  207. getInfoFu()
  208. }
  209. },
  210. [snaps, getInfoFu, id, topInfo]
  211. )
  212. // 查看模式点击删除
  213. const delFu = useCallback(async () => {
  214. const res = await B2_APIdel(id)
  215. if (res.code === 0) {
  216. MessageFu.success('删除成功')
  217. history.push('/identify')
  218. }
  219. }, [id])
  220. // 查看模式点击审批 编辑
  221. const lookJumpFu = useCallback(
  222. (val: '审批' | '编辑') => {
  223. history.push(`/identify_edit/${val === '审批' ? 3 : 2}/${id}`)
  224. MessageFu.success(`已跳转至${val}页面`)
  225. },
  226. [id]
  227. )
  228. // 查看模式下的按钮
  229. const lookBtn = useMemo(() => {
  230. return (
  231. <>
  232. {btnFlagFu2(topInfo)['创建'] ? (
  233. <Button type='primary' onClick={() => lookBtnFu('创建')}>
  234. 创建
  235. </Button>
  236. ) : null}
  237. {btnFlagFu2(topInfo)['提交'] ? (
  238. <Button type='primary' onClick={() => lookBtnFu('提交')}>
  239. 提交
  240. </Button>
  241. ) : null}
  242. {btnFlagFu2(topInfo)['撤回'] ? (
  243. <MyPopconfirm
  244. txtK='撤回'
  245. onConfirm={() => lookBtnFu('撤回')}
  246. Dom={
  247. <Button type='primary' danger>
  248. 撤回
  249. </Button>
  250. }
  251. />
  252. ) : null}
  253. {btnFlagFu2(topInfo)['审批'] ? (
  254. <Button type='primary' onClick={() => lookJumpFu('审批')}>
  255. 审批
  256. </Button>
  257. ) : null}
  258. {btnFlagFu2(topInfo)['编辑'] ? (
  259. <Button type='primary' onClick={() => lookJumpFu('编辑')}>
  260. 编辑
  261. </Button>
  262. ) : null}
  263. {btnFlagFu2(topInfo)['重新提交'] ? (
  264. <Button type='primary' onClick={() => lookBtnFu('提交')}>
  265. 重新提交
  266. </Button>
  267. ) : null}
  268. {EXbtnFu(topInfo)}
  269. {btnFlagFu2(topInfo)['删除'] ? (
  270. <MyPopconfirm
  271. txtK='删除'
  272. onConfirm={() => delFu()}
  273. Dom={
  274. <Button type='primary' danger>
  275. 删除
  276. </Button>
  277. }
  278. />
  279. ) : null}
  280. <Button onClick={() => history.push('/identify')}>返回</Button>
  281. </>
  282. )
  283. }, [delFu, lookBtnFu, lookJumpFu, topInfo])
  284. // 申请记录
  285. const [auditsShow, setAuditsShow] = useState(false)
  286. // 点击新增
  287. const [nowSta, setNowSta] = useState({ key: '', id: '' })
  288. return (
  289. <div className={styles.B2edit}>
  290. <div className='pageTitle'>藏品鉴定-{Reflect.get(pageTitTxtObj, key)}</div>
  291. <div className='B2main'>
  292. {['3'].includes(key) ? (
  293. <X3auditInfo
  294. dirCode='B2identify'
  295. myUrl='cms/goodsFile/upload'
  296. auditSta={auditSta}
  297. auditStaFu={val => setAuDitSta(val)}
  298. ref={ZAuditRef}
  299. />
  300. ) : null}
  301. {/* 表单字段、附件等 */}
  302. <div className='B2Tit'>
  303. 申请信息
  304. {key === '1' ? null : (
  305. <Button type='dashed'>{Reflect.get(statusObj, topInfo.status)}</Button>
  306. )}
  307. </div>
  308. <div className='B2rowAll'>
  309. <div className='B2row'>
  310. <div className='B2rowll'>业务单号:</div>
  311. <div className='B2rowrr'>{topInfo.num}</div>
  312. </div>
  313. <div className='B2row'>
  314. <div className='B2rowll'>业务名称:</div>
  315. <div className='B2rowrr'>{topInfo.name}</div>
  316. </div>
  317. <div className='B2row'>
  318. <div className='B2rowll'>发起人:</div>
  319. <div className='B2rowrr'>
  320. {topInfo.creatorName}
  321. {['3', '4'].includes(key) ? ' - ' + topInfo.createTime || '' : ''}
  322. </div>
  323. </div>
  324. <div className='B2row'>
  325. <div className='B2rowll'>发起部门:</div>
  326. <div className='B2rowrr'>{topInfo.deptName}</div>
  327. </div>
  328. <div className='B2row'>
  329. <div className='B2rowll'>鉴定单位:</div>
  330. <div className='B2rowrr'>
  331. <Input
  332. maxLength={30}
  333. showCount
  334. value={topInfo.authUnit}
  335. onChange={e => setTopInfo({ ...topInfo, authUnit: e.target.value })}
  336. placeholder={['3', '4'].includes(key) ? '(空)' : '请填入内容'}
  337. />
  338. </div>
  339. </div>
  340. <div className='B2row'>
  341. <div className='B2rowll'>核准单位:</div>
  342. <div className='B2rowrr'>
  343. <Input
  344. maxLength={30}
  345. showCount
  346. value={topInfo.confirmUnit}
  347. onChange={e => setTopInfo({ ...topInfo, confirmUnit: e.target.value })}
  348. placeholder={['3', '4'].includes(key) ? '(空)' : '请填入内容'}
  349. />
  350. </div>
  351. </div>
  352. <div className='B2row B2row2'>
  353. <div className='B2rowll'>鉴定人员:</div>
  354. <div className='B2rowrr'>
  355. <TextArea
  356. maxLength={50}
  357. showCount
  358. value={topInfo.authUser}
  359. onChange={e => setTopInfo({ ...topInfo, authUser: e.target.value })}
  360. placeholder={['3', '4'].includes(key) ? '(空)' : '请填入人员姓名,以逗号分隔'}
  361. />
  362. </div>
  363. </div>
  364. <div className='B2row B2row2'>
  365. <div className='B2rowll'>说明:</div>
  366. <div className='B2rowrr'>
  367. <TextArea
  368. maxLength={200}
  369. showCount
  370. value={topInfo.reason}
  371. onChange={e => setTopInfo({ ...topInfo, reason: e.target.value })}
  372. placeholder={['3', '4'].includes(key) ? '(空)' : '请填入内容'}
  373. />
  374. </div>
  375. </div>
  376. </div>
  377. {/* 藏品清单 */}
  378. <div className='B2goodsBox'>
  379. <div className='B2Tit2'>
  380. <div className='B2Tit2ll'>藏品清单</div>
  381. <div className='B2Tit2rr'>
  382. {['3', '4'].includes(key) ? null : (
  383. <Button
  384. type='primary'
  385. onClick={() => setNowSta({ key: '鉴定', id: 'cms/orderAuth/goods/getList' })}
  386. >
  387. 选择藏品
  388. </Button>
  389. )}
  390. </div>
  391. </div>
  392. {/* 表格 */}
  393. <MyTable
  394. list={snaps}
  395. columnsTemp={B2TableC2}
  396. startBtn={startBtn}
  397. lastBtn={tableLastBtn}
  398. pagingInfo={false}
  399. />
  400. </div>
  401. {/* 申请流程 */}
  402. {auditsShow ? (
  403. <ZflowTable tableArr={topInfo.audits || []} closeFu={() => setAuditsShow(false)} />
  404. ) : null}
  405. {/* 附件归档 */}
  406. {topInfo.status === 4 ? (
  407. <ZupFileTable
  408. listTemp={topInfo.filing || []}
  409. dirCode='B2identify'
  410. myUrl='cms/orderAuth/upload'
  411. fromData={{ moduleId: topInfo.id }}
  412. />
  413. ) : null}
  414. </div>
  415. {/* 底部按钮 */}
  416. <div className='B2btn'>
  417. {['3', '4'].includes(key) && topInfo.audits && topInfo.audits.length ? (
  418. <Button type='primary' onClick={() => setAuditsShow(true)}>
  419. 申请记录
  420. </Button>
  421. ) : null}
  422. {key === '4' ? (
  423. lookBtn
  424. ) : (
  425. <>
  426. {key === '3' ? (
  427. <Button type='primary' onClick={() => btnClickFu('审批')}>
  428. 审批
  429. </Button>
  430. ) : (
  431. <Button type='primary' onClick={() => btnClickFu(key === '1' ? '创建' : '保存')}>
  432. {key === '1' ? '创建' : '保存'}
  433. </Button>
  434. )}
  435. {key === '1' ? (
  436. <Button type='primary' onClick={() => btnClickFu('草稿')}>
  437. 存草稿
  438. </Button>
  439. ) : null}
  440. <MyPopconfirm txtK='取消' onConfirm={() => history.push('/identify')} />
  441. </>
  442. )}
  443. </div>
  444. {/* 打开侧边栏 */}
  445. <Y1cathet sId={cathet} closeFu={() => setCathet(0)} />
  446. {/* 新增弹窗 */}
  447. {nowSta.id ? (
  448. <ZGaddNow
  449. nowSta={nowSta}
  450. closeFu={() => setNowSta({ key: '', id: '' })}
  451. dataResFu={data => {
  452. //需要过滤掉已经有id的-不替换数据,没有id的替换数据 因为数据可能已经在另外一个弹窗更新了
  453. const nowIds = snaps.map(v => v.id)
  454. let dataRes = data.map((v, i) => {
  455. if (nowIds.includes(v.id)) return snaps[i]
  456. else return v
  457. })
  458. dataRes.forEach(v => {
  459. // id2表示的是自己这条数据的id id才是goodsId
  460. const obj = snapsID2ref.current.find(c => c.goodsId === v.id)
  461. if (obj) v.id2 = obj.id
  462. })
  463. setSnaps(dataRes)
  464. }}
  465. oldCheckArr={snaps}
  466. />
  467. ) : null}
  468. {openInfo.id ? (
  469. <B2MoAdd
  470. info={openInfo}
  471. closeFu={() => setOpenInfo({} as C1GoodType)}
  472. succFu={obj =>
  473. setSnaps(
  474. snaps.map(v => {
  475. if (v.id === obj.id) return obj
  476. else return v
  477. })
  478. )
  479. }
  480. look={['3', '4'].includes(key)}
  481. />
  482. ) : null}
  483. </div>
  484. )
  485. }
  486. const MemoB2edit = React.memo(B2edit)
  487. export default MemoB2edit