index.tsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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, DatePicker, Input, Modal, Select } from 'antd'
  5. import MyPopconfirm from '@/components/MyPopconfirm'
  6. import history, { btnFlagFu2 } from '@/utils/history'
  7. import { MessageFu } from '@/utils/message'
  8. import { statusObj } from '@/utils/tableData'
  9. import X3auditInfo from '@/pages/X_stock/X3auditInfo'
  10. import ZflowTable from '@/components/ZflowTable'
  11. import MyTable, { MyTableMethods } from '@/components/MyTable'
  12. import { EXbtnFu } from '@/utils/EXBtn'
  13. import {
  14. D7_APIcreate,
  15. D7_APIdel,
  16. D7_APIgetInfo,
  17. D7_APIsaveApply,
  18. D7_APIsaveAudit,
  19. D7_APIsaveCreate,
  20. D7_APIsaveDraft
  21. } from '@/store/action/D7check'
  22. import { ID7CheckItem } from '../types'
  23. import { useDispatch, useSelector } from 'react-redux'
  24. import { RootState } from '@/store'
  25. import { D2_APIgetList } from '@/store/action/D2storSet'
  26. import { StocktakingModal } from '../components/StocktakingModal'
  27. import { D7CHECK_COLLECTION_COLUMNS } from '../constants'
  28. import dayjs from 'dayjs'
  29. import { areAllCheckersFilled } from '@/utils/objects'
  30. import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type'
  31. import { BatchFillingModal } from '../components/BatchFillingModal'
  32. import { EXPORT_WORD_ENUM } from '@/utils/exportTemplates'
  33. export const pageTitTxtObj = {
  34. 1: '新增',
  35. 2: '编辑',
  36. 3: '审批',
  37. 4: '查看'
  38. }
  39. function D7edit() {
  40. const { key, id } = useParams<any>()
  41. // key:1 新增 2编辑 3审批 4查看
  42. // 滚到顶部
  43. const sollrDom = useRef<HTMLDivElement>(null)
  44. // 顶部数据
  45. const [topInfo, setTopInfo] = useState({} as ID7CheckItem)
  46. const { list: storageIdArr } = useSelector((state: RootState) => state.D2storSet.tableInfo)
  47. const [stocktakingVisible, setStocktakingVisible] = useState(false)
  48. const [batchFillingVisible, setBatchFillingVisible] = useState(false)
  49. const [collectionList, setCollectionList] = useState<C1GoodType[]>([])
  50. const tableRef = useRef<MyTableMethods | null>(null)
  51. const delSnapIdsRef = useRef<number[]>([])
  52. // 变更分库缩写 清空 藏品清单
  53. const [isModalOpen, setIsModalOpen] = useState(0)
  54. const dispatch = useDispatch()
  55. useEffect(() => {
  56. dispatch(D2_APIgetList({ pageNum: 1, pageSize: 99999 }))
  57. }, [dispatch])
  58. // 创建订单
  59. const creatFu = useCallback(async () => {
  60. const res = await D7_APIcreate()
  61. if (res.code === 0) {
  62. setTopInfo({
  63. ...res.data,
  64. date: dayjs().format('YYYY-MM-DD')
  65. })
  66. }
  67. }, [])
  68. // 获取详情
  69. const getInfoFu = useCallback(
  70. async (iid = id) => {
  71. const res = await D7_APIgetInfo(iid)
  72. if (res.code === 0) {
  73. const data = res.data
  74. setTopInfo(data)
  75. // 藏品清单快照信息id对比
  76. const arrTemp: any = []
  77. const snapsTemp = data.snaps || []
  78. snapsTemp.forEach((v: any) => {
  79. const { cusForm, ...obj } = JSON.parse(v.snap || '{}')
  80. if (obj.id) obj.id2 = v.id
  81. if (cusForm) tableRef.current?.form.setFieldsValue(cusForm)
  82. arrTemp.push(obj)
  83. })
  84. setCollectionList(arrTemp)
  85. }
  86. },
  87. [id]
  88. )
  89. useEffect(() => {
  90. if (key === '1') creatFu()
  91. else getInfoFu()
  92. if (sollrDom.current) sollrDom.current.scrollTop = 0
  93. }, [creatFu, getInfoFu, key])
  94. // 富文本的ref
  95. const ZRichTextRef = useRef<any>(null)
  96. // 审批意见的ref
  97. const ZAuditRef = useRef<any>(null)
  98. const pageTitTxt = useMemo(() => {
  99. return Reflect.get(pageTitTxtObj, key)
  100. }, [key])
  101. const checkDataFu = useCallback(() => {
  102. if (!topInfo.date) {
  103. MessageFu.warning('请选择盘点日期')
  104. return true
  105. }
  106. if (!topInfo.num) {
  107. MessageFu.warning('请填写盘点单编号')
  108. return true
  109. }
  110. if (!topInfo.storageId) {
  111. MessageFu.warning('请选择分库')
  112. return true
  113. }
  114. if (!topInfo.reason) {
  115. MessageFu.warning('请填写盘点事由')
  116. return true
  117. }
  118. if (!collectionList.length) {
  119. MessageFu.warning('请添加盘点范围')
  120. return true
  121. }
  122. const tableInputVals = tableRef.current?.form.getFieldsValue()
  123. if (!areAllCheckersFilled('checker', tableInputVals)) {
  124. MessageFu.warning(`请填写盘点人`)
  125. return true
  126. }
  127. return false
  128. }, [topInfo, collectionList])
  129. // 审批的sta
  130. const [auditSta, setAuDitSta] = useState('')
  131. // 新增的底部按钮点击
  132. const btnClickFu = useCallback(
  133. async (val: '草稿' | '创建' | '保存' | '审批') => {
  134. if (checkDataFu()) return
  135. if (val === '审批') {
  136. // console.log('审批信息富文本', rtf2)
  137. if (!auditSta) {
  138. if (sollrDom.current) sollrDom.current.scrollTop = 0
  139. return MessageFu.warning('请选择审批结果')
  140. }
  141. const rtf2 = ZAuditRef.current?.resData()
  142. const res = await D7_APIsaveAudit({
  143. orderId: topInfo.id,
  144. rtfOpinion: rtf2,
  145. status: auditSta === '同意' ? 1 : 2
  146. })
  147. if (res.code === 0) {
  148. MessageFu.success('审批成功')
  149. // 跳详情页
  150. history.push(`/check_edit/4/${topInfo.id}`)
  151. }
  152. } else {
  153. const tableValues = tableRef.current?.form.getFieldsValue()
  154. const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
  155. // console.log('申请信息富文本', JSON.stringify(rtf1.val || ''))
  156. const obj = {
  157. ...topInfo,
  158. goodsIds: collectionList.map(v => v.id).join(','),
  159. delSnapIds: delSnapIdsRef.current.length ? delSnapIdsRef.current : '',
  160. snaps: collectionList.map(i => ({
  161. goodsId: i.id,
  162. id: i.id2 ? i.id2 : null,
  163. orderId: topInfo.id,
  164. statusCheck: tableValues[`${i.id}-statusCheck`],
  165. snap: JSON.stringify({
  166. ...i,
  167. cusForm: tableValues
  168. })
  169. })),
  170. rtf: JSON.stringify(rtf1.val || '')
  171. }
  172. // console.log(123, obj)
  173. // if (1 + 1 === 2) return
  174. if (val === '草稿') {
  175. // 存草稿 当前页保存 不跳转
  176. const res = await D7_APIsaveDraft(obj)
  177. if (res.code === 0) {
  178. MessageFu.success('草稿保存成功')
  179. getInfoFu(topInfo.id)
  180. }
  181. } else {
  182. const res = val === '创建' ? await D7_APIsaveCreate(obj) : await D7_APIsaveApply(obj)
  183. if (res.code === 0) {
  184. MessageFu.success(`${val}成功`)
  185. // 跳到详情页
  186. history.push(`/check_edit/4/${topInfo.id}`)
  187. }
  188. }
  189. }
  190. },
  191. [auditSta, checkDataFu, topInfo, collectionList, getInfoFu]
  192. )
  193. // 查看的按钮创建-提交-撤回
  194. const lookBtnFu = useCallback(
  195. async (val: '创建' | '提交') => {
  196. const tableValues = tableRef.current?.form.getFieldsValue()
  197. const rtf1 = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
  198. // console.log('申请信息富文本', JSON.stringify(rtf1.val || ''))
  199. const obj = {
  200. ...topInfo,
  201. goodsIds: collectionList.map(v => v.id).join(','),
  202. delSnapIds: delSnapIdsRef.current.length ? delSnapIdsRef.current : '',
  203. snaps: collectionList.map(i => ({
  204. goodsId: i.id,
  205. id: i.id2 ? i.id2 : null,
  206. orderId: topInfo.id,
  207. statusCheck: tableValues[`${i.id}-statusCheck`],
  208. snap: JSON.stringify({
  209. ...i,
  210. cusForm: tableValues
  211. })
  212. })),
  213. rtf: JSON.stringify(rtf1.val || '')
  214. }
  215. const res = val === '创建' ? await D7_APIsaveCreate(obj) : await D7_APIsaveApply(obj)
  216. if (res.code === 0) {
  217. if (sollrDom.current) sollrDom.current.scrollTop = 0
  218. MessageFu.success(val + '成功')
  219. getInfoFu()
  220. }
  221. },
  222. [getInfoFu, topInfo, collectionList]
  223. )
  224. // 查看模式点击删除
  225. const delFu = useCallback(async () => {
  226. const res = await D7_APIdel(id)
  227. if (res.code === 0) {
  228. MessageFu.success('删除成功')
  229. history.push('/check')
  230. }
  231. }, [id])
  232. // 查看模式点击审批 编辑
  233. const lookJumpFu = useCallback(
  234. (val: '审批' | '编辑') => {
  235. history.push(`/check_edit/${val === '审批' ? 3 : 2}/${id}`)
  236. MessageFu.success(`已跳转至${val}页面`)
  237. },
  238. [id]
  239. )
  240. // 查看模式下的按钮
  241. const lookBtn = useMemo(() => {
  242. return (
  243. <>
  244. {btnFlagFu2(topInfo)['创建'] ? (
  245. <Button type='primary' onClick={() => lookBtnFu('创建')}>
  246. 创建
  247. </Button>
  248. ) : null}
  249. {btnFlagFu2(topInfo)['提交'] ? (
  250. <Button type='primary' onClick={() => lookBtnFu('提交')}>
  251. 提交
  252. </Button>
  253. ) : null}
  254. {btnFlagFu2(topInfo)['审批'] ? (
  255. <Button type='primary' onClick={() => lookJumpFu('审批')}>
  256. 审批
  257. </Button>
  258. ) : null}
  259. {btnFlagFu2(topInfo)['编辑'] ? (
  260. <Button type='primary' onClick={() => lookJumpFu('编辑')}>
  261. 编辑
  262. </Button>
  263. ) : null}
  264. {btnFlagFu2(topInfo)['重新提交'] ? (
  265. <Button type='primary' onClick={() => lookBtnFu('提交')}>
  266. 重新提交
  267. </Button>
  268. ) : null}
  269. {EXbtnFu(topInfo, [EXPORT_WORD_ENUM.COLLECTION_INVENTORY])}
  270. {btnFlagFu2(topInfo)['删除'] ? (
  271. <MyPopconfirm
  272. txtK='删除'
  273. onConfirm={() => delFu()}
  274. Dom={
  275. <Button type='primary' danger>
  276. 删除
  277. </Button>
  278. }
  279. />
  280. ) : null}
  281. <Button onClick={() => history.push('/check')}>返回</Button>
  282. </>
  283. )
  284. }, [delFu, lookBtnFu, lookJumpFu, topInfo])
  285. // 申请记录
  286. const [auditsShow, setAuditsShow] = useState(false)
  287. const handleStocktakingOk = (list: any[]) => {
  288. delSnapIdsRef.current.push(...collectionList.map(i => i.id2))
  289. setCollectionList(list)
  290. }
  291. const handleBatchFillingOk = (form: any) => {
  292. const temp: Record<string, string> = {}
  293. collectionList.forEach(item => {
  294. temp[`${item.id}-checker`] = form.checker
  295. temp[`${item.id}-remark`] = form.remark
  296. })
  297. tableRef.current?.form.setFieldsValue(temp)
  298. }
  299. return (
  300. <div className={styles.D3staff}>
  301. <div className='pageTitle'>藏品盘点-{pageTitTxt}</div>
  302. <div className='D4main' ref={sollrDom}>
  303. {['3'].includes(key) ? (
  304. <X3auditInfo
  305. dirCode='D7check'
  306. myUrl='cms/orderIn/upload'
  307. auditSta={auditSta}
  308. auditStaFu={val => setAuDitSta(val)}
  309. ref={ZAuditRef}
  310. />
  311. ) : null}
  312. {/* 表单字段、附件等 */}
  313. <div className='D4Tit'>
  314. 申请信息
  315. {key === '1' ? null : (
  316. <Button type='dashed'>{Reflect.get(statusObj, topInfo.status)}</Button>
  317. )}
  318. </div>
  319. <div className='D4rowAll'>
  320. <div className='D4row'>
  321. <div className='D4rowll'>
  322. <span>*</span>盘点日期:
  323. </div>
  324. <div className='D4rowrr'>
  325. {topInfo.id && (
  326. <DatePicker
  327. defaultValue={dayjs(topInfo.date)}
  328. style={{ width: '300px' }}
  329. onChange={e => {
  330. setTopInfo({ ...topInfo, date: e.format('YYYY-MM-DD') })
  331. }}
  332. />
  333. )}
  334. </div>
  335. </div>
  336. <div className='D4row'>
  337. <div className='D4rowll'>
  338. <span>*</span>盘点单编号:
  339. </div>
  340. <div className='D4rowrr'>
  341. <Input
  342. value={topInfo.num}
  343. onChange={e => setTopInfo({ ...topInfo, num: e.target.value })}
  344. readOnly={['3', '4'].includes(key)}
  345. placeholder='请输入内容'
  346. maxLength={30}
  347. showCount
  348. />
  349. </div>
  350. </div>
  351. <div className='D4row'>
  352. <div className='D4rowll'>
  353. <span>*</span>分库缩写:
  354. </div>
  355. <div className='D4rowrr'>
  356. <Select
  357. disabled={['3', '4'].includes(key)}
  358. placeholder='请搜索选择'
  359. showSearch
  360. filterOption={(input, option) => {
  361. const txt = option!.label
  362. return txt.toLowerCase().includes(input.toLowerCase())
  363. }}
  364. options={storageIdArr.map(v => ({ label: v.num + ' - ' + v.name, value: v.id }))}
  365. // fieldNames={{ label: 'num', value: 'num' }}
  366. allowClear={false}
  367. value={topInfo.storageId || null}
  368. onChange={e => {
  369. if (topInfo.storageId && topInfo.storageId !== e && collectionList.length) {
  370. setIsModalOpen(e)
  371. } else setTopInfo({ ...topInfo, storageId: e ? e : null })
  372. }}
  373. />
  374. </div>
  375. </div>
  376. <div className='D4row'>
  377. <div className='D4rowll'>
  378. <span>*</span>盘点事由:
  379. </div>
  380. <div className='D4rowrr'>
  381. <Input
  382. value={topInfo.reason}
  383. onChange={e => setTopInfo({ ...topInfo, reason: e.target.value })}
  384. readOnly={['3', '4'].includes(key)}
  385. placeholder='请输入内容'
  386. maxLength={200}
  387. showCount
  388. />
  389. </div>
  390. </div>
  391. </div>
  392. {/* 盘点范围 */}
  393. <div className='D4googsBox'>
  394. <div className='D4Tit2'>
  395. <div className='D4Tit2ll'>盘点范围</div>
  396. {!['3', '4'].includes(key) && (
  397. <div>
  398. <Button
  399. type='primary'
  400. disabled={!collectionList.length}
  401. style={{ marginRight: 15 }}
  402. onClick={() => setBatchFillingVisible(true)}
  403. >
  404. 批量填写
  405. </Button>
  406. <Button
  407. disabled={!topInfo.storageId}
  408. type='primary'
  409. onClick={() => setStocktakingVisible(true)}
  410. >
  411. 设置盘点范围
  412. </Button>
  413. </div>
  414. )}
  415. </div>
  416. <MyTable
  417. ref={tableRef}
  418. readOnly={['3', '4'].includes(key)}
  419. widthSet={{ statusCheck: 200, remark: 200 }}
  420. yHeight={350}
  421. list={collectionList}
  422. columnsTemp={D7CHECK_COLLECTION_COLUMNS}
  423. lastBtn={
  424. ['3', '4'].includes(key)
  425. ? undefined
  426. : [
  427. {
  428. title: '操作',
  429. render(item: C1GoodType, _: any, idx: number) {
  430. return (
  431. <MyPopconfirm
  432. txtK='删除'
  433. onConfirm={() => {
  434. if (item.id2 && !delSnapIdsRef.current.includes(item.id2))
  435. delSnapIdsRef.current.push(item.id2)
  436. const temp = [...collectionList]
  437. temp.splice(idx, 1)
  438. setCollectionList(temp)
  439. }}
  440. />
  441. )
  442. }
  443. }
  444. ]
  445. }
  446. />
  447. </div>
  448. {/* 申请流程 */}
  449. {auditsShow ? (
  450. <ZflowTable tableArr={topInfo.audits || []} closeFu={() => setAuditsShow(false)} />
  451. ) : null}
  452. </div>
  453. {/* 底部按钮 */}
  454. <div className='D4btn'>
  455. {['3', '4'].includes(key) &&
  456. topInfo.audits &&
  457. topInfo.audits.length &&
  458. [2, 3, 4].includes(topInfo.status) ? (
  459. <Button type='primary' onClick={() => setAuditsShow(true)}>
  460. 申请记录
  461. </Button>
  462. ) : null}
  463. {key === '4' ? (
  464. lookBtn
  465. ) : (
  466. <>
  467. {key === '3' ? (
  468. <Button type='primary' onClick={() => btnClickFu('审批')}>
  469. 审批
  470. </Button>
  471. ) : (
  472. <Button type='primary' onClick={() => btnClickFu(key === '1' ? '创建' : '保存')}>
  473. {key === '1' ? '创建' : '保存'}
  474. </Button>
  475. )}
  476. {key === '1' ? (
  477. <Button type='primary' onClick={() => btnClickFu('草稿')}>
  478. 存草稿
  479. </Button>
  480. ) : null}
  481. <MyPopconfirm txtK='取消' onConfirm={() => history.push('/check')} />
  482. </>
  483. )}
  484. </div>
  485. {/* 分库缩写改变的时候校验一下 */}
  486. <Modal
  487. wrapClassName={styles.D6editMo}
  488. title='变更分库后,将清空当前的藏品清单'
  489. open={!!isModalOpen}
  490. footer={[]}
  491. >
  492. <div className='D6editMoBtn'>
  493. <Button
  494. type='primary'
  495. onClick={() => {
  496. setTopInfo({ ...topInfo, storageId: isModalOpen })
  497. collectionList.forEach(v => {
  498. if (!delSnapIdsRef.current.includes(v.id)) delSnapIdsRef.current.push(v.id)
  499. })
  500. setCollectionList([])
  501. setIsModalOpen(0)
  502. }}
  503. >
  504. 继续
  505. </Button>
  506. &emsp;
  507. <Button onClick={() => setIsModalOpen(0)}>取消</Button>
  508. </div>
  509. </Modal>
  510. <BatchFillingModal
  511. visible={batchFillingVisible}
  512. setVisible={setBatchFillingVisible}
  513. onOk={handleBatchFillingOk}
  514. />
  515. <StocktakingModal
  516. storageId={topInfo.storageId}
  517. visible={stocktakingVisible}
  518. setVisible={setStocktakingVisible}
  519. onOk={handleStocktakingOk}
  520. />
  521. </div>
  522. )
  523. }
  524. const MemoD7edit = React.memo(D7edit)
  525. export default MemoD7edit