index.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import classNames from "classnames";
  2. import { useCallback, useEffect, useMemo, useState } from "react";
  3. import { Button, Form, Input, Select, Table } from "antd";
  4. import { PageContainer } from "@/components";
  5. import style from "./index.module.scss";
  6. import { debounce } from "lodash";
  7. import { changeArchiveApi, getManageFileListAPi } from "@/api";
  8. import { ARCHIVE_TYPE_MAP } from "@/constants";
  9. import { ARCHIVE_TYPE } from "@/types";
  10. import { downloadFile } from "@/utils";
  11. import { getBaseURL } from "@dage/service";
  12. const DEFAULT_PARAMS = {
  13. pageNum: 1,
  14. pageSize: 20,
  15. searchKey: "",
  16. archive: "",
  17. };
  18. const ManagementReportPage = () => {
  19. const [form] = Form.useForm();
  20. const [params, setParams] = useState({
  21. ...DEFAULT_PARAMS,
  22. });
  23. const [loading, setLoading] = useState(false);
  24. const [total, setTotal] = useState(0);
  25. const [list, setList] = useState<[]>([]);
  26. const baseUrl = getBaseURL();
  27. const debounceSearch = useMemo(
  28. () =>
  29. debounce((changedVal: unknown, vals: any) => {
  30. setParams({ ...params, ...vals });
  31. }, 500),
  32. [params]
  33. );
  34. const paginationChange = useCallback(
  35. () => (pageNum: number, pageSize: number) => {
  36. setParams({ ...params, pageNum, pageSize });
  37. },
  38. [params]
  39. );
  40. const getList = useCallback(async () => {
  41. setLoading(true);
  42. try {
  43. const data = await getManageFileListAPi(params);
  44. setList(data.records);
  45. setTotal(data.total);
  46. } finally {
  47. setLoading(false);
  48. }
  49. }, [params]);
  50. const handleArchive = async (item: any) => {
  51. await changeArchiveApi(
  52. item.archive === ARCHIVE_TYPE.ARCHIVED
  53. ? ARCHIVE_TYPE.UNARCHIVED
  54. : ARCHIVE_TYPE.ARCHIVED,
  55. item.id
  56. );
  57. getList();
  58. };
  59. useEffect(() => {
  60. getList();
  61. }, []);
  62. return (
  63. <PageContainer title="附件管理">
  64. <div className={style.filter}>
  65. <Form
  66. form={form}
  67. layout="inline"
  68. className="inline-form"
  69. onValuesChange={debounceSearch}
  70. >
  71. <Form.Item label="搜索" name="searchKey">
  72. <Input
  73. placeholder="请输入资料名称/考核名称./指标名称/责任部门名称"
  74. className="w450"
  75. allowClear
  76. />
  77. </Form.Item>
  78. <Form.Item label="归档状态">
  79. <div className="w160">
  80. <Form.Item noStyle name="archive">
  81. <Select
  82. allowClear
  83. options={[
  84. {
  85. label: "未归档",
  86. value: 0,
  87. },
  88. {
  89. label: "已归档",
  90. value: 1,
  91. },
  92. ]}
  93. placeholder="请选择"
  94. />
  95. </Form.Item>
  96. </div>
  97. </Form.Item>
  98. <Form.Item>
  99. <Button type="primary" onClick={getList}>
  100. 查询
  101. </Button>
  102. </Form.Item>
  103. </Form>
  104. </div>
  105. <div className={style.table}>
  106. <Table
  107. loading={loading}
  108. className={classNames("cus-table large")}
  109. dataSource={list}
  110. rowKey="id"
  111. scroll={{ x: "max-content" }}
  112. columns={[
  113. {
  114. title: "资料名称",
  115. dataIndex: "name",
  116. align: "center",
  117. minWidth: 100,
  118. },
  119. {
  120. title: "关联考核",
  121. dataIndex: "assessName",
  122. align: "center",
  123. minWidth: 100,
  124. },
  125. {
  126. title: "考核周期",
  127. align: "center",
  128. minWidth: 100,
  129. render: (item) => {
  130. return `${item.dateStart}-${item.dateEnd}`;
  131. },
  132. },
  133. {
  134. title: "关联指标",
  135. dataIndex: "normName",
  136. align: "center",
  137. minWidth: 100,
  138. },
  139. {
  140. title: "附件名称",
  141. dataIndex: "fileName",
  142. align: "center",
  143. minWidth: 100,
  144. },
  145. {
  146. title: "责任部门",
  147. dataIndex: "deptName",
  148. align: "center",
  149. minWidth: 100,
  150. },
  151. {
  152. title: "上传用户",
  153. dataIndex: "creatorName",
  154. align: "center",
  155. minWidth: 100,
  156. },
  157. {
  158. title: "归档状态",
  159. align: "center",
  160. minWidth: 100,
  161. // @ts-ignore
  162. render: (item) => ARCHIVE_TYPE_MAP[item.archive],
  163. },
  164. {
  165. title: "操作",
  166. align: "center",
  167. fixed: "right",
  168. render: (item) => {
  169. const isArchived = item.archive === ARCHIVE_TYPE.ARCHIVED;
  170. return (
  171. <>
  172. <Button
  173. type="link"
  174. onClick={() =>
  175. downloadFile(
  176. baseUrl +
  177. process.env.REACT_APP_IMG_PUBLIC +
  178. item.filePath,
  179. item.fileName
  180. )
  181. }
  182. >
  183. 下载
  184. </Button>
  185. <Button
  186. type="link"
  187. danger={isArchived}
  188. size="small"
  189. onClick={handleArchive.bind(undefined, item)}
  190. >
  191. {!isArchived ? "归档" : "取消归档"}
  192. </Button>
  193. </>
  194. );
  195. },
  196. },
  197. ]}
  198. pagination={{
  199. showQuickJumper: true,
  200. position: ["bottomCenter"],
  201. showSizeChanger: true,
  202. current: params.pageNum,
  203. pageSize: params.pageSize,
  204. total,
  205. onChange: paginationChange(),
  206. }}
  207. />
  208. </div>
  209. </PageContainer>
  210. );
  211. };
  212. export default ManagementReportPage;