index.jsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React from 'react';
  2. import { Button, notification } from "antd";
  3. import { ProTable } from "@ant-design/pro-components";
  4. import { useNavigate } from 'react-router-dom';
  5. import { queryTable, queryDict } from "@/utils/request";
  6. import Page from '@/components/Page';
  7. import { getTaCheck } from '@/service/tacheck';
  8. import { getTdLocType } from '@/service/tdloctype';
  9. import { getTaCheckAnswer, exportTaCheckAnswer } from '@/service/tacheckanswer';
  10. import useBool from '@/utils/hooks/useBool';
  11. const getCheck = queryDict(getTaCheck, { labelKey: 'title', valueKey: 'checkId' });
  12. const getLocType = queryDict(getTdLocType, { labelKey: 'name', valueKey: 'typeId' });
  13. const getAnswer = queryTable(getTaCheckAnswer);
  14. const addOnParams = { itemType: 'loc' };
  15. export default (props) => {
  16. const [loading, startLoading, stopLoading] = useBool();
  17. const paramsRef = React.useRef();
  18. const [notificationApi, contextHolder] = notification.useNotification();
  19. const navigate = useNavigate();
  20. const [params, setParams] = React.useState({});
  21. const goToDetail = (row) => {
  22. navigate(`/checkAnswer/loc/detail?answerId=${row.answerId}&itemType=loc`)
  23. }
  24. const columns = [
  25. {
  26. title: "模拟测评",
  27. dataIndex: "checkId",
  28. valueType: 'select',
  29. request: getCheck,
  30. hideInTable: true,
  31. formItemProps: {
  32. rules: [
  33. { required: true, message: '请选择模拟测评' }
  34. ]
  35. }
  36. },
  37. {
  38. title: "答题时间",
  39. dataIndex: "createDate",
  40. valueType: 'date',
  41. hideInSearch: true,
  42. },
  43. {
  44. title: "点位名称",
  45. valueType: 'select',
  46. request: getLocType,
  47. dataIndex: "typeId",
  48. },
  49. {
  50. title: "详细地址",
  51. dataIndex: "addr",
  52. hideInSearch: true,
  53. },
  54. {
  55. title: "答题人",
  56. dataIndex: "userName",
  57. },
  58. {
  59. title: "得分",
  60. dataIndex: "score",
  61. hideInSearch: true,
  62. },
  63. {
  64. title: '操作',
  65. hideInSearch: true,
  66. key: 'options',
  67. render: (_, row) => {
  68. return (
  69. <Button type="link" onClick={() => goToDetail(row)}>详情</Button>
  70. )
  71. }
  72. }
  73. ]
  74. const beforeSearchSubmit = (params) => {
  75. paramsRef.current = params;
  76. setParams(params);
  77. return params;
  78. }
  79. const onExport = () => {
  80. if (!paramsRef.current) {
  81. notificationApi.warning({ message: '请先进行条件查询' });
  82. return
  83. }
  84. startLoading();
  85. exportTaCheckAnswer({ ...addOnParams, ...params }).then(() => {
  86. // console.log('params', params);
  87. stopLoading();
  88. }).catch(() => {
  89. stopLoading();
  90. });
  91. }
  92. return (
  93. <Page>
  94. {contextHolder}
  95. <ProTable
  96. rowKey="answerId"
  97. manualRequest
  98. columns={columns}
  99. request={getAnswer}
  100. params={addOnParams}
  101. beforeSearchSubmit={beforeSearchSubmit}
  102. form={{ ignoreRules: false }}
  103. toolBarRender={() => [
  104. <Button
  105. key="1"
  106. type="primary"
  107. loading={loading}
  108. onClick={onExport}
  109. >
  110. 导出
  111. </Button>,
  112. ]}
  113. />
  114. </Page>
  115. )
  116. }