CommonClassifyEvent.js 59.5 KB
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
/* eslint-disable array-callback-return,no-undef,prefer-destructuring */
import React, { Component } from 'react';
import moment from 'moment';
import { Modal, message } from 'antd-v4';
import * as commonFunc from './commonFunc';
import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */
import * as commonUtils from '../../utils/utils'; /* 通用方法 */
import commonConfig from '../../utils/config';
import * as commonServices from '../../services/services';

const { confirm } = Modal;

export default (ChildComponent) => {
  return class extends Component {
    constructor(props) {
      super(props);
      this.state = {
      };
    }
    componentWillReceiveProps(nextProps) {
      const {
        formData, sModelsId, searchSolution, masterData,
      } = nextProps;
      const { slaveConfig: slaveConfigOld } = nextProps;
      let { iPageSize } = nextProps;
      if (commonUtils.isEmptyObject(slaveConfigOld) && formData.length > 0) {
        const sId = sModelsId !== undefined ? sModelsId : '';
        /* 数据Id */
        const slaveConfig = formData[0];
        const slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
        let filterCondition = [];
        if (commonUtils.isNotEmptyObject(masterData) && !commonUtils.isEmpty(masterData.sSearchSolutionId) && commonUtils.isNotEmptyArr(searchSolution)) {
          const iIndex = searchSolution.findIndex(item => item.sId === masterData.sSearchSolutionId);
          if (iIndex > -1 && !commonUtils.isEmpty(searchSolution[iIndex].sCondition)) {
            filterCondition = JSON.parse(searchSolution[iIndex].sCondition);
          }
        }
        /* 首先以下拉页数为准 否则以后台页数为准 如果以上都没有设置 则依照config配置的页码设置 */
        if (commonUtils.isNotEmptyNumber(formData[0].iPageSize) && formData[0].iPageSize !== 0) {
          iPageSize = formData[0].iPageSize;
        }
        this.handleGetData(slaveConfig, filterCondition, 1, iPageSize);
        slaveConfig.gdsconfigformslave.push({
          sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnFirst', sControlName: 'BtnFirst',
        });
        slaveConfig.gdsconfigformslave.push({
          sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnPrior', sControlName: 'BtnPrior',
        });
        slaveConfig.gdsconfigformslave.push({
          sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnNext', sControlName: 'BtnNext',
        });
        slaveConfig.gdsconfigformslave.push({
          sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnLast', sControlName: 'BtnLast',
        });
        /* 如果后台配置了审核按钮 则无需配置 */
        const filterExamineIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === '' && item.showName !== '' && item.sControlName === 'BtnExamine');
        if (filterExamineIndex === -1) {
          slaveConfig.gdsconfigformslave.push({
            sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnExamine', sControlName: 'BtnExamine',
          });
        }

        const filterCancelExamineIndex = slaveConfig.gdsconfigformslave.filter(item => item.sName === '' && item.showName !== '' && item.sControlName === 'BtnCancelExamine');
        if (filterCancelExamineIndex === -1) {
          slaveConfig.gdsconfigformslave.push({
            sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnCancelExamine', sControlName: 'BtnCancelExamine',
          });
        }

        slaveConfig.gdsconfigformslave.push({
          sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnUpCheck', sControlName: 'BtnUpCheck',
        });
        slaveConfig.gdsconfigformslave.push({
          sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnDownCheck', sControlName: 'BtnDownCheck',
        });
        slaveConfig.gdsconfigformslave.push({
          sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnCopyTo', sControlName: 'BtnCopyTo',
        });
        slaveConfig.gdsconfigformslave.push({
          sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnCopyFrom', sControlName: 'BtnCopyFrom',
        });
        this.props.onSaveState({
          masterConfig: slaveConfig, slaveConfig, slaveColumn, sId, pageLoading: false,
        });
      }
      if (commonUtils.isEmptyStr(this.props.sClomunType) && commonUtils.isNotEmptyObject(this.props.masterConfig)) {
        const { sTbName } = this.props.masterConfig;
        if (sTbName === 'cahsupplyinit' || sTbName === 'cahcustomerinit' || sTbName === 'cahcashierinit') {
          this.handleGetPeriod();
        }
      }
    }

    shouldComponentUpdate(nextProps) {
      const { slaveColumn } = nextProps;
      return commonUtils.isNotEmptyArr(slaveColumn);
    }
    componentDidUpdate() {
      const { app, slaveData } = this.props;
      const { currentPane } = app;
      if (currentPane.classifyOption === 'add' && slaveData !== undefined) {
        currentPane.classifyOption = '';
        this.handleAdd();
        this.props.onSaveState({ currentPane });
      }
    }

    componentWillUnmount() {
      const { sModelsId } = this.props;
      const { userinfo } = this.props.app;
      this.props.handleSendSocketMessage('release', 'noAction', sModelsId, userinfo.sId, null, null);
    }

    /** 键盘事件监听 */
    onKeyDown = (e, record, sName, name) => {
      const { [`${name}Data`]: tableData, [`${name}Column`]: tableColumn, [`${name}Config`]: tableConfig } = this.props;

      let keyCode = e.keyCode;
      let firstName;
      let bEnter = false;
      if (keyCode === 13) {
        // 判断当前单元格是否是最后,不是则跳到下一格,是则跳到下一行第一格
        bEnter = true;
        const uniqueTableId = `table_${this.props.sModelsId}_${tableConfig.sId}`;
        const currentTable = document.getElementById(uniqueTableId);
        const currentTr = currentTable.querySelector(`tr[data-row-key="${record.sId}"]`);
        const allInput = currentTr.querySelectorAll(`input[id*="${record.sId}"]`);
        const iIndex = Array.from(allInput).findIndex(item => item.getAttribute('id') === `${sName}${record.sId}`);
        if (iIndex < allInput.length - 1) {
          keyCode = 39;
        } else {
          const oFirstInput = allInput[0];
          firstName = oFirstInput.getAttribute('id').replace(record.sId, '');
          keyCode = 40;
        }
      }

      // 以下if条件为 为解决bug2031问题入口 需求:收款单里输入的收款金额,上下键操作把加减金额改为选择上下行(通过上下方向键切换行数)
      if ([38, 40].includes(keyCode)) { // 上键、下键
        e.preventDefault();
        if (tableData.length > 1) { // 当从表行数大于一行时才有上下移动的意义
          const index = tableData.findIndex(item => item.sId === record.sId); // 获取当前编辑行的下标
          if (index > -1) {
            if (keyCode === 38 && index > 0) { // 方向键上键 且 当前编辑行下标大于0时,为0时无法向上
              const lastSid = tableData[index - 1].sId; // 获取上一个id
              this.props.onSaveState({ [`${name}SelectedRowKeys`]: [lastSid] }, () => commonUtils.focus(`${sName}${lastSid}`));
            }
            if (keyCode === 40 && index < tableData.length - 1) { // 方向键下键 且 当前编辑行下标小于最大值时,为最大值时无法向下
              const nextSid = tableData[index + 1].sId; // 获取下一个id
              this.props.onSaveState({ [`${name}SelectedRowKeys`]: [nextSid] }, () => commonUtils.focus(`${firstName || sName}${nextSid}`));
            }
          }
        }
      }
      const move = (keyCode, cursortPosition, columnIndex, currentElement) => {
        const inputType = currentElement.getAttribute('type');
        const value = currentElement.value;
        if (keyCode === 37 && columnIndex > 0 && cursortPosition < 1) { // 左移 则 列下标必须大于0, 且光标在最左侧
          const lastId = `${tableColumn[columnIndex - 1].dataIndex}${record.sId}`;
          if (!commonUtils.focus(lastId, e)) move(keyCode, cursortPosition, columnIndex - 1, currentElement); // 递归
        }
        if (keyCode === 39 && columnIndex < tableColumn.length - 1) { // 右移 则 列下标必须小于列数量-1
          if (!record[sName] || cursortPosition >= value.length || inputType === 'search' || bEnter) { // 当前列为空 或 光标位置不小于当前值的长度
            const nextId = `${tableColumn[columnIndex + 1].dataIndex}${record.sId}`;
            if (!commonUtils.focus(nextId, e)) move(keyCode, cursortPosition, columnIndex + 1, currentElement); // 递归
          }
        }
      };
      if ([37, 39].includes(keyCode)) { // 左键、右键
        const currentElement = document.getElementById(`${sName}${record.sId}`); // 当前编辑框对象
        if (currentElement) {
          const cursortPosition = commonUtils.getCursortPosition(currentElement); // 光标位置
          const columnIndex = tableColumn.findIndex(item => item.dataIndex === sName); // 当前列下标
          move(keyCode, cursortPosition, columnIndex, currentElement);
        }
      }
    }

    /**   获取表数据   */
    handleGetData = async (slaveConfig, slaveFilterCondition, page, pageSize, slaveOrderBy) => {
      const {
        app, sModelsType, slavePagination, iPageSize,
      } = this.props;
      const { currentPane } = app;
      const conditonValues = currentPane.conditonValues;
      if (commonUtils.isNotEmptyObject(conditonValues)) {
        Object.keys(conditonValues).forEach((item) => {
          if (!conditonValues[item] && currentPane[item]) {
            conditonValues[item] = currentPane[item];
          }
        });
      }

      const pageNum = commonUtils.isEmpty(page) ? 1 : page;
      pageSize = commonUtils.isEmpty(pageSize) ? commonUtils.isEmpty(slavePagination) || commonUtils.isEmpty(slavePagination.pageSize) ? iPageSize : slavePagination.pageSize : pageSize;
      const getData = await this.props.handleGetDataSet({
        name: 'slave',
        configData: slaveConfig,
        condition: {
          pageNum, pageSize, bFilter: slaveFilterCondition, sFilterOrderBy: slaveOrderBy, sSqlCondition: conditonValues,
        },
        isWait: true,
      });
      const addState = {}; /* 用于界面树形展示的slaveData */
      if (sModelsType && (sModelsType === 'commonClassify/materialsClassify' || sModelsType.includes('children')) && commonUtils.isNotEmptyObject(getData)) {
        const slaveData = getData.slaveData;
        if (commonUtils.isNotEmptyArr(slaveData)) {
          // addState = this.handleGetSlaveTreeData(slaveData);
          const expandRowKeys = [];
          const firstLevelData = slaveData.filter(item => commonUtils.isEmptyObject(item.sParentId));
          if (commonUtils.isNotEmptyArr(firstLevelData)) {
            firstLevelData.forEach((item) => {
              expandRowKeys.push(item.sId);
            });
            addState.expKeys = expandRowKeys;
          }
        }
      }
      this.props.onSaveState({
        ...getData, ...addState,
      });
    };

    /* 获取树形slaveTreeData数据 */
    handleGetSlaveTreeData = (slaveData) => {
      const slaveTreeData = []; /* 用于界面树形展示的slaveData */
      const expKeys = [];
      const addState = {};
      if (commonUtils.isNotEmptyArr(slaveData)) {
        const { slaveConfig } = this.props;
        /* 若关联性sSqlCondition配置 则取配置 */
        let keyField = 'sId';
        let keyParentField = 'sParentId';
        let sSqlCondition = '';
        if (commonUtils.isNotEmptyObject(slaveConfig)) {
          sSqlCondition = slaveConfig.sSqlCondition;
          if (commonUtils.isNotEmptyObject(sSqlCondition) && commonUtils.isNotEmptyArr(sSqlCondition.split('.')) && sSqlCondition.split('.').length > 2) {
            keyField = sSqlCondition.split('.')[1];
            keyParentField = sSqlCondition.split('.')[2];
          }
        }

        slaveData.forEach((tableDataRow) => {
          const tableDataRowNew = JSON.parse(JSON.stringify(tableDataRow));
          if (commonUtils.isEmpty(tableDataRow[keyParentField])) { /* 一级分类 */
            const childrenData = this.handleGetChildData(slaveData, tableDataRowNew[keyField], keyField, keyParentField); /* 获取子数据 */
            if (commonUtils.isNotEmptyArr(childrenData)) {
              expKeys.push(tableDataRow.sSlaveId);
              tableDataRowNew.children = childrenData;
            }
            slaveTreeData.push(tableDataRowNew);
          }
        });
      }
      addState.slaveTreeData = slaveTreeData;
      addState.expKeys = expKeys;
      return addState;
    }
    /* 获取子节点数据 */
    handleGetChildData = (data, sId, keyField, keyParentField) => {
      if (commonUtils.isNotEmptyArr(data)) {
        const filterData = data.filter(item => item[keyParentField] === sId);
        if (commonUtils.isNotEmptyArr(filterData)) {
          filterData.forEach((child, index) => {
            const filterChildData = this.handleGetChildData(data, child[keyField], keyField, keyParentField);
            if (commonUtils.isNotEmptyArr(filterChildData)) {
              filterData[index].children = filterChildData;
            }
          });
        }
        return filterData;
      }
    }
    handlePaginationChange = (page) => {
      const { slaveConfig, slaveFilterCondition, slavePagination } = this.props;
      this.props.handleGetDataSet({
        name: 'slave', configData: slaveConfig, condition: { pageNum: page, pageSize: slavePagination.pageSize, bFilter: slaveFilterCondition },
      });
    };
    /*   取消操作  */
    handleCancel = () => {
      /*   待用数据声明   */
      const {
        sModelsId, slaveConfig, slaveFilterCondition, slavePagination, slaveOrderBy, app, iPageSize,
      } = this.props;
      const { userinfo } = app;
      const onSendSocketMessage = this.props.handleSendSocketMessage;
      const onGetDataOk = this.handleGetData;
      const onSaveStateOk = this.props.onSaveState;
      confirm({
        title: '确定要取消',
        onOk() {
          onGetDataOk(slaveConfig, slaveFilterCondition, slavePagination.current, iPageSize, slaveOrderBy);
          onSaveStateOk({ enabled: false });
          onSendSocketMessage('release', 'noAction', sModelsId, userinfo.sId, null, null);
        },
        onCancel() {
        },
      });
    };
    /**   点击修改按钮操作   */
    handleEdit = async () => {
      const {
        sModelsId, slaveConfig, slaveFilterCondition, slavePagination, slaveOrderBy, app, formSrcRoute, slaveSelectedRowKeys, dispatch, iPageSize,
      } = this.props;
      const { userinfo } = app;
      const addState = {};
      if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
        message.error('请选择修改行!');
        this.props.onSaveState({
          loading: false,
        });
        return;
      }
      const lockUrl = `${commonConfig.server_host}business/addSysLocking?sModelsId=${sModelsId}&sName=${formSrcRoute}`;
      const value = {
        tableName: slaveConfig.sTbName,
        sId: [slaveSelectedRowKeys[0]],
      };
      const { data } = await commonServices.postValueService(app.token, value, lockUrl);
      // eslint-disable-next-line no-underscore-dangle
      const _this = this;
      if (data.code === 1) { /*   失败   */
        _this.props.onSaveState({ enabled: true, loading: false });
      } else if (data.code === -7) {
        // eslint-disable-next-line no-underscore-dangle
        confirm({
          title: '单据校验', /* 防呆校验 */
          content: data.msg,
          onOk() {
            _this.props.onSaveState({ enabled: true });
          },
          onCancel() {
          },
          okText: '是',
          cancelText: '否',
        });
        this.props.onSaveState({
          loading: false,
        });
        return true;
      } else if (data.code === 2 || data.code === -8) {
        Modal.info({
          title: '温馨提示:',
          content: (
            <div>
              {commonFunc.getReturnMsg(data.msg)}
            </div>
          ),
          okText: '确认',
          onOk() {
            _this.props.onSaveState({ enabled: false, loading: false });
            addState.sUseInfo = data.msg;
          },
        });
      } else { /*   失败   */
        this.props.onSaveState({ enabled: false, loading: false });
        addState.sUseInfo = data.msg;
        if (commonUtils.isNotEmptyObject(data.erroMsg)) {
          message.error(data.erroMsg);
        }
        return;
      }
      this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, iPageSize, slaveOrderBy);
      let timValue = 0;
      if (this.props.app.webSocket === null || this.props.app.webSocket.readyState !== WebSocket.OPEN) {
        this.props.dispatch({ type: 'app/createWebSocket', payload: { reStart: true, dispatch } });
        timValue = 3000;
      }
      const reset = (ws, config1) => {
        clearTimeout(config1.timerServer);
        clearTimeout(config1.serverTimer);
        start(ws, config1);
      };
      const start = (ws, config1) => {
        config1.timerServer = setTimeout(() => {
          const message = { sendFrom: this.props.app.userinfo.sId, connectTest: 'test' }; // param 存放其它参数  keyName 需要放入Redis的数据key,keyValue 需要放入Redis的数据key 的值
          ws.send(JSON.stringify(message));
        }, config1.timeoutServer);
      };
      setTimeout(() => {
        this.props.app.webSocket.onmessage = (msg) => {
          reset(this.props.app.webSocket, commonConfig);
          const rtmsg = JSON.parse(msg.data);
          if (rtmsg.action === 'showMsg') {
            message.warning(rtmsg.msg);
            this.props.onSaveState({ loading: false });
          } else if (rtmsg.action === 'loginOut') {
            if (location.pathname.indexOf('/indexOee') > -1) {
              dispatch({ type: 'app/throwErrorOee', payload: { code: -2, msg: rtmsg.msg } });
            } else if (location.pathname.indexOf('/indexMobile') > -1) {
              dispatch({ type: 'app/throwErrorMobile', payload: { code: -2, msg: rtmsg.msg } });
            } else {
              dispatch({ type: 'app/throwError', payload: { code: -2, msg: rtmsg.msg } });
            }
          } else if (rtmsg.action === 'update') {
            this.props.onSaveState({ enabled: true, loading: false });
          } else if (this.props.app.webSocket.homeAction) {
            this.props.app.webSocket.homeAction(msg);
          }
        };
        this.props.handleSendSocketMessage('update', 'showMsg', sModelsId, userinfo.sId, null, null); // 分类型不能以Id来,涉及到多条修改
      }, timValue);
    };
    /**   点击新增按钮操作   */
    handleAdd = () => {
      const { sModelsType, sModelsId } = this.props;
      let { slaveSelectedRowKeys, masterData } = this.props;
      let { slaveData } = this.props;
      if (slaveData === undefined) {
        slaveData = [];
      }
      const newData = this.props.onDataRowAdd('slave', true);/* 调用父级新增 */
      if (commonUtils.isNotEmptyObject(newData)) {
        newData.iOrder = slaveData.length;
      }
      if (sModelsType === 'commonClassfiy/sisPosition') {
        newData.maxBillNo = 'sNo';
      }
      if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) { /* 通用分类新增,默认新增行为选中行 */
        slaveSelectedRowKeys = [];
        slaveSelectedRowKeys.push(newData.sId);
      }
      /* 多级增加 新增同级 */
      if ((sModelsType === 'commonClassify/materialsClassify' || (commonUtils.isNotEmptyObject(sModelsType) && sModelsType.includes('children')))) {
        const iIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
        /* 找到同级子元素的sControlParentId */
        if (iIndex > -1) {
          newData.sParentId = slaveData[iIndex].sParentId;
          /* 找到同级父级sAllId */
          const pId = slaveData[iIndex].sParentId;
          const iParentIndex = slaveData.findIndex(item => item.sId === pId);
          if (iParentIndex > -1) {
            const sAllId = slaveData[iParentIndex].sAllId;
            if (commonUtils.isEmptyObject(sAllId)) {
              message.warn('数据生成错误![sAllId为空]');
              return;
            }
            newData.sAllId = `${sAllId},${newData.sId}`;
          } else {
            newData.sAllId = newData.sId;
          }
          slaveSelectedRowKeys = [newData.sId];
        } else {
          newData.sAllId = newData.sId;
        }
        newData.sStatus = '0';
      }
      newData.sFormId = sModelsId;
      if (commonUtils.isNotEmptyObject(masterData)) {
        masterData = { ...masterData, ...newData };
      }
      newData.sFormId = sModelsId;
      this.props.onSaveState({
        slaveData: [newData, ...slaveData],
        slaveSelectedRowKeys,
        masterData,
        enabled: true,
      });
    };

    /**   点击新增子级按钮操作   */
    handleAddChild = () => {
      const { sModelsType, sModelsId } = this.props;
      let { slaveSelectedRowKeys, expKeys } = this.props;
      let { slaveData } = this.props;
      if (slaveData === undefined) {
        slaveData = [];
      }
      const newData = this.props.onDataRowAdd('slave', true);/* 调用父级新增 */
      if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
        newData.sParentId = slaveSelectedRowKeys[0];
        const iIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
        if (iIndex > -1) {
          const sAllId = slaveData[iIndex].sAllId;
          if (commonUtils.isEmptyObject(sAllId)) {
            message.warn('子级数据生成错误![sAllId为空]'); // 获取父节点的sAllId
            return;
          }
          newData.sAllId = `${sAllId},${newData.sId}`;
        }
      } else {
        message.error('请选择父级分类!');
      }

      if (sModelsType === 'commonClassfiy/sisPosition') {
        newData.maxBillNo = 'sNo';
      }
      newData.sFormId = sModelsId;
      if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) { /* 通用分类新增,默认新增行为选中行 */
        slaveSelectedRowKeys = [];
        slaveSelectedRowKeys.push(newData.sId);
      }
      if (commonUtils.isEmptyArr(expKeys)) { /* 通用分类新增,默认新增行为选中行 */
        expKeys = [];
        expKeys.push(slaveSelectedRowKeys[0]);
      } else {
        expKeys.push(slaveSelectedRowKeys[0]);
      }
      slaveData.push(newData);
      this.props.onSaveState({
        slaveData,
        slaveSelectedRowKeys,
        enabled: true,
        expKeys,
      });
    };
    /* 删除 */
    handleDel = () => {
      const onOkDel = this.handleOkDel;
      confirm({
        title: '确定要删除',
        onOk() {
          onOkDel();
        },
        onCancel() {
        },
      });
    };
    handleOkDel = async () => {
      const returnData = await this.handleTableDel('slave');
      if (returnData) {
        this.handleValidateSave();
      }
    };
    handleTableDel = (name, isWait) => {
      const { app } = this.props;
      const { [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys, sModelsType } = this.props;
      let { [`${name}DelData`]: tableDelData } = this.props;
      tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData;
      if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) {
        if (commonUtils.isNotEmptyObject(sModelsType) && sModelsType.includes('children') && commonUtils.isNotEmptyArr(tableData)) {
          /* 删除该节点及所有子节点 */
          const controlChildData = tableData.filter(item => commonUtils.isNotEmptyObject(item.sAllId) && item.sAllId.indexOf(tableSelectedRowKeys[0]) > -1 && item.sId !== tableSelectedRowKeys[0]);
          if (commonUtils.isNotEmptyArr(tableData)) {
            controlChildData.forEach((itemNew) => {
              tableSelectedRowKeys.push(itemNew.sId);
            });
          }
        }

        for (const sId of tableSelectedRowKeys) {
          /*   看看删除集合和从表中是否都存在该条数据   */
          const tableDataIndex = tableData.findIndex(item => item.sId === sId);
          if (tableDataIndex > -1) {
            /*   删除从表中的数据并存入删除集合中   */
            const slaveDataFilter = tableData[tableDataIndex];
            slaveDataFilter.handleType = 'del';
            tableDelData.push(slaveDataFilter);
          }
        }
        if (isWait) {
          return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [] };
        } else {
          this.props.onSaveState({
            [`${name}Data`]: tableData,
            [`${name}DelData`]: tableDelData,
            [`${name}SelectedRowKeys`]: [],
          });
          return true;
        }
      } else {
        message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseDelData')); // 请选择删除数据
        return false;
      }
    };
    handleViewClick = (name, sName, record, index, myConfig) => {
      if (sName === 'myTableConfig') {
        this.handleQuickViewClick(name, sName, record, index, myConfig);
      } else if (sName === 'sLookFlowHistory') {
        const flowHistroyId = commonUtils.isNotEmptyObject(record) ? record.sId : '';
        this.props.onSaveState({ flowHistroyVisible: true, flowHistroyId });
      } else {
        this.props.onViewClick(name, sName, record, index, myConfig);
      }
    }
    handleGetTableConfig = async (name, sModelsId) => {
      if (commonUtils.isNotEmptyObject(sModelsId)) {
        const newConfig = await this.props.onGetTableConfig(name, sModelsId);
        if (commonUtils.isNotEmptyObject(newConfig)) {
          this.props.onSaveState({ [`${[name]}Config`]: newConfig });
        }
      }
    }
    handleQuickViewClick = async (name, sName, record, index, myConfigArr) => {
      const {
        slaveConfig,
        slaveData,
        slaveFilterCondition,
        slavePagination,
        formRoute,
        sModelsId,
        // slaveSelectedData,
        // masterData,
        // employeeConfig,
      } = this.props;

      let picArr = slaveConfig.gdsconfigformslave.filter(item => (item.sName === sName));
      if (commonUtils.isNotEmptyArr(myConfigArr)) {
        picArr = myConfigArr;
      }

      if (picArr.length > 0) {
        const getConfig = this.handleGetTableConfig;
        const tableDataRow = record;
        const iIndex = index;
        const [{ sActiveId }] = picArr;
        let [{ sActiveKey }] = picArr;
        const sFormId = sActiveId === '1' ? commonUtils.isEmpty(tableDataRow.sFormId) ? tableDataRow.sSrcFormId : tableDataRow.sFormId : sActiveId;
        if (commonUtils.isNotEmptyObject(sActiveKey) && sActiveKey.includes('.')) { /* 接口按钮跳转 如果有slave.对应字段 则需要取出对应字段 */
          const index = sActiveKey.lastIndexOf('.');
          sActiveKey = sActiveKey.substring(index + 1, sActiveKey.length);
        }
        const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sFormId}?sModelsId=${sFormId}&sName=${formRoute}`;
        const filterCondition = [];
        const conditionValues = this.props.getSqlCondition(picArr[0], name, tableDataRow);
        if (!commonUtils.isEmpty(conditionValues)) {
          Object.keys(conditionValues).forEach((item) => {
            if ((item === 'tStartDate_pro' || item.substring(0, 1) === 'p')) {
              if (!commonUtils.isEmpty(conditionValues[item]) && conditionValues[item].length >= 2) {
                const tStartDate = moment(conditionValues[item][0]).format(this.sDateFormat);
                const tEndDate = moment(conditionValues[item][1]).add(1, 'days').format(this.sDateFormat);
                filterCondition.push({
                  bFilterName: item,
                  bFilterCondition: '=',
                  bFilterValue: `${tStartDate},${tEndDate}`,
                });
              }
            } else if ((item === 'mStartDate_pro' || item.substring(0, 1) === 'm')) {
              if (!commonUtils.isEmpty(conditionValues[item])) {
                const tStartDate = moment(conditionValues[item]).startOf('month').format(this.sDateFormat);
                const tEndDate = moment(conditionValues[item]).endOf('month').add(1, 'days').format(this.sDateFormat);
                filterCondition.push({
                  bFilterName: `t${item.substring(1, item.length)}`,
                  bFilterCondition: '=',
                  bFilterValue: `${tStartDate},${tEndDate}`,
                });
              }
            } else if (item.substring(0, 1) === 't') {
              filterCondition.push({
                bFilterName: item,
                bFilterCondition: '=',
                bFilterValue: moment(conditionValues[item]).format(this.sDateFormat),
              });
            } else {
              filterCondition.push({
                bFilterName: item,
                bFilterCondition: '=',
                bFilterValue: conditionValues[item],
              });
            }
          });
        }

        this.props.dispatch({
          type: 'content/onRouter',
          payload: {
            url: sNameUrl,
            refresh: getConfig.bind(this, name, sModelsId), /*   刷新方法   */
            sTabId: commonUtils.createSid(),
            sParentId: this.state.sTabId,
            urlDataType: 'newPane',
            checkedId: myConfigArr[0].sId,
            sName: myConfigArr[0].sName,
            bFilter: slaveFilterCondition,
            pageSize: commonConfig.pageSize,
            pages: slavePagination,
            currentData: slaveData,
            conditonValues: conditionValues,
            newKey: tableDataRow[sActiveKey],
            currentIndex: iIndex,
            filterCondition,
          },
        });
      }
    };
    handleViewChoose= (name, sName, record) => {
      if (sName === 'sParams') { // 产量上报 工艺参数
        const { enabled } = this.props;
        const slaveSelectOneData = record;
        const sProcessParamsSelects = [];
        const sParamData = [];
        let paramType = '';
        if (commonUtils.isNotEmptyObject(slaveSelectOneData)) {
          paramType = slaveSelectOneData.sReportParam; /* 上报参数 */
        }
        if (commonUtils.isEmpty(paramType)) {
          message.warn('无工艺参数!');
          return;
        }
        /* 工序参数以表格形式展示 列 */
        const sParamConfig = {
          bisMutiSelect: false,
          bMutiSelect: false,
        };
        const gdsconfigformslave = [{
          sId: commonUtils.createSid(),
          sName: 'sId',
          showName: '主键',
          bVisible: false,
          iFitWidth: 200,
        }, {
          sId: commonUtils.createSid(),
          sName: 'bSelfCbx',
          showName: '选择',
          bVisible: true,
          iFitWidth: 37,
        }, {
          sId: commonUtils.createSid(),
          sName: 'sParamKey',
          showName: '参数主键',
          bVisible: false,
          iFitWidth: 200,
        }, {
          sId: commonUtils.createSid(),
          sName: 'sParamName',
          showName: '参数名',
          bVisible: true,
          iFitWidth: 230,
        }, {
          sId: commonUtils.createSid(),
          sName: 'sParamValue',
          showName: '参数值',
          bVisible: true,
          iFitWidth: 230,
        }];
        sParamConfig.gdsconfigformslave = gdsconfigformslave;
        const sParamColumn = commonFunc.getHeaderConfig(sParamConfig);
        if (commonUtils.isNotEmptyObject(paramType)) {
          /* 要把数据以表格的形式显示出来 */
          const sParamJsonObj = JSON.parse(paramType);
          for (const key of Object.keys(sParamJsonObj)) {
            if (key.includes('sParam') && !key.includes('DropDown') && !key.includes('Default')) {
              const obj = {};
              obj.sId = commonUtils.createSid();
              obj.sParamKey = key;
              obj.sParamName = sParamJsonObj[key];
              /* 找到数字 找到下拉数据源 */
              const num = key.replace(/[^\d]/g, '').trim();
              if (Number(num)) {
                const number = Number(num);
                const sParamDropDownKey = `sParamDropDown${number}`;
                obj.sDropDownData = sParamJsonObj[sParamDropDownKey]; /* 下拉 */
                const sParamDefaultKey = `sParamDefault${number}`;
                obj.sParamValue = sParamJsonObj[sParamDefaultKey]; /* 默认值 */
                /* 如果sParamValue有值 则替换默认值 */
                const oldKey = `sParamValue${number}`;
                const oldParamValue = slaveSelectOneData[oldKey]; /* 界面打开时,数据集中原始的sParamValue1,sParamValue2数据填充到数据上 */
                if (commonUtils.isNotEmptyObject(oldParamValue)) {
                  obj.sParamValue = oldParamValue; /* 默认值 */
                }
              }
              sParamData.push(obj);
            }
          }
          /* 将sParam1中的数据 还原到sParamData数据中 */
          if (commonUtils.isNotEmptyObject(record.sParams)) {
            const selectedData = JSON.parse(record.sParams);
            if (commonUtils.isNotEmptyArr(selectedData)) {
              selectedData.forEach((itemS) => {
                const iIndex = sParamData.findIndex(item => item.sParamName === itemS.sParamName);
                if (iIndex > -1) {
                  const addState = {};
                  addState.sParamValue = itemS.sParamValue;
                  addState.bSelfCbx = itemS.bSelfCbx;
                  sParamData[iIndex] = { ...sParamData[iIndex], ...addState };
                }
              });
            }

            /* 如果数据集有一个是非选中的则非选中状态 否则全选 */
            if (commonUtils.isNotEmptyArr(sParamColumn)) {
              const iIndex = sParamColumn.findIndex(item => item.dataIndex === 'bSelfCbx');
              if (iIndex > -1) {
                const filterData = sParamData.filter(item => !item.bSelfCbx);
                if (commonUtils.isNotEmptyArr(filterData)) {
                  sParamColumn[iIndex] = { ...sParamColumn[iIndex], bCheckAll: false };
                } else {
                  sParamColumn[iIndex] = { ...sParamColumn[iIndex], bCheckAll: true };
                }
              }
            }
          }
        }
        this.props.onSaveState({
          slaveRecord: record,
          sProcessParamsSelects,
          sParamsModalVisible: true,
          sParamConfig,
          sParamColumn,
          sParamData,
          sParamModalType: 'sReport',
          enabled,
        });
      }
    }

    /* 动态参数标题选择框 全选/取消全选 */
    handleCheckParamChange = () => {
      const {
        sParamData,
        sParamColumn,
      } = this.props;
      /* 全选 取消全选功能 */
      if (commonUtils.isNotEmptyArr(sParamData)) {
        /* 标题bSelfCbx加标识 */
        const iIndex = sParamColumn.findIndex(item => item.dataIndex === 'bSelfCbx');
        if (iIndex > -1) {
          let bSelfCbx = false;
          if (sParamColumn[iIndex].bCheckAll) {
            bSelfCbx = false;
          } else {
            bSelfCbx = true;
          }
          sParamColumn[iIndex] = { ...sParamColumn[iIndex], bCheckAll: bSelfCbx };
          sParamData.forEach((item, index) => {
            sParamData[index] = { ...sParamData[index], bSelfCbx };
          });
        }
        this.props.onSaveState({
          sParamData,
          sParamColumn,
        });
      }
    }

    /* 选择上报参数点击确定 */
    handleReportParamsOk = () => { // 工艺参数弹窗确定按钮
      const {
        slaveData,
        slaveRecord,
        sParamData,
        // enabled,
        sParamModalType,
      } = this.props;
      if (true) {
        if (commonUtils.isNotEmptyArr(slaveData) && commonUtils.isNotEmptyObject(slaveRecord)) {
          const processSelectDataIndex = slaveData.findIndex(item => item.sId === slaveRecord.sId);
          if (processSelectDataIndex > -1) {
            if (commonUtils.isNotEmptyArr(sParamData)) {
              let sParamJsonData = '';
              const sParamSeletedData = sParamData.filter(item => item.bSelfCbx);
              if (commonUtils.isNotEmptyObject(sParamSeletedData)) {
                sParamJsonData = JSON.stringify(sParamSeletedData);
              }
              let { handleType } = slaveData[processSelectDataIndex];
              handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
              if (sParamModalType === 'sReport') { /* 报价参数点击确定 */
                slaveData[processSelectDataIndex].sParams = sParamJsonData;
              }
              slaveData[processSelectDataIndex].handleType = handleType;
            }
          }
        }
        this.props.onSaveState({
          slaveData,
          sParamsModalVisible: false,
        });
      } else {
        this.props.onSaveState({
          sParamsModalVisible: false,
        });
      }
    }

    /**   toolbar审核(消审)   */
    handleAudit = async (flag) => {
      /*   待用数据声明   */
      const { masterData, gdsformconst } = this.props;
      if (!commonUtils.isEmpty(masterData)) {
        /*   作废订单不能审核   */
        if (masterData.bInvalid) {
          message.warning(gdsformconst.filter(item => (item.sName === 'sToVoid'))[0].showName);
          return '';
        }
        /**   数据审核   */
        await this.dataAudit(flag);
      } else {
        this.props.onSaveState({
          loading: false,
        });
      }
    };

    /**   数据审核   */
    dataAudit = async (flag, tmpCheck, isWait) => {
      message.destroy();
      /*   待用数据声明   */
      const {
        sModelsId, masterData, app, slaveConfig, token, sModelsType, slaveData, slaveSelectedRowKeys, slaveFilterCondition,
      } = this.props;
      const sSlaveIdArray = [];
      if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
        slaveSelectedRowKeys.forEach((item) => {
          sSlaveIdArray.push(item);
        });
      }
      const slaveId = sSlaveIdArray.toString();
      /*   数据参数   */
      const value = {
        sClientType: '1',
        paramsMap: {
          iFlag: flag,
          iTmpCheck: commonUtils.isEmptyNumber(tmpCheck) ? 0 : tmpCheck,
          sFormGuid: sModelsId,
          sGuid: masterData.sId,
          sSlaveId: slaveId,
          sBillNo: commonUtils.isNotEmptyObject(masterData.sBillNo) ? masterData.sBillNo : '',
        },
      };
      let clearFlag = false;
      if (sModelsType.includes('sales/salesOrder') || sModelsType.includes('manufacture/workOrder')) {
        if (commonUtils.isNotEmptyArr(slaveData)) {
          for (const item of slaveData) {
            if (commonUtils.isNotEmptyStr(item.sProductInfo)) {
              clearFlag = true;
              break;
            }
          }
        } else {
          this.props.onSaveState({
            loading: false,
          });
          return;
        }
      }
      /*   数据审核   */
      const url = `${commonConfig.server_host}business/doExamine?sModelsId=${sModelsId}`;
      const returnData = (await commonServices.postValueService(app.token, value, url)).data;
      if (isWait) {
        return returnData;
      } else {
        /*   接收返回值   */
        const check = commonFunc.showMessage(app.commonConst, 'BtnExamine');/* 审核 */
        const BtnCancelExamine = commonFunc.showMessage(app.commonConst, 'BtnCancelExamine');/* 销审 */
        if (returnData.code === 1) { /*   成功   */
          this.props.onSaveState({
            loading: false,
          });
          if (flag === 1) {
            /*   审核   */
            if (clearFlag && (sModelsType.includes('sales/salesOrder') || sModelsType.includes('manufacture/workOrder'))) {
              commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductId', []);
              commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductNo', []);
              commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductName', []);
            }
            let outData;
            if (commonUtils.isNotEmptyObject(returnData.dataset)) {
              outData = returnData.dataset.rows[0].dataSet.outData;
            }
            if (commonUtils.isNotEmptyStr(outData[0].sReturn)) {
              const sReturnArray = outData[0].sReturn.split('|');
              if (outData[0].sReturn.split('-').length < 2) {
                // 正常业务提示,非审核模板
                // if (this.props.app.currentPane.refresh !== undefined) {
                //   this.props.app.currentPane.refresh();
                // }
                message.error(check + outData[0].sReturn);
                return;
              }
              const checkConditions = [];
              let checkPersonData = {};
              sReturnArray.forEach((item) => {
                const checkCondition = item.split('-')[2];
                const iIndex = checkConditions.findIndex(itemCondition => itemCondition.condition === checkCondition);
                if (iIndex <= -1) {
                  checkConditions.push({
                    key: commonUtils.createSid(),
                    condition: checkCondition,
                  });
                }
              });
              const sCheckModelId = sReturnArray[0].split('-')[1];
              if (commonUtils.isNotEmptyStr(sCheckModelId)) {
                const urlCheck = `${commonConfig.server_host}checkModel/getUserListByModelId/${sCheckModelId}?sModelsId=${sModelsId}`;
                const dataReturn = (await commonServices.getService(token, urlCheck)).data;
                if (dataReturn.code === 1) {
                  checkPersonData = dataReturn.dataset.rows;
                  checkPersonData.forEach((item) => {
                    item.key = commonUtils.createSid();
                  });
                  this.props.onSaveState({
                    checkConditions, checkPersonData, sCheckModelId, visible: true,
                  });
                  return true;
                } else { /*   失败   */
                  this.props.getServiceError({ msg: check + dataReturn });
                }
              }
            } else {
              message.success(check + returnData.msg);
            }
          } else {
            /*   消审   */
            const { outData } = returnData.dataset.rows[0].dataSet;
            if (commonUtils.isNotEmptyStr(outData[0].sReturn)) {
              message.error(outData[0].sReturn);
            } else {
              // if (this.props.app.currentPane.refresh !== undefined) {
              //   this.props.app.currentPane.refresh();
              // }
              message.success(BtnCancelExamine + returnData.msg);
            }
          }
          await this.handleGetData(slaveConfig, slaveFilterCondition, 1);
          if (this.props.app.currentPane.refresh !== undefined) {
            this.props.app.currentPane.refresh();
          }
        } else { /*   失败   */
          this.props.getServiceError(returnData);
          this.props.onSaveState({
            loading: false,
          });
        }
        return true;
      }
    };

    /**   toolbar校验保存   */
    handleValidateSave = async () => {
      let isTrue = true;
      this.form.validateFields((err) => {
        /*   验证通过与不通过走不同的流程   */
        if (err) { /*   验证失败   */
          /*   直接渲染显示错误提示   */
          for (const key of Object.keys(err)) {
            message.warning(err[key].errors[0].message);
          }
          isTrue = false;
          this.props.onSaveState({
            loading: false,
          });
        } else { /*   验证成功   */
          const {
            slaveData, slaveConfig, slaveDelData,
          } = this.props;
          const data = [];
          if (!commonBusiness.validateTable(slaveConfig, slaveData, this.props)) {
            this.props.onSaveState({
              loading: false,
            });
            isTrue = false;
            return;
          }
          data.push(commonBusiness.mergeData('slave', slaveConfig.sTbName, slaveData, slaveDelData));
          if (slaveConfig.sTbName.toLowerCase().includes('master')) {
            const { sUserName = '' } = commonUtils.convertStrToObj(localStorage.getItem('xlybusinessuserinfo'));
            data[0].column.forEach((item) => {
              const { handleType } = item;
              if (handleType !== 'add') {
                item.sUpdatePerson = sUserName;
                item.tUpdate = moment().format('YYYY-MM-DD HH:mm:ss');
              }
            });
          }
          this.handleSaveData({ data, sClientType: '1' });
        }
      });
      if (!isTrue) throw new Error('异常');
    };
    /**   toolbar保存   */
    handleSaveData = async (params) => {
      const {
        token, sModelsId, slaveFilterCondition, slaveConfig, slavePagination, slaveOrderBy, app, slaveData, iPageSize,
      } = this.props;
      const { userinfo } = app;
      const onSendSocketMessage = this.props.handleSendSocketMessage;
      const returnData = await commonBusiness.saveData({ token, value: params, sModelsId });
      if (commonUtils.isNotEmptyObject(returnData)) {
        /* 防呆校验 */
        if (returnData.code === -7) {
          // eslint-disable-next-line no-underscore-dangle
          const _this = this;
          confirm({
            title: '单据校验', /* 防呆校验 */
            content: returnData.msg,
            onOk() {
              params.iFlag = 1;
              _this.handleSaveData(params);
            },
            onCancel() {
            },
            okText: '保存',
            cancelText: '不保存',
          });
          this.props.onSaveState({
            loading: false,
          });
          return true;
        } else if (returnData.code === 2 || returnData.code === -8) {
          Modal.info({
            title: '温馨提示:',
            content: (
              <div>
                {commonFunc.getReturnMsg(returnData.msg)}
              </div>
            ),
            okText: '确认',
            onOk() {},
          });
        }
        commonUtils.clearStoreDropDownData();
        /* 新记录时,关闭后能自动带值  */
        const callBackRecord = this.props.app.currentPane.newRecordMethod;
        if (callBackRecord !== undefined && commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
          const filterData = slaveData.filter(item => (item.handleType === 'add'));
          const sId = commonUtils.isNotEmptyArr(filterData) && filterData.length > 0 ? filterData[0].sId : null;
          /* 回调 传[新增的数据sId] */
          if (this.props.app.currentPane.newRecordMethod !== undefined) {
            this.props.app.currentPane.newRecordMethod(sId);
          }
        }
        if (this.props.app.currentPane.refresh !== undefined) {
          this.props.app.currentPane.refresh();
        }
        /* END  */
        onSendSocketMessage('release', 'noAction', sModelsId, userinfo.sId, null, null);
        this.props.onSaveState({
          enabled: false, slaveDelData: [], loading: false,
        });
        this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, iPageSize, slaveOrderBy);
        return true;
      } else {
        this.props.onSaveState({
          slaveDelData: [],
          loading: false,
        });
        return false;
      }
    };
    /**   表单回带   */
    handleForm = (form) => {
      this.form = form;
    };
    /* 作废、取消作废的公用函数 */
    handleInvalid = (obj) => {
      const props = { ...this.props, ...this.state, ...obj };
      const onOkInvaild = this.handleOkChangeInvaild;
      confirm({
        title: obj.title,
        onOk() {
          onOkInvaild(props);
        },
        onCancel() {
        },
      });
    };
    /* 切换作废状态 */
    handleOkChangeInvaild = async (props) => {
      props = this.handleOkInvalid(props);
      this.setState({ ...props });
    };
    /** 作废,取消作废 */
    handleOkInvalid = async (props) => {
      const {
        sModelsId, slaveData, slaveConfig, handleType, slaveSelectedRowKeys, app, slavePagination,
      } = props;
      if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
        const { token } = props.app;
        const { sTbName } = slaveConfig;
        const value = {
          sClientType: '1',
          sId: slaveSelectedRowKeys,
          sTableName: sTbName,
          handleType,
          sBooleanCheck: false,
        };
        const url = `${commonConfig.server_host}checkModel/updatebInvalid?sModelsId=${sModelsId}`;
        const { data } = await commonServices.postValueService(token, value, url);
        if (data.code === 1) {
          message.success(data.msg);
          for (const key of slaveSelectedRowKeys) {
            const selectData = slaveData.filter(item => item.sId === key);
            selectData.bInvalid = handleType === 'toVoid';
          }
          /*  作废(取消作废)后刷新页面 */
          this.handlePaginationChange(slavePagination.current);
        } else {
          this.props.getServiceError(data);
        }
        return props;
      } else {
        message.warn(commonFunc.showMessage(app.commonConst, 'sChoosebInvalid'));/* 请选择作废数据 */
      }
    };
    /** 按钮操作事件 */
    handleButtonClick = (name) => {
      if (name === 'BtnOut') {
        this.handleOut();
      } else if (name === 'BtnRefresh') {
        const { slavePagination } = this.props;
        this.handlePaginationChange(slavePagination.current);
      } else if (name === 'BtnSetPeriod') {
        this.handleBtnSetPeriod();
      } else if (name === 'BtnRelievePeriod') {
        this.handleBtnRelievePeriod();
      }
    };

    /* 导出Excel */
    handleOut = async () => {
      const {
        slaveConfig, formRoute, masterData,
      } = this.props;

      /* 导出使用Post提交 */
      const url = `${commonConfig.server_host}excel/export/${slaveConfig.sId}?sModelsId=${slaveConfig.sParentId}&sName=${formRoute}&token=${encodeURIComponent(this.props.app.token)}`;
      const conditionValuesStr = JSON.stringify({ sId: masterData?.sId, sBillNo: masterData?.sBillNo });
      this.handleOpenOut(url, '', '', undefined, conditionValuesStr);
    };

    /* Get提交地址栏参数过多,更改Get提交为Post提交 */
    handleOpenOut = (url, bFilter, slaveOrderBy, sGroupByList, conditionValues) => {
      const newWin = window.open();
      let formStr = '';
      // 设置样式为隐藏,打开新标签再跳转页面前,如果有可现实的表单选项,用户会看到表单内容数据
      formStr = `<form style="visibility:hidden;" method="POST" action="${url}">` +
        `<input type="hidden" name="bFilter" value='${bFilter}' />`;
      if (commonUtils.isNotEmptyObject(conditionValues)) {
        formStr += `<input type="hidden" name="sSqlCondition" value='${conditionValues}' />`;
      }
      formStr += '</form>';
      newWin.document.body.innerHTML = formStr;
      newWin.document.forms[0].submit();
      return newWin;
    }

    /* 获取期初 */
    handleGetPeriod = async () => {
      const { sTbName } = this.props.masterConfig;
      let sClomunType = '';
      if (sTbName === 'cahsupplyinit') {
        sClomunType = 'bAP';
      } else if (sTbName === 'cahcustomerinit') {
        sClomunType = 'bAR';
      } else if (sTbName === 'cahcashierinit') {
        sClomunType = 'bCashier';
      }
      const { sModelsId } = this.props;
      const { token } = this.props.app;
      const url = `${commonConfig.server_host}sysAccountPeriod/getSysAccountPeriod?sModelsId=${sModelsId}`;
      const value = { sClientType: '1', sClomunType };
      const { data } = await commonServices.postValueService(token, value, url);
      if (data.code === 1) {
        const [{ isSysAccountPeriod }] = data.dataset.rows;
        this.props.onSaveState({
          adDisabled: isSysAccountPeriod,
          sClomunType,
        });
      } else {
        this.props.getServiceError(data);
      }
    };
    /* 设置期初 */
    handleBtnSetPeriod = async () => {
      const { sTbName } = this.props.masterConfig;
      let sClomunType = '';
      if (sTbName === 'cahsupplyinit') {
        sClomunType = 'bAP';
      } else if (sTbName === 'cahcustomerinit') {
        sClomunType = 'bAR';
      } else if (sTbName === 'cahcashierinit') {
        sClomunType = 'bCashier';
      }
      const { sModelsId } = this.props;
      const { token } = this.props.app;
      const url = `${commonConfig.server_host}sysAccountPeriod/updateSysAccountPeriod?sModelsId=${sModelsId}`;
      const value = { sClientType: '1', handleType: 'add', sClomunType };
      const { data } = await commonServices.postValueService(token, value, url);
      if (data.code === 1) {
        message.success(data.msg);
        this.props.onSaveState({ adDisabled: true, enabled: false });
      } else {
        this.props.getServiceError(data);
      }
    };
    /* 解除锁定 */
    handleBtnRelievePeriod = async () => {
      const { sModelsId } = this.props;
      const { token } = this.props.app;
      const { sTbName } = this.props.masterConfig;
      let sClomunType = '';
      if (sTbName === 'cahsupplyinit') {
        sClomunType = 'bAP';
      } else if (sTbName === 'cahcustomerinit') {
        sClomunType = 'bAR';
      } else if (sTbName === 'cahcashierinit') {
        sClomunType = 'bCashier';
      }
      const url = `${commonConfig.server_host}sysAccountPeriod/updateSysAccountPeriod?sModelsId=${sModelsId}`;
      const value = { sClientType: '1', handleType: 'reset', sClomunType };
      const { data } = await commonServices.postValueService(token, value, url);
      if (data.code === 1) {
        message.success(data.msg);
        this.props.onSaveState({ adDisabled: false });
      } else {
        this.props.getServiceError(data);
      }
    };

    handleTitleChange = (slavePagination, filters, sorter) => {
      const { slaveConfig, slaveFilterCondition } = this.props;
      const sort = sorter.order === 'ascend' ? 'asc' : 'desc';
      const slaveOrderBy = Object.keys(sorter).length > 0 ? { [sorter.columnKey]: sort } : ''; // 后端未支持空对象, 先用空表示
      this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, slavePagination.pageSize, slaveOrderBy);
    };
    handleTitleChangeEnabled = (slavePagination) => {
      this.props.onSaveState({ slavePagination });
    };
    handleTableSelectRowChange = async (name, selectedRowKeys) => {
      const {
        [`${name}Data`]: tableData, sModelsType, sModelsId, token, masterConfig, enabled,
      } = this.props;
      if (commonUtils.isNotEmptyArr(selectedRowKeys)) {
        if (sModelsType === 'commonClassfiy/salesMan') {
          const addState = this.props.onTableSelectRowChange(name, selectedRowKeys, true);
          const { [`${name}SelectedRowKeys`]: rowKeys } = addState;
          for (const sId of rowKeys) {
            const tableDataIndex = tableData.findIndex(item => item.sId === sId);
            const sNameIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sName');/* 判断配置中是否有员工编号字段 */
            if (tableDataIndex > -1 && sNameIndex > -1) {
              const tableDataRow = JSON.parse(JSON.stringify(tableData[tableDataIndex]));
              masterConfig.gdsconfigformslave[sNameIndex].iTag = 0; /* 默认是0 */
              if (enabled && tableDataRow.handleType !== 'add') { /* 判断销售人员是否已被占用 */
                const value = {
                  tableName: masterConfig.sTbName,
                  sId: [sId],
                };
                const url = `${commonConfig.server_host}business/addSysLocking?sModelsId=${sModelsId}`;
                /*   接收返回值   */
                const { data } = await commonServices.postValueService(token, value, url);
                if (data.code === 1) {
                  const sNameIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sName');
                  masterConfig.gdsconfigformslave[sNameIndex].iTag = 1; /* ,已占用销售人员,员工不能修改 即下拉不可选 */
                } else { /*   失败   */
                  this.props.getServiceError(data);
                }
              }
            }
          }
        } else if (name === 'sParam' && commonUtils.isNotEmptyArr(selectedRowKeys)) {
          /* 点击工艺参数列表 根据点击行动态加载配置 */
          const { sParamData, sParamConfig } = this.props;
          /* 找到最后一个选中 */
          const lastSelectedKeys = selectedRowKeys[selectedRowKeys.length - 1];
          const iIndex = sParamData.findIndex(item => lastSelectedKeys === item.sId);
          /* 选中数据时 塞入选中行的配置 */
          if (iIndex > -1) {
            const sParamObj = sParamData[iIndex];
            const index = sParamConfig.gdsconfigformslave.findIndex(item => item.sName === 'sParamValue');
            if (index > -1) {
              if (commonUtils.isNotEmptyObject(sParamObj.sDropDownData)) {
                sParamConfig.gdsconfigformslave[index].sDropDownType = 'const';
                sParamConfig.gdsconfigformslave[index].showDropDown = JSON.stringify(sParamObj.sDropDownData);
              } else {
                sParamConfig.gdsconfigformslave[index].sDropDownType = '';
                sParamConfig.gdsconfigformslave[index].showDropDown = undefined;
              }
            }
            /* 点击时 若没打钩 则选择框打钩 若已经打钩则取消打钩 */
            if (sParamData[iIndex].bSelfCbx) {
              // sParamData[iIndex] = { ...sParamData[iIndex], bSelfCbx: false };
            } else {
              sParamData[iIndex] = { ...sParamData[iIndex], bSelfCbx: true };
            }
            this.props.onSaveState({
              sParamData,
            });
          }
        }
      }
      this.props.onTableSelectRowChange(name, selectedRowKeys);
    }
    /* 点击展开图标时,调用接口获取嵌套字表数据 */
    handleOnExpand = async (expanded, record) => {
      const { expKeys } = this.props;
      /* 添加移除展开的sId */
      const { formRoute } = this.props;
      let newExp = commonUtils.isNotEmptyArr(expKeys) ? expKeys : [];
      let rowKeyId = '';
      if (formRoute === '/indexPage/materialRequirementsPlanning') {
        rowKeyId = record.sMaterialsGS;
      }
      if (expanded) {
        if (commonUtils.isNotEmptyObject(rowKeyId)) {
          newExp.push(rowKeyId);
        }
      } else {
        newExp = newExp.filter(item => item !== rowKeyId);
      }
      this.props.onSaveState({ expKeys: newExp });
    }

    render() {
      return (
        <ChildComponent
          {...this.props}
          {...this.state}
          onKeyDown={this.onKeyDown}
          onCancel={this.handleCancel}
          onAdd={this.handleAdd}
          onAddChild={this.handleAddChild}
          onEdit={this.handleEdit}
          onDel={this.handleDel}
          onSubmit={this.handleValidateSave}
          onReturnForm={this.handleForm}
          onViewClick={this.handleViewClick}
          onPaginationChange={this.handlePaginationChange}
          onGetData={this.handleGetData}
          onButtonClick={this.handleButtonClick}
          onChangeInvalid={this.handleInvalid}
          onTitleChange={this.handleTitleChange}
          onTitleChangeEnabled={this.handleTitleChangeEnabled}
          onTableSelectRowChange={this.handleTableSelectRowChange}
          onExpand={this.handleOnExpand}
          onGetSlaveTreeData={this.handleGetSlaveTreeData}
          onViewChoose={this.handleViewChoose}
          onCheckParamChange={this.handleCheckParamChange}
          onReportParamsOk={this.handleReportParamsOk}
          onBtnExamine={this.handleAudit.bind(this, 1)}
          onBtnCancelExamine={this.handleAudit.bind(this, 0)}
        />
      );
    }
  };
};