index.jsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import React from 'react';
  2. import Page from '@/components/Page';
  3. import { useNavigate } from 'react-router-dom';
  4. import { queryTable } from "@/utils/request";
  5. import { ProTable } from "@ant-design/pro-components";
  6. import { Button, message, Popconfirm } from "antd";
  7. import { getTaCheck, deleteTaCheck, putTaCheck } from '@/service/tacheck';
  8. const queryList = queryTable(getTaCheck);
  9. export default (props) => {
  10. const navigate = useNavigate();
  11. const actionRef = React.useRef();
  12. const onDelete = (item) => {
  13. deleteTaCheck(item.checkId).then(() => {
  14. actionRef.current.reload();
  15. })
  16. }
  17. const onUpdateStatus = (item) => {
  18. putTaCheck(item.checkId, {...item, status: Math.abs(item.status - 1)}).then(() => {
  19. actionRef.current.reload();
  20. })
  21. }
  22. const columns = [
  23. {
  24. title: "测评名称",
  25. dataIndex: "title",
  26. },
  27. {
  28. title: "测评日期",
  29. hideInTable: true,
  30. dataIndex: "dateRange",
  31. valueType: 'dateRange',
  32. search: {
  33. transform: value => ({ startDate: value[0], endDate: value[1] }),
  34. },
  35. },
  36. {
  37. title: "开始日期",
  38. dataIndex: "startDate",
  39. hideInSearch: true,
  40. },
  41. {
  42. title: "结束日期",
  43. dataIndex: "endDate",
  44. hideInSearch: true,
  45. },
  46. {
  47. title: "状态",
  48. dataIndex: "status",
  49. search: false,
  50. valueEnum: {
  51. 1: {
  52. text: "正常",
  53. status: "Processing",
  54. },
  55. 0: {
  56. text: "禁用",
  57. status: "Error",
  58. },
  59. },
  60. },
  61. {
  62. title: "操作",
  63. valueType: "option",
  64. width: 200,
  65. render: (_, record) => [
  66. <Button
  67. key={1}
  68. style={{ padding: 0 }}
  69. type="link"
  70. onClick={() => {
  71. onUpdateStatus(record);
  72. }}
  73. >
  74. {record.status === 1 ? "禁用" : "启用"}
  75. </Button>,
  76. <Button
  77. key={2}
  78. style={{ padding: 0 }}
  79. type="link"
  80. onClick={() => {
  81. navigate(`/check/edit?id=${record.checkId}`);
  82. }}
  83. >
  84. 编辑
  85. </Button>,
  86. <Popconfirm
  87. key={3}
  88. title="您是否确认删除 ?"
  89. onConfirm={() => onDelete(record)}
  90. okText="确定"
  91. cancelText="取消"
  92. >
  93. {/* manualPush */}
  94. <Button style={{ padding: 0 }} type="link">
  95. 删除
  96. </Button>
  97. </Popconfirm>,
  98. ],
  99. },
  100. ]
  101. return (
  102. <Page>
  103. <ProTable
  104. actionRef={actionRef}
  105. rowKey="checkId"
  106. toolBarRender={() => [
  107. <Button
  108. key="1"
  109. type="primary"
  110. onClick={() => {
  111. navigate("/check/edit");
  112. }}
  113. >
  114. 新增
  115. </Button>,
  116. ]}
  117. request={queryList}
  118. columns={columns}
  119. />
  120. </Page>
  121. )
  122. }