ReportsSetting.js 72.3 KB
Newer Older
陈龙's avatar
陈龙 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982
/**
 * * 报表设置列表 * create by ChenLong on 2022/6/28 *
 * 功能路径:src\pages\product\ReportsManage\Components\ReportsSetting.js *
 * 菜单参数列表:*变量名*(变量说明,数据类型,是否必填,取值范围) * @changelog: edit by ChenLong 2022年7月7日
 * 增加日期类型的过滤,可以配置日期选择器,只允许存在一个日期类型的过滤;在表单提交时做校验 edit by ChenLong 2022年7月8日 表单的使用方式需要变更,需求为:1.
 * 动态表单控件需要封装成组件; 2. 动态列表需要使用Form.List替换】 待执行 edit by ChenLong 2022年7月8日 变更单页、全部统计的规则
 */

import React, { useEffect, useRef, useState } from 'react';
import {
  DeleteOutlined,
  FormOutlined,
  MinusCircleOutlined,
  PlusOutlined,
  MenuOutlined,
  SettingOutlined,
  LeftOutlined,
  ExportOutlined,
  ImportOutlined,
} from '@ant-design/icons';
import {
  Button,
  Checkbox,
  Divider,
  Form,
  Input,
  InputNumber,
  message,
  Modal,
  Row,
  Select,
  Space,
  Switch,
  Tooltip,
  Table,
  Upload,
} from 'antd';
import { SketchPicker } from 'react-color';
import { arrayMoveImmutable } from 'array-move';
import BasicTable from '@wisdom-components/basictable';
import { reportService } from '../api';
import style from './ReportsSetting.less';
import classname from 'classnames';
import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';
import {
  addReportDetailInfoIndex,
  API,
  exportReportConfig,
  importReportConfig,
} from '../api/service/report';
import { isNumber, isString } from './utils/utils';
import moment from 'moment';
import CustomerColorPicker from './Components/customerColorPicker/CustomerColorPicker';

const { Option } = Select;
const { TextArea } = Input;
const { Search } = Input;
const typeArray = ['文本', '标签', '数值', '链接', '功能', '弹窗', '日期', '日期时间', '附件'];
const filterRule = ['文本', '下拉', '多选', '日期'];
const publicSplit = '&split;';
const USER_ID = window.globalConfig.userInfo.OID;
const ReportsSetting = () => {
  // 报表列表
  const layout = {
    labelCol: { span: 4 },
    wrapperCol: { span: 20 },
  };
  const [form] = Form.useForm();
  const [createMainTableForm] = Form.useForm();
  const [patchSubTableForm] = Form.useForm();
  const [editDetailForm] = Form.useForm();
  const watchType = Form.useWatch('type', form);
  const showFilter = Form.useWatch('isFilter', form);
  const fieldGroupLevel = Form.useWatch('level', form);
  const isStatistics = Form.useWatch('isStatistics', form);
  const [isCreatingMainTable, setIsCreatingMainTable] = useState(false);
  const colorPicker = useRef();
  const reportDetails = useRef();
  const [tableData, setTableData] = useState([]); // 常规使用的数据
  const [tableLoading, setTableLoading] = useState(false);
  const [detailTableVisible, setDetailTableVisible] = useState(false);
  const columns = [
    {
      title: '报表名称',
      dataIndex: 'reportName',
      key: 'reportName',
    },
    {
      title: '主表名称',
      dataIndex: 'tableName',
      key: 'tableName',
    },
    {
      title: '报表字段',
      dataIndex: 'reportFields',
      key: 'reportFields',
      // ellipsis:true,
      render: (text) => (
        <Tooltip title={text}>
          {/* 自动折叠内容时,如果使用Tooltip,Tooltip会无法正确定位;建议手动设置内容折叠 */}
          <span className={style.reportFiled}>{text}</span>
        </Tooltip>
      ),
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      key: 'createTime',
    },
    {
      title: '创建人',
      dataIndex: 'creator',
      key: 'creator',
    },
    {
      title: '操作',
      width: 120,
      render: (text, record) => {
        return (
          <div style={{ display: 'flex', justifyContent: 'space-around' }}>
            <FormOutlined
              title={'编辑字段'}
              onClick={() => editReport(record)}
              style={{ color: '#1685FF' }}
            />
            <SettingOutlined
              title={'设置'}
              style={{ color: 'rgba(0,0,0,.55)' }}
              onClick={() => {
                setCurrentReport(record);
                clickReport(record.id);
              }}
            />
            <ExportOutlined title={'导出配置'} onClick={() => exportConfigs(record)} />
            <DeleteOutlined
              title={'删除报表'}
              style={{ color: 'red' }}
              onClick={() => deleteReport(record.id)}
            />
          </div>
        );
      },
    },
  ];
  // 详情表
  const [detailData, setDetailData] = useState([]); // 详情表的数据
  const [tempDetailData, setTempDetailData] = useState([]); // 备份数据
  const [detailVisible, setDetailVisible] = useState(false);
  const [backgroundColor, setBackgroundColor] = useState('rgba(0,0,0,.85)');
  const [showSketchPicker, setShowSketchPicker] = useState(false);
  const [createModalVisible, setCreateModalVisible] = useState(false);
  const [activeID, setActiveID] = useState(null);
  const [currentField, setCurrentField] = useState(null);
  const [patchFieldVisible, setPatchFieldVisible] = useState(false);
  const [subTableList, setSubTableList] = useState([]);
  const [allTableList, setAllTableList] = useState([]); // 数据库表
  const [allFields, setAllFields] = useState([]); // 新增主表时的选择的表字段
  const [allSubFields, setAllSubFields] = useState([]); // 新增子表字段
  const [createBtnLoading, setCreateBtnLoading] = useState(false);
  const [currentReport, setCurrentReport] = useState({});
  const [colorCardPosition, setColorCardPosition] = useState({});
  const [labelColorPickerArray, setLabelColorPickerArray] = useState([]); // 标签色板
  const [numberColorPickerArray, setNumberColorPickerArray] = useState([]); // 数值色板
  const [currentColorPicker, setCurrentColorPicker] = useState({
    // 因为使用单例,需要记录是哪一个色板触发了
    data: [],
    callback: () => {},
    index: 0,
    key: 'init', // init 初始化时的key,用来解决初始化报错的问题;wordColor 用来区分是那部分的色板
  }); // 记录需要修改的对象
  const [submitFieldLoading, setSubmitFieldLoading] = useState(false);
  const [relationship, setRelationship] = useState([]);
  const [patchSubTableBtnLoading, setPatchSubTableBtnLoading] = useState(false);
  const [isEditing, setIsEditing] = useState(true);
  const [detailTableLoading, setDetailTableLoading] = useState(false);
  const [selectedRowKeys, setSelectedRowKeys] = useState([]);
  const [selectedRows, setSelectedRows] = useState([]);
  const SortableItem = SortableElement((props) => <tr {...props} />);
  const SortableBody = SortableContainer((props) => <tbody {...props} />);
  // 导入配置
  const uploadProps = {
    action: `${window.location.origin}${API.IMPORT_REPORT_DATA}`,
    multiple: false,
    showUploadList: false,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    withCredentials: true,
    customRequest({ action, file, headers, withCredentials }) {
      const formData = new FormData();
      formData.append('file', file);
      const _data = { userId: USER_ID };
      importReportConfig(
        {
          headers: {
            'Content-Type': 'multipart/form-data',
          },
        },
        { ..._data },
        formData,
      ).then((res) => {
        if (res.code === 0) {
          message.success('导入成功!');
          getData();
        } else {
          message.info(res.msg);
        }
      });
    },
  };
  const onSortEnd = ({ oldIndex, newIndex }) => {
    if (oldIndex !== newIndex) {
      const newData = arrayMoveImmutable(detailData.slice(), oldIndex, newIndex).filter(
        (el) => !!el,
      );
      console.log('Sorted items: ', newData);
      setDetailData(newData);
      setTempDetailData(newData);
      editDetailForm.setFieldsValue(newData);
      saveOrder(newData);
    }
  };
  const DraggableContainer = (props) => (
    <SortableBody
      useDragHandle
      disableAutoscroll
      helperClass="row-dragging"
      onSortEnd={onSortEnd}
      {...props}
    />
  );

  const DraggableBodyRow = ({ className, style, ...restProps }) => {
    const index = detailData.findIndex((x) => x.id === restProps['data-row-key']);
    return <SortableItem index={index} {...restProps} />;
  };
  const returnEqual = (index, key) => {
    // return detailData !== tempDetailData || detailData[index] !== tempDetailData[index] || (detailData[index] && tempDetailData[index] && detailData[index][key] !== tempDetailData[index][key]);
    return (
      (detailData[index] && !tempDetailData[index]) ||
      (detailData[index] &&
        tempDetailData[index] &&
        detailData[index][key] !== tempDetailData[index][key])
    );
  };
  const detailColumns = [
    {
      title: '',
      dataIndex: 'sort',
      width: isEditing ? 0 : 30,
      className: 'drag-visible',
      render: () => <DragHandle />,
    },
    {
      title: '表名',
      dataIndex: 'tableName',
      className: 'drag-visible',
      key: 'tableName',
    },
    {
      title: '字段名',
      dataIndex: 'fieldName',
      key: 'fieldName',
    },
    /*      {
              title: '别名',
              dataIndex: 'fieldAlias',
              key: 'fieldAlias',
              render: (text, record, index) => {
                return isEditing ? <Form.Item name={[index, 'fieldAlias']} rules={[{
                  required: true,
                  message: '请输入字段别名',
                }]}><Input key={`fieldAlias_${index}`} value={record?.fieldAlias}
                           className={returnEqual(index, 'fieldAlias') ? style.boxShadow : ''}
                           onChange={(e) => modifyDetailData('fieldAlias', e.target.value, record, index)} /></Form.Item> : text;
              },
            }, */
    {
      title: '字段组',
      dataIndex: 'fieldGroup',
      key: 'fieldGroup',
    },
    {
      title: '形态',
      dataIndex: 'type',
      key: 'type',
      width: 60,
    },
    {
      title: '列宽',
      dataIndex: 'columnWidth',
      key: 'columnWidth',
      width: 120,
      render: (text, record, index) => {
        return isEditing ? (
          <Form.Item
            name={[index, 'columnWidth']}
            rules={[
              {
                required: true,
                message: '列宽不能为空',
              },
            ]}
          >
            <InputNumber
              value={record?.columnWidth}
              className={returnEqual(index, 'columnWidth') ? style.boxShadow : ''}
              onChange={(e) => modifyDetailData('columnWidth', e, record, index)}
            />
          </Form.Item>
        ) : (
          `${text}px`
        );
      },
    },
    {
      title: '对齐方式',
      dataIndex: 'alignType',
      key: 'alignType',
      width: 80,
      render: (text, record, index) => {
        const _map = {
          left: '左',
          right: '右',
          center: '中',
        };
        return isEditing ? (
          <Form.Item name={[index, 'alignType']}>
            <Select
              onChange={(e) => modifyDetailData('alignType', e, record, index)}
              className={returnEqual(index, 'alignType') ? style.boxShadowOfSelect : ''}
            >
              <Option value={text ? 'left' : ''}></Option>
              <Option value={'center'}></Option>
              <Option value={'right'}></Option>
            </Select>
          </Form.Item>
        ) : (
          _map[text] || '左'
        );
      },
    },
    {
      title: '是否固定',
      dataIndex: 'fixedColumn',
      key: 'fixedColumn',
      width: 120,
      render: (text, record, index) => {
        const _map = {
          left: '左',
          right: '右',
        };
        return isEditing ? (
          <Form.Item name={[index, 'fixedColumn']}>
            <Select
              onChange={(e) => modifyDetailData('fixedColumn', e, record, index)}
              className={returnEqual(index, 'fixedColumn') ? style.boxShadowOfSelect : ''}
            >
              <Option value={''}>不固定</Option>
              <Option value={'left'}></Option>
              <Option value={'right'}></Option>
            </Select>
          </Form.Item>
        ) : (
          _map[text] || '不固定'
        );
      },
    },
    {
      title: '是否显示',
      dataIndex: 'isShow',
      key: 'isShow',
      width: 100,
      render: (text, record, index) => {
        return isEditing ? (
          <Form.Item name={[index, 'isShow']} valuePropName="checked">
            <Switch
              onChange={(e) => modifyDetailData('isShow', e, record, index)}
              checkedChildren="显示"
              unCheckedChildren="不显示"
              defaultChecked={false}
              className={returnEqual(index, 'isShow') ? style.boxShadowOfSwitch : ''}
            />
          </Form.Item>
        ) : text ? (
          '是'
        ) : (
          '否'
        );
      },
    },
    {
      title: '是否过滤',
      dataIndex: 'isFilter',
      key: 'isFilter',
      width: 120,
      render: (text, record, index) => {
        return isEditing ? (
          <Form.Item name={[index, 'isFilter']} valuePropName="checked">
            <Switch
              onChange={(e) => modifyDetailData('isFilter', e, record, index)}
              checkedChildren="开启"
              unCheckedChildren="关闭"
              defaultChecked={false}
              className={returnEqual(index, 'isFilter') ? style.boxShadowOfSwitch : ''}
            />
          </Form.Item>
        ) : text ? (
          '是'
        ) : (
          '否'
        );
      },
    },
    {
      title: '过滤类型',
      dataIndex: 'filterRule',
      key: 'filterRule',
      width: 120,
      render: (text, record, index) => {
        return isEditing ? (
          <Form.Item name={[index, 'filterRule']}>
            <Select
              disabled={!record.isFilter}
              onChange={(e) => modifyDetailData('filterRule', e, record, index)}
              className={returnEqual(index, 'filterRule') ? style.boxShadowOfSelect : ''}
            >
              <Option value={''}>不过滤</Option>
              {filterRule.map((item) => (
                <Option value={item}>{item}</Option>
              ))}
            </Select>
          </Form.Item>
        ) : (
          text
        );
      },
    },
    {
      title: '向下合并',
      dataIndex: 'isMerge',
      key: 'isMerge',
      width: 120,
      render: (text, record, index) => {
        return isEditing ? (
          <Form.Item name={[index, 'isMerge']} valuePropName="checked">
            <Switch
              onChange={(e) => modifyDetailData('isMerge', e, record, index)}
              checkedChildren="开启"
              unCheckedChildren="关闭"
              defaultChecked={false}
              className={returnEqual(index, 'isMerge') ? style.boxShadowOfSwitch : ''}
            />
          </Form.Item>
        ) : text ? (
          '合并'
        ) : (
          '不合并'
        );
      },
    },
    {
      title: '是否必填',
      dataIndex: 'isRequired',
      key: 'isRequired',
      width: 100,
      render: (text, record, index) => {
        return isEditing ? (
          <Form.Item name={[index, 'isRequired']} valuePropName="checked">
            <Switch
              onChange={(e) => modifyDetailData('isRequired', e, record, index)}
              checkedChildren="是"
              unCheckedChildren="否"
              defaultChecked={false}
              className={returnEqual(index, 'isRequired') ? style.boxShadowOfSwitch : ''}
            />
          </Form.Item>
        ) : text ? (
          '是'
        ) : (
          '否'
        );
      },
    },
    {
      title: '操作',
      width: 80,
      render: (text, record) => {
        return (
          <div style={{ display: 'flex', justifyContent: 'space-around' }}>
            <FormOutlined
              onClick={() => {
                setActiveID(record.id);
                if (record.color) setBackgroundColor(record.color);
                form.setFieldsValue(setDefaultValue(record));
                setCurrentField(setDefaultValue(record));
                setDetailVisible(true);
              }}
            />
            <DeleteOutlined
              onClick={() => deleteReportDetail(record.id)}
              style={{ color: 'red' }}
            />
          </div>
        );
      },
    },
  ];
  const rowSelection = {
    onChange: (selectedRowKeys, selectedRows) => {
      setSelectedRowKeys(selectedRowKeys);
      setSelectedRows(selectedRows);
    },
  };
  const wordInputWidth = 300;
  const numberInputWidth = 120;
  const rangeWidth = 500;
  const tagWidth = 400;
  const getData = () => {
    setTableLoading(true);
    reportService
      .getReportConfigList()
      .then((res) => {
        if (res.code === 0) {
          // 增加visible属性,后续搜索时需要
          let _data = res.data.map((item) => {
            let _item = { ...item };
            _item.visible = true;
            return _item;
          });
          setTableData(_data);
        } else {
          message.error(res.msg);
        }
        setTableLoading(false);
      })
      .catch((err) => {
        setTableLoading(false);
      });
  };
  const clickReport = (reportId) => {
    setTableLoading(true);
    reportService
      .getReportDetailsInfo({ reportId })
      .then((res) => {
        if (res.code === 0) {
          setTableLoading(false);
          setDetailTableVisible(true);
          // 增加visible属性,方便后续检索的属性变更
          let _final = res.data.details.map((item) => {
            let _item = { ...item };
            _item.visible = true;
            return _item;
          });
          editDetailForm.setFieldsValue(_final);
          setDetailData(_final);
          setTempDetailData(_final);
          // 存储关联关系
          setRelationship(res.data.child);
        }
      })
      .catch((err) => {
        setTableLoading(false);
      });
  };
  const restCreateReportForm = () => {
    createMainTableForm.resetFields();
    setAllFields([]);
  };
  const createReport = () => {
    setCreateBtnLoading(true);
    createMainTableForm
      .validateFields()
      .then((values) => {
        let _data = {
          reportName: values.reportName,
          tableName: values.tableName,
          reportFields: values.reportFields.join(','),
          creator: String(globalConfig.userInfo.OID),
        };
        if (currentReport && currentReport.id) {
          _data.id = currentReport.id;
          return editReportOrSubTable({ rM_ReportInfo: [_data] }, () => {
            setCreateBtnLoading(false);
            setCreateModalVisible(false);
            getData();
            restCreateReportForm();
          });
        }
        addReportOrPatchSubTable({ rM_ReportInfo: [_data] }, () => {
          setCreateBtnLoading(false);
          setCreateModalVisible(false);
          getData();
          restCreateReportForm();
        });
      })
      .catch((err) => {
        setCreateBtnLoading(false);
      });
  };
  const deleteReport = (reportId) => {
    Modal.confirm({
      title: '请确认',
      content: '是否删除该报表?',
      onOk: () => {
        reportService.deleteReportInfo({ reportId }).then((res) => {
          if (res.code === 0) {
            message.success('删除成功!');
            getData();
          }
        });
      },
    });
  };
  const deleteReportDetail = (reportDetailId) => {
    Modal.confirm({
      title: '请确认',
      content: '是否删除该参数?',
      onOk: () => {
        reportService.deleteReportDetailInfo({ reportDetailId }).then((res) => {
          if (res.code === 0) {
            clickReport(currentReport.id);
            message.success('删除成功!');
          } else {
            message.error(res.code);
          }
        });
      },
    });
  };
  const deleteField = () => {};
  const editReport = (record) => {
    openCreateModal();
    setCurrentReport(record);
    setIsCreatingMainTable(false);
    createMainTableForm.setFieldsValue({
      tableName: record.tableName,
      reportName: record.reportName,
      reportFields: record.reportFields.split(','),
    });
    getFieldsFromTable(record.tableName, 'mainTable');
  };
  const addReportOrPatchSubTable = (data, callback) => {
    reportService.addReportInfo(data).then((res) => {
      if (res.code === 0) {
        message.success('提交成功!');
      } else {
        message.error(res.msg);
      }
      if (callback) callback();
    });
  };
  const editReportOrSubTable = (data, callback) => {
    reportService.editReportInfo(data).then((res) => {
      if (res.code === 0) {
        message.success('提交成功!');
      } else {
        message.error(res.msg);
      }
      if (callback) callback();
    });
  };
  // 切换字段的同时,如果数据有修改,那需要保存之前的数据 edit by ChenLong 2022年8月29日
  const changeField = (record) => {
    // submitReportDetails('changeField').then(res => {
    setActiveID(record.id);
    form.setFieldsValue(setDefaultValue(record));
    // 手动设置文字的颜色
    setBackgroundColor(record.color);
    // 手动设置labelConfig和number的设置
    setNumberColorPickerArray(record.numericalConfigs);
    setLabelColorPickerArray(record.labelConfigs);
    setCurrentField(setDefaultValue(record)); // 为了确保前后数据统一
    // });
  };
  const setDefaultValue = (record) => {
    if (!record) return {};
    let _record = { ...record };
    if (!_record.type) _record.type = '文本';
    if (isString(_record.fieldGroup)) {
      _record.fieldGroup = _record.fieldGroup.split('-').reduce((final, curr, index) => {
        final[`fieldGroup_${record.fieldAlias}_${index}`] = curr;
        return final;
      }, {});
    }
    if (!_record.filterRule) _record.filterRule = '下拉';
    if (!_record.statisticsRule) _record.statisticsRule = '求和';
    // 统计规则变更
    if (isString(_record.statisticsData))
      _record.statisticsData = {
        单页: _record.statisticsData.includes('单页'),
        全部: _record.statisticsData.includes('全部'),
      };
    // 对齐方式设置默认值
    if (!_record.alignType) _record.alignType = 'left';
    return _record;
  };
  // @params: {type:String} 不传入type,默认提交表单、关闭表单;传入type时
  const submitReportDetails = (type) => {
    // 1.表单内的值;2.标签值
    return form.validateFields().then((value) => {
      // 需要将表单内带索引的fieldGroup_[number]处理成后端需要的fieldGroups: a-b-c-d;
      value.fieldGroup = Object.values(value.fieldGroup).join('-');
      let _value = Object.assign(currentField, value);
      // 处理数值颜色和标签颜色
      // 后端需求:labelConfig和numberConfig里面都需要设置默认configId并且id设置为0;
      if (numberColorPickerArray.length)
        _value.numericalConfigs = numberColorPickerArray.map((item) => {
          let _item = { ...item };
          Object.keys(_item).forEach((key) => {
            if (_item[key] === '') _item[key] = null;
          });
          _item.configId = _value.id;
          _item.id = 0;
          return _item;
        });
      if (labelColorPickerArray.length)
        _value.labelConfigs = labelColorPickerArray.map((item) => {
          let _item = { ...item };
          _item.configId = _value.id;
          _item.id = 0;
          return _item;
        });
      // 文字的颜色
      if (backgroundColor) {
        _value.color = backgroundColor;
      }
      // 过滤规则的设置,需要确保日期类型的过滤规则字段是唯一的
      let _isDateArray = detailData.filter((item) => item.filterRule === '日期');
      if (
        _isDateArray.length > 1 ||
        (_isDateArray.length === 1 &&
          _value.filterRule === '日期' &&
          _isDateArray[0].fieldName !== _value.fieldName)
      )
        return message.error('已存在日期类型的过滤,请确保日期类型的过滤规则只存在一个!');
      // 统计规则的提交变更
      let _statisticsData = _value.statisticsData;
      _value.statisticsData = Object.keys(_statisticsData)
        .filter((key) => _statisticsData[key])
        .join(',');
      // 提交请求
      setSubmitFieldLoading(true);
      reportService.addReportDetailInfo({ reportDetails: [_value] }).then((res) => {
        if (res.code === 0) {
          message.success('提交成功!');
        } else {
          message.error(res.msg);
        }
        setSubmitFieldLoading(false);
        if (!type) {
          setDetailVisible(false);
        }
        clickReport(currentReport.id);
      });
    });
  };
  const searchReportList = (e) => {
    let _data = [...tableData];
    let final = _data.map((item) => {
      let _item = { ...item };
      if (!e) {
        _item.visible = true;
      } else {
        _item.visible = _item.reportName.includes(e);
      }
      return _item;
    });
    setTableData(final);
  };
  const openCreateModal = (callback) => {
    if (callback) callback();
    getTableFromDB((data) => {
      setAllTableList(data);
      setCreateModalVisible(true);
    });
  };
  const getTableFromDB = (callback) => {
    reportService.getTables().then((res) => {
      if (res.code === 0) {
        callback(res.data);
      } else {
        message.error(res.msg);
      }
    });
  };
  const getFieldsFromTable = (tableName, type) => {
    let _data = tableName.split(',').map((name) => ({ name: name }));
    reportService.getTableFields({ tableName: _data }).then((res) => {
      if (res.code === 0) {
        if (type === 'mainTable') {
          setAllFields(res.data[0].fieldName);
        }
        if (type === 'subTable') {
          // setTable
          setAllSubFields(res.data);
        }
      }
    });
  };
  const showPatchSubModal = () => {
    getTableFromDB((data) => {
      setSubTableList(data.filter((item) => item.name !== currentReport.tableName));
    });
    setPatchFieldVisible(true);
    getFieldsFromTable(currentReport.tableName, 'mainTable');
    let subTableName = relationship.map((item) => item.tableName);
    if (subTableName && subTableName.length) getFieldsFromTable(subTableName.join(','), 'subTable');
    let _relationshipObject = {};
    relationship.forEach((item) => {
      let _arr = item.relation.split('=');
      _relationshipObject[item.tableName + publicSplit + 'mainTable'] = _arr[0];
      _relationshipObject[item.tableName + publicSplit + 'subTable'] = _arr[1];
    });
    patchSubTableForm.setFieldsValue({
      subTableName,
      subTableFields: detailData.map((item) => item.tableName + publicSplit + item.fieldName),
      ..._relationshipObject,
    });
  };
  const addVirtualColumn = () => {
    // 添加虚拟列;1. 增加字段;2.保存
    const _detailData = [...detailData];
    const _temp = { ..._detailData[0] };
    delete _temp.id;
    // delete _temp.tableName;
    _temp.index = _detailData.length - 1;
    _temp.isVirtualColumn = true;
    //fieldAlias: "软件开票"
    // fieldGroup: "软件开票"
    // fieldName: "软件开票"
    _temp.fieldAlias =
      _temp.fieldGroup =
      _temp.fieldName =
        `虚拟字段${moment().format('YYYY-MM-DD-HH-mm-ss').replace(/-/g, '')}`;
    _detailData.push(_temp);
    setDetailData(_detailData);
    // setTempDetailData(_detailData);
    editDetailForm.setFieldsValue(_detailData);
    // submitDetailFromTable();
  };
  const editDetailInTable = () => {
    // setIsEditing(true);
  };
  const submitDetailFromTable = () => {
    setDetailTableLoading(true);
    editDetailForm.validateFields().then((res) => {
      // 去除掉标签、数字区间内的id
      let _detailData = detailData.map((item) => {
        let _item = { ...item };
        _item.numericalConfigs = _item.numericalConfigs.map((obj) => {
          let _obj = { ...obj };
          _obj.id = 0;
          return _obj;
        });
        _item.labelConfigs = _item.labelConfigs.map((obj) => {
          let _obj = { ...obj };
          _obj.id = 0;
          return _obj;
        });
        return _item;
      });
      reportService
        .addReportDetailInfo({ reportDetails: _detailData })
        .then((res) => {
          if (res.code === 0) {
            message.success('提交成功!');
          } else {
            message.error(res.msg);
          }
          setDetailTableLoading(false);
          setSubmitFieldLoading(false);
          setDetailVisible(false);
          clickReport(currentReport.id);
        })
        .catch((err) => {
          setDetailTableLoading(false);
        });
    });
  };
  const patchSubTable2MainTable = () => {
    patchSubTableForm.validateFields().then(async (value) => {
      setPatchSubTableBtnLoading(true);
      // 由于是动态表单数据,导致表单对象无法正常监听数据,要过滤掉未能监听的数据。
      let _tempArray = value.subTableFields
        .filter((item) => value.subTableName.includes(item.split(publicSplit)[0]))
        .map((item) => item.split(publicSplit));
      let _tempObject = {};
      _tempArray.forEach((item) => {
        if (_tempObject[item[0]]) {
          _tempObject[item[0]].push(item[1]);
        } else {
          _tempObject[item[0]] = [item[1]];
        }
      });
      let rM_ReportInfo = Object.keys(_tempObject).map((key) => {
        return {
          parentId: currentReport.id,
          tableName: key,
          reportFields: _tempObject[key].join(','),
          relation: `${value[key + `${publicSplit}mainTable`]}=${
            value[key + `${publicSplit}subTable`]
          }`,
        };
      });
      await reportService
        .addReportInfo({
          rM_ReportInfo,
        })
        .then((res) => {
          if (res.code === 0) {
            message.success('保存成功!');
            setPatchFieldVisible(false);
          } else {
            message.error(res.msg);
          }
        })
        .catch((err) => {
          message.error('保存失败!');
          setPatchSubTableBtnLoading(false);
        });
      setPatchSubTableBtnLoading(false);
      clickReport(currentReport.id);
    });
  };
  const clickColorCard = (e) => {
    let _cardPosition = e.target.getBoundingClientRect();
    let _wrapperPosition = reportDetails.current.getBoundingClientRect();
    let _colorPicker = colorPicker.current.getBoundingClientRect();
    // 减去最外层的边距之后,还需要减去色块的高度+外边白边的高度+1px的边框+1px间隙 + 8px的最外层容器的padding
    let _cardLeft = _cardPosition.left - _wrapperPosition.left - 4 - 8;
    let _cardTop = _cardPosition.top - _wrapperPosition.top + 14 + 4 + 1 + 1 - 8;
    // 需要考虑超出边距的问题,如果超出边界,则向上,向左平移
    let isOuterOfBottom = _cardTop + _colorPicker.height - _wrapperPosition.height;
    // let isOuterOfRight = (_colorPicker.left + _colorPicker.width) - (_wrapperPosition.top + _wrapperPosition.height);
    if (isOuterOfBottom > 0) {
      _cardTop -= isOuterOfBottom + 10; // 向上平移,10px保证显示效果
      _cardLeft -= _colorPicker.width + 5; // 向左平移,5px保证显示效果
    }
    setColorCardPosition({
      left: _cardLeft,
      top: _cardTop,
    });
    setShowSketchPicker(true);
  };
  const addColorPicker = (data, callback, init) => {
    let _labels = [...data];
    _labels.push(init);
    callback(_labels);
  };
  const removeColorPicker = (data, callback, index) => {
    let _labels = [...data];
    _labels.splice(index, 1);
    callback(_labels);
  };
  const changeColorLabel = (e, data, callback, key, index) => {
    // 接口需要id全部为 0
    let _labels = [...data];
    _labels[index][key] = isNumber(e) ? e : e.target.value; // e为数值时是InputNumber,e为对象时是Input
    callback(_labels);
  };
  const changeBackgroundColor = (e) => {
    // 改变当前的
    let _rgb = e.rgb;
    if (currentColorPicker.key === 'wordColor') {
      setBackgroundColor(`rgba(${_rgb.r},${_rgb.g},${_rgb.b},${_rgb.a})`);
      return;
    }
    let { data, callback, index, key } = currentColorPicker;
    let _data = [...data];
    if (currentColorPicker.key === 'tagColor') {
      _data[index].color = e;
    } else {
      _data[index][key] = `rgba(${_rgb.r},${_rgb.g},${_rgb.b},${_rgb.a})`;
    }
    callback(_data);
  };
  const returnCurrentColor = () => {
    let { data, index, key } = currentColorPicker;
    if (key === 'init') return 'rgba(0,0,0,.65)';
    return data[index][key];
  };
  // 拖拽
  const DragHandle = SortableHandle(() => (
    <MenuOutlined
      style={{
        cursor: 'grab',
        color: '#999',
      }}
    />
  ));
  const saveOrder = (data) => {
    let _data = data.map((item, index) => {
      let _item = {};
      _item.index = index;
      _item.id = item.id;
      return _item;
    });
    addReportDetailInfoIndex(_data).then((res) => {
      if (res.code !== 0) {
        message.error(res.msg);
      } else {
        clickReport(currentReport.id);
      }
    });
  };
  const submitDetail = (data) => {
    reportService.addReportDetailInfo({ reportDetails: data }).then((res) => {
      if (res.code === 0) {
        message.success('提交成功!');
      } else {
        message.error(res.msg);
      }
      setSubmitFieldLoading(false);
      clickReport(currentReport.id);
    });
  };
  const modifyDetailData = (key, value, record, index, data = detailData) => {
    let _data = [...data];
    let _record = { ...record };
    _record[key] = value;
    _data.splice(index, 1, _record);
    setDetailData(_data);
  };
  const batchModify = (key, value) => {
    console.log(key, ':', value);
    // 1.取出勾选的字段;2.批量修改值
    if (selectedRowKeys.length === 0) return message.info('未勾选任何字段');
    let _detailData = detailData.map((item) => {
      let _item = { ...item };

      if (selectedRowKeys.includes(_item.id)) {
        _item[key] = value;
      }
      return _item;
    });
    setDetailData(_detailData);
    editDetailForm.setFieldsValue(_detailData);
  };
  const exportConfigs = (record) => {
    setTableLoading(true);
    exportReportConfig(
      { responseType: 'blob' },
      {
        reportId: record.id,
      },
    ).then((res) => {
      setTableLoading(false);
      if (res && res.code === -1) return message.error(res.msg);
      const url = window.URL.createObjectURL(
        new Blob([res], { type: 'application/json;charset=UTF-8' }),
      );
      const a = document.createElement('a');
      a.href = url;
      a.target = '_blank';
      a.download = `${record.reportName}.json`;
      a.click();
      a.remove();
    });
  };
  useEffect(() => {
    getData();
  }, []);
  useEffect(() => {
    let numericalConfigs = currentField ? currentField.numericalConfigs : [];
    let labelConfigs = currentField ? currentField.labelConfigs : [];
    setNumberColorPickerArray(numericalConfigs);
    setLabelColorPickerArray(labelConfigs);
  }, [watchType]);
  return (
    <div className={style.reportSettings}>
      {detailTableVisible ? (
        <div ref={reportDetails} className={style.reportDetails}>
          {/* 色板容器 */}
          <div
            onClick={(e) => {
              if (e.target.className.includes('colorSketch')) {
                setShowSketchPicker(false);
              }
            }}
            style={{
              visibility: showSketchPicker ? 'visible' : 'hidden',
            }}
            className={style.colorSketch}
          >
            <div
              ref={colorPicker}
              style={{
                position: 'absolute',
                left: colorCardPosition.left,
                top: colorCardPosition.top,
              }}
            >
              {currentColorPicker.key === 'tagColor' ? (
                <CustomerColorPicker
                  clickColorPicker={(backgroundColor) => {
                    changeBackgroundColor(backgroundColor);
                  }}
                />
              ) : (
                <SketchPicker
                  width={240}
                  presetColors={[
                    'rgb(129, 134, 143)',
                    'rgb(41, 114, 244)',
                    'rgb(0, 163, 245)',
                    'rgb(69, 176, 118)',
                    'rgb(222, 60, 54)',
                    'rgb(248, 136, 37)',
                    'rgb(216,180,255)',
                    'rgb(154, 56, 215)',
                    'rgb(221, 64, 151)',
                  ]}
                  color={
                    currentColorPicker.key === 'wordColor' ? backgroundColor : returnCurrentColor()
                  }
                  onChange={(e) => changeBackgroundColor(e)}
                />
              )}
            </div>
          </div>
          <Modal
            title={'附加子表'}
            width={600}
            visible={patchFieldVisible}
            onCancel={() => {
              setPatchFieldVisible(false);
              setAllFields([]);
              setAllSubFields([]);
            }}
            onOk={patchSubTable2MainTable}
            okButtonProps={{
              loading: patchSubTableBtnLoading,
            }}
          >
            <Form form={patchSubTableForm} {...layout}>
              <Form.Item
                label={'子表'}
                rules={[
                  {
                    required: true,
                    message: '请选择需要附加的子表',
                  },
                ]}
                name={'subTableName'}
              >
                <Select
                  placeholder={'请选择子表'}
                  maxTagCount={2}
                  style={{ width: '100%' }}
                  mode={'multiple'}
                  onChange={(value) => {
                    console.log(value);
                    getFieldsFromTable(value.join(','), 'subTable');
                  }}
                >
                  {subTableList.map((item) => (
                    <Option value={item.name}>{item.name}</Option>
                  ))}
                </Select>
              </Form.Item>
              {allSubFields && allSubFields.length ? (
                <Form.Item
                  label={'子表字段'}
                  rules={[
                    {
                      required: true,
                      message: '请选择字段',
                    },
                  ]}
                  name={'subTableFields'}
                >
                  <Checkbox.Group style={{ height: 400, overflowY: 'scroll' }}>
                    {allSubFields.map((item, index) => {
                      return (
                        <div>
                          <Divider orientation="left">{item.tableName}</Divider>
                          <Row style={{ display: 'flex' }}>
                            <Form.Item
                              label={'主表'}
                              name={`${item.tableName}${publicSplit}mainTable`}
                              rules={[
                                {
                                  required: true,
                                  message: '请选择对应字段',
                                },
                              ]}
                            >
                              <Select style={{ width: 150 }} placeholder={'主表对应字段'}>
                                {allFields.map((field) => (
                                  <Option value={`${currentReport.tableName}.${field.name}`}>
                                    {field.name}
                                  </Option>
                                ))}
                              </Select>
                            </Form.Item>
                            <Form.Item
                              label={'子表'}
                              name={`${item.tableName}${publicSplit}subTable`}
                              rules={[
                                {
                                  required: true,
                                  message: '请选择对应字段',
                                },
                              ]}
                            >
                              <Select style={{ width: 150 }} placeholder={'子表关联字段'}>
                                {item.fieldName.map((field) => (
                                  <Option value={`${item.tableName}.${field.name}`}>
                                    {field.name}
                                  </Option>
                                ))}
                              </Select>
                            </Form.Item>
                          </Row>
                          {item.fieldName.map((field) => {
                            return (
                              <Row>
                                <Checkbox value={`${item.tableName}${publicSplit}${field.name}`}>
                                  {field.name}
                                </Checkbox>
                              </Row>
                            );
                          })}
                        </div>
                      );
                    })}
                  </Checkbox.Group>
                </Form.Item>
              ) : (
                ''
              )}
            </Form>
          </Modal>
          <Modal
            title={'编辑字段属性'}
            width={920}
            visible={detailVisible}
            onCancel={() => setDetailVisible(false)}
            destroyOnClose
            footer={null}
            onClick={() => setShowSketchPicker(false)}
          >
            <div style={{ display: 'flex' }}>
              <div style={{ width: 200 }}>
                {detailData ? (
                  <ul>
                    {detailData.map((item, index) => (
                      <li
                        onClick={() => changeField(item)}
                        className={classname(
                          style.fieldList,
                          activeID === item.id ? style.active : '',
                        )}
                        key={item.id}
                      >
                        {item.fieldAlias}
                      </li>
                    ))}
                  </ul>
                ) : (
                  ''
                )}
              </div>
              <div
                style={{
                  flex: 1,
                }}
              >
                {/*<Form {...layout} form={form} initialValues={setDefaultValue(currentField)}*/}
                <Form {...layout} form={form} onFinish={submitReportDetails}>
                  <div style={{ height: 500, overflowY: 'scroll' }}>
                    <Form.Item
                      disabled
                      label={'字段'}
                      name={'fieldName'}
                      rules={[
                        {
                          required: true,
                          message: '编码名称必填',
                        },
                      ]}
                    >
                      <Input disabled style={{ width: wordInputWidth }} />
                    </Form.Item>
                    <Form.Item
                      label={'别名'}
                      name={'fieldAlias'}
                      rules={[
                        {
                          required: true,
                          message: '别名必填且不可重复',
                        },
                      ]}
                    >
                      <Input style={{ width: wordInputWidth }} />
                    </Form.Item>
                    <Form.Item
                      label={'表头级数'}
                      name={'level'}
                      rules={[
                        {
                          required: true,
                          message: '别名必填且不可重复',
                        },
                      ]}
                    >
                      <InputNumber min={1} />
                    </Form.Item>
                    {fieldGroupLevel ? (
                      <Form.Item style={{ marginBottom: 0 }} label={'分组'}>
                        <Input.Group compact>
                          {new Array(Number(fieldGroupLevel) * 2 - 1).fill(1).map((item, index) => {
                            if (index % 2 === 0) {
                              return (
                                <Form.Item
                                  key={`fieldGroup_${index / 2}`}
                                  style={{ width: 160 }}
                                  name={[
                                    'fieldGroup',
                                    `fieldGroup_${currentField.fieldAlias}_${index / 2}`,
                                  ]}
                                  rules={[
                                    {
                                      required: true,
                                      message: '分组名称必填',
                                    },
                                  ]}
                                >
                                  <Input />
                                </Form.Item>
                              );
                            } else {
                              return (
                                <span style={{ color: 'rgba(0,0,0,.25)' }}> &nbsp; _ &nbsp;</span>
                              );
                            }
                          })}
                        </Input.Group>
                      </Form.Item>
                    ) : (
                      ''
                    )}
                    <Form.Item label={'形态'} name={'type'}>
                      <Select style={{ width: wordInputWidth }}>
                        {typeArray.map((item) => (
                          <Option value={item}>{item}</Option>
                        ))}
                      </Select>
                    </Form.Item>
                    <Form.Item label={'字体颜色'} name={'color'}>
                      <div
                        style={{
                          padding: 4,
                          display: 'inline-flex',
                          borderRadius: '2px',
                          border: '1px solid rgba(0,0,0,.35)',
                        }}
                      >
                        <div
                          style={{
                            width: '36px',
                            height: '14px',
                            borderRadius: '2px',
                            border: '1px solid rgba(0,0,0,.35)',
                            backgroundColor: backgroundColor,
                          }}
                          onClick={(e) => {
                            clickColorCard(e);
                            setCurrentColorPicker({
                              key: 'wordColor',
                            });
                          }}
                        />
                      </div>
                    </Form.Item>
                    {watchType === '数值' ? (
                      <Form.Item label={'区间设置'}>
                        {numberColorPickerArray.map((item, index) => {
                          return (
                            <Space
                              key={item.key}
                              style={{
                                display: 'flex',
                                marginBottom: 8,
                                width: rangeWidth,
                              }}
                              align="baseline"
                            >
                              <Form.Item label={'最小值'}>
                                <InputNumber
                                  value={item.minValue}
                                  onChange={(e) =>
                                    changeColorLabel(
                                      e,
                                      numberColorPickerArray,
                                      setNumberColorPickerArray,
                                      'minValue',
                                      index,
                                    )
                                  }
                                />
                              </Form.Item>
                              <Form.Item label={'最大值'}>
                                <InputNumber
                                  value={item.maxValue}
                                  onChange={(e) =>
                                    changeColorLabel(
                                      e,
                                      numberColorPickerArray,
                                      setNumberColorPickerArray,
                                      'maxValue',
                                      index,
                                    )
                                  }
                                />
                              </Form.Item>
                              <Form.Item label={'颜色'}>
                                <div
                                  style={{
                                    padding: 4,
                                    display: 'inline-flex',
                                    borderRadius: '2px',
                                    border: '1px solid rgba(0,0,0,.35)',
                                  }}
                                >
                                  <div
                                    style={{
                                      width: '36px',
                                      height: '14px',
                                      borderRadius: '2px',
                                      border: '1px solid rgba(0,0,0,.35)',
                                      backgroundColor: item.color,
                                    }}
                                    onClick={(e) => {
                                      clickColorCard(e);
                                      setCurrentColorPicker({
                                        data: numberColorPickerArray,
                                        callback: setNumberColorPickerArray,
                                        index,
                                        key: 'color',
                                      });
                                    }}
                                  />
                                </div>
                              </Form.Item>
                              <MinusCircleOutlined
                                onClick={() =>
                                  removeColorPicker(
                                    numberColorPickerArray,
                                    setNumberColorPickerArray,
                                    index,
                                  )
                                }
                              />
                            </Space>
                          );
                        })}
                        <Form.Item>
                          <Button
                            type="dashed"
                            onClick={() =>
                              addColorPicker(numberColorPickerArray, setNumberColorPickerArray, {
                                maxValue: '',
                                minValue: '',
                                color: 'rgba(0,0,0,.65)',
                              })
                            }
                            block
                            icon={<PlusOutlined />}
                          >
                            增加区间
                          </Button>
                        </Form.Item>
                      </Form.Item>
                    ) : (
                      ''
                    )}
                    {watchType === '数值' ? (
                      <Form.Item label={'统计规则'} style={{ display: 'flex' }}>
                        <Space
                          style={{
                            display: 'flex',
                            marginBottom: 8,
                          }}
                        >
                          <Form.Item
                            style={{ marginBottom: 0 }}
                            name={'isStatistics'}
                            valuePropName={'checked'}
                          >
                            <Switch
                              checkedChildren="开启"
                              unCheckedChildren="关闭"
                              defaultChecked={false}
                            />
                          </Form.Item>
                          {isStatistics ? (
                            <>
                              <Form.Item
                                label={'统计规则'}
                                rules={[
                                  {
                                    required: true,
                                    message: '请选择统计规则',
                                  },
                                ]}
                                style={{ marginBottom: 0 }}
                                name={'statisticsRule'}
                              >
                                <Select style={{ width: 120 }}>
                                  <Option value={'求和'}>求和</Option>
                                  <Option value={'求平均'}>求平均</Option>
                                  <Option value={'求方差'}>求方差</Option>
                                </Select>
                              </Form.Item>
                              <Form.Item
                                name={['statisticsData', '单页']}
                                style={{ marginBottom: 0 }}
                                label={'单页统计'}
                                valuePropName={'checked'}
                              >
                                <Switch checkedChildren="开启" unCheckedChildren="关闭" />
                              </Form.Item>
                              <Form.Item
                                name={['statisticsData', '全部']}
                                style={{ marginBottom: 0 }}
                                label={'全部统计'}
                                valuePropName={'checked'}
                              >
                                <Switch checkedChildren="开启" unCheckedChildren="关闭" />
                              </Form.Item>
                            </>
                          ) : (
                            ''
                          )}
                        </Space>
                      </Form.Item>
                    ) : (
                      ''
                    )}
                    {watchType === '标签' ? (
                      <Form.Item label={'标签设置'}>
                        {labelColorPickerArray.map((item, index) => {
                          return (
                            <Space
                              key={item.key}
                              style={{
                                display: 'flex',
                                marginBottom: 8,
                              }}
                              align="baseline"
                            >
                              <Form.Item label={'标签'}>
                                <Input
                                  value={item.labelValue}
                                  onChange={(e) =>
                                    changeColorLabel(
                                      e,
                                      labelColorPickerArray,
                                      setLabelColorPickerArray,
                                      'labelValue',
                                      index,
                                    )
                                  }
                                />
                              </Form.Item>
                              <Form.Item label={'颜色'}>
                                <div
                                  style={{
                                    padding: 4,
                                    display: 'inline-flex',
                                    borderRadius: '2px',
                                    border: '1px solid rgba(0,0,0,.35)',
                                  }}
                                >
                                  <div
                                    style={{
                                      width: '36px',
                                      height: '14px',
                                      borderRadius: '2px',
                                      border: '1px solid rgba(0,0,0,.35)',
                                      backgroundColor: item.color,
                                    }}
                                    onClick={(e) => {
                                      clickColorCard(e);
                                      setCurrentColorPicker({
                                        data: labelColorPickerArray,
                                        callback: setLabelColorPickerArray,
                                        index,
                                        key: 'tagColor',
                                      });
                                    }}
                                  />
                                </div>
                              </Form.Item>
                              <MinusCircleOutlined
                                onClick={() =>
                                  removeColorPicker(
                                    labelColorPickerArray,
                                    setLabelColorPickerArray,
                                    index,
                                  )
                                }
                              />
                            </Space>
                          );
                        })}
                        <Form.Item>
                          <Button
                            type="dashed"
                            onClick={() =>
                              addColorPicker(labelColorPickerArray, setLabelColorPickerArray, {
                                color: 'rgba(0,0,0,.65)',
                                labelValue: '',
                              })
                            }
                            block
                            icon={<PlusOutlined />}
                          >
                            增加区间
                          </Button>
                        </Form.Item>
                      </Form.Item>
                    ) : (
                      ''
                    )}
                    <Form.Item label={'配置'} name={'configItems'}>
                      <TextArea rows={6} />
                    </Form.Item>
                  </div>
                  <Form.Item label={' '} colon={false} style={{ marginTop: 10 }}>
                    <Button onClick={() => setDetailVisible(false)}>取消</Button>
                    <Button
                      loading={submitFieldLoading}
                      style={{ marginLeft: 8 }}
                      type="primary"
                      htmlType="submit"
                    >
                      提交
                    </Button>
                  </Form.Item>
                </Form>
              </div>
            </div>
          </Modal>
          <div className={style.tableWrapper}>
            <Row className={style.controlRow}>
              <LeftOutlined
                className={style.leftBtn}
                onClick={() => {
                  setDetailTableVisible(false);
                }}
              />
              <Form
                layout={'inline'}
                style={{ display: 'flex', flex: 1, justifyContent: 'space-between' }}
              >
                <div style={{ display: 'flex' }}>
                  <Form.Item label={'快速索引'}>
                    <Search
                      onSearch={(e) => {
                        let _detailData = detailData.map((item) => {
                          let _item = { ...item };
                          if (e) {
                            _item.visible =
                              item.fieldName.includes(e) || item.fieldAlias.includes(e);
                          } else {
                            _item.visible = true;
                          }
                          return _item;
                        });
                        setDetailData(_detailData);
                        setTempDetailData(_detailData);
                      }}
                    />
                  </Form.Item>
                  <Form.Item>
                    <Button style={{ marginRight: 8 }} onClick={showPatchSubModal}>
                      附加子表
                    </Button>
                    <Button onClick={addVirtualColumn}>添加虚拟字段</Button>
                  </Form.Item>
                </div>
                <Form.Item style={{ marginRight: 0 }}>
                  {isEditing ? (
                    <>
                      <Button
                        style={{ marginRight: 8 }}
                        onClick={() => {
                          setDetailData(tempDetailData);
                          editDetailForm.setFieldsValue(tempDetailData);
                        }}
                      >
                        重置
                      </Button>
                      <Button
                        type={'primary'}
                        loading={detailTableLoading}
                        style={{ marginRight: 8 }}
                        onClick={submitDetailFromTable}
                      >
                        保存字段
                      </Button>
                    </>
                  ) : (
                    ''
                  )}
                  {isEditing ? (
                    <Button type={'primary'} onClick={() => setIsEditing(false)}>
                      拖动排序
                    </Button>
                  ) : (
                    <Button type={'primary'} onClick={() => setIsEditing(true)}>
                      关闭排序
                    </Button>
                  )}
                </Form.Item>
              </Form>
            </Row>
            <div className={style.tableContent}>
              <Form className={style.tableForm} form={editDetailForm}>
                <BasicTable
                  loading={detailTableLoading}
                  pagination={false}
                  bordered
                  scroll={{ y: `calc(100% - ${selectedRowKeys.length ? 90 : 40}px)` }} // 需要考虑总结栏的高度
                  rowKey={'id'}
                  columns={detailColumns}
                  rowSelection={
                    isEditing
                      ? {
                          type: 'checkbox',
                          ...rowSelection,
                        }
                      : null
                  }
                  dataSource={detailData.filter((item) => item.visible)}
                  summary={(pageData) => {
                    if (detailData && detailData.length > 1 && isEditing && selectedRows.length) {
                      return (
                        <Table.Summary fixed>
                          <Table.Summary.Row>
                            <Table.Summary.Cell colSpan={7}>批量操作</Table.Summary.Cell>
                            <Table.Summary.Cell>
                              <Form.Item>
                                <InputNumber onChange={(e) => batchModify('columnWidth', e)} />
                              </Form.Item>
                            </Table.Summary.Cell>
                            <Table.Summary.Cell>
                              <Form.Item>
                                <Select onChange={(e) => batchModify('alignType', e)}>
                                  <Option value={'left'}></Option>
                                  <Option value={'center'}></Option>
                                  <Option value={'right'}></Option>
                                </Select>
                              </Form.Item>
                            </Table.Summary.Cell>
                            <Table.Summary.Cell>
                              <Form.Item>
                                <Select onChange={(e) => batchModify('fixedColumn', e)}>
                                  <Option value={''}>不固定</Option>
                                  <Option value={'left'}></Option>
                                  <Option value={'right'}></Option>
                                </Select>
                              </Form.Item>
                            </Table.Summary.Cell>
                            <Table.Summary.Cell>
                              <Form.Item>
                                <Switch
                                  checkedChildren="显示"
                                  unCheckedChildren="不显示"
                                  defaultChecked={false}
                                  onChange={(e) => batchModify('isShow', e)}
                                />
                              </Form.Item>
                            </Table.Summary.Cell>
                            <Table.Summary.Cell>
                              <Form.Item>
                                <Switch
                                  checkedChildren="开启"
                                  unCheckedChildren="关闭"
                                  defaultChecked={false}
                                  onChange={(e) => batchModify('isFilter', e)}
                                />
                              </Form.Item>
                            </Table.Summary.Cell>
                            <Table.Summary.Cell>
                              <Form.Item>
                                <Select onChange={(e) => batchModify('isFilter', e)}>
                                  <Option value={''}>不过滤</Option>
                                  <Option value={'文本'}>文本</Option>
                                  <Option value={'下拉'}>下拉</Option>
                                  <Option value={'多选'}>多选</Option>
                                  <Option value={'日期'}>日期</Option>
                                </Select>
                              </Form.Item>
                            </Table.Summary.Cell>
                            <Table.Summary.Cell>
                              <Form.Item>
                                <Switch
                                  checkedChildren="开启"
                                  unCheckedChildren="关闭"
                                  defaultChecked={false}
                                  onChange={(e) => batchModify('isMerge', e)}
                                />
                              </Form.Item>
                            </Table.Summary.Cell>
                            <Table.Summary.Cell>
                              <Form.Item>
                                <DeleteOutlined
                                  onClick={() => batchModify('delete')}
                                  title={'批量删除'}
                                  style={{ color: 'red' }}
                                />
                              </Form.Item>
                            </Table.Summary.Cell>
                          </Table.Summary.Row>
                        </Table.Summary>
                      );
                    }
                  }}
                  components={
                    isEditing
                      ? ''
                      : {
                          body: {
                            wrapper: DraggableContainer,
                            row: DraggableBodyRow,
                          },
                        }
                  }
                  onRow={(record) => {
                    return {
                      onDoubleClick: (e) => {
                        return false;
                        if (
                          e.target.cellIndex === detailColumns.length - 1 ||
                          e.target.cellIndex === void 0
                        )
                          return false;
                        setActiveID(record.id);
                        if (record.color) setBackgroundColor(record.color);
                        form.setFieldsValue(setDefaultValue(record));
                        setCurrentField(setDefaultValue(record));
                        setDetailVisible(true);
                      },
                    };
                  }}
                />
              </Form>
            </div>
          </div>
        </div>
      ) : (
        <div className={style.reportDetails}>
          <Modal
            onCancel={() => setCreateModalVisible(false)}
            closable={false}
            visible={createModalVisible}
            footer={null}
            destroyOnClose
          >
            <Form form={createMainTableForm} {...layout} onFinish={createReport}>
              <Form.Item
                label={'主表'}
                name={'tableName'}
                rules={[
                  {
                    required: true,
                    message: '请选择一张主表',
                  },
                ]}
              >
                <Select
                  disabled={!isCreatingMainTable}
                  placeholder={'选择一张表作为主表'}
                  showSearch
                  optionFilterProp="children"
                  filterOption={(input, option) => option.children.includes(input)}
                  onChange={(e) => {
                    getFieldsFromTable(e, 'mainTable');
                    createMainTableForm.setFields([{ reportFields: [] }]);
                  }}
                >
                  {allTableList.map((item) => (
                    <Option value={item.name}>{item.name}</Option>
                  ))}
                </Select>
              </Form.Item>
              <Form.Item
                label={'报表名称'}
                name={'reportName'}
                rules={[
                  {
                    required: true,
                    message: '请输入报表名称',
                  },
                ]}
              >
                <Input placeholder={'请输入报表名称'} />
              </Form.Item>
              {allFields.length ? (
                <Form.Item
                  label={'报表字段'}
                  name={'reportFields'}
                  rules={[{ required: true, message: '请选择需要绑定的字段!' }]}
                >
                  <Checkbox.Group style={{ maxHeight: 400, overflowY: 'scroll' }}>
                    {allFields.map((item) => (
                      <Row>
                        <Checkbox value={item.name}>{item.name}</Checkbox>
                      </Row>
                    ))}
                  </Checkbox.Group>
                </Form.Item>
              ) : (
                ''
              )}
              <Form.Item label={' '} colon={false}>
                <Button onClick={() => setCreateModalVisible(false)}>取消</Button>
                <Button
                  loading={createBtnLoading}
                  style={{ marginLeft: 8 }}
                  type={'primary'}
                  htmlType={'submit'}
                >
                  提交
                </Button>
              </Form.Item>
            </Form>
          </Modal>
          <div className={style.tableWrapper}>
            <Row className={style.controlRow}>
              <Form layout={'inline'}>
                <Form.Item label={'快速索引'}>
                  <Search onSearch={(e) => searchReportList(e)} />
                </Form.Item>
                <Form.Item>
                  <Button
                    type={'primary'}
                    style={{ marginRight: 8 }}
                    onClick={() =>
                      openCreateModal(() => {
                        setCurrentReport({});
                        setAllFields([]);
                        setIsCreatingMainTable(true);
                        createMainTableForm.setFieldsValue({
                          tableName: '',
                          reportName: '',
                          reportFields: [],
                        });
                      })
                    }
                  >
                    新增
                  </Button>
                  <Upload {...uploadProps}>
                    <Button size="middle" icon={<ImportOutlined />}>
                      导入
                    </Button>
                  </Upload>
                </Form.Item>
              </Form>
            </Row>
            <div className={style.tableContent}>
              <BasicTable
                pagination={false}
                bordered
                loading={tableLoading}
                rowKey={'id'}
                columns={columns}
                dataSource={tableData.filter((item) => item.visible)}
              />
            </div>
          </div>
        </div>
      )}
    </div>
  );
};
export default ReportsSetting;