LocTable.jsx 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. import styles from './style.module.less';
  8. export default (props) => {
  9. const { checkId } = props;
  10. const [list, setList] = React.useState([]);
  11. const [curItem, setCurItem] = React.useState();
  12. const [loading, startLoading, stopLoading] = useBool();
  13. const [open, setOpen] = React.useState(false);
  14. const onEdit = (row) => {
  15. setCurItem(row);
  16. setOpen(true);
  17. }
  18. const columns = [
  19. {
  20. title: '点位名称',
  21. dataIndex: 'name',
  22. key: 'name',
  23. },
  24. {
  25. title: '分值',
  26. key: 'avgScore',
  27. render: (_, row) => row.fullScore ? Number(row.fullScore / (row.num || 1)).toFixed(2) : '-',
  28. },
  29. {
  30. title: '数量',
  31. dataIndex: 'num',
  32. key: 'num',
  33. },
  34. {
  35. title: '小计',
  36. dataIndex: 'fullScore',
  37. key: 'fullScore',
  38. },
  39. {
  40. title: '测评得分',
  41. dataIndex: 'score',
  42. key: 'score',
  43. },
  44. {
  45. title: '操作',
  46. key: 'options',
  47. width: 100,
  48. render: (_, row) => {
  49. return (
  50. <Space>
  51. <Button type="link" onClick={() => onEdit(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. const getRowClassName = (row) => {
  62. return [
  63. styles['yz-table-row'],
  64. (row.itemId == curItem?.itemId) ? styles.active : false,
  65. ].filter(Boolean).join(' ');
  66. }
  67. React.useEffect(() => {
  68. if (checkId) {
  69. startLoading();
  70. getTaCheckItem({pageSize: 500, checkId, itemType: "loc"}).then(res => {
  71. setList(res.records || []);
  72. stopLoading();
  73. }).catch(() => {
  74. stopLoading();
  75. });
  76. }
  77. }, [checkId]);
  78. return (
  79. <Row gutter={24}>
  80. <Col span={12}>
  81. <Card>
  82. <Table
  83. rowKey="typeId"
  84. loading={loading}
  85. columns={columns}
  86. dataSource={list}
  87. pagination={false}
  88. rowClassName={getRowClassName}
  89. onRow={(row) => ({
  90. onClick: () => setCurItem(row),
  91. })}
  92. />
  93. <LocForm
  94. open={open}
  95. checkItem={curItem}
  96. onOpenChange={setOpen}
  97. onChange={onChange}
  98. />
  99. </Card>
  100. </Col>
  101. <Col span={12}>
  102. <QuList itemId={curItem?.itemId} />
  103. </Col>
  104. </Row>
  105. )
  106. }