index.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. import React, { useCallback, useEffect, useMemo, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { useParams } from 'react-router-dom'
  4. import { Y1tabArr, Y1TabArrType } from '../Y1cathet/Y1main'
  5. import classNames from 'classnames'
  6. import { Button, Dropdown, MenuProps, Tag } from 'antd'
  7. import Y11com from '../Y1cathet/Y11com'
  8. import Y22com from '../Y1cathet/Y22com'
  9. import Y33com from '../Y1cathet/Y33com'
  10. import Y44com from '../Y1cathet/Y44com'
  11. import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type'
  12. import { API_getGoodsLedger, API_goodsInfo } from '@/store/action/C1ledger'
  13. import { EXPORT_WORD_ENUM, exportWordHandler } from '@/utils/exportTemplates'
  14. import { API_goodFileList } from '@/store/action/C2files'
  15. import { C3_APIfocus, C3_APIfocusNo } from '@/store/action/C3focus'
  16. import { MessageFu } from '@/utils/message'
  17. import C22revamp from '@/pages/C_goodsManage/C22goodEdit/C22revamp'
  18. import history, { useQuery } from '@/utils/history'
  19. import { statusStorageObj } from '@/utils/tableData'
  20. import { useSelector } from 'react-redux'
  21. import { RootState } from '@/store'
  22. import NoPower from '@/components/NoPower'
  23. import { selectObj } from '@/utils/select'
  24. function Y2look() {
  25. // 获取权限数据
  26. const goodsInfoPower = useSelector((state: RootState) => state.A0Layout.goodsInfoPower)
  27. const downImg = useSelector((state: RootState) => state.A0Layout.downImg)
  28. const { id: sId, menuId } = useParams<any>()
  29. const query = useQuery()
  30. const [info, setInfo] = useState({} as C1GoodType)
  31. const getInfoFu = useCallback(
  32. async (id: number) => {
  33. const res = await API_goodsInfo(id, menuId, query.oId)
  34. if (res.code === 0) {
  35. setInfo(res.data)
  36. }
  37. },
  38. [menuId, query.oId]
  39. )
  40. const handleExport = async () => {
  41. Promise.all([API_goodFileList(sId), API_getGoodsLedger(sId)]).then(res => {
  42. exportWordHandler(EXPORT_WORD_ENUM.COLLECTION_ARCHIVES, {
  43. ...info,
  44. records: res[1].data
  45. .filter((i: any) => i.type === 'JD')
  46. .map((i: any) => ({ ...i, ...JSON.parse(i.snap) })),
  47. repairs: res[1].data
  48. .filter((i: any) => i.type === 'XF')
  49. .map((i: any) => ({ ...i, ...JSON.parse(i.snap) })),
  50. status: res[1].data
  51. .filter((i: any) => i.type === 'XZ')
  52. .map((i: any) => ({ ...i, ...JSON.parse(i.snap) })),
  53. imagePages: [
  54. {
  55. thumb: info.thumb
  56. },
  57. ...res[0].data.filter((i: any) => i.type === 'img')
  58. ]
  59. })
  60. })
  61. }
  62. const handleExport2 = async () => {
  63. const res = await API_getGoodsLedger(sId)
  64. exportWordHandler(EXPORT_WORD_ENUM.COLLECTION_CARD, {
  65. ...info,
  66. records: res.data
  67. .filter((i: any) => i.type === 'JD')
  68. .map((i: any) => ({ ...i, ...JSON.parse(i.snap) }))
  69. })
  70. }
  71. useEffect(() => {
  72. getInfoFu(sId)
  73. }, [getInfoFu, sId])
  74. const [tabAc, setTabAc] = useState<Y1TabArrType>('藏品信息')
  75. const items1 = useMemo(() => {
  76. let arr: MenuProps['items'] = [
  77. {
  78. key: '1',
  79. label: (
  80. <span
  81. className='Y2xia'
  82. onClick={() => {
  83. if (info.isEdit === 1) MessageFu.warning('该藏品修改审核中,无法重复修改')
  84. else setIsEdit(true)
  85. }}
  86. >
  87. 编辑
  88. </span>
  89. )
  90. },
  91. {
  92. key: '2',
  93. label: (
  94. <span
  95. style={{ color: '#ff4d4d' }}
  96. className='Y2xia'
  97. onClick={() => {
  98. if (info.statusStorage === 6) {
  99. MessageFu.warning('该藏品注销审核中,无法重复注销')
  100. } else if (info.statusStorage === 7) {
  101. MessageFu.warning('该藏品已注销')
  102. } else history.push(`/cancel_edit/1/null?id=${sId}`)
  103. }}
  104. >
  105. 注销
  106. </span>
  107. )
  108. }
  109. ]
  110. return arr
  111. }, [info.isEdit, info.statusStorage, sId])
  112. const items2 = useMemo(() => {
  113. let arr: MenuProps['items'] = [
  114. {
  115. key: '1',
  116. label: (
  117. <span
  118. className='Y2xia'
  119. onClick={() => {
  120. if (!info.statusStorage || info.statusStorage === 4) {
  121. history.push(`/impStor_edit/1/null?id=${sId}`)
  122. } else {
  123. const txt = statusStorageObj[info.statusStorage]
  124. MessageFu.warning(`该藏品${txt},无法入库`)
  125. }
  126. }}
  127. >
  128. 入库
  129. </span>
  130. )
  131. },
  132. {
  133. key: '2',
  134. label: (
  135. <span
  136. className='Y2xia'
  137. onClick={() => {
  138. let txt = statusStorageObj[info.statusStorage] || ''
  139. const txtRes = txt ? `该藏品${txt},` : ''
  140. if (info.statusStorage === 2) history.push(`/moveStor_edit/1/null?id=${sId}`)
  141. else MessageFu.warning(txtRes + `只有已入库的藏品才能移库`)
  142. }}
  143. >
  144. 移库
  145. </span>
  146. )
  147. },
  148. {
  149. key: '3',
  150. label: (
  151. <span
  152. className='Y2xia'
  153. onClick={() => {
  154. let txt = statusStorageObj[info.statusStorage] || ''
  155. const txtRes = txt ? `该藏品${txt},` : ''
  156. if (info.statusStorage === 2) history.push(`/putsStor_edit/1/null?id=${sId}`)
  157. else MessageFu.warning(txtRes + `只有已入库的藏品才能出库`)
  158. }}
  159. >
  160. 出库
  161. </span>
  162. )
  163. }
  164. ]
  165. return arr
  166. }, [info.statusStorage, sId])
  167. const items3 = useMemo(() => {
  168. let arr: MenuProps['items'] = [
  169. {
  170. key: '1',
  171. label: (
  172. <span className='Y2xia' onClick={() => history.push(`/accident_edit/1/null?id=${sId}`)}>
  173. 事故登记
  174. </span>
  175. )
  176. },
  177. {
  178. key: '3',
  179. label: (
  180. <span className='Y2xia' onClick={() => history.push(`/actuality_edit/1/null?id=${sId}`)}>
  181. 现状登记
  182. </span>
  183. )
  184. },
  185. {
  186. key: '4',
  187. label: (
  188. <span className='Y2xia' onClick={() => history.push(`/repair_edit/1/null?id=${sId}`)}>
  189. 文物修复
  190. </span>
  191. )
  192. }
  193. ]
  194. return arr
  195. }, [sId])
  196. // 点击关注
  197. const focusFu = useCallback(
  198. async (val: '关注' | '取消关注') => {
  199. const res = val === '关注' ? await C3_APIfocus(sId) : await C3_APIfocusNo(sId)
  200. if (res.code === 0) {
  201. MessageFu.success(val + '成功!')
  202. getInfoFu(sId)
  203. }
  204. },
  205. [getInfoFu, sId]
  206. )
  207. // 点击藏品编辑(修改)
  208. const [isEdit, setIsEdit] = useState(false)
  209. return (
  210. <div className={styles.Y2look}>
  211. <div className='pageTitle'>
  212. 藏品详情
  213. {info.statusStorage > 0 && (
  214. <Tag>{selectObj['库存状态'].find(i => i.value === info.statusStorage)?.label}</Tag>
  215. )}
  216. </div>
  217. <div className='Y2top'>
  218. <div className='Y2topll'>
  219. {Y1tabArr.map(v => (
  220. <div
  221. key={v}
  222. className={classNames('Y1tRow', tabAc === v ? 'Y1tRowAc' : '')}
  223. onClick={() => setTabAc(v)}
  224. >
  225. {v}
  226. </div>
  227. ))}
  228. </div>
  229. <div className='Y2toprr'>
  230. {info.display === 1 ? (
  231. <>
  232. <Button
  233. type='primary'
  234. danger={info.isFocus === 1}
  235. onClick={() => focusFu(info.isFocus === 1 ? '取消关注' : '关注')}
  236. >
  237. {info.isFocus === 1 ? '取消' : ''}关注
  238. </Button>
  239. &emsp;
  240. </>
  241. ) : null}
  242. {info.display === 1 ? (
  243. <>
  244. {goodsInfoPower.includes('goodsBtn1') ? (
  245. <>
  246. <Button type='primary' onClick={handleExport}>
  247. 导出藏品档案
  248. </Button>
  249. &emsp;
  250. </>
  251. ) : null}
  252. {goodsInfoPower.includes('goodsBtn2') ? (
  253. <>
  254. <Button type='primary' onClick={handleExport2}>
  255. 导出藏品卡片
  256. </Button>
  257. &emsp;
  258. </>
  259. ) : null}
  260. {goodsInfoPower.includes('goodsBtn3') ? (
  261. <>
  262. <Dropdown menu={{ items: items1 }} placement='bottom' arrow>
  263. <Button type='primary'>档案管理</Button>
  264. </Dropdown>
  265. &emsp;
  266. </>
  267. ) : null}
  268. {goodsInfoPower.includes('goodsBtn4') ? (
  269. <>
  270. <Dropdown menu={{ items: items2 }} placement='bottom' arrow>
  271. <Button type='primary'>分库管理</Button>
  272. </Dropdown>
  273. &emsp;
  274. </>
  275. ) : null}
  276. {goodsInfoPower.includes('goodsBtn5') ? (
  277. <>
  278. <Dropdown menu={{ items: items3 }} placement='bottom' arrow>
  279. <Button type='primary'>保管管理</Button>
  280. </Dropdown>
  281. &emsp;
  282. </>
  283. ) : null}
  284. </>
  285. ) : null}
  286. {/* <Button onClick={() => history.go(-1)}>返回</Button> */}
  287. </div>
  288. </div>
  289. {info.id ? (
  290. <div className='Y2info'>
  291. {tabAc === '藏品信息' ? (
  292. goodsInfoPower.includes('goodsPage1') ? (
  293. <Y11com info={info} />
  294. ) : (
  295. <NoPower />
  296. )
  297. ) : null}
  298. {tabAc === '库存信息' ? (
  299. goodsInfoPower.includes('goodsPage2') ? (
  300. <Y22com info={info} />
  301. ) : (
  302. <NoPower />
  303. )
  304. ) : null}
  305. {tabAc === '藏品附件' ? (
  306. goodsInfoPower.includes('goodsPage3') || downImg['可见'] ? (
  307. <Y33com sId={sId} isLook={true} info={info} setImgCover={() => getInfoFu(sId)} />
  308. ) : (
  309. <NoPower />
  310. )
  311. ) : null}
  312. {tabAc === '藏品日志' ? (
  313. goodsInfoPower.includes('goodsPage4') ? (
  314. <Y44com sId={sId} isLook={true} />
  315. ) : (
  316. <NoPower />
  317. )
  318. ) : null}
  319. </div>
  320. ) : null}
  321. {isEdit ? (
  322. <div className='C22revampBox'>
  323. <C22revamp goodsId={sId} closeFu={() => setIsEdit(false)} type='新增' />
  324. </div>
  325. ) : null}
  326. </div>
  327. )
  328. }
  329. const MemoY2look = React.memo(Y2look)
  330. export default MemoY2look