index.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. import classNames from "classnames";
  2. import { useCallback, useEffect, useMemo, useState } from "react";
  3. import { Button, Form, Input, Select, Table } from "antd";
  4. import { PlusOutlined } from "@ant-design/icons";
  5. import { useNavigate } from "react-router-dom";
  6. import { PageContainer } from "@/components";
  7. import { DageTableActions } from "@dage/pc-components";
  8. import style from "./index.module.scss";
  9. import {
  10. PUBLISH_STATUS_MAP,
  11. ASSESSMENT_TYPE_OPTIONS,
  12. PUBLISH_STATUS_OPTIONS,
  13. } from "../../../constants";
  14. import { deleteManageIndexApi, getManageIndexListApi } from "@/api";
  15. import { debounce } from "lodash";
  16. import { ASS_INDEX_TYPE, IManageIndexDetail } from "@/types";
  17. const DEFAULT_PARAMS = {
  18. pageNum: 1,
  19. pageSize: 20,
  20. searchKey: "",
  21. status: "",
  22. type: "",
  23. };
  24. const ManagementIndexPage = () => {
  25. const navigate = useNavigate();
  26. const [form] = Form.useForm();
  27. const [loading, setLoading] = useState(false);
  28. const [params, setParams] = useState({
  29. ...DEFAULT_PARAMS,
  30. });
  31. const [total, setTotal] = useState(0);
  32. const [list, setList] = useState<IManageIndexDetail[]>([]);
  33. const debounceSearch = useMemo(
  34. () =>
  35. debounce((changedVal: unknown, vals: any) => {
  36. setParams({ ...params, ...vals });
  37. }, 500),
  38. [params]
  39. );
  40. const paginationChange = useCallback(
  41. () => (pageNum: number, pageSize: number) => {
  42. setParams({ ...params, pageNum, pageSize });
  43. },
  44. [params]
  45. );
  46. const getList = useCallback(async () => {
  47. setLoading(true);
  48. try {
  49. const data = await getManageIndexListApi(params);
  50. setList(data.records);
  51. setTotal(data.total);
  52. } finally {
  53. setLoading(false);
  54. }
  55. }, [params]);
  56. const handleDelete = async (item: IManageIndexDetail) => {
  57. await deleteManageIndexApi(item.id);
  58. getList();
  59. };
  60. useEffect(() => {
  61. getList();
  62. }, []);
  63. return (
  64. <PageContainer
  65. title="考核管理"
  66. headerSlot={
  67. <div>
  68. <Button
  69. type="primary"
  70. icon={<PlusOutlined />}
  71. size="large"
  72. className="second-button"
  73. onClick={() =>
  74. navigate("/management/index/create/" + ASS_INDEX_TYPE.FIXED)
  75. }
  76. >
  77. 新增定级评估考核
  78. </Button>
  79. <Button
  80. type="primary"
  81. icon={<PlusOutlined />}
  82. size="large"
  83. className="second-button"
  84. onClick={() =>
  85. navigate("/management/index/create/" + ASS_INDEX_TYPE.OPERATION)
  86. }
  87. >
  88. 新增运行评估考核
  89. </Button>
  90. </div>
  91. }
  92. >
  93. <div className={style.filter}>
  94. <Form
  95. form={form}
  96. layout="inline"
  97. className="inline-form"
  98. onValuesChange={debounceSearch}
  99. >
  100. <Form.Item label="考核类别">
  101. <div className="w160">
  102. <Form.Item noStyle name="type">
  103. <Select
  104. allowClear
  105. placeholder="请选择"
  106. options={ASSESSMENT_TYPE_OPTIONS}
  107. />
  108. </Form.Item>
  109. </div>
  110. </Form.Item>
  111. <Form.Item label="发布状态">
  112. <div className="w160">
  113. <Form.Item noStyle name="status">
  114. <Select
  115. allowClear
  116. placeholder="请选择"
  117. options={PUBLISH_STATUS_OPTIONS}
  118. />
  119. </Form.Item>
  120. </div>
  121. </Form.Item>
  122. <Form.Item label="搜索" name="searchKey">
  123. <Input allowClear className="w160" placeholder="请输入考核名称" />
  124. </Form.Item>
  125. <Form.Item>
  126. <Button type="primary" onClick={getList}>
  127. 查询
  128. </Button>
  129. </Form.Item>
  130. </Form>
  131. </div>
  132. <div className={style.table}>
  133. <Table
  134. loading={loading}
  135. className={classNames("cus-table large")}
  136. dataSource={list}
  137. rowKey="id"
  138. scroll={{ x: "max-content" }}
  139. columns={[
  140. {
  141. title: "名称",
  142. dataIndex: "name",
  143. align: "center",
  144. minWidth: 100,
  145. },
  146. {
  147. title: "类别",
  148. align: "center",
  149. minWidth: 100,
  150. render: (item: IManageIndexDetail) => {
  151. return ASSESSMENT_TYPE_OPTIONS.find(
  152. (i) => i.value === item.type
  153. )?.label;
  154. },
  155. },
  156. {
  157. title: "说明",
  158. dataIndex: "remark",
  159. align: "center",
  160. minWidth: 100,
  161. ellipsis: true,
  162. },
  163. {
  164. title: "考核周期",
  165. align: "center",
  166. minWidth: 100,
  167. render: (item: IManageIndexDetail) => {
  168. return `${item.dateStart}-${item.dateEnd}`;
  169. },
  170. },
  171. {
  172. title: "发布状态",
  173. align: "center",
  174. minWidth: 100,
  175. render: (item: IManageIndexDetail) => {
  176. return (
  177. <p style={{ color: PUBLISH_STATUS_MAP[item.status].color }}>
  178. {PUBLISH_STATUS_MAP[item.status].label}
  179. </p>
  180. );
  181. },
  182. },
  183. {
  184. title: "编辑时间",
  185. dataIndex: "updateTime",
  186. align: "center",
  187. minWidth: 160,
  188. },
  189. {
  190. title: "编辑人",
  191. dataIndex: "creatorName",
  192. align: "center",
  193. minWidth: 100,
  194. },
  195. {
  196. title: "操作",
  197. align: "center",
  198. fixed: "right",
  199. render: (item: IManageIndexDetail) => {
  200. return (
  201. <DageTableActions
  202. onEdit={() =>
  203. navigate(`/management/index/edit/${item.type}/${item.id}`)
  204. }
  205. onDelete={handleDelete.bind(undefined, item)}
  206. renderBefore={
  207. <>
  208. <Button
  209. type="text"
  210. className={style.button}
  211. onClick={() => navigate("/management/index/detail/1")}
  212. >
  213. 查看
  214. </Button>
  215. <Button
  216. type="text"
  217. className={style.button}
  218. onClick={() =>
  219. navigate(
  220. `/management/index/setting-index/${item.type}/${item.id}`
  221. )
  222. }
  223. >
  224. 设置指标
  225. </Button>
  226. <Button
  227. type="text"
  228. className={style.button}
  229. onClick={() =>
  230. navigate("/management/index/setting-role")
  231. }
  232. >
  233. 设置角色
  234. </Button>
  235. </>
  236. }
  237. />
  238. );
  239. },
  240. },
  241. ]}
  242. pagination={{
  243. showQuickJumper: true,
  244. position: ["bottomCenter"],
  245. showSizeChanger: true,
  246. current: params.pageNum,
  247. pageSize: params.pageSize,
  248. total,
  249. onChange: paginationChange(),
  250. }}
  251. />
  252. </div>
  253. </PageContainer>
  254. );
  255. };
  256. export default ManagementIndexPage;