index.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import React, { useMemo, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { authorityFu } from '@/utils/authority'
  4. import { selectObj, getDictFu, resJiLianFu } from '@/utils/dataChange'
  5. import history, { openLink } from '@/utils/history'
  6. import TableList from '@/pages/Zother/TableList'
  7. import { useSelector } from 'react-redux'
  8. import { RootState } from '@/store'
  9. import { API_getGoodsList, API_getGoodsListAll } from '@/store/action/Cledger/C1ledger'
  10. import { baseFormData } from '@/pages/Zother/data'
  11. import { goodsSonTableC } from '@/utils/tableData'
  12. import { Button, Dropdown, Modal, Radio, Checkbox } from 'antd'
  13. import { exportExcelFile } from '@/utils/xlsxExport'
  14. import { CaretDownOutlined } from '@ant-design/icons'
  15. const C1topSearch = [
  16. {
  17. type: 'input',
  18. key: 'searchKey',
  19. placeholder: '搜索藏品登记号、藏品名称'
  20. },
  21. {
  22. type: 'input',
  23. key: 'searchTagName',
  24. placeholder: `搜索藏品标签`
  25. },
  26. {
  27. type: 'select',
  28. key: 'level',
  29. placeholder: '级别',
  30. options: selectObj['藏品级别']
  31. },
  32. {
  33. type: 'cascader',
  34. key: 'typeDictId',
  35. placeholder: '类别',
  36. options: getDictFu('藏品类别')
  37. },
  38. {
  39. type: 'cascader',
  40. key: 'ageDictId',
  41. placeholder: '年代',
  42. options: getDictFu('藏品年代')
  43. },
  44. {
  45. type: 'cascader',
  46. key: 'textureDictId',
  47. placeholder: '质地',
  48. options: getDictFu('质地')
  49. },
  50. {
  51. type: 'select',
  52. key: 'tornLevel',
  53. placeholder: '完残程度',
  54. options: selectObj['完残程度']
  55. },
  56. // TODO
  57. {
  58. type: 'select',
  59. key: 'status',
  60. placeholder: '入藏状态',
  61. options: selectObj['藏品入藏状态']
  62. },
  63. {
  64. type: 'select',
  65. key: 'siteStatus',
  66. placeholder: '库存状态',
  67. options: selectObj['藏品库存状态']
  68. },
  69. {
  70. type: 'select',
  71. key: 'siteLoc',
  72. placeholder: `搜索库房位置`
  73. }
  74. ]
  75. const C1baseFormData = {
  76. ...baseFormData,
  77. typeDictId: '',
  78. ageDictId: '',
  79. textureDictId: ''
  80. }
  81. const columnsTempAdd = [
  82. ...goodsSonTableC(false),
  83. ['select', '入藏状态', 'status', selectObj['藏品入藏状态']],
  84. ['txt', '库存状态', 'siteStatus'],
  85. ['txt', '库房位置', 'siteLoc']
  86. ]
  87. const ExportModal = ({
  88. open,
  89. availableYears,
  90. onConfirm,
  91. onCancel
  92. }: {
  93. open: boolean
  94. availableYears: number[] | string[]
  95. onConfirm: (exportType: number, years: number[]) => void
  96. onCancel: () => void
  97. }) => {
  98. const [exportValue, setExportValue] = useState<number>(1)
  99. const [selectedYears, setSelectedYears] = useState<number[]>([])
  100. const onExportTypeChange = (e: any) => {
  101. setExportValue(e.target.value)
  102. }
  103. return (
  104. <Modal
  105. title='数据导出'
  106. open={open}
  107. onOk={() => onConfirm(exportValue, selectedYears)}
  108. onCancel={onCancel}
  109. okText='导出'
  110. cancelText='取消'
  111. >
  112. <span style={{ marginBottom: 16 }}>导出范围:</span>
  113. <Radio.Group
  114. onChange={onExportTypeChange}
  115. value={exportValue}
  116. options={[
  117. { value: 1, label: '所有年份' },
  118. { value: 2, label: '按年份' }
  119. ]}
  120. />
  121. {exportValue === 2 && (
  122. <div style={{ marginTop: 24 }}>
  123. <Checkbox.Group
  124. style={{ flexDirection: 'column', gap: '5px' }}
  125. options={availableYears.map(year => ({
  126. label: `${year}年`,
  127. value: year
  128. }))}
  129. value={selectedYears}
  130. onChange={checkedValues => setSelectedYears(checkedValues as number[])}
  131. />
  132. <div style={{ opacity: '0.5', marginTop: '10px' }}>上述年份为藏品制档日期所在年份</div>
  133. </div>
  134. )}
  135. </Modal>
  136. )
  137. }
  138. function C1ledger() {
  139. const tableInfo = useSelector((state: RootState) => state.C1ledger.tableInfo)
  140. const rightBtnOptions = useMemo(() => {
  141. return {
  142. dangan: [
  143. {
  144. key: '1',
  145. label: '登记',
  146. onClick: () => authorityFu(410, '藏品登记', () => history.push(`/register_edit/1/null`))
  147. },
  148. {
  149. key: '2',
  150. label: '注销',
  151. onClick: () => authorityFu(430, '藏品注销', () => history.push(`/writeOff_edit/1/null`))
  152. }
  153. ],
  154. kufang: [
  155. {
  156. key: '1',
  157. label: '入库',
  158. onClick: () => authorityFu(1010, '藏品入库', () => history.push(`/inStorage_edit/1/null`))
  159. },
  160. {
  161. key: '2',
  162. label: '移库',
  163. onClick: () =>
  164. authorityFu(1020, '藏品移库', () => history.push(`/moveStorage_edit/1/null`))
  165. },
  166. {
  167. key: '3',
  168. label: '出库',
  169. onClick: () =>
  170. authorityFu(1030, '藏品出库', () => history.push(`/outStorage_edit/1/null`))
  171. }
  172. ],
  173. weihu: [
  174. {
  175. key: '1',
  176. label: '鉴定登记',
  177. onClick: () => authorityFu(230, '藏品鉴定', () => history.push(`/auth_edit/1/null`))
  178. },
  179. {
  180. key: '2',
  181. label: '事故登记',
  182. onClick: () => authorityFu(510, '事故登记', () => history.push(`/accident_edit/1/null`))
  183. },
  184. {
  185. key: '3',
  186. label: '现状登记',
  187. onClick: () => authorityFu(540, '现状登记', () => history.push(`/actuality_edit/1/null`))
  188. },
  189. {
  190. key: '4',
  191. label: '修复登记',
  192. onClick: () => authorityFu(550, '修复登记', () => history.push(`/repair_edit/1/null`))
  193. }
  194. ]
  195. }
  196. }, [])
  197. const [allData, setAllData] = useState([])
  198. const [isModalOpen, setIsModalOpen] = useState(false)
  199. const [availableYears, setAvailableYears] = useState<any>([])
  200. const showModal = async () => {
  201. setIsModalOpen(true)
  202. const res = await API_getGoodsListAll()
  203. setAllData(res.data.records)
  204. //获取年份信息
  205. const years = Array.from(
  206. new Set(
  207. res.data.records
  208. .map((item: any) => item.createTime?.slice(0, 4))
  209. .filter(Boolean) as string[]
  210. )
  211. ).sort((a, b) => Number(b) - Number(a))
  212. setAvailableYears(years)
  213. }
  214. const dataExport = async (exportType: number = 1, years: number[] = []) => {
  215. // 根据导出范围筛选数据:
  216. // exportType === 1:所有年份,不做筛选
  217. // exportType === 2:按年份,只保留所选年份的数据
  218. const filteredData =
  219. exportType === 2 && years.length
  220. ? allData.filter((item: any) => {
  221. if (!item.createTime) return false
  222. const yearStr = item.createTime.slice(0, 4)
  223. const yearNum = yearStr
  224. return years.includes(yearNum)
  225. })
  226. : allData
  227. const listData = filteredData.map((item: any) => {
  228. return {
  229. 藏品登记号: item.num,
  230. 封面: item.thumb,
  231. 藏品标签: item.tagDictId,
  232. 藏品名称: item.name,
  233. 级别: item.level,
  234. 类别: resJiLianFu(item.typeDictId),
  235. 年代: resJiLianFu(item.ageDictId),
  236. 质地: resJiLianFu(item.textureDictId),
  237. 完残程度: item.tornLevel,
  238. 数量: item.pcs,
  239. 入藏状态: item.status,
  240. 库存状态: item.siteStatus,
  241. 库房位置: item.siteLoc
  242. }
  243. })
  244. console.log(years)
  245. exportExcelFile(
  246. listData,
  247. [100, 100, 100, 100, 100, 200, 200, 200, 100, 100, 100, 100, 100],
  248. '藏品总账数据'
  249. )
  250. setIsModalOpen(false)
  251. }
  252. // 故事管理/藏品总账定制右侧内容
  253. const storyTableListToprr = ({
  254. clickSearch,
  255. resetSelectFu
  256. }: {
  257. clickSearch: () => void
  258. resetSelectFu: () => void
  259. }) => {
  260. return (
  261. <>
  262. <Dropdown menu={{ items: rightBtnOptions['dangan'] }} trigger={['click']}>
  263. <Button type='primary'>
  264. 档案管理
  265. <CaretDownOutlined />
  266. </Button>
  267. </Dropdown>
  268. <Dropdown menu={{ items: rightBtnOptions['kufang'] }} trigger={['click']}>
  269. <Button type='primary'>
  270. 库房管理
  271. <CaretDownOutlined />
  272. </Button>
  273. </Dropdown>
  274. <Dropdown menu={{ items: rightBtnOptions['weihu'] }} trigger={['click']}>
  275. <Button type='primary'>
  276. 藏品维护
  277. <CaretDownOutlined />
  278. </Button>
  279. </Dropdown>
  280. <Button type='primary' onClick={() => console.log(123)}>
  281. 数据导入
  282. </Button>
  283. <Button type='primary' onClick={showModal}>
  284. 数据导出
  285. </Button>
  286. <ExportModal
  287. open={isModalOpen}
  288. availableYears={availableYears}
  289. onConfirm={dataExport}
  290. onCancel={() => setIsModalOpen(false)}
  291. />
  292. <Button type='primary' onClick={clickSearch}>
  293. 查询
  294. </Button>
  295. <Button onClick={resetSelectFu}>重置</Button>
  296. </>
  297. )
  298. }
  299. // 故事管理/藏品总账定制右侧操作按钮
  300. const storyTableLastBtn = useMemo(() => {
  301. return [
  302. {
  303. title: '操作',
  304. render: (item: any) => (
  305. <Button size='small' type='text' onClick={() => openLink(`/goodsLook/${item.id}`)}>
  306. 查看
  307. </Button>
  308. )
  309. }
  310. ]
  311. }, [])
  312. return (
  313. <div className={styles.C1ledger}>
  314. <div className='pageTitle'>藏品总账</div>
  315. <TableList
  316. baseFormData={C1baseFormData}
  317. getListAPI={API_getGoodsList}
  318. pageKey='ledger'
  319. tableInfo={tableInfo}
  320. columnsTemp={columnsTempAdd}
  321. rightBtnWidth={360}
  322. leftRowWidth={'20%'}
  323. yHeight={592}
  324. searchDom={C1topSearch}
  325. storyTableListToprr={storyTableListToprr}
  326. storyTableLastBtn={storyTableLastBtn}
  327. />
  328. </div>
  329. )
  330. }
  331. const MemoC1ledger = React.memo(C1ledger)
  332. export default MemoC1ledger