index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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 {
  5. C2_APIaduit,
  6. C2_APIcreate,
  7. C2_APIgetInfo,
  8. C2_APIresubmit
  9. } from '@/store/action/C2storageIn'
  10. import { C2lookPageStaObj, locTxtChangeFu, locTxtValueFu } from '../data'
  11. import { B1listType } from '@/pages/B1ledger/data'
  12. import { Button, DatePicker, Input } from 'antd'
  13. import { statusSelect } from '@/utils/select'
  14. import history, { backPageFu, openLink } from '@/utils/history'
  15. import MyPopconfirm from '@/components/MyPopconfirm'
  16. import { MessageFu } from '@/utils/message'
  17. import dayjs from 'dayjs'
  18. import TextArea from 'antd/es/input/TextArea'
  19. import Z3upFiles from '@/components/Z3upFiles'
  20. import MyTable from '@/components/MyTable'
  21. import { auditTableC, goodsSelectTableC } from '@/utils/tableData'
  22. import A0selectGoods from '@/pages/A0selectGoods'
  23. import { API_getGoodsInfo } from '@/store/action/B1ledger'
  24. function C2look() {
  25. const { key, id } = useParams<any>()
  26. // key:1-新增 2-重新提交/编辑 3-查看 4-审批
  27. // 从藏品信息模块进来,带上当前藏品信息
  28. const isGoodsInfoRu = useCallback(async (id: number) => {
  29. const res = await API_getGoodsInfo(id)
  30. if (res.code === 0) {
  31. setSnaps([res.data])
  32. }
  33. }, [])
  34. useEffect(() => {
  35. const urlAll = window.location.href
  36. if (key === '1' && urlAll.includes('?oldId=')) {
  37. isGoodsInfoRu(Number(urlAll.split('?oldId=')[1]))
  38. }
  39. }, [isGoodsInfoRu, key])
  40. // 顶部数据
  41. const [info, setInfo] = useState({} as B1listType)
  42. // 新增的时候进页面创建订单
  43. const createFu = useCallback(async () => {
  44. const res = await C2_APIcreate()
  45. if (res.code === 0) {
  46. setInfo(res.data)
  47. }
  48. }, [])
  49. // 获取详情
  50. const getInfoFu = useCallback(async () => {
  51. const res = await C2_APIgetInfo(id)
  52. if (res.code === 0) {
  53. // console.log('获取详情:', res)
  54. const data = res.data
  55. setInfo(data)
  56. // 设置附件(需要异步)
  57. setTimeout(() => {
  58. filesRef.current?.showList(data.files || [])
  59. }, 100)
  60. // 藏品清单快照信息id对比
  61. const arrTemp: any = []
  62. const snapsTemp = data.snaps || []
  63. snapsTemp.forEach((v: any) => {
  64. snapsID2ref.current.push({ goodsId: v.goodsId, id: v.id })
  65. const obj = JSON.parse(v.snap || '{}')
  66. if (obj.id) obj.id2 = v.id
  67. arrTemp.push({ ...obj })
  68. })
  69. setSnaps(arrTemp)
  70. }
  71. }, [id])
  72. useEffect(() => {
  73. if (key === '1') createFu()
  74. else if (['2', '3', '4'].includes(key)) getInfoFu()
  75. }, [createFu, getInfoFu, key])
  76. // 申请状态
  77. const topStatusRes = useMemo(() => {
  78. let txt = '创建订单'
  79. const obj = statusSelect.find(v => v.value === info.status)
  80. if (obj) txt = obj.label
  81. return txt
  82. }, [info.status])
  83. // 审批的sta
  84. const [auditSta, setAuDitSta] = useState('')
  85. const [rtfOpinion, setRtfOpinion] = useState('')
  86. const boxRef = useRef<HTMLDivElement>(null)
  87. // 上传附件的ref
  88. const filesRef = useRef<any>(null)
  89. // 藏品清单 和 快照数据
  90. const [snaps, setSnaps] = useState<B1listType[]>([])
  91. const delSnapIdsRef = useRef<number[]>([])
  92. const snapsID2ref = useRef<{ goodsId: number; id: number }[]>([])
  93. const goodsTableBtn = useMemo(() => {
  94. return [
  95. {
  96. title: '入库位置',
  97. render: (item: B1listType) => {
  98. return (
  99. <>
  100. {['柜号', '层数', '层格编号'].map((txt, index) => (
  101. <div key={index} className='C2TableTxt'>
  102. <Input
  103. readOnly={['3', '4'].includes(key)}
  104. placeholder={['3', '4'].includes(key) ? '(空)' : `请输入${txt}`}
  105. maxLength={10}
  106. value={locTxtValueFu(index, item.siteIn)}
  107. showCount
  108. onChange={e =>
  109. setSnaps(
  110. snaps.map(v => ({
  111. ...v,
  112. siteIn:
  113. v.id === item.id
  114. ? locTxtChangeFu(index, e.target.value.trim(), item.siteIn)
  115. : v.siteIn
  116. }))
  117. )
  118. }
  119. />
  120. </div>
  121. ))}
  122. </>
  123. )
  124. }
  125. },
  126. {
  127. title: '操作',
  128. render: (item: B1listType) => {
  129. return (
  130. <>
  131. <Button size='small' type='text' onClick={() => openLink(`/goodsLook/${item.id}`)}>
  132. 查看
  133. </Button>
  134. {['3', '4'].includes(key) ? null : (
  135. <MyPopconfirm
  136. txtK='删除'
  137. onConfirm={() => {
  138. if (item.id2 && !delSnapIdsRef.current.includes(item.id2))
  139. delSnapIdsRef.current.push(item.id2)
  140. setSnaps(snaps.filter(v => v.id !== item.id))
  141. }}
  142. />
  143. )}
  144. </>
  145. )
  146. }
  147. }
  148. ]
  149. }, [key, snaps])
  150. // 点击提交
  151. const btnOk = useCallback(async () => {
  152. if (key === '4') {
  153. // 审批
  154. if (!auditSta) {
  155. MessageFu.warning('请选择审批结果')
  156. boxRef.current?.scrollTo({ top: 0, behavior: 'smooth' })
  157. return
  158. }
  159. const res = await C2_APIaduit({
  160. orderId: info.id,
  161. rtfOpinion,
  162. status: auditSta === '同意' ? 1 : 2
  163. })
  164. if (res.code === 0) {
  165. MessageFu.success('审批成功')
  166. history.replace(`/storageIn_look/3/${info.id}`)
  167. }
  168. } else if (['1', '2'].includes(key)) {
  169. // 新增和重新提交
  170. // 处理日期格式
  171. if (!info.date) {
  172. MessageFu.warning('请选择入库日期')
  173. boxRef.current?.scrollTo({ top: 0, behavior: 'smooth' })
  174. return
  175. }
  176. if (!info.num) {
  177. MessageFu.warning('请输入入库单编号')
  178. boxRef.current?.scrollTo({ top: 0, behavior: 'smooth' })
  179. return
  180. }
  181. if (snaps.length === 0) return MessageFu.warning('请添加藏品')
  182. // 附件
  183. let fileIds = ''
  184. const fileArr: any[] = filesRef.current?.filesRes()
  185. if (fileArr && fileArr.length) fileIds = fileArr.map(v => v.id).join(',')
  186. const snapsRes = snaps.map(v => ({
  187. goodsId: v.id,
  188. id: v.id2 ? v.id2 : null,
  189. orderId: info.id,
  190. siteIn: v.siteIn,
  191. snap: JSON.stringify(v)
  192. }))
  193. const obj = {
  194. date: info.date,
  195. delSnapIds: delSnapIdsRef.current.length ? delSnapIdsRef.current : '',
  196. fileIds,
  197. goodIds: snaps.map(v => v.id).join(','),
  198. id: info.id,
  199. num: info.num,
  200. reason: info.reason,
  201. snaps: snapsRes
  202. }
  203. // if (1 + 1 === 2) {
  204. // console.log(123, obj)
  205. // return
  206. // }
  207. const res = await C2_APIresubmit(obj)
  208. if (res.code === 0) {
  209. MessageFu.success(key === '1' ? '创建订单成功' : '重新提交成功')
  210. history.replace(`/storageIn_look/3/${info.id}`)
  211. }
  212. }
  213. }, [auditSta, info, key, rtfOpinion, snaps])
  214. // 点击新增打开弹窗
  215. const [addShow, setAddShow] = useState(false)
  216. return (
  217. <div className={styles.C2look} ref={boxRef}>
  218. <div className='pageTitle'>藏品入库 - {Reflect.get(C2lookPageStaObj, key)}</div>
  219. {info.id ? (
  220. <>
  221. <div className='C2lTop'>
  222. <div className='C2lTopll'>
  223. <div className='C2lTit'>申请信息</div>
  224. <div className='C2lTopllBtn'>
  225. <Button type='dashed'>{topStatusRes}</Button>
  226. </div>
  227. </div>
  228. <div className='C2lToprr'>
  229. {key !== '3' ? (
  230. <>
  231. <Button type='primary' onClick={btnOk}>
  232. 提交
  233. </Button>
  234. &emsp;
  235. </>
  236. ) : null}
  237. {['1', '2'].includes(key) ? (
  238. <MyPopconfirm txtK='返回' onConfirm={() => backPageFu('/storageIn')} />
  239. ) : (
  240. <Button onClick={() => backPageFu('/storageIn')}>返回</Button>
  241. )}
  242. </div>
  243. </div>
  244. <div className='C2form'>
  245. {['3', '4'].includes(key) ? (
  246. <>
  247. <div className='C2formRow'>
  248. <div className='C2formRowll'>订单类型:</div>
  249. <div className='C2formRowrr C2formRowrr2'>藏品入库</div>
  250. </div>
  251. <div className='C2formRow'>
  252. <div className='C2formRowll'>发起人员:</div>
  253. <div className='C2formRowrr C2formRowrr2'>
  254. {info.creatorName + ' - ' + info.createTime}
  255. </div>
  256. </div>
  257. </>
  258. ) : null}
  259. <div className='C2formRow'>
  260. <div className='C2formRowll'>
  261. <span>* </span>入库日期:
  262. </div>
  263. <div className='C2formRowrr'>
  264. <DatePicker
  265. disabled={['3', '4'].includes(key)}
  266. allowClear={false}
  267. value={info.date ? dayjs(info.date) : null}
  268. onChange={e => setInfo({ ...info, date: dayjs(e).format('YYYY-MM-DD') })}
  269. />
  270. </div>
  271. </div>
  272. <div className='C2formRow'>
  273. <div className='C2formRowll'>
  274. <span>* </span>入库单编号:
  275. </div>
  276. <div className='C2formRowrr'>
  277. <Input
  278. value={info.num}
  279. onChange={e => setInfo({ ...info, num: e.target.value.trim() })}
  280. readOnly={['3', '4'].includes(key)}
  281. placeholder='请输入内容'
  282. maxLength={30}
  283. showCount
  284. />
  285. </div>
  286. </div>
  287. <div className='C2formRow C2formRowAll'>
  288. <div className='C2formRowll'>事由说明:</div>
  289. <div className='C2formRowrr'>
  290. <TextArea
  291. value={info.reason}
  292. onChange={e => setInfo({ ...info, reason: e.target.value })}
  293. readOnly={['3', '4'].includes(key)}
  294. placeholder={['3', '4'].includes(key) ? '(空)' : '请输入内容'}
  295. maxLength={1000}
  296. showCount
  297. />
  298. </div>
  299. </div>
  300. {['3', '4'].includes(key) ? (
  301. <div style={{ width: '100%', height: '10px' }}></div>
  302. ) : null}
  303. <div className='C2formRow C2formRowAll'>
  304. <div className='C2formRowll'>附件:</div>
  305. <div className='C2formRowrr'>
  306. <Z3upFiles
  307. size={500}
  308. isLook={['3', '4'].includes(key)}
  309. ref={filesRef}
  310. fileCheck={false}
  311. dirCode='storageIn_look'
  312. myUrl='cms/orderSite/in/upload'
  313. />
  314. </div>
  315. </div>
  316. {/* 审批相关 */}
  317. {key === '4' ? (
  318. <>
  319. <div className='C2formRow C2formRowAll'>
  320. <div className='C2formRowll'>
  321. <span>* </span>审批结果:
  322. </div>
  323. <div className='C2formRowrr'>
  324. {['同意', '不同意'].map(v => (
  325. <Button
  326. key={v}
  327. onClick={() => setAuDitSta(v)}
  328. type={auditSta === v ? 'primary' : 'default'}
  329. >
  330. {v}
  331. </Button>
  332. ))}
  333. </div>
  334. </div>
  335. <div className='C2formRow C2formRowAll' style={{ marginBottom: 25 }}>
  336. <div className='C2formRowll'>审批意见:</div>
  337. <div className='C2formRowrr'>
  338. <TextArea
  339. value={rtfOpinion}
  340. onChange={e => setRtfOpinion(e.target.value)}
  341. placeholder='请输入内容'
  342. maxLength={200}
  343. showCount
  344. />
  345. </div>
  346. </div>
  347. </>
  348. ) : null}
  349. </div>
  350. <div className='C2lTit2'>
  351. <div className='C2lTit'>藏品清单</div>
  352. {['1', '2'].includes(key) ? (
  353. <Button type='primary' onClick={() => setAddShow(true)}>
  354. 新增
  355. </Button>
  356. ) : (
  357. <div></div>
  358. )}
  359. </div>
  360. <MyTable
  361. list={snaps}
  362. columnsTemp={goodsSelectTableC}
  363. lastBtn={goodsTableBtn}
  364. pagingInfo={false}
  365. />
  366. {['3', '4'].includes(key) ? (
  367. <>
  368. <div className='C2lTit'>申请流程</div>
  369. <MyTable
  370. list={info.audits || []}
  371. columnsTemp={auditTableC}
  372. pagingInfo={false}
  373. widthSet={{ rtfOpinion: 600 }}
  374. />
  375. </>
  376. ) : null}
  377. </>
  378. ) : null}
  379. {/* 打开藏品选择弹窗 */}
  380. {addShow ? (
  381. <A0selectGoods
  382. type='入库'
  383. closeFu={() => setAddShow(false)}
  384. oldCheckArr={snaps}
  385. dataResFu={data => {
  386. //需要过滤掉已经有id的-不替换数据,没有id的替换数据 因为数据可能已经在另外一个弹窗更新了
  387. const nowIds = snaps.map(v => v.id)
  388. let dataRes = data.map((v, i) => {
  389. if (nowIds.includes(v.id)) return snaps[i]
  390. else return v
  391. })
  392. dataRes.forEach(v => {
  393. // id2表示的是自己这条数据的id id才是goodsId
  394. const obj = snapsID2ref.current.find(c => c.goodsId === v.id)
  395. if (obj) v.id2 = obj.id
  396. })
  397. setSnaps(dataRes)
  398. }}
  399. />
  400. ) : null}
  401. </div>
  402. )
  403. }
  404. const MemoC2look = React.memo(C2look)
  405. export default MemoC2look