index.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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 { FourTableType } from '@/pages/B_enterTibet/B3_4page/type'
  5. import {
  6. E3_APIcreate,
  7. E3_APIdel,
  8. E3_APIgetInfo,
  9. E3_APIrevocation,
  10. E3_APIsaveApply,
  11. E3_APIsaveAudit,
  12. E3_APIsaveCreate,
  13. E3_APIsaveDraft
  14. } from '@/store/action/E3actuality'
  15. import { pageTitTxtObj } from '@/pages/D_storeManage/D4impStor/D4edit'
  16. import dayjs from 'dayjs'
  17. import { MessageFu } from '@/utils/message'
  18. import history, { btnFlagFu2, openGoodsInfoFu } from '@/utils/history'
  19. import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type'
  20. import classNames from 'classnames'
  21. import { Button, DatePicker, Input, Select } from 'antd'
  22. import MyPopconfirm from '@/components/MyPopconfirm'
  23. import { EXbtnFu } from '@/utils/EXBtn'
  24. import X3auditInfo from '@/pages/X_stock/X3auditInfo'
  25. import { D4goodsTableC, statusObj } from '@/utils/tableData'
  26. import { B3aForm1 } from '@/pages/B_enterTibet/B3_4page/B3edit/data'
  27. import Z3upFiles from '@/components/Z3upFiles'
  28. import ZRichTexts from '@/components/ZRichTexts'
  29. import MyTable from '@/components/MyTable'
  30. import B3flowTable from '@/pages/B_enterTibet/B3flowTable'
  31. import Y1cathet from '@/pages/Y_goodsDetails/Y1cathet'
  32. import B3GaddNow from '@/pages/B_enterTibet/B3goodsTable/B3GaddNow'
  33. function E3edit() {
  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 creatFu = useCallback(async () => {
  42. const res = await E3_APIcreate()
  43. if (res.code === 0) {
  44. setTopInfo(res.data)
  45. }
  46. }, [])
  47. // 获取详情
  48. const getInfoFu = useCallback(async () => {
  49. const res = await E3_APIgetInfo(id)
  50. if (res.code === 0) {
  51. setTopInfo(res.data)
  52. // 设置富文本
  53. ZRichTextRef.current?.ritxtShowFu(JSON.parse(res.data.rtf || '{}'))
  54. }
  55. }, [id])
  56. useEffect(() => {
  57. if (key === '1') creatFu()
  58. else getInfoFu()
  59. if (sollrDom.current) sollrDom.current.scrollTop = 0
  60. }, [creatFu, getInfoFu, key])
  61. // 上传附件的ref
  62. const filesRef = useRef<any>(null)
  63. // const filesRes = filesRef.current.filesIdRes();
  64. // 富文本的ref
  65. const ZRichTextRef = useRef<any>(null)
  66. // 审批意见的ref
  67. const ZAuditRef = useRef<any>(null)
  68. const pageTitTxt = useMemo(() => {
  69. return Reflect.get(pageTitTxtObj, key)
  70. }, [key])
  71. const timeChange = useCallback(
  72. (e: any) => {
  73. setTopInfo({ ...topInfo, date: dayjs(e).format('YYYY-MM-DD') })
  74. },
  75. [topInfo]
  76. )
  77. // 审批的sta
  78. const [auditSta, setAuDitSta] = useState('')
  79. // 新增的底部按钮点击
  80. const btnClickFu = useCallback(
  81. async (val: '草稿' | '创建' | '保存' | '审批') => {
  82. if (!topInfo.name) return MessageFu.warning('申请名称不能为空')
  83. if (val !== '草稿') {
  84. if (!topInfo.goods || (topInfo.goods && topInfo.goods.length === 0)) {
  85. return MessageFu.warning('请添加藏品')
  86. }
  87. }
  88. if (val === '审批') {
  89. // console.log('审批信息富文本', rtf2)
  90. if (!auditSta) {
  91. if (sollrDom.current) sollrDom.current.scrollTop = 0
  92. return MessageFu.warning('请选择审批结果')
  93. }
  94. const rtf2 = ZAuditRef.current?.resData()
  95. const res = await E3_APIsaveAudit({
  96. orderId: topInfo.id,
  97. rtfOpinion: rtf2,
  98. status: auditSta === '同意' ? 1 : 2
  99. })
  100. if (res.code === 0) {
  101. MessageFu.success('审批成功')
  102. // 跳详情页
  103. history.push(`/actuality_edit/4/${topInfo.id}`)
  104. }
  105. } else {
  106. const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
  107. // console.log('申请信息富文本', JSON.stringify(rtf1.val || ''))
  108. // 上传附件
  109. const filesRes = filesRef.current.filesIdRes()
  110. const obj = {
  111. ...topInfo,
  112. fileIds: filesRes.join(','),
  113. rtf: JSON.stringify(rtf1.val || ''),
  114. goodsIds: (topInfo.goods || []).map(v => v.id).join(',')
  115. }
  116. // console.log(123, obj)
  117. // if (1 + 1 === 2) return
  118. if (val === '草稿') {
  119. // 存草稿 当前页保存 不跳转
  120. const res = await E3_APIsaveDraft(obj)
  121. if (res.code === 0) {
  122. MessageFu.success('草稿保存成功')
  123. }
  124. } else {
  125. const res = val === '创建' ? await E3_APIsaveCreate(obj) : await E3_APIsaveApply(obj)
  126. if (res.code === 0) {
  127. MessageFu.success(`${val}成功`)
  128. // 跳到详情页
  129. history.push(`/actuality_edit/4/${topInfo.id}`)
  130. }
  131. }
  132. }
  133. },
  134. [auditSta, topInfo]
  135. )
  136. // 打开侧边栏
  137. const [cathet, setCathet] = useState(0)
  138. const startBtn = useMemo(() => {
  139. return [
  140. {
  141. title: '藏品编号',
  142. render: (item: C1GoodType) => {
  143. return (
  144. <span
  145. onClick={() => setCathet(item.id)}
  146. className={classNames('D1GtNum', item.id === cathet ? 'D1GtNumAc' : '')}
  147. >
  148. {item.num}
  149. </span>
  150. )
  151. }
  152. }
  153. ]
  154. }, [cathet])
  155. const tableLastBtn = useMemo(() => {
  156. return [
  157. {
  158. title: '存放位置',
  159. width: 200,
  160. render: (item: C1GoodType) => {
  161. return item.siteStr ? item.siteStr.replaceAll(',', ' / ') : '(空)'
  162. }
  163. },
  164. {
  165. title: '操作',
  166. render: (item: C1GoodType) => {
  167. return (
  168. <>
  169. <Button size='small' type='text' onClick={() => openGoodsInfoFu(item.id)}>
  170. 查看
  171. </Button>
  172. {['3', '4'].includes(key) ? null : (
  173. <MyPopconfirm
  174. txtK='删除'
  175. onConfirm={() =>
  176. setTopInfo({
  177. ...topInfo,
  178. goods: topInfo.goods.filter(v => v.id !== item.id)
  179. })
  180. }
  181. />
  182. )}
  183. </>
  184. )
  185. }
  186. }
  187. ]
  188. }, [key, topInfo])
  189. // 新增和从已关注的藏品中添加
  190. const [nowSta, setNowSta] = useState({ key: '', id: '' })
  191. // 查看的按钮创建-提交-撤回
  192. const lookBtnFu = useCallback(
  193. async (val: '创建' | '提交' | '撤回') => {
  194. if (val !== '撤回') {
  195. if (!topInfo.goods || (topInfo.goods && topInfo.goods.length === 0)) {
  196. return MessageFu.warning('请添加藏品')
  197. }
  198. }
  199. const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
  200. // console.log('申请信息富文本', JSON.stringify(rtf1.val || ''))
  201. // 上传附件
  202. const filesRes = filesRef.current.filesIdRes()
  203. const obj = {
  204. ...topInfo,
  205. fileIds: filesRes.join(','),
  206. rtf: JSON.stringify(rtf1.val || ''),
  207. goodsIds: (topInfo.goods || []).map(v => v.id).join(','),
  208. goods: topInfo.goods.map(v => ({
  209. goodsId: v.id,
  210. siteId: v.siteId
  211. }))
  212. }
  213. const res =
  214. val === '创建'
  215. ? await E3_APIsaveCreate(obj)
  216. : val === '提交'
  217. ? await E3_APIsaveApply(obj)
  218. : await E3_APIrevocation(id)
  219. if (res.code === 0) {
  220. if (sollrDom.current) sollrDom.current.scrollTop = 0
  221. MessageFu.success(val + '成功')
  222. getInfoFu()
  223. }
  224. },
  225. [getInfoFu, id, topInfo]
  226. )
  227. // 查看模式点击删除
  228. const delFu = useCallback(async () => {
  229. const res = await E3_APIdel(id)
  230. if (res.code === 0) {
  231. MessageFu.success('删除成功')
  232. history.push('/actuality')
  233. }
  234. }, [id])
  235. // 查看模式点击审批 编辑
  236. const lookJumpFu = useCallback(
  237. (val: '审批' | '编辑') => {
  238. history.push(`/actuality_edit/${val === '审批' ? 3 : 2}/${id}`)
  239. MessageFu.success(`已跳转至${val}页面`)
  240. },
  241. [id]
  242. )
  243. // 查看模式下的按钮
  244. const lookBtn = useMemo(() => {
  245. return (
  246. <>
  247. {btnFlagFu2(topInfo)['创建'] ? (
  248. <Button type='primary' onClick={() => lookBtnFu('创建')}>
  249. 创建
  250. </Button>
  251. ) : null}
  252. {btnFlagFu2(topInfo)['提交'] ? (
  253. <Button type='primary' onClick={() => lookBtnFu('提交')}>
  254. 提交
  255. </Button>
  256. ) : null}
  257. {btnFlagFu2(topInfo)['撤回'] ? (
  258. <MyPopconfirm
  259. txtK='撤回'
  260. onConfirm={() => lookBtnFu('撤回')}
  261. Dom={
  262. <Button type='primary' danger>
  263. 撤回
  264. </Button>
  265. }
  266. />
  267. ) : null}
  268. {btnFlagFu2(topInfo)['审批'] ? (
  269. <Button type='primary' onClick={() => lookJumpFu('审批')}>
  270. 审批
  271. </Button>
  272. ) : null}
  273. {btnFlagFu2(topInfo)['编辑'] ? (
  274. <Button type='primary' onClick={() => lookJumpFu('编辑')}>
  275. 编辑
  276. </Button>
  277. ) : null}
  278. {btnFlagFu2(topInfo)['重新提交'] ? (
  279. <Button type='primary' onClick={() => lookBtnFu('提交')}>
  280. 重新提交
  281. </Button>
  282. ) : null}
  283. {EXbtnFu(topInfo)}
  284. {btnFlagFu2(topInfo)['删除'] ? (
  285. <MyPopconfirm
  286. txtK='删除'
  287. onConfirm={() => delFu()}
  288. Dom={
  289. <Button type='primary' danger>
  290. 删除
  291. </Button>
  292. }
  293. />
  294. ) : null}
  295. <Button onClick={() => history.push('/actuality')}>返回</Button>
  296. </>
  297. )
  298. }, [delFu, lookBtnFu, lookJumpFu, topInfo])
  299. return (
  300. <div className={styles.E3edit}>
  301. <div className='pageTitle'>现状登记-{pageTitTxt}</div>
  302. <div className='E2main' ref={sollrDom}>
  303. {['3'].includes(key) ? (
  304. <X3auditInfo
  305. dirCode='E3actuality'
  306. myUrl='cms/orderPreserveCurrent/upload'
  307. auditSta={auditSta}
  308. auditStaFu={val => setAuDitSta(val)}
  309. ref={ZAuditRef}
  310. />
  311. ) : null}
  312. {/* 表单字段、附件等 */}
  313. <div className='E2Tit'>
  314. 申请信息
  315. {key === '1' ? null : (
  316. <Button type='dashed'>{Reflect.get(statusObj, topInfo.status)}</Button>
  317. )}
  318. </div>
  319. <div className='E2rowAll'>
  320. <div className='E2row'>
  321. <div className='E2rowll'>
  322. <span> * </span>申请名称:
  323. </div>
  324. <div className='E2rowrr'>
  325. <Input
  326. value={topInfo.name}
  327. onChange={e => setTopInfo({ ...topInfo, name: e.target.value.trim() })}
  328. readOnly={['3', '4'].includes(key)}
  329. placeholder='请输入内容'
  330. maxLength={30}
  331. showCount
  332. />
  333. </div>
  334. </div>
  335. {B3aForm1.map(v => (
  336. <div className='E2row' key={v.name}>
  337. <div className='E2rowll'>{v.name}:</div>
  338. <div className='E2rowrr'>
  339. {topInfo[v.key as 'name']}
  340. {['3', '4'].includes(key) && v.name === '发起人'
  341. ? ' - ' + topInfo.createTime || ''
  342. : ''}
  343. </div>
  344. </div>
  345. ))}
  346. <div className='E2row'>
  347. <div className='E2rowll'>
  348. <span> * </span>业务日期:
  349. </div>
  350. <div className='E2rowrr'>
  351. <DatePicker
  352. disabled={['3', '4'].includes(key)}
  353. allowClear={false}
  354. value={dayjs(topInfo.date)}
  355. onChange={timeChange}
  356. />
  357. </div>
  358. </div>
  359. <div className='E2row'>
  360. <div className='E2rowll'>相关盘点:</div>
  361. {/* 待完善 */}
  362. <div className='E2rowrr'>
  363. <Select
  364. disabled={['3', '4'].includes(key)}
  365. placeholder={['3', '4'].includes(key) ? '(空)' : '请搜索编码'}
  366. showSearch
  367. options={[]}
  368. fieldNames={{ label: 'num', value: 'num' }}
  369. allowClear={true}
  370. // value={topInfo.relatedOrderNum || null}
  371. // onChange={e => setTopInfo({ ...topInfo, relatedOrderNum: e ? e : '' })}
  372. />
  373. </div>
  374. </div>
  375. <div className='E2row'>
  376. <div className='E2rowll'>原因事由:</div>
  377. <div className='E2rowrr'>
  378. <Input
  379. value={topInfo.reason}
  380. onChange={e => setTopInfo({ ...topInfo, reason: e.target.value })}
  381. readOnly={['3', '4'].includes(key)}
  382. placeholder='请输入内容'
  383. maxLength={30}
  384. showCount
  385. />
  386. </div>
  387. </div>
  388. <div className='E2row E2row2'>
  389. <div className='E2rowll'>附件:</div>
  390. <div className='E2rowrr'>
  391. <Z3upFiles
  392. max={10}
  393. isLook={['3', '4'].includes(key)}
  394. ref={filesRef}
  395. fileCheck={false}
  396. dirCode='E3actuality'
  397. myUrl='cms/orderPreserveCurrent/upload'
  398. lookData={topInfo.files || []}
  399. size={500}
  400. fromData={{ moduleId: topInfo.id }}
  401. />
  402. </div>
  403. </div>
  404. <div className='E2row E2rowFull'>
  405. <div className='E2rowll'>备注:</div>
  406. <div className='E2rowrr'>
  407. <ZRichTexts
  408. check={false}
  409. dirCode='E3actuality'
  410. myUrl='cms/orderPreserveCurrent/upload'
  411. isLook={['3', '4'].includes(key)}
  412. ref={ZRichTextRef}
  413. isOne={true}
  414. upAudioBtnNone={true}
  415. />
  416. </div>
  417. </div>
  418. </div>
  419. {/* 藏品清单 */}
  420. <div className='E2googsBox'>
  421. <div className='E2Tit2'>
  422. <div className='E2Tit2ll'>藏品清单</div>
  423. <div className='E2Tit2rr'>
  424. {['3', '4'].includes(key) ? null : (
  425. <Button
  426. type='primary'
  427. onClick={() =>
  428. setNowSta({
  429. key: 'E2',
  430. id: 'cms/orderPreserveCurrent/goods/getList'
  431. })
  432. }
  433. >
  434. 新增
  435. </Button>
  436. )}
  437. </div>
  438. </div>
  439. {/* 表格 */}
  440. <MyTable
  441. list={topInfo.goods || []}
  442. columnsTemp={D4goodsTableC}
  443. startBtn={startBtn}
  444. lastBtn={tableLastBtn}
  445. pagingInfo={false}
  446. />
  447. </div>
  448. {/* 申请流程 */}
  449. {['3', '4'].includes(key) ? <B3flowTable tableArr={topInfo.audits || []} /> : null}
  450. </div>
  451. {/* 底部按钮 */}
  452. <div className='E2btn'>
  453. {key === '4' ? (
  454. lookBtn
  455. ) : (
  456. <>
  457. {key === '3' ? (
  458. <Button type='primary' onClick={() => btnClickFu('审批')}>
  459. 审批
  460. </Button>
  461. ) : (
  462. <Button type='primary' onClick={() => btnClickFu(key === '1' ? '创建' : '保存')}>
  463. {key === '1' ? '创建' : '保存'}
  464. </Button>
  465. )}
  466. {key === '1' ? (
  467. <Button type='primary' onClick={() => btnClickFu('草稿')}>
  468. 存草稿
  469. </Button>
  470. ) : null}
  471. <MyPopconfirm txtK='取消' onConfirm={() => history.push('/actuality')} />
  472. </>
  473. )}
  474. </div>
  475. {/* 打开侧边栏 */}
  476. <Y1cathet sId={cathet} closeFu={() => setCathet(0)} />
  477. {nowSta.id ? (
  478. <B3GaddNow
  479. nowSta={nowSta}
  480. closeFu={() => setNowSta({ key: '', id: '' })}
  481. dataResFu={data => setTopInfo({ ...topInfo, goods: data })}
  482. oldCheckArr={topInfo.goods || []}
  483. // 待完善
  484. // canObj={{ storageId: topInfo.storageId }}
  485. />
  486. ) : null}
  487. </div>
  488. )
  489. }
  490. const MemoE3edit = React.memo(E3edit)
  491. export default MemoE3edit