MergeModal.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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, Radio, Row, Col, message, Tabs } from 'antd';
  5. import { connect } from 'dva';
  6. const { TabPane } = Tabs;
  7. // 选择比对清单
  8. function MergeModal(props) {
  9. const { visible, versionList, onClose, onOk, dispatch, version, flowDetail } = props;
  10. const [checkValue, setCheckValue] = useState([]);
  11. const onChange = e => {
  12. setCheckValue(e.target.value);
  13. };
  14. const handleOk = () => {
  15. if (!checkValue) {
  16. message.error('请选择要合并的清单');
  17. } else {
  18. let checkSheet = versionList.find(item => item.id == checkValue);
  19. onOk(checkSheet);
  20. onClose();
  21. setCheckValue();
  22. }
  23. };
  24. const items = useMemo(() => {
  25. let list = {};
  26. versionList.forEach(version => {
  27. let nodeId = version.template_node_id;
  28. if (!nodeId || nodeId === '0' || !version.version_no) return;
  29. if (!list[nodeId]) {
  30. list[nodeId] = [];
  31. }
  32. list[nodeId].push(version);
  33. });
  34. let nodeIds = Object.keys(list)
  35. return nodeIds.filter(nodeId => {
  36. let name = flowDetail.nodes.find(node => node.Id == nodeId)?.label
  37. return name
  38. }).map(nodeId => ({
  39. label: flowDetail.nodes.find(node => node.Id == nodeId)?.label,
  40. key: nodeId + "",
  41. // list: list[nodeId],
  42. children: list[nodeId].map(version => (
  43. <div style={{ marginBottom: 16 }} key={version.id}>
  44. <Radio value={version.id}>{version.version_name}_{version.version_no}</Radio>
  45. </div>
  46. ))
  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. <Radio.Group value={checkValue} style={{ width: '100%' }} onChange={onChange}>
  59. {/* <Row gutter={16}>
  60. {versionList.map(v => {
  61. if (v.id == version.id) return null;
  62. return (
  63. <Col span={8} key={v.id}>
  64. <Radio value={v.id}>{v.version_name}</Radio>
  65. </Col>
  66. );
  67. })}
  68. </Row> */}
  69. <Tabs defaultActiveKey={items[0]?.key} items={items} />
  70. </Radio.Group>
  71. </Modal>
  72. );
  73. }
  74. export default connect(({ detail, xflow }) => ({
  75. versionList: detail.versionList,
  76. flowDetail: xflow.flowDetail,
  77. }))(MergeModal);