index.tsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import React, { useEffect, useMemo, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import BreadTit from '@/components/BreadTit'
  4. import { useDispatch, useSelector } from 'react-redux'
  5. import { getObject7List, getObject7ListNum, object7DelAPI } from '@/store/action/object7'
  6. import { RootState } from '@/store'
  7. import { useLocation } from 'react-router-dom'
  8. import history from '@/utils/history'
  9. import { MessageFu } from '@/utils/message'
  10. import { Button, DatePicker, Input, Popconfirm, Select, Table } from 'antd'
  11. import AuthButton from '@/components/AuthButton'
  12. import classNames from 'classnames'
  13. const { RangePicker } = DatePicker
  14. function Object7() {
  15. const dispatch = useDispatch()
  16. // 获取顶部数量
  17. useEffect(() => {
  18. dispatch(getObject7ListNum())
  19. }, [dispatch])
  20. // 顶部的状态改变了,统一管理,传到二级页码
  21. const statusRef = useRef<null | number>(null)
  22. const dataTit = useSelector((state: RootState) => state.object7Store.infoNum1)
  23. // 封装发送请求的函数
  24. const getList = () => {
  25. const data = {
  26. ...tableSelect,
  27. pageNum: pageNumRef.current,
  28. status: statusRef.current
  29. }
  30. dispatch(getObject7List(data))
  31. }
  32. // 获取地址栏参数
  33. const location = useLocation()
  34. const pageNumRef = useRef(1)
  35. // 如果有参数 根据参数页码在次发送请求
  36. useEffect(() => {
  37. const urlParam = location.state || {}
  38. setTableSelect({
  39. ...tableSelect,
  40. pageNum: Number(urlParam.k) ? Number(urlParam.k) : 1,
  41. // eslint-disable-next-line eqeqeq
  42. status: urlParam.d && urlParam.d != 'null' ? Number(urlParam.d) : null
  43. })
  44. // eslint-disable-next-line react-hooks/exhaustive-deps
  45. }, [location])
  46. // 顶部筛选
  47. const [tableSelect, setTableSelect] = useState({
  48. status: null as null | number,
  49. sourceName: null,
  50. searchKey: '',
  51. startTime: '',
  52. endTime: '',
  53. pageSize: 10,
  54. pageNum: 1
  55. })
  56. // 当前页码统一
  57. useEffect(() => {
  58. pageNumRef.current = tableSelect.pageNum
  59. }, [tableSelect.pageNum])
  60. // 顶部状态统一
  61. useEffect(() => {
  62. statusRef.current = tableSelect.status
  63. }, [tableSelect.status])
  64. // 防止返回的时候发送了2次请求来对应页码
  65. const getListRef = useRef(-1)
  66. useEffect(() => {
  67. clearTimeout(getListRef.current)
  68. getListRef.current = window.setTimeout(() => {
  69. getList()
  70. }, 100)
  71. // eslint-disable-next-line react-hooks/exhaustive-deps
  72. }, [tableSelect])
  73. // 藏品来源下拉框筛选
  74. const handleChange = (value: any) => {
  75. setTableSelect({ ...tableSelect, sourceName: value, pageNum: 1 })
  76. }
  77. // 登记人员输入
  78. const nameTime = useRef(-1)
  79. const nameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
  80. clearTimeout(nameTime.current)
  81. nameTime.current = window.setTimeout(() => {
  82. setTableSelect({ ...tableSelect, searchKey: e.target.value, pageNum: 1 })
  83. }, 500)
  84. }
  85. // 时间选择器改变
  86. const timeChange = (date: any, dateString: any) => {
  87. let startTime = ''
  88. let endTime = ''
  89. if (dateString[0] && dateString[1]) {
  90. startTime = dateString[0] + ' 00:00:00'
  91. endTime = dateString[1] + ' 23:59:59'
  92. }
  93. setTableSelect({ ...tableSelect, startTime, endTime, pageNum: 1 })
  94. }
  95. // 点击新增或者编辑按钮
  96. const addObject = (id?: any) => {
  97. // 清空详情页面里面的附件表格信息
  98. dispatch({ type: 'login/setGoodsSonListZJ', payload: [] })
  99. if (id) history.push(`/object/7/add?k=${pageNumRef.current}&d=${statusRef.current}&id=${id}`)
  100. else history.push(`/object/7/add?k=${pageNumRef.current}&d=${statusRef.current}`)
  101. }
  102. // 点击删除按钮
  103. const delOne = async (id: number) => {
  104. const res: any = await object7DelAPI(id)
  105. if (res.code === 0) {
  106. MessageFu.success('删除成功!')
  107. getList()
  108. dispatch(getObject7ListNum())
  109. }
  110. }
  111. // ---------关于表格
  112. // 页码变化
  113. const paginationChange = (pageNum: number, pageSize: number) => {
  114. setTableSelect({ ...tableSelect, pageNum, pageSize })
  115. }
  116. const results = useSelector((state: RootState) => state.object7Store.info1)
  117. const columns = useMemo(() => {
  118. return [
  119. {
  120. title: '登记编号',
  121. dataIndex: 'num'
  122. },
  123. {
  124. title: '藏品来源',
  125. dataIndex: 'sourceName'
  126. },
  127. {
  128. title: '登记人员',
  129. dataIndex: 'creatorName'
  130. },
  131. {
  132. title: '创建日期',
  133. dataIndex: 'createTime'
  134. },
  135. {
  136. title: '完成日期',
  137. render: (item: any) => (item.day && item.status === 3 ? item.day : '-')
  138. },
  139. {
  140. title: '状态',
  141. dataIndex: 'statusTxt'
  142. },
  143. {
  144. title: '操作',
  145. render: (item: any) => (
  146. <>
  147. <Button
  148. type='text'
  149. danger
  150. onClick={() =>
  151. history.push(
  152. `/object/7/look?k=${pageNumRef.current}&d=${statusRef.current}&id=${item.id}`
  153. )
  154. }
  155. >
  156. 查看
  157. </Button>
  158. {item.status === 0 || item.status === 2 ? (
  159. <AuthButton id={902} type='text' danger onClick={() => addObject(item.id)}>
  160. 编辑
  161. </AuthButton>
  162. ) : null}
  163. {item.status === 1 ? (
  164. <AuthButton
  165. id={904}
  166. onClick={() =>
  167. history.push(
  168. `/object/7/audit?k=${pageNumRef.current}&d=${statusRef.current}&id=${item.id}`
  169. )
  170. }
  171. type='text'
  172. danger
  173. >
  174. 审核
  175. </AuthButton>
  176. ) : null}
  177. {item.status === 0 || item.status === 2 ? (
  178. <Popconfirm
  179. title='确定删除吗?'
  180. okText='确定'
  181. cancelText='取消'
  182. onConfirm={() => delOne(item.id)}
  183. >
  184. <AuthButton id={903} type='text' danger>
  185. 删除
  186. </AuthButton>
  187. </Popconfirm>
  188. ) : null}
  189. </>
  190. )
  191. }
  192. ]
  193. // eslint-disable-next-line react-hooks/exhaustive-deps
  194. }, [])
  195. // 从仓库中获取藏品来源下拉数据
  196. const options = useSelector((state: RootState) => state.loginStore.selectAll['文物来源'])
  197. return (
  198. <div className={styles.Object7}>
  199. <div className='breadTit'>
  200. <BreadTit>
  201. <div className='breadTitRow active'>征集管理</div>
  202. </BreadTit>
  203. </div>
  204. <div className='objectSonMain'>
  205. {/* 顶部筛选 */}
  206. <div className='objectSonMainTit'>
  207. {dataTit.map((v: any) => (
  208. <div
  209. key={v.id}
  210. onClick={() => setTableSelect({ ...tableSelect, status: v.id, pageNum: 1 })}
  211. className={classNames(v.id === tableSelect.status ? 'active' : '')}
  212. >
  213. {v.name}({v.num})
  214. </div>
  215. ))}
  216. </div>
  217. <div className='objectSonMainTable'>
  218. {/* 表格数据筛选 */}
  219. <div className='tableSelectBox'>
  220. <div className='row'>
  221. <span>藏品来源:</span>
  222. <Select
  223. placeholder='请选择'
  224. allowClear
  225. style={{ width: 150 }}
  226. value={tableSelect.sourceName}
  227. onChange={handleChange}
  228. options={options.map((v: any) => ({
  229. label: v.name,
  230. value: v.name
  231. }))}
  232. />
  233. </div>
  234. <div className='row'>
  235. <span>登记人员:</span>
  236. <Input
  237. maxLength={10}
  238. style={{ width: 150 }}
  239. placeholder='请输入'
  240. allowClear
  241. onChange={e => nameChange(e)}
  242. />
  243. </div>
  244. <div className='row'>
  245. <span>创建日期:</span>
  246. <RangePicker onChange={timeChange} />
  247. </div>
  248. <div className='row'>
  249. <AuthButton id={102} type='primary' onClick={() => addObject()}>
  250. 新增
  251. </AuthButton>
  252. </div>
  253. </div>
  254. {/* 表格主体 */}
  255. <div className='tableMain'>
  256. <Table
  257. scroll={{ y: 428 }}
  258. dataSource={results.list}
  259. columns={columns}
  260. rowKey='id'
  261. pagination={{
  262. showQuickJumper: true,
  263. position: ['bottomCenter'],
  264. showSizeChanger: true,
  265. current: tableSelect.pageNum,
  266. pageSize: tableSelect.pageSize,
  267. total: results.total,
  268. onChange: paginationChange
  269. }}
  270. />
  271. </div>
  272. </div>
  273. </div>
  274. </div>
  275. )
  276. }
  277. const MemoObject7 = React.memo(Object7)
  278. export default MemoObject7