index.jsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 { getTaIssue } from '@/service/taissue';
  11. import useBool from '@/utils/hooks/useBool';
  12. const getCheck = queryDict(getTaCheck, { labelKey: 'title', valueKey: 'checkId' });
  13. const getLocType = queryDict(getTdLocType, { labelKey: 'name', valueKey: 'typeId' });
  14. const getAnswer = queryTable(getTaCheckAnswer);
  15. const getIssue = queryDict(getTaIssue, { labelKey: 'userName', valueKey: 'issueId' });
  16. export default (props) => {
  17. const [loading, startLoading, stopLoading] = useBool();
  18. const paramsRef = React.useRef();
  19. const [notificationApi, contextHolder] = notification.useNotification();
  20. const columns = [
  21. {
  22. title: "模拟测评",
  23. dataIndex: "checkId",
  24. valueType: 'select',
  25. request: getCheck,
  26. hideInTable: true,
  27. formItemProps: {
  28. rules: [
  29. { required: true, message: '请选择模拟测评' }
  30. ]
  31. }
  32. },
  33. {
  34. title: "点位名称",
  35. valueType: 'select',
  36. request: getLocType,
  37. dataIndex: "typeId",
  38. },
  39. {
  40. title: "问题",
  41. dataIndex: "quTitle",
  42. hideInSearch: true,
  43. },
  44. {
  45. title: "答案",
  46. dataIndex: "answer",
  47. hideInSearch: true,
  48. },
  49. {
  50. title: "答题时间",
  51. dataIndex: "createDate",
  52. valueType: 'date',
  53. hideInSearch: true,
  54. },
  55. {
  56. title: "答题人",
  57. dataIndex: "userName",
  58. valueType: 'select',
  59. request: getIssue,
  60. formItemProps: {
  61. rules: [
  62. { required: true, message: '请选择答题人' }
  63. ]
  64. }
  65. },
  66. ]
  67. const beforeSearchSubmit = (params) => {
  68. paramsRef.current = params;
  69. return params;
  70. }
  71. const onExport = () => {
  72. if (!paramsRef.current) {
  73. notificationApi.warning({ message: '请先进行条件查询' });
  74. return
  75. }
  76. startLoading();
  77. exportTaCheckAnswer(paramsRef.current).then(() => {
  78. stopLoading();
  79. }).catch(() => {
  80. stopLoading();
  81. });
  82. }
  83. return (
  84. <Page>
  85. {contextHolder}
  86. <ProTable
  87. rowKey="answerItemId"
  88. manualRequest
  89. columns={columns}
  90. request={getAnswer}
  91. beforeSearchSubmit={beforeSearchSubmit}
  92. form={{ ignoreRules: false }}
  93. toolBarRender={() => [
  94. <Button
  95. key="1"
  96. type="primary"
  97. loading={loading}
  98. onClick={onExport}
  99. >
  100. 导出
  101. </Button>,
  102. ]}
  103. />
  104. </Page>
  105. )
  106. }