index.tsx 8.1 KB

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