CompareModal.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React, { useEffect, useState, useRef, useMemo } from 'react';
  2. import { Form } from '@ant-design/compatible';
  3. import '@ant-design/compatible/assets/index.css';
  4. import { Modal, Checkbox, Row, Col, message, Tabs } from 'antd';
  5. import { connect } from 'dva';
  6. const { TabPane } = Tabs;
  7. // 选择比对清单
  8. function CompareModal(props) {
  9. const { visible, versionList, onClose, onOk, dispatch, version, flowDetail } = props;
  10. const [checkValue, setCheckValue] = useState([]);
  11. const onChange = check => {
  12. if (check.length <= 2) {
  13. setCheckValue(check);
  14. } else {
  15. message.error('只能比对两个文件');
  16. }
  17. };
  18. const handleOk = () => {
  19. if (checkValue.length != 2) {
  20. message.error('请选择要比对的两个文件');
  21. } else {
  22. let checkSheet = [];
  23. versionList.forEach(item => {
  24. if (checkValue.indexOf(item.id) != -1) {
  25. checkSheet.push(item);
  26. }
  27. });
  28. onOk(checkSheet);
  29. onClose();
  30. setCheckValue([]);
  31. }
  32. };
  33. const tabList = useMemo(() => {
  34. let list = {};
  35. versionList.forEach(version => {
  36. let nodeId = version.template_node_id;
  37. if (!nodeId || nodeId === '0') return;
  38. if (!list[nodeId]) {
  39. list[nodeId] = [];
  40. }
  41. list[nodeId].push(version);
  42. });
  43. return Object.keys(list).map(nodeId => ({
  44. name: flowDetail.nodes.find(node => node.Id == nodeId)?.label,
  45. id: nodeId,
  46. list: list[nodeId],
  47. }));
  48. }, [versionList, flowDetail]);
  49. return (
  50. <Modal
  51. title="选择比对文件"
  52. visible={visible}
  53. onCancel={onClose}
  54. onOk={handleOk}
  55. width={600}
  56. bodyStyle={{ paddingTop: 0 }}
  57. >
  58. <Checkbox.Group value={checkValue} style={{ width: '100%' }} onChange={onChange}>
  59. {/* <Row gutter={16}>
  60. {versionList.map(version => (
  61. <Col span={8} key={version.id}>
  62. <Checkbox value={version.id}>{version.version_name}</Checkbox>
  63. </Col>
  64. ))}
  65. </Row> */}
  66. <Tabs>
  67. {tabList.map(tab => (
  68. <TabPane tab={tab.name} key={tab.id}>
  69. {/* <Row gutter={24}>
  70. {tab.list.map(version => (
  71. <Col span={24} key={version.id}>
  72. </Col>
  73. ))}
  74. </Row> */}
  75. {tab.list.map(version => (
  76. <div style={{ marginBottom: 16 }} key={version.id}>
  77. <Checkbox value={version.id}>{version.version_name}</Checkbox>
  78. </div>
  79. ))}
  80. </TabPane>
  81. ))}
  82. </Tabs>
  83. </Checkbox.Group>
  84. </Modal>
  85. );
  86. }
  87. export default connect(({ detail, xflow }) => ({
  88. versionList: detail.versionList,
  89. flowDetail: xflow.flowDetail,
  90. }))(CompareModal);