LocTable.jsx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import React from 'react';
  2. import useBool from '@/utils/hooks/useBool';
  3. import { Table, Space, Button, Row, Col, Card } from 'antd';
  4. import { getTaCheckItem } from '@/service/tacheckitem';
  5. import QuList from './QuList';
  6. import LocForm from './LocForm';
  7. export default (props) => {
  8. const { checkId } = props;
  9. const [list, setList] = React.useState([]);
  10. const [curItem, setCurItem] = React.useState();
  11. const [loading, startLoading, stopLoading] = useBool();
  12. const [open, setOpen] = React.useState(false);
  13. const onEdit = (row) => {
  14. setCurItem(row);
  15. setOpen(true);
  16. }
  17. const columns = [
  18. {
  19. title: '点位名称',
  20. dataIndex: 'name',
  21. key: 'name',
  22. },
  23. {
  24. title: '分值',
  25. key: 'avgScore',
  26. render: (_, row) => row.fullScore ? Number(row.fullScore / (row.num || 1)).toFixed(2) : '-',
  27. },
  28. {
  29. title: '数量',
  30. dataIndex: 'num',
  31. key: 'num',
  32. },
  33. {
  34. title: '小计',
  35. dataIndex: 'fullScore',
  36. key: 'fullScore',
  37. },
  38. {
  39. title: '测评得分',
  40. dataIndex: 'score',
  41. key: 'score',
  42. },
  43. {
  44. title: '操作',
  45. key: 'options',
  46. width: 100,
  47. render: (_, row) => {
  48. return (
  49. <Space>
  50. <Button type="link" onClick={() => onEdit(row)}>编辑</Button>
  51. <Button type="link" onClick={() => setCurItem(row)}>试题</Button>
  52. </Space>
  53. )
  54. }
  55. },
  56. ]
  57. const onChange = (item) => {
  58. const newList = list.map(x => x.itemId === item.itemId ? item : x);
  59. setList(newList);
  60. }
  61. React.useEffect(() => {
  62. if (checkId) {
  63. startLoading();
  64. getTaCheckItem({pageSize: 500, checkId, itemType: "loc"}).then(res => {
  65. setList(res.records || []);
  66. stopLoading();
  67. }).catch(() => {
  68. stopLoading();
  69. });
  70. }
  71. }, [checkId]);
  72. return (
  73. <Row gutter={24}>
  74. <Col span={12}>
  75. <Card>
  76. <Table
  77. rowKey="typeId"
  78. loading={loading}
  79. columns={columns}
  80. dataSource={list}
  81. pagination={false}
  82. />
  83. <LocForm
  84. open={open}
  85. checkItem={curItem}
  86. onOpenChange={setOpen}
  87. onChange={onChange}
  88. />
  89. </Card>
  90. </Col>
  91. <Col span={12}>
  92. <QuList itemId={curItem?.itemId} />
  93. </Col>
  94. </Row>
  95. )
  96. }