/* eslint-disable prefer-destructuring,no-await-in-loop,radix,,no-loop-func */
/**
 * Created by pm on 2021-08-17 用于送货单个性化.
 */
import React, { Component } from 'react';
import { Modal, message } from 'antd-v4';
import moment from 'moment';
import * as commonUtils from '../../utils/utils'; /* 通用方法 */
import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */
import * as commonServices from '../../services/services'; /*   服务类   */
import commonConfig from '../../utils/config';
import * as commonFunc from './commonFunc';

const { confirm } = Modal;

export default (ChildComponent) => {
  return class extends Component {
    constructor(props) {
      super(props);
      this.state = {
        changleCustomerId: '',
        dPackQtyChange: 0,
      };
      this.form = {}; /*   表单对象   */
      const { sModelsId, sModelsType } = props;
      if (sModelsType.includes('cashier/')) {
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerName', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyName', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyName', []);
      }
      commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sSrcNo', []);
    }
    async componentWillReceiveProps(nextProps) {
      const {
        formData, currentId, sModelsType, formRoute,
      } = nextProps;
      const {
        slaveConfig: slaveConfigOld,
        masterConfig: masterConfigOld,
        app,
        employeeConfig: employeeConfigOld,
      } = nextProps;
      if (commonUtils.isEmptyObject(slaveConfigOld) && formData.length > 0 && (sModelsType !== 'cashier/financialTransfer' && sModelsType !== 'cashier/financialAdjustment' && sModelsType !== 'quality/accident' && sModelsType !== 'purchase/purchaseEnquiry' && sModelsType !== 'complaint/complaint' && sModelsType !== 'print/printLabel' && sModelsType !== 'commonBill/onlyMaster' && formRoute.indexOf('indexOee') === -1)) {
        const sId = currentId || nextProps.masterData?.sId || '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        const BtnDesignFunctionConfig = commonUtils.isNotEmptyObject(masterConfig) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'BtnBsOperation.BtnDesignFunction') : {};
        const reportDesign = commonFunc.showMessage(app.commonConst, 'reportDesign');/* 报表设计 */
        if (commonUtils.isEmptyObject(BtnDesignFunctionConfig)) {
          masterConfig.gdsconfigformslave.push({
            bCanInput: false,
            bEntireLine: false,
            bFilter: false,
            bFind: false,
            bFirstEmpty: false,
            bIsOther: false,
            bMultipleChoice: false,
            bNewRecord: false,
            bNotEmpty: false,
            bNotRepeat: false,
            bReadonly: false,
            bSum: false,
            bTree: false,
            bVisible: true,
            iColValue: 1,
            iFitWidth: 120,
            /* iIncrement: 26154, */
            iOrder: 1,
            iTag: 0,
            iVisCount: 0,
            iconName: 'menu-unfold',
            sActiveKey: '',
            sAssignField: '',
            sBig5: '',
            sBig5DropDown: '',
            sBrandsId: '1111111111',
            sChinese: '报表设计',
            sChineseDropDown: '',
            sColor: '',
            sColorTerms: '',
            sControlName: 'BtnBsOperation.BtnDesignFunction',
            sDateFormat: '',
            sDefault: '',
            sDropDownType: '',
            sEnglish: '',
            sEnglishDropDown: '',
            sFilterSql: '',
            /* sId: '19211681019715580740769130', */
            sKeyUpFilter: '',
            sMaxValue: '',
            sMinValue: '',
            sName: '',
            sNotRepeatColumn: '',
            /* sParentId: '19211681019715428730724240', */
            sRelation: '',
            sSelectRelation: '',
            sSqlCondition: '',
            sSubsidiaryId: '1111111111',
            showDropDown: '',
            showName: reportDesign,
          });
        }
        /* bGrd代表是否是表格 */
        let slaveConfig = formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult')[0];
        let slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
        const checkConfig = formData.filter(item => item.bGrd && item.sTbName === 'sysbillcheckresult')[0];
        const checkColumn = commonFunc.getHeaderConfig(checkConfig);
        let addState = {};
        if (formRoute === '/indexPage/commonBill' && sModelsType === 'cost/cosexpenseshare') {
          const { sModelsId } = this.props;
          const { sId, sParentId } = slaveConfig;
          let sAssignStandardConfig = {};
          const filterData = slaveConfig.gdsconfigformslave.filter(item => item.sName === 'sAssignStandard');
          if (commonUtils.isNotEmptyArr(filterData)) {
            sAssignStandardConfig = filterData[0];
          }
          const url = `${commonConfig.server_host}costCenter/getCostCenterConfig?sModelsId=${sModelsId}`;
          const body = {
            sId,
            sParentId,
            sAssignStandardConfig,
          };
          const dataReturn = (await commonServices.postValueService(app.token, body, url)).data;
          if (dataReturn.code === 1) {
            /*   获取数据集   */
            const { rows } = dataReturn.dataset;/* 获取费用分摊单据配置 */
            if (commonUtils.isNotEmptyArr(rows) && rows.length > 0) {
              slaveConfig = rows[0];
              slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
            }
          } else { /*   失败s   */
            this.props.getServiceError(dataReturn);
            return [];
          }
        }
        if (formRoute === '/indexPage/commonBill' || formRoute === '/indexPage/commonBillDeliver') {
          if (sId === '') {
            const config = {};
            let addState1 = {};
            if (sModelsType.includes('sales/salesOrder')) {
              const controlConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordercontrol'.toUpperCase())[0];
              const controlColumn = commonFunc.getHeaderConfig(controlConfig);
              const materialsConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordermaterials'.toUpperCase())[0];
              const materialsColumn = commonFunc.getHeaderConfig(materialsConfig);
              const processConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesorderprocess'.toUpperCase())[0];
              const processColumn = commonFunc.getHeaderConfig(processConfig);
              const colorConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesorderparam'.toUpperCase())[0];
              let colorColumn;
              if (commonUtils.isNotEmptyObject(colorConfig)) {
                colorColumn = commonFunc.getHeaderConfig(colorConfig);
              }
              const packConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordercontrolcombine'.toUpperCase())[0];
              let packColumn;
              if (commonUtils.isNotEmptyObject(packConfig)) {
                packColumn = commonFunc.getHeaderConfig(packConfig);
              }
              config.controlConfig = controlConfig;
              config.materialsConfig = materialsConfig;
              config.processConfig = processConfig;
              config.colorConfig = colorConfig;
              config.packConfig = packConfig;
              addState1 = {
                controlConfig,
                controlColumn,
                materialsConfig,
                materialsColumn,
                processConfig,
                processColumn,
                colorConfig,
                colorColumn,
                packConfig,
                packColumn,
              };
            } else if (sModelsType === 'purchase/purchaseOrder') {
              const orderDetailConfig = formData.filter(item => item.sTbName.toUpperCase() === 'purpurchaseorderDetail'.toUpperCase())[0];
              const orderDetailColumn = commonFunc.getHeaderConfig(orderDetailConfig);
              config.orderDetailConfig = orderDetailConfig;
              this.handleGetOneMemoData('orderDetail', orderDetailConfig);
              addState1 = {
                orderDetailConfig,
                orderDetailColumn,
              };
            } else if (sModelsType === 'sales/salesSgoods') { /* 个性化送货单 */
              const slaveChildConfig = formData.filter(item => item.sTbName.toUpperCase() === 'saldelivergoodsslavechildren'.toUpperCase())[0];
              const slaveChildColumn = commonFunc.getHeaderConfig(slaveChildConfig);
              this.handleGetOneMemoData('slaveChild', slaveChildConfig);
              addState1 = {
                slaveChildConfig,
                slaveChildColumn,
              };
            }
            config.masterConfig = masterConfig;
            config.slaveConfig = slaveConfig;
            addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
            addState = { ...addState, ...addState1 };
            // if (sModelsType.includes('sales/salesOrder') || sModelsType === 'purchase/purchaseOrder') {
            //   this.props.onSaveState(addState1);
            // }
          } else {
            this.handleGetData(masterConfig, slaveConfig, checkConfig);
            if (sModelsType.includes('sales/salesOrder')) {
              const controlConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordercontrol'.toUpperCase())[0];
              const controlColumn = commonFunc.getHeaderConfig(controlConfig);
              const materialsConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordermaterials'.toUpperCase())[0];
              const materialsColumn = commonFunc.getHeaderConfig(materialsConfig);
              const processConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesorderprocess'.toUpperCase())[0];
              const processColumn = commonFunc.getHeaderConfig(processConfig);
              const colorConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesorderparam'.toUpperCase())[0];
              let colorColumn;
              if (commonUtils.isNotEmptyObject(colorConfig)) {
                colorColumn = commonFunc.getHeaderConfig(colorConfig);
              }
              const packConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordercontrolcombine'.toUpperCase())[0];
              let packColumn;
              if (commonUtils.isNotEmptyObject(packConfig)) {
                packColumn = commonFunc.getHeaderConfig(packConfig);
              }
              this.handleGetMemoData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig);
              this.props.onSaveState({
                controlConfig,
                controlColumn,
                materialsConfig,
                materialsColumn,
                processConfig,
                processColumn,
                colorConfig,
                colorColumn,
                packConfig,
                packColumn,
              });
            } else if (sModelsType === 'manufacture/workOrder3') {
              const controlConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductcontrol'.toUpperCase())[0];
              const controlColumn = commonFunc.getHeaderConfig(controlConfig);
              const materialsConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductmaterials'.toUpperCase())[0];
              const materialsColumn = commonFunc.getHeaderConfig(materialsConfig);
              const processConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductprocess'.toUpperCase())[0];
              const processColumn = commonFunc.getHeaderConfig(processConfig);
              this.handleGetMemoData(controlConfig, materialsConfig, processConfig);
              this.props.onSaveState({
                controlConfig,
                controlColumn,
                materialsConfig,
                materialsColumn,
                processConfig,
                processColumn,
              });
            } else if (sModelsType === 'purchase/purchaseOrder') {
              const orderDetailConfig = formData.filter(item => item.sTbName.toUpperCase() === 'purpurchaseorderDetail'.toUpperCase())[0];
              const orderDetailColumn = commonFunc.getHeaderConfig(orderDetailConfig);
              this.handleGetOneMemoData('orderDetail', orderDetailConfig);
              this.props.onSaveState({
                orderDetailConfig,
                orderDetailColumn,
              });
            } else if (sModelsType === 'sales/salesSgoods') { /* 个性化送货单 */
              const slaveChildConfig = formData.filter(item => item.sTbName.toUpperCase() === 'saldelivergoodsslavechildren'.toUpperCase())[0];
              const slaveChildColumn = commonFunc.getHeaderConfig(slaveChildConfig);
              this.handleGetOneMemoData('slaveChild', slaveChildConfig);
              this.props.onSaveState({
                slaveChildConfig,
                slaveChildColumn,
              });
            }
          }
        }
        this.props.onSaveState({
          masterConfig, slaveConfig, slaveColumn, checkConfig, checkColumn, sId, pageLoading: false, ...addState,
        });
      } else if (commonUtils.isEmptyObject(masterConfigOld) && formData.length === 1 && (sModelsType === 'cashier/financialTransfer' || sModelsType === 'purchase/purchaseEnquiry' || sModelsType === 'cashier/financialAdjustment' || sModelsType === 'print/printLabel' || sModelsType === 'complaint/complaint' || sModelsType === 'commonBill/onlyMaster') && formRoute.indexOf('indexOee') === -1) {
        const config = {};
        const sId = currentId || nextProps.masterData?.sId || '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        let addState = {};
        if (formRoute === '/indexPage/commonBill') {
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetData(masterConfig, undefined, undefined);
          }
        }
        addState.onlyMaster = true;
        if (formRoute === '/indexPage/printlabel') {
          config.masterConfig = masterConfig;
          addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
        }
        this.props.onSaveState({
          masterConfig, sId, pageLoading: false, ...addState,
        });
      } else if (commonUtils.isEmptyObject(slaveConfigOld) && commonUtils.isEmptyObject(masterConfigOld) && formData.length === 2 && (sModelsType === 'quality/accident') && formRoute.indexOf('indexOee') === -1) {
        const sId = currentId || nextProps.masterData?.sId || '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        const slaveConfig = formData.filter(item => item.bGrd && item.sTbName === 'mftqualityaccidentSlave')[0];
        const slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
        let addState = {};
        if (formRoute === '/indexPage/commonBill') {
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            config.slaveConfig = slaveConfig;
            addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetData(masterConfig, slaveConfig, undefined);
          }
        }
        addState.onlyMaster = true;
        addState.onlyMasterAndSlave = true;
        this.props.onSaveState({
          masterConfig, sId, slaveConfig, slaveColumn, pageLoading: false, ...addState,
        });
      } else if (formRoute.indexOf('indexOee') > -1 && commonUtils.isEmptyObject(employeeConfigOld) && commonUtils.isEmptyObject(slaveConfigOld) && formData.length > 0) {
        if (formRoute === '/indexOee/labelPrint' && commonUtils.isEmpty(slaveConfigOld)) { /* 入库标签打印 */
          const sId = currentId || nextProps.masterData?.sId || '';
          /* 数据Id */
          const masterConfig = formData[0];
          const slaveConfig = formData[0];
          const slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
          // this.props.handleGetDataOne({ name: 'master', configData: masterConfig, condition: { sSqlCondition: { sParentId: sId } } });
          this.handleGetOneMemoData('slave', slaveConfig);
          this.props.onSaveState({
            masterConfig, sId, slaveConfig, slaveColumn, pageLoading: false,
          });
        }
      }
    }

    shouldComponentUpdate(nextProps) {
      const { slaveColumn, masterConfig } = nextProps;
      return commonUtils.isNotEmptyArr(slaveColumn) || commonUtils.isNotEmptyObject(masterConfig);
    }

    /*
      修改日期：2021-03-18
      修改人：吕杰
      区域：以下onKeyDown函数
      需求变更：为解决bug 2031添加
    */
    /** 键盘事件监听 */
    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);
        }
      }
    }

    /* 单击右键全部更新，弹出窗选择后，更新此列所有数据 （只更新非只读字段） */
    onContextMenu = (e, record, showConfig, tbName) => {
      const contextMenuConfig = [];
      const showConfigNew = JSON.parse(JSON.stringify(showConfig)); /* 深拷贝配置 */
      contextMenuConfig.push(showConfigNew);
      this.props.onSaveState({
        contextMenuModalVisible: true, /* 右击全部更新弹窗 */
        contextMenuConfig, /* 右击字段配置 数组形式 */
        contextMenuRecord: record, /* 右击数据 */
        contextMenuName: showConfig.showName, /* 右击字段 */
        contextMenuTbName: tbName, /* 右击字段 */
      });
    }

    /**   获取应收账款   */
    getCustomerReceipt = async (masterData) => {
      const { sModelsId } = this.props;
      if (!commonUtils.isEmpty(masterData.sCustomerId)) {
        const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
        const value = { sProName: 'Sp_Receivables_AR', paramsMap: { sStatistics: masterData.sCustomerId } };
        const dataReturn = (await commonServices.postValueService(this.props.app.token, value, url)).data;
        if (dataReturn.code === 1) {
          /*   数据查询成功   */
          const [returnData] = dataReturn.dataset.rows[0].dataSet.outData;
          const masterDataNew = {
            ...masterData,
            dNoReceiptMoney: returnData.dNoReceiptMoney,
            dDueReceiptMoney: returnData.dNoReceiptMoney,
          };
          this.props.onSaveState({ masterData: masterDataNew });
        } else { /*   失败   */
          this.props.getServiceError(dataReturn);
        }
      }
    };

    /**   获取上查下查数据   */
    getSearchUpDownData = async (showConfig) => {
      const { sModelsId } = this.props;
      const url = `${commonConfig.server_host}searchupdown/getSearchUpDown/${showConfig.sId}?sModelsId=${sModelsId}`;
      const conditonValues = this.props.getSqlCondition(showConfig);
      if (commonUtils.isNotEmptyObject(conditonValues)) {
        const iIndex = Object.keys(conditonValues).findIndex(item => commonUtils.isEmpty(conditonValues[item]));
        if (iIndex === -1) {
          /*   调用后台接口   */
          const body = {
            sSqlCondition: commonUtils.isEmptyObject(conditonValues) ? '' : conditonValues, /*   查询条件   */
          };
          const dataReturn = (await commonServices.postValueService(this.props.app.token, body, url)).data;
          if (dataReturn.code === 1) {
            /*   数据查询成功   */
            return dataReturn.dataset.rows;
          } else { /*   失败   */
            this.props.getServiceError(dataReturn);
            return [];
          }
        }
      }
    };
    handlePackDataAdd= (item, index, sControlId) => {
      const tableDataRow = {};
      tableDataRow.sId = commonUtils.createSid();
      tableDataRow.handleType = 'add';
      tableDataRow.sSlaveId = item.sId;
      tableDataRow.sParentId = item.sParentId;
      tableDataRow.sControlId = sControlId;
      tableDataRow.iOrder = item.iOrder;
      tableDataRow.sProductId = item.sProductId; /* 产品id */
      tableDataRow.sCustomerId = item.sCustomerId; /* 客户id */
      tableDataRow.sCustomerName = item.sCustomerName; /* 客户名称 */
      tableDataRow.sProductName = item.sProductName; /* 产品名称 */
      tableDataRow.sProductNo = item.sProductNo; /* 产品编号 */
      tableDataRow.dProductQty = commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0); /* 生产数量 */ /* 生产数量 */
      tableDataRow.sProductUnit = item.sProductUnit; /* 单位 */
      tableDataRow.sProductStyle = item.sProductStyle; /* 产品规格 */
      return tableDataRow;
    }
    sortData = (tableData, processData) => {
      processData.sort((g1, g2) => {
        const iIndex1 = tableData.findIndex(item => item.sId === g1.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g1.sControlId);
        let sPartOrder1 = `0000${iIndex1}`;
        sPartOrder1 = sPartOrder1.substring(sPartOrder1.length - 3);
        let sOrder1 = `000${g1.iOrder}`;
        sOrder1 = sOrder1.substring(sOrder1.length - 3);

        const iIndex2 = tableData.findIndex(item => item.sId === g2.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g2.sControlId);
        let sPartOrder2 = `0000${iIndex2}`;
        sPartOrder2 = sPartOrder2.substring(sPartOrder2.length - 3);
        let sOrder2 = `000${g2.iOrder}`;
        sOrder2 = sOrder2.substring(sOrder2.length - 3);
        return parseInt(sPartOrder1 + g1.sType + sOrder1, 10) - parseInt(sPartOrder2 + g2.sType + sOrder2, 10);
      });
      return processData;
    };

    /**   获取主表、从表、审核表数据   */
    handleGetData = async (masterConfig, slaveConfig, checkConfig, bEditClick) => {
      const { currentId } = this.props; /* 当前页签数据 */
      const sId = currentId || this.props.masterData?.sId || '';
      await this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' }, bEditClick,
      });
      // commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductId', []);
      // commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductNo', []);
      // commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductName', []);
      if (!commonUtils.isEmptyObject(slaveConfig)) {
        const getData = await this.props.handleGetDataSet({
          name: 'slave', configData: slaveConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
        });
        if (commonUtils.isNotEmptyObject(getData) && commonUtils.isNotEmptyArr(getData.slaveData)) {
          getData.slaveData.forEach((item, iIndex) => {
            if (commonUtils.isNotEmptyObject(item.sReportParam)) {
              item = { ...item, ...commonUtils.convertStrToObj(item.sReportParam) };
              getData.slaveData[iIndex] = item;
            }
          });
          this.props.onSaveState({ ...getData });
        }
        if (commonUtils.isNotEmptyStr(getData.slaveData)) {
          const selectRowKey = getData.slaveData[0].sId;
          const selectRowKeyArr = [];
          selectRowKeyArr.push(selectRowKey);
          this.handleTableSelectRowChange('slave', selectRowKeyArr);
        }
      }

      if (!commonUtils.isEmptyObject(checkConfig)) {
        this.props.handleGetDataSet({
          name: 'check', configData: checkConfig, condition: { sSqlCondition: { sParentId: sId } },
        });
      }
    };
    /* 获取表数据 */
    handleGetMemoData = async (controlConfig, materialsConfig, processConfig, colorConfig, packConfig) => {
      const { currentId, sModelsType } = this.props; /* 当前页签数据 */
      const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */
      const addStateControl = await this.props.handleGetDataSet({
        name: 'control', configData: controlConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
      });
      const { controlData, controlSelectedRowKeys } = addStateControl; /* 同步树选中节点与部件选中节点 */
      let treeState = [];
      if (sModelsType === 'sales/salesOrderPack') {
        treeState = this.handleGetControlTreeData(controlData, true);
      }
      this.props.handleGetDataSet({
        name: 'materials', configData: materialsConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      const addStateProcess = await this.props.handleGetDataSet({
        name: 'process', configData: processConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
      });
      if (addStateProcess) {
        if (Array.isArray(addStateProcess.processData)) {
          // eslint-disable-next-line array-callback-return
          addStateProcess.processData.map((itemProcess) => {
            if (commonUtils.isNotEmptyObject(sModelsType.includes('quotation/') ? itemProcess.sProcessParam : sModelsType.includes('manufacture/') ? itemProcess.sWorkOrderParam : itemProcess.sProcessParam)) {
              itemProcess.sProcessParamStr = '';
              // eslint-disable-next-line no-plusplus
              for (let i = 1; i < 7; i++) {
                const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
                if (iIndex > -1 && !commonUtils.isEmpty(itemProcess[`sParam${i.toString()}`])) {
                  itemProcess.sProcessParamStr += `${itemProcess[`sParam${i.toString()}`]}:${itemProcess[`sParamValue${i.toString()}`]},`;
                }
              }
              if (itemProcess.sProcessParamStr === '') {
                itemProcess.sProcessParamStr = '工艺参数';
              }
            }
          });
          addStateProcess.processData = this.sortData(addStateControl.controlData, addStateProcess.processData);
        }
      }
      if (commonUtils.isNotEmptyObject(colorConfig)) {
        this.props.handleGetDataSet({
          name: 'color', configData: colorConfig, condition: { sSqlCondition: { sParentId: sId } },
        });
      }
      if (commonUtils.isNotEmptyObject(packConfig)) {
        this.props.handleGetDataSet({
          name: 'pack', configData: packConfig, condition: { sSqlCondition: { sParentId: sId } },
        });
      }
      this.props.onSaveState({
        pageLoading: false, ...addStateControl, ...addStateProcess, ...treeState, treeSelectedKeys: controlSelectedRowKeys,
      });
    };
    /* 获取单张表数据 */
    handleGetOneMemoData = (memoName, memoConfig) => {
      const { currentId } = this.props; /* 当前页签数据 */
      const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */
      if (commonUtils.isNotEmptyObject(sId)) { /* 解决detail数据没有问题 */
        this.props.handleGetDataSet({
          name: memoName, configData: memoConfig, condition: { sSqlCondition: { sParentId: sId } },
        });
      }
    };
    /**   获取部件树   */
    handleGetControlTreeData= (controlDataOld, isWait, sSlaveId) => {
      /* 生成部件树结构 */
      let treeData = [];
      const expandedKeys = [];
      let { treeSelectedKeys } = this.props;
      let controlData = [];
      if (commonUtils.isNotEmptyObject(sSlaveId)) {
        controlData = controlDataOld.filter(item => item.sSlaveId === sSlaveId);
      } else {
        controlData = controlDataOld;
      }
      if (commonUtils.isNotEmptyArr(controlData)) {
        const rootData = commonUtils.isNotEmptyArr(controlData) ? controlData.filter(item => commonUtils.isEmpty(item.sControlParentId)) : []; /* 找到所有一级树结构 */
        rootData.forEach((item) => {
          const treeDataRow = {};
          const { sId, sPartsName } = item;
          treeDataRow.key = sId;
          treeDataRow.showName = sPartsName;
          treeDataRow.sAllId = item.sAllId;
          const children = this.handleGetControlTreeChildData(sId, controlData);
          let sChildren = '1'; /* 树形结构最后一个节点设置为1 */
          if (commonUtils.isNotEmptyArr(children)) {
            sChildren = '0'; /* 树形结构其他节点设置为0 */
          }
          treeDataRow.sChildren = sChildren;
          /* 添加sChildren,sAllId 值 */
          const iIndex = controlData.findIndex(item => item.sId === sId);
          if (iIndex > -1) {
            // controlData[iIndex].sAllId = sAllId;
            controlData[iIndex].sChildren = sChildren;
          }
          treeDataRow.children = commonUtils.isNotEmptyArr(children) ? children : [];
          treeData.push(treeDataRow);
        });
        if (commonUtils.isEmptyArr(treeSelectedKeys)) {
          expandedKeys.push(treeData[treeData.length - 1].key);
        }
      } else {
        treeSelectedKeys = [];
        treeData = [];
      }
      if (isWait) {
        return { treeData };
      } else {
        this.props.onSaveState({
          treeData,
          // expandedKeys,
        });
      }
    };

    /**   获取子节点数据   */
    handleGetControlTreeChildData= (sParentId, controlData) => {
      if (commonUtils.isNotEmptyObject(sParentId) && commonUtils.isNotEmptyArr(controlData)) {
        const childTree = commonUtils.isNotEmptyArr(controlData) ? controlData.filter(item => item.sControlParentId === sParentId) : [];
        const children = [];
        if (commonUtils.isNotEmptyArr(childTree)) {
          childTree.forEach((child) => {
            const { sId, sPartsName } = child;
            const treeDataRow = {};
            treeDataRow.key = sId;
            treeDataRow.showName = sPartsName;
            treeDataRow.parentKey = sParentId;
            treeDataRow.sAllId = child.sAllId;
            const data = this.handleGetControlTreeChildData(sId, controlData);
            let sChildren = '1'; /* 最后一个节点设置为1 */
            if (commonUtils.isNotEmptyArr(data)) {
              sChildren = '0';
            }
            treeDataRow.sChildren = sChildren;
            /* 添加sChildren,sAllId 值 */
            const iIndex = controlData.findIndex(item => item.sId === sId);
            if (iIndex > -1) {
              // controlData[iIndex].sAllId = sAllId;
              controlData[iIndex].sChildren = sChildren;
            }
            treeDataRow.children = commonUtils.isNotEmptyArr(data) ? data : [];
            children.push(treeDataRow);
          });
        }
        return children;
      }
    };

    /**  根据key查找树节点并改变属性 */
    handleSearchNodes= (key, data, showNameNew) => {
      if (commonUtils.isNotEmptyObject(showNameNew)) {
        data.forEach((item) => {
          if (item.key === key) {
            item.showName = showNameNew;
          } else if (commonUtils.isNotEmptyArr(item.children)) {
            this.handleSearchNodes(key, item.children, showNameNew);
          }
        });
      }
    };

    /**  点击新增按钮   */
    handleAdd = async (config, copyTo, isWait) => {
      /*   外置处理业务   */
      const {
        sModelsId, sModelsType, app, token,
      } = this.props;
      if (sModelsType.includes('cashier/')) {
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerName', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyName', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyName', []);
      }
      let masterConfig = commonUtils.isEmptyObject(config) ? {} : config.masterConfig;
      if (!isWait) {
        masterConfig = this.props.masterConfig;
      }
      let configNew = {};
      if (commonUtils.isEmptyObject(config)) {
        const { slaveConfig } = this.props;
        configNew.slaveConfig = slaveConfig;
      } else {
        configNew = config;
      }
      let masterData = commonFunc.getDefaultData(masterConfig);
      masterData.handleType = 'add';
      masterData.sId = commonUtils.createSid();
      masterData.sFormId = sModelsId;
      masterData.maxBillNo = 'sBillNo';
      let slaveData = [];
      const controlData = [];
      const materialsData = [];
      const processData = [];
      const orderDetailData = [];
      const dailyData = [];
      const packData = [];
      const colorData = [];
      // const slaveTotal = [];
      // const tableDataTotal = {};
      if (commonUtils.isNotEmptyObject(copyTo)) {
        const copyToMasterConfig = copyTo.config.filter(item => item.sControlName === copyTo.name);
        const masterAssignField = commonUtils.isNotEmptyArr(copyToMasterConfig) ? copyToMasterConfig[0].sAssignField : '';
        const newCopyTo = {};
        newCopyTo.master = copyTo.masterData;
        newCopyTo.slave = commonUtils.isEmpty(copyTo.slaveData) ? [] : copyTo.slaveData[0];
        masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterAssignField, copyTo.masterData, newCopyTo) };
        if (commonBusiness.getGeyPayDate(masterData) !== undefined) {
          masterData.tGetPayDate = commonBusiness.getGeyPayDate(masterData);
        }
        let sWareHouseNameDropDown;
        const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sWareHouseName');
        if (iIndex > -1 && commonUtils.isEmptyObject(masterData.sWareHouseId)) {
          const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
          let dataUrl;
          let condition;
          if (models === 'Product') {
            dataUrl = `${commonConfig.server_host}eleProductStock/getProductWareHouse?sModelsId=${sModelsId}`;
            condition = { sProductId: copyTo.slaveData[0].sProductId };
          } else {
            dataUrl = `${commonConfig.server_host}eleMaterialsStock/getMaterialsWareHouse?sModelsId=${sModelsId}`;
            condition = { sMaterialsId: copyTo.slaveData[0].sMaterialsId, sMaterialsStyle: copyTo.slaveData[0].sMaterialsStyle };
          }
          const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
          if (dataReturn.code === 1) {
            const sWareHouseId = dataReturn.dataset.rows.length > 0 ? dataReturn.dataset.rows[0].sWareHouseId : '';
            const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', masterConfig.gdsconfigformslave[iIndex]);
            sWareHouseNameDropDown = sqlDropDownData.dropDownData;
            if (commonUtils.isNotEmptyArr(sWareHouseNameDropDown) && !sModelsType.includes('materialsStock/productionmaterialsadjust')) {
              const { sAssignField } = masterConfig.gdsconfigformslave[iIndex];
              const iWareHouseNameIndex = sWareHouseNameDropDown.findIndex(item => item.sId === sWareHouseId);
              if (iWareHouseNameIndex > -1) {
                masterData = { ...masterData, ...commonFunc.getAssignFieldValue(sAssignField, sWareHouseNameDropDown[iWareHouseNameIndex]) };
              }
            }
          }
        }

        const copyToSlaveConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slave`.toLowerCase());
        const slaveAssignField = commonUtils.isNotEmptyArr(copyToSlaveConfig) ? copyToSlaveConfig[0].sAssignField : '';
        if (slaveAssignField !== '') {
          let iCount = 0;
          let flagCopyTo = false;
          if (commonUtils.isEmptyArr(copyTo.controlData)) {
            flagCopyTo = true;
          }
          for (const slaveItem of copyTo.slaveData) {
            const newCopyTo = {};
            newCopyTo.master = copyTo.masterData;
            newCopyTo.slave = slaveItem;
            let slaveRow = commonFunc.getDefaultData(config.slaveConfig, newCopyTo); // 取默认值
            slaveRow = { ...slaveRow, ...commonFunc.getAssignFieldValue(slaveAssignField, slaveItem, newCopyTo) }; // 取赋值字段
            if ((!commonUtils.isEmpty(slaveRow.dProductQty) && slaveRow.dProductQty !== slaveRow.dSrcQty) ||
              (!commonUtils.isEmpty(slaveRow.dAuxiliaryQty) && slaveRow.dAuxiliaryQty !== slaveRow.dSrcAuxiliaryQty)) {
              const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
              const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
              commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, slaveRow);
            }
            if (commonUtils.isNotEmptyObject(slaveRow.sReportParam)) {
              slaveRow = { ...slaveRow, ...commonUtils.convertStrToObj(slaveRow.sReportParam) };
            }
            slaveRow.handleType = 'add';
            slaveRow.sId = commonUtils.createSid();
            slaveRow.sParentId = masterData.sId;
            slaveRow.sWareHouseId = masterData.sWareHouseId;
            slaveRow.sWareHouseNo = masterData.sWareHouseNo;
            slaveRow.sWareHouseName = masterData.sWareHouseName;
            slaveRow.sLocationId = masterData.sLocationId;
            slaveRow.sLocationNo = masterData.sLocationNo;
            slaveRow.sLocationName = masterData.sLocationName;
            slaveRow.sWareHouseLocationId = masterData.sWareHouseLocationId;
            slaveRow.sWareHouseLocationNo = masterData.sWareHouseLocationNo;
            slaveRow.sWareHouseLocationName = masterData.sWareHouseLocationName;
            slaveRow.sOriginalId = slaveItem.sSlaveId;/* 翻单前的sId */
            /* 若复制到没有序号，则序号从1自增 */
            if (commonUtils.isEmptyNumber(slaveRow.iOrder)) {
              iCount += 1;
              slaveRow.iOrder = iCount;
            }
            if (sModelsType === 'purchase/purchaseInstore') {
              const iIndex = app.systemData.findIndex(item => item.sName === 'CbxMaterialsDefine');
              if (iIndex > -1) {
                const sCbxMaterialsDefine = app.systemData[iIndex].sValue;
                if (sCbxMaterialsDefine === 'datenum') {
                  slaveRow.sDefineNo = moment(new Date()).format('YYYYMMDD');
                } else if (sCbxMaterialsDefine === 'datetimenum') {
                  slaveRow.sDefineNo = moment(new Date()).format('YYYYMMDDHHmm');
                } else if (sCbxMaterialsDefine === 'yearnum') {
                  slaveRow.sDefineNo = moment(new Date()).format('YYYY');
                } else if (sCbxMaterialsDefine === 'yearmonthnum') {
                  slaveRow.sDefineNo = moment(new Date()).format('YYYYMM');
                } else if (sCbxMaterialsDefine === 'worknum') {
                  slaveRow.sDefineNo = slaveRow.sWorkOrderNo;
                } else if (sCbxMaterialsDefine === 'manuualno') {
                  slaveRow.sDefineNo = slaveRow.sManualNo;
                } else if (sCbxMaterialsDefine === 'createnownum') { /* 批号根据生产日期+当前日期 */
                  slaveRow.sDefineNo = moment(slaveRow.tProductionDate).format('YYYYMMDDHHmm') + moment(new Date()).format('YYYYMMDDHHmm');
                }
              }
            } else if (sModelsType === 'productStock/productInStore' || sModelsType === 'outside/outsideinstoreAll') { /* 成品入库、整单发外入库 */
              const iIndex = app.systemData.findIndex(item => item.sName === 'CbxProductDefine');
              if (iIndex > -1) {
                const sCbxProductDefine = app.systemData[iIndex].sValue;
                if (sCbxProductDefine === 'datenum') {
                  slaveRow.sDefineNo = moment(new Date()).format('YYYYMMDD');
                } else if (sCbxProductDefine === 'datetimenum') {
                  slaveRow.sDefineNo = moment(new Date()).format('YYYYMMDDHHmm');
                } else if (sCbxProductDefine === 'yearnum') {
                  slaveRow.sDefineNo = moment(new Date()).format('YYYY');
                } else if (sCbxProductDefine === 'yearmonthnum') {
                  slaveRow.sDefineNo = moment(new Date()).format('YYYYMM');
                } else if (sCbxProductDefine === 'worknum') {
                  slaveRow.sDefineNo = slaveRow.sWorkOrderNo;
                } else if (sCbxProductDefine === 'manuualno') {
                  slaveRow.sDefineNo = slaveRow.sManualNo;
                } else if (sCbxProductDefine === 'worktimenum') { /* 批号根据工单号码+日期时间批号 */
                  slaveRow.sDefineNo = slaveRow.sWorkOrderNo + moment(new Date()).format('YYYYMMDDHH');
                } else if (sCbxProductDefine === 'yearToDate') { /* 2259 批号根据工单制单日期年月日，年取两位 */
                  slaveRow.sDefineNo = moment(copyTo.masterData.tCreateDate || new Date()).format('YYMMDD');
                }
              }
            } else if (sModelsType === 'sales/salesCheck') {
              slaveRow.dSrcNoCheckMoney = slaveRow.dProductForeignMoney;
            } else if (sModelsType === 'purchase/purchasecheck') {
              slaveRow.dSrcNoCheckMoney = slaveRow.dMaterialsMoney;
            } else if (sModelsType === 'purchase/purchaseOrder') { // bug 2171 修正 吕杰 2021-03-26
              const dProcurementCycle = commonUtils.isNull(slaveRow.dProcurementCycle, 0);
              const tCreateDate = masterData && commonUtils.isNotEmptyObject(masterData.tCreateDate) ? masterData.tCreateDate : new Date();
              const tDeliverDate = moment(tCreateDate).add(dProcurementCycle, 'days').format(commonUtils.dateFormatA);
              slaveRow.tDeliverDate = tDeliverDate;
              slaveRow.dProcurementCycle = dProcurementCycle;
            }
            slaveData.push(slaveRow);

            if (sModelsType.includes('sales/salesOrder') && flagCopyTo && commonUtils.isNotEmptyArr(copyTo.slaveData)) {
              const { token } = this.props;
              const sSlaveId = commonUtils.isNotEmptyStr(slaveItem.sSlaveId) ? slaveItem.sSlaveId : slaveItem.sId;
              const sParentId = commonUtils.isNotEmptyStr(slaveItem.sParentId) ? slaveItem.sParentId : slaveItem.sId;
              let condition = {};
              if (sModelsType === 'sales/salesOrderPack') {
                condition = { sParentId };
              } else {
                condition = { sSlaveId };
              }
              /* 通用报价单:101251240115016244276286330 */
              const dataUrl = slaveItem.sFormId === '19211681019715780306452560' || slaveItem.sFormId === '101251240115016076506222050'
              || slaveItem.sFormId === '101251240115016036175782700' || slaveItem.sFormId === '101251240115016002356125200' || slaveItem.sFormId === '101251240115016244276286330' ?
                `${commonConfig.server_host}salesorder/getQuotationPartsInfo?sModelsId=${sModelsId}` :
                `${commonConfig.server_host}salesorder/getPartsInfo?sModelsId=${sModelsId}`;
              const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
              if (dataReturn.code === 1) {
                const returnData = dataReturn.dataset.rows[0];
                slaveItem.sId = sSlaveId;
                copyTo.controlData = returnData.controlData;
                copyTo.materialsData = returnData.materialsData;
                copyTo.processData = returnData.processData;
                copyTo.packData = returnData.packData;
                copyTo.colorData = returnData.colorData;
              } else {
                this.props.getServiceError(dataReturn);
              }
            }

            const copyToControlConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.control`.toLowerCase());
            const controlAssignField = commonUtils.isNotEmptyArr(copyToControlConfig) ? copyToControlConfig[0].sAssignField : '';
            if (controlAssignField !== '') {
              if (commonUtils.isNotEmptyObject(copyTo.controlData)) {
                const treeCopyNodes = new Map();
                let controlFilterData = [];
                const srcFormRoute = copyTo.srcFormRoute;
                if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
                  controlFilterData = copyTo.controlData;
                } else {
                  controlFilterData = copyTo.controlData.filter(controlItem => controlItem.sSlaveId === slaveItem.sId);
                }
                await controlFilterData.forEach(async (controlItem) => {
                  const newCopyTo = {};
                  newCopyTo.master = copyTo.masterData;
                  newCopyTo.control = controlItem;
                  let controlRow = commonFunc.getDefaultData(config.controlConfig, newCopyTo); // 取默认值
                  controlRow = { ...controlRow, ...commonFunc.getAssignFieldValue(controlAssignField, controlItem, newCopyTo) }; // 取赋值字段
                  if ((!commonUtils.isEmpty(controlRow.dProductQty) && controlRow.dProductQty !== controlRow.dSrcQty) ||
                    (!commonUtils.isEmpty(controlRow.dAuxiliaryQty) && controlRow.dAuxiliaryQty !== controlRow.dSrcAuxiliaryQty)) {
                    const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
                    const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
                    commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, controlRow);
                  }
                  controlRow.handleType = 'add';
                  controlRow.sId = commonUtils.createSid();
                  controlRow.sOriginalId = controlItem.sId; /* 复制前的部件表sId */
                  controlRow.sParentId = masterData.sId;
                  controlRow.sSlaveId = slaveRow.sId;
                  if (sModelsType === 'sales/salesOrderPack') {
                    /* 如果有树形结构 则sAllId,sControlParentId赋值 */
                    const sAllOldId = controlItem.sAllId;
                    let arr = [];
                    if (commonUtils.isNotEmptyObject(sAllOldId)) {
                      arr = sAllOldId.split(',');
                    }
                    const newId = controlRow.sId;
                    let sOldParentId = '';
                    let sNewParentAllId = '';
                    if (arr.length < 2) { /* 根节点复制 */
                      controlRow.sAllId = newId;
                      sOldParentId = newId;
                      sNewParentAllId = newId;
                    } else {
                      sOldParentId = arr[arr.length - 2];
                      if (treeCopyNodes.has(sOldParentId)) {
                        sNewParentAllId = treeCopyNodes.get(sOldParentId);
                      } else {
                        const obj = arr[arr.length - 1];
                        sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
                      }
                      const sNewArr = sNewParentAllId.split(',');
                      controlRow.sControlParentId = sNewArr[sNewArr.length - 1];
                      sNewParentAllId = `${sNewParentAllId},${newId}`;
                      controlRow.sAllId = sNewParentAllId;
                    }
                    treeCopyNodes.set(controlItem.sId, sNewParentAllId);
                  }
                  controlData.push(controlRow);

                  const copyToMaterialsConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.materials`.toLowerCase());
                  const materialsAssignField = commonUtils.isNotEmptyArr(copyToMaterialsConfig) ? copyToMaterialsConfig[0].sAssignField : '';
                  if (materialsAssignField !== '') {
                    if (commonUtils.isNotEmptyObject(copyTo.materialsData)) {
                      let materialsFilterData = [];
                      const srcFormRoute = copyTo.srcFormRoute;
                      if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
                        materialsFilterData = copyTo.materialsData.filter(materialsItem => materialsItem.sControlId === controlItem.sId);
                      } else {
                        materialsFilterData = copyTo.materialsData.filter(materialsItem => materialsItem.sSlaveId === slaveItem.sId && materialsItem.sControlId === controlItem.sId);
                      }
                      await materialsFilterData.forEach(async (materialsItem) => {
                        const newCopyTo = {};
                        newCopyTo.master = copyTo.masterData;
                        newCopyTo.materials = materialsItem;
                        let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo); // 取默认值
                        materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
                        if ((!commonUtils.isEmpty(materialsRow.dProductQty) && materialsRow.dProductQty !== materialsRow.dSrcQty) ||
                          (!commonUtils.isEmpty(materialsRow.dAuxiliaryQty) && materialsRow.dAuxiliaryQty !== materialsRow.dSrcAuxiliaryQty)) {
                          const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
                          const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
                          commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, materialsRow);
                        }
                        materialsRow.handleType = 'add';
                        materialsRow.sId = commonUtils.createSid();
                        materialsRow.sParentId = masterData.sId;
                        materialsRow.sControlId = controlRow.sId;
                        materialsRow.sPartsName = controlRow.sPartsName;
                        materialsRow.sSlaveId = slaveRow.sId;
                        // 材料对应工序的ID要变化
                        if (commonUtils.isNotEmptyArr(copyTo.processData)) {
                          const iProcessIndex = processData.findIndex(item => item.sControlId === controlRow.sId && item.sSrcProcessTbId === materialsItem.sProcessTbId);
                          if (iProcessIndex > -1) {
                            materialsRow.sProcessTbId = processData[iProcessIndex].sId;
                          }
                        }
                        if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
                          const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                          const valueMaterialsStock = {
                            sProName: 'Sp_Inventory_MaterialsInventoryV56',
                            paramsMap: {
                              sMaterialsGuid: materialsRow.sMaterialsId,
                              sMaterialsStyle: materialsRow.sMaterialsStyle,
                              sWarehouseGuid: materialsRow.sWarehouseId,
                              sLocationalGuid: materialsRow.sLocationId,
                              sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                              sDefine_no: materialsRow.sDefineNo,
                              sDefine_no2: materialsRow.sDefineNo2,
                              iGetQty: 1,
                              iHasZero: 1,
                            },
                          };
                          const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
                          if (returnDataMaterialsStock.code === 1) {
                            materialsRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                          }
                        }
                        if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
                          const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                          const valueMaterialsAvailableQty = {
                            sProName: 'Sp_Inventory_MaterialsInventoryV56',
                            paramsMap: {
                              sMaterialsGuid: materialsRow.sMaterialsId,
                              sMaterialsStyle: materialsRow.sMaterialsStyle,
                              sWarehouseGuid: materialsRow.sWarehouseId,
                              sLocationalGuid: materialsRow.sLocationId,
                              sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                              sDefine_no: materialsRow.sDefineNo,
                              sDefine_no2: materialsRow.sDefineNo2,
                              iGetQty: 2,
                              iHasZero: 1,
                            },
                          };
                          const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
                          if (returnDataMaterialsAvailableQty.code === 1) {
                            materialsRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                          }
                        }
                        materialsData.push(materialsRow);
                      });
                    }
                  }
                  const copyToProcessConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.process`.toLowerCase());
                  const processAssignField = commonUtils.isNotEmptyArr(copyToProcessConfig) ? copyToProcessConfig[0].sAssignField : '';
                  if (processAssignField !== '') {
                    if (commonUtils.isNotEmptyObject(copyTo.processData)) {
                      let processFilterData = [];
                      const srcFormRoute = copyTo.srcFormRoute;
                      if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
                        processFilterData = copyTo.processData.filter(processItem => processItem.sControlId === controlItem.sId);
                      } else {
                        processFilterData = copyTo.processData.filter(processItem => processItem.sSlaveId === slaveItem.sId && processItem.sControlId === controlItem.sId);
                      }
                      processFilterData.forEach((processItem) => {
                        const newCopyTo = {};
                        newCopyTo.master = copyTo.masterData;
                        newCopyTo.process = processItem;
                        let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                        processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                        if ((!commonUtils.isEmpty(processRow.dProductQty) && processRow.dProductQty !== processRow.dSrcQty) ||
                          (!commonUtils.isEmpty(processRow.dAuxiliaryQty) && processRow.dAuxiliaryQty !== processRow.dSrcAuxiliaryQty)) {
                          const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'process';
                          const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
                          commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, processRow);
                        }
                        processRow.handleType = 'add';
                        processRow.sId = commonUtils.createSid();
                        processRow.sParentId = masterData.sId;
                        processRow.sControlId = controlRow.sId;
                        processRow.sPartsName = controlRow.sPartsName;
                        processRow.sSlaveId = slaveRow.sId;
                        processData.push(processRow);
                      });
                    }
                  }
                  /* 合版表复制到 */
                  if (sModelsType === 'sales/salesOrderPack') {
                    const copyToPackConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.pack`.toLowerCase());
                    const packAssignField = commonUtils.isNotEmptyArr(copyToPackConfig) ? copyToPackConfig[0].sAssignField : '';
                    if (commonUtils.isNotEmptyObject(packAssignField)) {
                    /* 复制到时增加合版表 */
                      if (commonUtils.isNotEmptyArr(copyTo.packData)) {
                        await copyTo.packData.filter(item => item.sSlaveId === slaveItem.sId && item.sControlId === controlItem.sId).forEach(async (packItem) => {
                          newCopyTo.pack = packItem;
                          let packRow = commonFunc.getDefaultData(config.packConfig, newCopyTo); // 取默认值
                          packRow = { ...packRow, ...commonFunc.getAssignFieldValue(packAssignField, packItem, newCopyTo) }; // 取赋值字段
                          /* sSlaveId赋值 */
                          const packRowAdd = this.handlePackDataAdd(slaveRow, 0, controlRow.sId);
                          packRow = { ...packRow, ...packRowAdd };

                          /* 将控制表中的合版备注sId为新的sId */
                          let JsonData = [];
                          const jsonStr = controlRow.sCombinedMemo;
                          if (commonUtils.isNotEmptyObject(jsonStr) && commonUtils.isJSON(jsonStr)) {
                            JsonData = JSON.parse(jsonStr);
                            if (commonUtils.isNotEmptyArr(JsonData)) {
                              let sCombinedMemoNew = '';
                              JsonData.forEach((item, index) => {
                                if (item.sId === packItem.sId) {
                                  JsonData[index].sId = packRow.sId;
                                }
                              });
                              sCombinedMemoNew = JSON.stringify(JsonData);
                              controlRow.sCombinedMemo = sCombinedMemoNew;
                              const icontrolIndex = controlData.findIndex(item => item.sId === controlRow.sId);
                              if (icontrolIndex) {
                                controlData[icontrolIndex] = { ...controlData[icontrolIndex], sCombinedMemo: sCombinedMemoNew };
                              }
                            }
                          }

                          packData.push(packRow);
                        });
                      }
                    }
                  }
                });
              }

              const copyToMaterialsConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.materials`.toLowerCase());
              const materialsAssignField = commonUtils.isNotEmptyArr(copyToMaterialsConfig) ? copyToMaterialsConfig[0].sAssignField : '';
              if (materialsAssignField !== '') {
                if (commonUtils.isNotEmptyObject(copyTo.materialsData)) {
                  let materialsFilterData = [];
                  const srcFormRoute = copyTo.srcFormRoute;
                  if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
                    materialsFilterData = copyTo.materialsData.filter(item => item.sType === '2');
                  } else {
                    materialsFilterData = copyTo.materialsData.filter(item => item.sSlaveId === slaveItem.sId && item.sType === '2');
                  }
                  await materialsFilterData.forEach(async (materialsItem) => {
                    const newCopyTo = {};
                    newCopyTo.master = copyTo.masterData;
                    newCopyTo.materials = materialsItem;
                    let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo); // 取默认值
                    materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
                    if ((!commonUtils.isEmpty(materialsRow.dProductQty) && materialsRow.dProductQty !== materialsRow.dSrcQty) ||
                      (!commonUtils.isEmpty(materialsRow.dAuxiliaryQty) && materialsRow.dAuxiliaryQty !== materialsRow.dSrcAuxiliaryQty)) {
                      const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
                      const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
                      commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, materialsRow);
                    }
                    materialsRow.handleType = 'add';
                    materialsRow.sId = commonUtils.createSid();
                    materialsRow.sParentId = masterData.sId;
                    materialsRow.sSlaveId = slaveRow.sId;
                    if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
                      const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                      const valueMaterialsStock = {
                        sProName: 'Sp_Inventory_MaterialsInventoryV56',
                        paramsMap: {
                          sMaterialsGuid: materialsRow.sMaterialsId,
                          sMaterialsStyle: materialsRow.sMaterialsStyle,
                          sWarehouseGuid: materialsRow.sWarehouseId,
                          sLocationalGuid: materialsRow.sLocationId,
                          sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                          sDefine_no: materialsRow.sDefineNo,
                          sDefine_no2: materialsRow.sDefineNo2,
                          iGetQty: 1,
                          iHasZero: 1,
                        },
                      };
                      const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
                      if (returnDataMaterialsStock.code === 1) {
                        materialsRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                      }
                    }
                    if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
                      const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                      const valueMaterialsAvailableQty = {
                        sProName: 'Sp_Inventory_MaterialsInventoryV56',
                        paramsMap: {
                          sMaterialsGuid: materialsRow.sMaterialsId,
                          sMaterialsStyle: materialsRow.sMaterialsStyle,
                          sWarehouseGuid: materialsRow.sWarehouseId,
                          sLocationalGuid: materialsRow.sLocationId,
                          sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                          sDefine_no: materialsRow.sDefineNo,
                          sDefine_no2: materialsRow.sDefineNo2,
                          iGetQty: 2,
                          iHasZero: 1,
                        },
                      };
                      const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
                      if (returnDataMaterialsAvailableQty.code === 1) {
                        materialsRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                      }
                    }
                    materialsData.push(materialsRow);
                  });
                }
              }
              const copyToProcessConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.process`.toLowerCase());
              const processAssignField = commonUtils.isNotEmptyArr(copyToProcessConfig) ? copyToProcessConfig[0].sAssignField : '';
              if (processAssignField !== '') {
                if (commonUtils.isNotEmptyObject(copyTo.processData)) {
                  let processFilterData = [];
                  const srcFormRoute = copyTo.srcFormRoute;
                  if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
                    processFilterData = copyTo.processData.filter(item => item.sType === '3');
                  } else {
                    processFilterData = copyTo.processData.filter(item => item.sSlaveId === slaveItem.sId && item.sType === '3');
                  }
                  processFilterData.forEach((processItem) => {
                    const newCopyTo = {};
                    newCopyTo.master = copyTo.masterData;
                    newCopyTo.process = processItem;
                    let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                    processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                    if ((!commonUtils.isEmpty(processRow.dProductQty) && processRow.dProductQty !== processRow.dSrcQty) ||
                      (!commonUtils.isEmpty(processRow.dAuxiliaryQty) && processRow.dAuxiliaryQty !== processRow.dSrcAuxiliaryQty)) {
                      const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'process';
                      const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
                      commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, processRow);
                    }
                    processRow.handleType = 'add';
                    processRow.sId = commonUtils.createSid();
                    processRow.sParentId = masterData.sId;
                    processRow.sSlaveId = slaveRow.sId;
                    /* 通用报价单的合版部件名称换成新生成的控制表sId */
                    if (commonUtils.isNotEmptyObject(processRow.sCombinePartsName)) {
                      /* 新的sCombinePartsName赋值 */
                      let sCombinePartsNameStr = ''; /* 新生成合版部件名称 */
                      const sCombinePartsNameOldArr = processRow.sCombinePartsName.split(',');
                      if (commonUtils.isNotEmptyArr(sCombinePartsNameOldArr)) {
                        const controlFilterData = controlData.filter(item => sCombinePartsNameOldArr.includes(item.sOriginalId));
                        if (commonUtils.isNotEmptyArr(controlFilterData)) {
                          controlFilterData.forEach((item) => {
                            sCombinePartsNameStr += `${item.sId},`;
                          });
                        }
                        sCombinePartsNameStr = commonUtils.isNotEmptyObject(sCombinePartsNameStr) ? sCombinePartsNameStr.substr(0, sCombinePartsNameStr.length - 1) : '';
                        processRow.sCombinePartsName = sCombinePartsNameStr;
                      }
                    }
                    processData.push(processRow);
                  });
                }
              }
              /* 颜色表 */
              const copyToColorConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.param`.toLowerCase());
              const colorAssignField = commonUtils.isNotEmptyArr(copyToColorConfig) ? copyToColorConfig[0].sAssignField : '';
              if (colorAssignField !== '') {
                if (commonUtils.isNotEmptyArr(copyTo.colorData)) {
                  if (commonUtils.isNotEmptyObject(config.colorConfig)) {
                    copyTo.colorData.forEach((colorItem) => {
                      newCopyTo.color = colorItem;
                      let colorRow = commonFunc.getDefaultData(config.colorConfig, newCopyTo); // 取默认值
                      colorRow = { ...colorRow, ...commonFunc.getAssignFieldValue(colorAssignField, colorItem, newCopyTo) }; // 取赋值字段
                      colorRow.handleType = 'add';
                      colorRow.sId = commonUtils.createSid();
                      colorRow.sParentId = masterData.sId;
                      colorData.push(colorRow);
                    });
                  }
                }
              }
            }
          }
        }
        if (!commonUtils.isEmpty(masterData.sTestStandardId)) {
          const dataUrl = `${commonConfig.server_host}eleteamemployee/getObtainInspectionStandards?sModelsId=${sModelsId}&sParentId=${masterData.sTestStandardId}`;
          const dataReturn = (await commonServices.getService(this.props.app.token, dataUrl)).data;
          const slaveDelData = [];
          if (dataReturn.code === 1) {
            const returnSlaveData = dataReturn.dataset.rows;
            slaveData.forEach((item) => {
              item.handleType = 'del';
              slaveDelData.push(item);
            });
            slaveData = [];
            const newCopyTo = {};
            newCopyTo.master = masterData;
            const iConfigIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'sTestStandardName');
            returnSlaveData.forEach((item, iIndex) => {
              let tableDataRow = commonFunc.getDefaultData(config.slaveConfig, {});
              tableDataRow.handleType = 'add';
              tableDataRow.sId = commonUtils.createSid();
              tableDataRow.sParentId = masterData && masterData.sId ? masterData.sId : null;
              tableDataRow.key = tableDataRow.sId;
              tableDataRow.iOrder = iIndex;
              if (iConfigIndex > -1) {
                tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(masterConfig.gdsconfigformslave[iConfigIndex].sAssignField, item, newCopyTo) }; // 取赋值字段
              }
              slaveData.push(tableDataRow);
            });
          }
        }
      }
      if (sModelsType === 'purchase/purchaseOrder' && !commonUtils.isEmpty(copyTo) && commonUtils.isNotEmptyArr(copyTo.copyOtherData)) {
        const copyToDetailConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.detail`.toLowerCase());
        const detailAssignField = commonUtils.isNotEmptyArr(copyToDetailConfig) ? copyToDetailConfig[0].sAssignField : '';
        if (detailAssignField !== '') {
          const copyDetail = copyTo.copyOtherData.filter(item => item.name === 'detail')[0];
          const detail = copyDetail.data;
          detail.forEach((detailItem) => {
            const newCopyTo = {};
            newCopyTo.master = copyTo.masterData;
            newCopyTo.detail = detailItem;
            let tempDetail = commonFunc.getDefaultData(config.orderDetailConfig, newCopyTo); // 取默认值
            tempDetail = { ...tempDetail, ...commonFunc.getAssignFieldValue(detailAssignField, detailItem, newCopyTo) }; // 取赋值字段
            const iIndex = slaveData.findIndex(slaveItem => slaveItem.sMaterialsId + slaveItem.sMaterialsStyle === detailItem.sMaterialsGS);
            if (iIndex !== -1) {
              slaveData[iIndex].sWorkOrderNo = commonUtils.isEmptyObject(slaveData[iIndex].sWorkOrderNo) ? detailItem.sWorkOrderNo : `${slaveData[iIndex].sWorkOrderNo},${detailItem.sWorkOrderNo}`;
            }
            tempDetail.handleType = 'add';
            tempDetail.sId = commonUtils.createSid();
            tempDetail.sParentId = masterData.sId;
            orderDetailData.push(tempDetail);
          });
        }
      }
      /* 剔除订单到收款单,费用分摊单据新增空行 */
      if (slaveData.length === 0 && commonUtils.isNotEmptyObject(configNew.slaveConfig) && this.props.sModelsType !== 'cashier/receipt' && this.props.sModelsType !== 'cashier/payment' && this.props.sModelsType !== 'cost/cosexpenseshare'
        && sModelsType !== 'sales/salesInvoice' && sModelsType !== 'purchase/purchaseInvoice' && sModelsType !== 'purchase/outsideInvoice') {
        const allTableData = {};
        allTableData.master = masterData;
        allTableData.slave = slaveData;
        const tableDataRowAdd = commonFunc.getDefaultData(configNew.slaveConfig, allTableData);
        tableDataRowAdd.handleType = 'add';
        tableDataRowAdd.sId = commonUtils.createSid();
        tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
        tableDataRowAdd.key = tableDataRowAdd.sId;
        tableDataRowAdd.bDefault = false;
        tableDataRowAdd.iOrder = 1;
        slaveData.push(tableDataRowAdd);
      }
      if (sModelsType === 'sales/salesSgoods') { /* 送货单中如果只有一个仓库，默认带这个仓库 */
        // const sWareHouseNameDropDown = commonUtils.getStoreDropDownData(sModelsId, 'master', 'sWareHouseName');
        let sWareHouseNameDropDown;
        const masterIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sWareHouseName');
        if (masterIndex > -1) {
          const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', masterConfig.gdsconfigformslave[masterIndex]);
          sWareHouseNameDropDown = sqlDropDownData.dropDownData;
        }
        if (commonUtils.isNotEmptyArr(sWareHouseNameDropDown) && sWareHouseNameDropDown.length === 1) {
          const addStata = {};
          addStata.sWareHouseId = sWareHouseNameDropDown[0].sId;
          addStata.sWareHouseNo = sWareHouseNameDropDown[0].sNo;
          addStata.sWareHouseName = sWareHouseNameDropDown[0].sName;
          addStata.sLocationId = sWareHouseNameDropDown[0].sLocationId;
          addStata.sLocationNo = sWareHouseNameDropDown[0].sLocationNo;
          addStata.sLocationName = sWareHouseNameDropDown[0].sLocationName;
          addStata.sWareHouseLocationId = sWareHouseNameDropDown[0].sWareHouseLocationId;
          addStata.sWareHouseLocationNo = sWareHouseNameDropDown[0].sWareHouseLocationNo;
          addStata.sWareHouseLocationName = sWareHouseNameDropDown[0].sWareHouseLocationName;
          const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sWareHouseName');
          if (iIndex > -1) {
            masterData = { ...masterData, ...addStata }; /* 主表赋默认仓库 */
            if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) { /* 从表赋默认仓库 */
              slaveData.forEach((item, index) => {
                slaveData[index] = { ...item, ...addStata };
              });
            }
          }
        }
      }
      const treeState = this.handleGetControlTreeData(controlData, true); /* 加载树形结构数据 */
      const state = {
        masterData,
        slaveData,
        slaveTotal: [],
        slaveSelectedRowKeys: [],
        checkData: [],
        checkSelectedRowKeys: [],
        searchUpDownData: {},
        enabled: true,
        controlData,
        materialsData,
        processData,
        dailyData,
        packData,
        colorData,
        orderDetailData,
        ...treeState,
        processSelectedRowKeys: [],
        controlSelectedRowKeys: [],
        materialsSelectedRowKeys: [],
        calculated: false,
      };
      state.sUseInfo = '';
      if (isWait) {
        return state;
      } else {
        this.props.onSaveState(state);
        return true;
      }
    };
    /**   点击修改按钮操作   */
    handleEdit = async () => {
      const {
        masterConfig, slaveConfig, checkConfig, currentId, app, masterData, dispatch, billnosetting,
      } = this.props;
      const { userinfo, systemData } = app;
      const { sMakePerson } = masterData; /* 本单据制单人 */
      const { sUserName, sType } = userinfo;/* 登录用户 */
      // 判断是否全局都有配置
      const iIndex = systemData.findIndex(item => item.sName === 'CkxModifyBillNoMakePerson');
      let sValue = 0;
      if (iIndex > -1) {
        sValue = systemData[iIndex].sValue; // 全局配置的值; 1为开启：所有人都可以编辑，0是关闭;
      }
      const bModify = billnosetting.bModify; /* 勾选了可修改及代表普通用户非制单人可以修改单据 */
      if (!+sValue && !bModify && sType !== 'sysadmin' && sUserName !== sMakePerson) {
        message.error(commonFunc.showMessage(app.commonConst, 'NoUpdateByNoMakePerson'));
        this.props.onSaveState({
          loading: false,
        });
        return;
      }
      this.props.app.webSocket.onmessageTmp = async (msg) => {
        const rtmsg = JSON.parse(msg.data);
        if (rtmsg.action === 'showMsg') {
          message.warning(rtmsg.msg);
          this.props.onSaveState({ loading: false });
        } else if (rtmsg.action === 'update') {
          await this.handleGetData(masterConfig, slaveConfig, checkConfig, 'update');
          this.props.onSaveState({ enabled: true, calculated: false, loading: false });
        }
      };
      this.props.handleSendSocketMessage('update', 'showMsg', currentId, userinfo.sId, null, null);
    };
    /**   表单回带   */
    handleForm = (form) => {
      this.form = form;
    };
    /**   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, masterConfig, slaveConfig, checkConfig, token, sModelsType, controlConfig, materialsConfig, processConfig, colorConfig, packConfig, slaveData, orderDetailConfig, slaveChildConfig,
      } = this.props;
      const sSlaveIdArray = [];
      if (commonUtils.isNotEmptyArr(slaveData)) {
        slaveData.forEach((item) => {
          sSlaveIdArray.push(commonUtils.isNotEmptyObject(item.sId) ? item.sId : item.sSlaveId);
        });
      }
      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(masterConfig, slaveConfig, checkConfig);
          if ((sModelsType.includes('sales/salesOrder') || sModelsType === 'manufacture/workOrder3') && !commonUtils.isEmpty(controlConfig)) {
            await this.handleGetMemoData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig);
          } else if (sModelsType === 'purchase/purchaseOrder') {
            await this.handleGetOneMemoData('orderDetail', orderDetailConfig);
          } else if (sModelsType === 'sales/salesSgoods' && !commonUtils.isEmpty(slaveChildConfig)) {
            await this.handleGetOneMemoData('slaveChild', slaveChildConfig);
          }
          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保存   */
    handleSaveData = async (params) => {
      const {
        token, sModelsId, currentId, masterData, masterConfig, slaveConfig, checkConfig, billnosetting, app, sModelsType, controlConfig, materialsConfig, processConfig, colorConfig, packConfig, orderDetailConfig, dispatch, slaveChildConfig,
      } = this.props;
      const { userinfo } = app;
      const { copyTo } = app.currentPane;
      const onSendSocketMessage = this.props.handleSendSocketMessage;
      const BtnSave = commonFunc.showMessage(app.commonConst, 'BtnSave');/* 保存 */
      params.optName = BtnSave;
      const returnData = await commonBusiness.saveData({ token, value: params, sModelsId });
      if (commonUtils.isNotEmptyObject(returnData)) {
        if (commonUtils.isNotEmptyObject(copyTo)) {
          const { slaveData } = copyTo;
          const sIdArray = [];
          slaveData.forEach((item) => {
            const redisKey = item.sSlaveId;
            sIdArray.push(redisKey);
          });
          const sId = sIdArray.toString();
          onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
        }
        onSendSocketMessage('release', 'noAction', currentId, userinfo.sId, null, null);
        this.props.onSaveState({
          enabled: false, currentId: masterData.sId,
        });
        // 保存后更新panes,currentPane的checkedId，防止浏览器刷新时重新又变成新增。
        const iPaneIndex = app.panes.findIndex(item => item.key === app.currentPane.key);
        app.panes[iPaneIndex].checkedId = masterData.sId;
        app.currentPane.checkedId = masterData.sId;
        dispatch({ type: 'app/savePanesAndCurrentPane', payload: { panes: app.panes, currentPane: app.currentPane } });

        if (billnosetting.bAutoCheck) {
          await this.handleAudit(1);
        } else {
          await this.handleGetData(masterConfig, slaveConfig, checkConfig);
          if ((sModelsType.includes('sales/salesOrder') || sModelsType.includes('manufacture/workOrder')) && !commonUtils.isEmpty(controlConfig)) {
            await this.handleGetMemoData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig);
          } else if (sModelsType === 'purchase/purchaseOrder') {
            await this.handleGetOneMemoData('orderDetail', orderDetailConfig);
          } else if (sModelsType === 'sales/salesSgoods' && !commonUtils.isEmpty(slaveChildConfig)) {
            await this.handleGetOneMemoData('slaveChild', slaveChildConfig);
          }
          if (this.props.app.currentPane.refresh !== undefined) {
            this.props.app.currentPane.refresh();
          }
        }
        this.props.onSaveState({
          loading: false,
        });
        return true;
      } else {
        this.props.onSaveState({
          loading: false,
        });
        return false;
      }
    };
    /**   toolbar校验保存   */
    handleValidateSave = () => {
      this.form.validateFields(async (err) => {
        /*   验证通过与不通过走不同的流程    */
        if (err) { /*   验证失败   */
          /*   直接渲染显示错误提示   */
          for (const key of Object.keys(err)) {
            message.error(err[key].errors[0].message);
          }
          this.props.onSaveState({
            loading: false,
          });
        } else { /*   验证成功   */
          const {
            masterConfig, slaveConfig, slaveData, slaveDelData, app, sModelsType, controlConfig, controlData, controlDelData, materialsConfig, materialsData, materialsDelData, processConfig, processData, processDelData, colorConfig, colorData, colorDelData, packConfig, packData, packDelData, orderDetailConfig, orderDetailData, orderDetailDelData,
            slaveChildConfig, slaveChildData, slaveChildDelData,
          } = this.props;
          let { masterData } = this.props;
          if (sModelsType !== 'commonBill/onlyMaster' && commonUtils.isEmptyArr(slaveData) && !sModelsType.includes('sales/salesInvoice') && !sModelsType.includes('purchase/purchaseInvoice') && !sModelsType.includes('purchase/outsideInvoice') && sModelsType !== 'cashier/financialTransfer' && sModelsType !== 'cashier/financialAdjustment'
            && !sModelsType.includes('cashier/receipt') && !sModelsType.includes('cashier/payment') && !sModelsType.includes('purchase/purchaseEnquiry')) {
            message.error(commonFunc.showMessage(app.commonConst, 'slaveNotNull')); // 从表不能为空！
            this.props.onSaveState({
              loading: false,
            });
            return;
          }
          // && sModelsType === 'materialsStock/productionmaterialsadjust'
          if (commonUtils.isNotEmptyArr(slaveData)) {
            let flag = true;
            for (const item of slaveData) {
              if (sModelsType === 'materialsStock/productionmaterialsadjust') {
                if (commonUtils.isNotEmptyStr(item.sWareHouseId)) {
                  if (masterData.sWareHouseId === item.sWareHouseId && masterData.sWarehouseLocationId === item.sWarehouseLocationId && masterData.sLocationId === item.sLocationId) {
                    message.error(commonFunc.showMessage(app.commonConst, 'NotSameMateMaterialWarehouse'));/* 材料调拨原仓库与调入仓库不能一致 */
                    flag = false;
                    break;
                  }
                }
              }
              // {"paper":"纸张","finished":"成品","half_finished":"半成品","accessories":"辅料","corrugated":"瓦楞"}
              if (commonUtils.isNotEmptyObject(item.sMaterialsType) && item.sMaterialsType === 'paper' && commonUtils.isEmptyObject(item.sMaterialsStyle)) {
                if (sModelsType.includes('sales/')) {
                  message.error(item.sProductName + commonFunc.showMessage(app.commonConst, 'NoStyle'));/* 请填写"${item.sProductName}"的规格 */
                } else {
                  message.error(item.sMaterialsName + commonFunc.showMessage(app.commonConst, 'NoStyle'));/* 请填写"${item.sMaterialsName}"的规格 */
                }
                flag = false;
                break;
              }
            }
            if (!flag) {
              this.props.onSaveState({
                loading: false,
              });
              return;
            }
          }
          if (!commonBusiness.validateTable(slaveConfig, slaveData, this.props)) {
            this.props.onSaveState({
              loading: false,
            });
            return;
          }
          if (commonUtils.isNotEmptyArr(slaveData) && sModelsType === 'materialsStock/productionmaterials') {
            let flag = true;
            const iIndex = app.systemData.findIndex(item => item.sName === 'CkxMaterialsStockLimit');
            if (iIndex > -1) {
              const bCkxMaterialsStockLimit = app.systemData[iIndex].sValue;
              if (bCkxMaterialsStockLimit === '1') {
                flag = await this.handleEleMaterialsStoreCurrQty(slaveData);
              }
            }
            if (!flag) {
              this.props.onSaveState({
                loading: false,
              });
              return;
            }
          }
          if (sModelsType === 'purchase/purchaseEnquiry') {
            delete masterData.maxBillNo;
          }
          if (sModelsType === 'sales/salesSgoods' && !commonUtils.isEmpty(slaveChildConfig)) { /* 送货单千彩 若子表没填 则不能保存！ */
            if (commonUtils.isEmptyArr(slaveChildData)) {
              message.error('未选择出库产品 不能保存!');
              this.props.onSaveState({
                loading: false,
              });
              return;
            } else if (!commonBusiness.validateTable(slaveChildConfig, slaveChildData, this.props, '2')) {
              this.props.onSaveState({
                loading: false,
              });
              return;
            }
          }
          if (sModelsType === 'cashier/receipt' || sModelsType === 'cashier/payment') {
            let flag = true;
            if (masterData.sSettlementId === 'bank') {
              if (commonUtils.isEmptyStr(masterData.sBankId) || commonUtils.isEmptyStr(masterData.sBankAccount)) {
                message.error(commonFunc.showMessage(app.commonConst, 'requiredsBankAccount'));/* 收/付款条件为银行时，银行、银行账号为必填项 */
                flag = false;
              }
            }
            if (masterData.sSettlementId === 'bill') {
              if (commonUtils.isEmptyStr(masterData.sBankId) || commonUtils.isEmptyStr(masterData.sInvoiceNo)) {
                message.error(commonFunc.showMessage(app.commonConst, 'requiredsInvoiceNo'));/* 收/付款条件为票据时，银行、票据号码为必填项 */
                flag = false;
              }
            }
            let dslaveTotalMoney = 0;
            let flagCheckSave = true;
            if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
              for (const item of slaveData) {
                if (item.handleType !== 'del') {
                  if (commonUtils.isNotEmptyNumber(item.dTotalMoney)) {
                    dslaveTotalMoney += item.dTotalMoney;
                  }
                  const dBalanceMoney = commonUtils.isNull(item.dBalanceMoney, 0);
                  const dTotalMoney = commonUtils.isNull(item.dTotalMoney, 0);
                  const dRoundingMoney = commonUtils.isNull(item.dRoundingMoney, 0);
                  const dCount = dRoundingMoney + dTotalMoney;
                  let bWarning = false;
                  if (dBalanceMoney > 0 || dBalanceMoney === 0) {
                    if (dCount > dBalanceMoney) {
                      bWarning = true;
                    }
                  } else if (dCount < dBalanceMoney) {
                    bWarning = true;
                  }
                  if (bWarning) {
                    if (sModelsType.includes('cashier/receipt')) {
                      message.error(commonFunc.showMessage(app.commonConst, 'NoOverBalanceMoneyReceipt'));/* 总金额不能超过未收/付款宽金额 */
                    } else if (sModelsType.includes('cashier/payment')) {
                      message.error(commonFunc.showMessage(app.commonConst, 'NoOverBalanceMoneyPay'));/* 总金额不能超过未收/付款宽金额 */
                    }
                    this.props.onSaveState({
                      loading: false,
                    });
                    return;
                  }
                }
                const flatDel = commonUtils.isNull(item.dTotalMoney, 0) !== 0 || commonUtils.isNull(item.dRoundingMoney, 0) !== 0;
                if (!flatDel) {
                  item.handleType = undefined; /*  付款单和收款单，去掉收款和付款金额为0的记录 */
                } else {
                  flagCheckSave = false;
                }
              }
            }
            if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0 && flagCheckSave) {
              message.warning('表格内容不能为空![dTotalMoney或dRoundingMoney必须大于0]');
              this.props.onSaveState({
                loading: false,
              });
              return;
            }
            const dPmoney = this.props.getFloatNum('dProductMoney');
            dslaveTotalMoney = commonUtils.convertFixNum(dslaveTotalMoney, dPmoney);/* 取系统设定小数位 */
            if (commonUtils.isNotEmptyArr(slaveData) && commonUtils.isNotEmptyNumber(masterData.dTotalMoney) && commonUtils.isNotEmptyNumber(masterData.dAdvanceMoney) && commonUtils.convertFixNum(masterData.dTotalMoney - masterData.dAdvanceMoney, dPmoney) !== dslaveTotalMoney) {
              message.error(commonFunc.showMessage(app.commonConst, 'NotSameTotalMoney'));/* 主从表总金额不一致 */
              flag = false;
            }
            /* 收付款保存前，看到从表没数据，预收勾上时，自动调用一下分摊 */
            if (commonUtils.isEmptyArr(slaveData)) {
              masterData = this.handleShare();
            }
            if (!flag) {
              this.props.onSaveState({
                loading: false,
              });
              return;
            }
          }
          /*  销售发票、采购发票、发外发票 ，去掉总金额+舍入为0的数据 */
          if (sModelsType === 'sales/salesInvoice' || sModelsType === 'purchase/purchaseInvoice' || sModelsType === 'purchase/outsideInvoice') {
            let flagCheckSave = true;
            if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
              for (const item of slaveData) {
                const flatDel = commonUtils.isNull(item.dTotalMoney, 0) !== 0 || commonUtils.isNull(item.dRoundingMoney, 0) !== 0;
                if (!flatDel) {
                  item.handleType = undefined; /*  付款单和收款单，去掉收款和付款金额为0的记录 */
                } else {
                  flagCheckSave = false;
                }
              }
            }
            /* 收付款保存前，看到从表没数据，预收勾上时，自动调用一下分摊 */
            if (commonUtils.isEmptyArr(slaveData)) {
              masterData = this.handleShare();
            }
            if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0 && flagCheckSave) {
              message.warning('表格内容不能为空![dTotalMoney或dRoundingMoney必须大于0]');
              this.props.onSaveState({
                loading: false,
              });
              return;
            }
          }
          const data = [];
          data.push(commonBusiness.mergeData('master', masterConfig.sTbName, [masterData]));
          if (sModelsType !== 'commonBill/onlyMaster' && sModelsType !== 'cashier/financialTransfer' && sModelsType !== 'cashier/financialAdjustment' && !sModelsType.includes('purchase/purchaseEnquiry')) {
            data.push(commonBusiness.mergeData('slave', slaveConfig.sTbName, slaveData, slaveDelData));
          }
          if (sModelsType.includes('sales/salesOrder') && !commonUtils.isEmpty(controlConfig)) {
            if (commonUtils.isNotEmptyArr(materialsData)) {
              const flag = true;
              // for (const item of materialsData) { /* 销售订单中的物料规格不是必填项，只有工单里才要判断必填 */
              //   if (commonUtils.isNotEmptyObject(item.sMaterialsType) && item.sMaterialsType === 'paper' && commonUtils.isEmptyObject(item.sMaterialsStyle)) {
              //     message.error(item.sMaterialsName + commonFunc.showMessage(app.commonConst, 'NoStyle'));/* 请填写规格 */
              //     flag = false;
              //     break;
              //   }
              // }
              if (!flag) {
                this.props.onSaveState({
                  loading: false,
                });
                return;
              }
            }
            data.push(commonBusiness.mergeData('control', controlConfig.sTbName, controlData, controlDelData));
            data.push(commonBusiness.mergeData('materials', materialsConfig.sTbName, materialsData, materialsDelData));
            data.push(commonBusiness.mergeData('process', processConfig.sTbName, processData, processDelData));
            if (commonUtils.isNotEmptyObject(colorConfig)) {
              data.push(commonBusiness.mergeData('color', colorConfig.sTbName, colorData, colorDelData));
            }
            if (commonUtils.isNotEmptyObject(packConfig)) {
              data.push(commonBusiness.mergeData('pack', packConfig.sTbName, packData, packDelData));
            }
          }
          if (sModelsType === 'purchase/purchaseOrder' && !commonUtils.isEmpty(orderDetailConfig)) {
            data.push(commonBusiness.mergeData('detail', orderDetailConfig.sTbName, orderDetailData, orderDetailDelData));
          } else if (sModelsType === 'sales/salesSgoods' && !commonUtils.isEmpty(slaveChildConfig)) {
            data.push(commonBusiness.mergeData('slaveChild', slaveChildConfig.sTbName, slaveChildData, slaveChildDelData));
          }
          this.handleSaveData({ data, sClientType: '1', sSysLogSrcId: masterData.sId });
        }
      });
    };

    /* 切换作废状态 */
    handleOkChangeInvaild = async (props) => {
      const {
        sModelsId, masterData, masterConfig, handleType,
      } = props;
      const value = {
        sClientType: '1',
        sId: [masterData.sId],
        sTableName: masterConfig.sTbName,
        handleType,
      };
      const url = `${commonConfig.server_host}checkModel/updatebInvalid?sModelsId=${sModelsId}`;
      const { data } = await commonServices.postValueService(props.app.token, value, url);
      if (data.code === 1) {
        message.success(data.msg);
        masterData.bInvalid = handleType === 'toVoid'; /* 作废状态 */
        props.onSaveState({ masterData });
        /*  审核(消审)后刷新跳转路由数据（commonList）的数据 */
        if (props.app.currentPane.refresh !== undefined) {
          props.app.currentPane.refresh();
        }
      } else {
        props.getServiceError(data);
      }
    };

    /* 作废、取消作废的公用函数 */
    handleInvalid = (obj) => {
      const props = { ...this.props, ...this.state, ...obj };
      const onOkInvaild = this.handleOkChangeInvaild;
      confirm({
        title: obj.title,
        onOk() {
          onOkInvaild(props);
        },
        onCancel() {
        },
      });
    };

    /*   单据页上查下查跳转页面   */
    handleSearchUpDown = async (sId, sActiveId) => {
      /*   待用数据声明   */
      const { dispatch, sTabId } = this.props;
      dispatch({
        type: 'content/onRouter',
        payload: {
          url: `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}`, /*   接口地址   */
          sParentId: sTabId, /*   父页面编号   */
          checkedId: sId,
        },
      });
    };

    /*   上查下查三级菜单  在上一条下一条时必须清除searchUpDownData  */
    handleSearchUpDownThird = async (upDownKey) => {
      /*   待用数据声明   */
      const { masterConfig, searchUpDownData: searchUpDownDataOld } = this.props;
      /**   获取sqlCondition参数：{sSqlCondition,sId}   */
      const searchUpDownData = commonUtils.isEmptyObject(searchUpDownDataOld) ? {} : { ...searchUpDownDataOld };
      if (commonUtils.isNotEmptyObject(masterConfig)) {
        const searchUpDownConfig = masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes(`${upDownKey}`));
        for (const item of searchUpDownConfig) {
          if (commonUtils.isEmptyArr(searchUpDownData[item.sControlName])) {
            searchUpDownData[item.sControlName] = await this.getSearchUpDownData(item);
          }
        }
        this.props.onSaveState({ searchUpDownData });
      }
    };

    /*   单据页复制到   */
    handleCopyTo = async (name, sActiveId) => {
      /*   待用数据声明   */
      const {
        masterConfig,
        masterData,
        slaveData,
        controlData,
        materialsData,
        processData,
        packData,
        app,
        token,
        sModelsId,
        formRoute,
      } = this.props;

      // 从表有sCopyToCondition则不能复制，并提示
      if (commonUtils.isNotEmptyArr(slaveData) && name.includes('.')) {
        const sCopyToConditionIndex = slaveData.findIndex(item => item.sCopyToCondition);
        if (sCopyToConditionIndex !== -1) {
          message.warning(slaveData[sCopyToConditionIndex].sCopyToCondition);
          return;
        }
      }

      const copyTo = {};
      const copyToConfig = masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes(name));
      copyTo.name = name;
      copyTo.config = copyToConfig;
      copyTo.masterData = masterData;
      copyTo.slaveData = slaveData;
      copyTo.controlData = controlData;
      copyTo.materialsData = materialsData;
      copyTo.processData = processData;
      copyTo.packData = packData;
      const tbSuffix = '';
      let sId = '';
      if (!commonUtils.isEmpty(slaveData)) {
        sId = slaveData[0].sId;
      }

      const dataUrl = `${commonConfig.server_host}bill/billCopyToCheck/?sModelsId=${sModelsId}&sActiveId=${sActiveId}&tbSuffix=${tbSuffix}&sName=${formRoute}`;
      const values = { sSlaveId: sId };
      const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
      if (dataReturn.code === 1) {
        // eslint-disable-next-line no-underscore-dangle
        const _this = this; // 解决confirm中this指向问题；
        if (dataReturn.dataset.rows.length > 0) {
          confirm({
            title: commonFunc.showMessage(app.commonConst, 'beUsedToNew'), /* 单据已存在，是否填写新单据 */
            onOk() {
              _this.handleDispatch(copyTo, sActiveId);
            },
            onCancel() {
            },
          });
        } else {
          this.handleDispatch(copyTo, sActiveId);
        }
      }
    };
    handleDispatch = (copyTo, sActiveId) => {
      const { dispatch } = this.props;
      dispatch({
        type: 'content/onRouter',
        payload: {
          url: `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}`, /*   接口地址   */
          copyTo,
        },
      });
    }

    /*   复制从产品工艺卡列表   */
    handleCopyFrom = async (obj) => {
      /*   待用数据声明   */
      const {
        slaveData,
      } = this.props;
      if (commonUtils.isEmptyStr(slaveData[0].sCustomerId)) {
        message.error(commonFunc.showMessage(this.props.app.commonConst, 'pleaseInputCustomer'));/* 请填写客户 */
        return;
      }
      const { token } = this.props;
      const url = `${commonConfig.server_host}/gdsmodule/getGdsmoduleById/${obj.copyFromSActiveId}?sModelsId=${obj.copyFromSActiveId}`;
      const dataReturn = (await commonServices.getService(token, url)).data;
      if (dataReturn.code === 1) {
        const returnData = dataReturn.dataset.rows[0];
        this.props.onSaveState({ productProcessInfoChooseVisible: true, productProcessInfoChooseData: returnData, productProcessInfoCopyFromKey: obj.copyFromKey });
      } else {
        this.props.getServiceError(dataReturn);
      }
    };

    /*  上一条、下一条、首条、末条 */
    handleSearchData = async (handleType) => {
      const {
        sModelsId, app, currentIndexFlag, currentPageNo,
      } = this.props;
      const { currentPane, token } = app;
      const {
        pages, sFilterOrderBy, bFilter, sListFormmasterId, currentIndex,
      } = currentPane;
      let currentPosition = currentIndexFlag ? currentPageNo : commonUtils.isEmptyObject(pages) ? 1 : (((pages.current - 1) * commonConfig.pageSize) + Number.parseInt(currentIndex, 10)) + 1;
      if (currentIndex === undefined) {
        currentPosition = 1;
      }
      if (handleType === 'first') {
        currentPosition = 1;
      } else if (handleType === 'end') {
        currentPosition = pages.total;
      }
      if (!commonUtils.isNum(currentPosition)) { // 如果是列表直接点增加，就跳到第一条去
        currentPosition = 1;
      }
      this.props.onSaveState({ loading: true });
      const value = {
        sClientType: '1', sFilterOrderBy, bFilter, sListFormmasterId, currentPosition, handleType, iCountSum: pages.total,
      };
      const url = `${commonConfig.server_host}business/getBusinessDataByIndex?sModelsId=${sModelsId}`;
      /*   接收返回值   */
      const { data } = await commonServices.postValueService(token, value, url);
      /*   接收返回值   */
      /*   成功的话刷新页面(同步主表和从表数据),不成功就弹出错误提示   */
      if (data.code === 1) {
        /*   数据查询成功   */
        const returnData = data.dataset.rows[0];
        const { masterConfig, slaveConfig, checkConfig } = this.props;
        this.props.onSaveState({
          currentIndexFlag: true,
          currentPageNo: returnData.currentPosition,
          currentId: returnData.sId,
          searchUpDownData: {},
          slaveSelectedRowKeys: [],
        });
        this.handleGetData(masterConfig, slaveConfig, checkConfig);
        return true;
      } else { /*   失败   */
        this.props.getServiceError(data);
        return false;
      }
    };

    /*   取消操作  */
    handleCancel = (obj) => {
      /*   待用数据声明   */
      const that = this;
      const {
        currentId, masterConfig, slaveConfig, checkConfig, app,
      } = this.props;
      const { userinfo } = app;
      const onSendSocketMessage = this.props.handleSendSocketMessage;
      const onGetDataOk = this.handleGetData;
      const onSaveStateOk = this.props.onSaveState;
      const { copyTo } = app.currentPane;
      confirm({
        title: obj.title,
        onOk() {
          // 解决新建页签sid为空的bug
          if (!currentId) {
            const { panes, currentPane } = that.props.app;
            const currentPaneIndex = panes.findIndex(item => item.key === currentPane.key);
            const newPanes = [];
            if (currentPaneIndex > 0) {
              panes.forEach((item, index) => {
                if (index !== currentPaneIndex) {
                  newPanes.push(item);
                }
              });
              that.props.dispatch({ type: 'app/removePane', payload: { changePanes: newPanes, currentPane: panes[currentPaneIndex - 1] } });/* 关闭当前页签 */
            }
            /* 复制到新增页签取消时 关闭页签 并清除操作记录 */
            if (commonUtils.isNotEmptyObject(copyTo)) {
              const { slaveData, srcFormRoute, copyOtherData } = copyTo;
              if (commonUtils.isNotEmptyObject(srcFormRoute) && srcFormRoute.includes('materialRequirementsPlanning')) { /* 物料需求计划用sWorkOrderMaterialId作为唯一键 */
                const sIdArray = [];
                if (commonUtils.isNotEmptyArr(copyOtherData) && copyOtherData[0].name === 'detail' && commonUtils.isNotEmptyArr(copyOtherData[0].data)) {
                  const slaveDetailData = copyOtherData[0].data;
                  slaveDetailData.forEach((item) => {
                    const redisKey = item.sWorkOrderMaterialId;
                    sIdArray.push(redisKey);
                  });
                } else { /* 变更单、采购申请单 */
                  slaveData.forEach((item) => {
                    const redisKey = item.sWorkOrderMaterialId;
                    sIdArray.push(redisKey);
                  });
                }

                const sId = sIdArray.toString();
                onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
              } else if (commonUtils.isNotEmptyArr(slaveData)) {
                const sIdArray = [];
                slaveData.forEach((item) => {
                  const redisKey = item.sSlaveId;
                  sIdArray.push(redisKey);
                });
                const sId = sIdArray.toString();
                onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
              }
            }

            return;
          }
          //
          onGetDataOk(masterConfig, slaveConfig, checkConfig);
          onSaveStateOk({ enabled: false });
          if (commonUtils.isNotEmptyObject(copyTo)) {
            const { slaveData } = copyTo;
            const sIdArray = [];
            slaveData.forEach((item) => {
              const redisKey = item.sSlaveId;
              sIdArray.push(redisKey);
            });
            const sId = sIdArray.toString();
            onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
          }
          onSendSocketMessage('release', 'noAction', currentId, userinfo.sId, null, null);
        },
        onCancel() {
        },
      });
    };

    /* 删除 */
    handleDel = (obj) => {
      const props = { ...this.props, ...this.state };
      const onOkDel = this.handleOkDel;
      confirm({
        title: obj.title,
        onOk() {
          onOkDel(props);
        },
        onCancel() {
        },
      });
    };

    /* 确定要删除 */
    handleOkDel = async (props) => {
      /*   数据参数   */
      const {
        token, sModelsId, sModelsType, masterConfig, masterData, slaveConfig, checkConfig, orderDetailConfig, slaveChildConfig, app,
      } = props;
      const { userinfo, systemData } = app;
      const { sMakePerson } = masterData; /* 本单据制单人 */
      const { sUserName, sType } = userinfo;/* 登录用户 */
      const iIndex = systemData.findIndex(item => item.sName === 'CkxModifyBillNoMakePerson');
      if (iIndex > -1) {
        const sValue = systemData[iIndex].sValue;
        if (sValue === '0') { /* 系统未启用非制单人修改单据，普通用户非制单人不可以修改制单人的单据 */
          if (sType !== 'sysadmin' && sUserName !== sMakePerson) {
            message.error(commonFunc.showMessage(app.commonConst, 'NoDelByNoMakePerson'));
            return;
          }
        }
      }
      const value = {
        sClientType: '1',
        data: {
          sMasterTable: masterConfig.sTbName,
          sId: [masterData.sId],
        },
      };
      const sSlaveTable = [];
      if (commonUtils.isNotEmptyObject(slaveConfig)) {
        sSlaveTable.push({
          tableName: slaveConfig.sTbName,
          relationName: 'sParentId',
        });
      }
      if (commonUtils.isNotEmptyObject(checkConfig)) {
        sSlaveTable.push({
          tableName: checkConfig.sTbName,
          relationName: 'sParentId',
        });
      }
      if (sModelsType === 'purchase/purchaseOrder') {
        sSlaveTable.push({
          tableName: orderDetailConfig.sTbName,
          relationName: 'sParentId',
        });
      }
      if (sModelsType === 'sales/salesSgoods' && !commonUtils.isEmpty(slaveChildConfig)) {
        sSlaveTable.push({
          tableName: slaveChildConfig.sTbName,
          relationName: 'sParentId',
        });
      }
      value.sSlaveTable = sSlaveTable;
      const { sBillNo, sId } = masterData || {};
      const url = `${commonConfig.server_host}business/delMasSlaBusinessData?sModelsId=${sModelsId}&sBillNo=${sBillNo}&sSysLogSrcId=${sId}`;
      /*   接收返回值   */
      const { data } = await commonServices.postValueService(token, value, url);
      if (data.code === 1) {
        /*   数据删除成功   */
        if (this.props.app.currentPane.refresh !== undefined) {
          this.props.app.currentPane.refresh();
        }
        this.handleDelDataSuccess(props);
      } else { /*   失败   */
        this.props.getServiceError(data);
      }
    };

    /* 数据删除成功跳转到新路由即pane */
    handleDelDataSuccess = (props) => {
      const { app } = props;
      let { panes, currentPane } = app;
      /* 删除单据后退出当前路由后,标签panes变化后的集合 */
      panes = panes.filter(pane => pane.key !== currentPane.key);
      /* 跳转到panes集合的最后一个路由，因为panes集合一定含有主页路由所以panes的集合大于等于1 */
      currentPane = panes[panes.length - 1];
      this.props.onRemovePane(panes, currentPane);
    };

    /**   添加表格空行   */
    handleTableAdd = (name, isWait) => {
      /*   从CommonBase获取默认参数   */
      const {
        masterData, masterConfig, sModelsType, app, [`${name}Pagination`]: tablePagination,
      } = this.props;
      let { [`${name}Data`]: tableData } = this.props;
      tableData = commonUtils.isEmptyObject(tableData) ? [] : tableData;
      const tableDataRow = this.props.onDataRowAdd(name, true);
      /*   添加行的业务处理拿出去   */
      if (sModelsType.includes('sales/')) {
        if (commonUtils.isEmptyStr(masterData.sCustomerId)) {
          const iIndex = masterConfig.gdsconfigformslave.findIndex(item => ((item.sName === 'sCustomerId' || item.sName === 'sCustomerNo' || item.sName === 'sCustomerName') && item.bVisible));
          if (iIndex > -1) {
            const { showName } = masterConfig.gdsconfigformslave[iIndex];
            message.warn(showName + commonFunc.showMessage(app.commonConst, 'isNotNull')); // 不能为空
            return;
          }
        }
      }
      tableDataRow.sWareHouseId = masterData.sWareHouseId;
      tableDataRow.sWareHouseNo = masterData.sWareHouseNo;
      tableDataRow.sWareHouseName = masterData.sWareHouseName;
      tableDataRow.sLocationId = masterData.sLocationId;
      tableDataRow.sLocationNo = masterData.sLocationNo;
      tableDataRow.sLocationName = masterData.sLocationName;
      tableDataRow.sWareHouseLocationId = masterData.sWareHouseLocationId;
      tableDataRow.sWareHouseLocationNo = masterData.sWareHouseLocationNo;
      tableDataRow.sWareHouseLocationName = masterData.sWareHouseLocationName;
      if (isWait) {
        return tableDataRow;
      } else if (commonUtils.isNotEmptyObject(tableDataRow)) {
        tableData.push(tableDataRow);
        this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 }, [`${name}SelectedRowKeys`]: [tableDataRow.sId] });
      }
    };

    /**   复制   */
    handleTableCopy = (name, isWait, isTree) => {
      const {
        [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys, [`${name}Pagination`]: tablePagination, sModelsType,
      } = this.props;
      if (commonUtils.isEmptyArr(tableSelectedRowKeys)) {
        message.warn(commonFunc.showMessage(this.props.app.commonConst, 'pleaseChooseCopyData'));/* 请选择复制数据 */
      } else {
        if (sModelsType === 'sales/salesOrderPack' && isTree) { /* 树形 */
          const {
            [`${name}SelectedRowKeys`]: treeSelectedKeys,
          } = this.props;
          const controlChildData = tableData.filter(item => item.sAllId.indexOf(treeSelectedKeys[0]) > -1 && item.sId !== treeSelectedKeys[0]);
          if (commonUtils.isNotEmptyArr(tableData)) {
            controlChildData.forEach((itemNew) => {
              tableSelectedRowKeys.push(itemNew.sId);
            });
          }
        }
        const treeCopyNodes = new Map();
        for (const sId of tableSelectedRowKeys) {
          const tableDataIndex = tableData.findIndex(item => item.sId === sId);
          if (tableDataIndex > -1) {
            const tableDataRow = JSON.parse(JSON.stringify(tableData[tableDataIndex]));
            tableDataRow.sId = commonUtils.createSid();
            tableDataRow.handleType = 'add';
            tableDataRow.key = tableDataRow.sId;
            tableDataRow.sSrcSlaveId = '';
            tableDataRow.sSrcId = '';
            tableDataRow.dSrcQty = null;
            tableDataRow.rowTag = null;
            tableDataRow.sOrderdetailUsed = '';
            tableDataRow.sProductionUsed = '';
            tableDataRow.sWorkOrderUsed = '';
            tableDataRow.dWorkOrderQty = 0;
            const iOrderArr = [];
            tableData.forEach((item) => {
              const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
              iOrderArr.push(iOrder);
            });
            const iOrderMax = Math.max(...iOrderArr);
            tableDataRow.iOrder = commonUtils.isNotEmptyArr(tableData) ? iOrderMax + 1 : 0;

            if (commonUtils.isNotEmptyObject(tableDataRow.sMaterialsMemo)) {
              tableDataRow.sMaterialsMemo = '';
            }
            if (commonUtils.isNotEmptyObject(tableDataRow.sProcessMemo)) {
              tableDataRow.sProcessMemo = '';
            }
            if (sModelsType === 'sales/salesOrderPack' && isTree) { /* 树形 */
              const sAllOldId = tableData[tableDataIndex].sAllId;
              const arr = sAllOldId.split(',');
              const newId = commonUtils.createSid();
              tableDataRow.sId = newId;
              let sOldParentId = '';
              let sNewParentAllId = '';
              if (arr.length < 2) { /* 根节点复制 */
                tableDataRow.sAllId = newId;
                sOldParentId = newId;
                sNewParentAllId = newId;
              } else {
                sOldParentId = arr[arr.length - 2];
                if (treeCopyNodes.has(sOldParentId)) {
                  sNewParentAllId = treeCopyNodes.get(sOldParentId);
                } else {
                  const obj = arr[arr.length - 1];
                  sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
                }
                const sNewArr = sNewParentAllId.split(',');
                tableDataRow.sControlParentId = sNewArr[sNewArr.length - 1];
                sNewParentAllId = `${sNewParentAllId},${newId}`;
                tableDataRow.sAllId = sNewParentAllId;
              }
              treeCopyNodes.set(sId, sNewParentAllId);
            }
            if (isWait) {
              return tableDataRow;
            } else if (commonUtils.isNotEmptyObject(tableDataRow)) {
              tableData.push(tableDataRow);
              let treeState = [];
              if (sModelsType === 'sales/salesOrderPack') {
                treeState = this.handleGetControlTreeData(tableData, true);
              }
              this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 }, ...treeState });
            }
          }
        }
      }
    };


    /**   复制全部   */
    handleTableCopyAll = (name, isWait, isTree) => {
      const {
        slaveData, controlData, slaveSelectedRowKeys, materialsData, [`${name}Pagination`]: tablePagination, sModelsType,
      } = this.props;
      let { processData } = this.props;
      if (name === 'slave') {
        if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
          message.warn(commonFunc.showMessage(this.props.app.commonConst, 'pleaseChooseCopyData'));/* 请选择复制数据 */
        } else {
          for (const sId of slaveSelectedRowKeys) {
            const slaveDataIndex = slaveData.findIndex(item => item.sId === sId);
            if (slaveDataIndex > -1) {
              const slaveDataRow = JSON.parse(JSON.stringify(slaveData[slaveDataIndex]));
              slaveDataRow.sId = commonUtils.createSid();
              slaveDataRow.handleType = 'add';
              slaveDataRow.key = slaveDataRow.sId;
              const iOrderArr = [];
              slaveData.forEach((item) => {
                const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
                iOrderArr.push(iOrder);
              });
              const iOrderMax = Math.max(...iOrderArr);
              slaveDataRow.iOrder = commonUtils.isNotEmptyArr(slaveData) ? iOrderMax + 1 : 0;
              slaveData.push(slaveDataRow);
              if (sModelsType !== 'sales/salesOrderPack') {
                if (commonUtils.isNotEmptyArr(controlData)) {
                  controlData.filter(itemControl => itemControl.sSlaveId === sId).forEach((itemControl) => {
                    const tableDataRow = JSON.parse(JSON.stringify(itemControl));
                    tableDataRow.sId = commonUtils.createSid();
                    tableDataRow.handleType = 'add';
                    tableDataRow.key = tableDataRow.sId;
                    tableDataRow.sSlaveId = slaveDataRow.sId;
                    controlData.push(tableDataRow);
                    /* 部件表复制其材料表、工序表 */
                    materialsData.filter(item => item.sControlId === itemControl.sId && item.sType !== '2').forEach((item) => {
                      const materialsRow = JSON.parse(JSON.stringify(item));
                      materialsRow.sId = commonUtils.createSid();
                      materialsRow.handleType = 'add';
                      materialsRow.sControlId = tableDataRow.sId;
                      materialsRow.sPartsName = tableDataRow.sPartsName;
                      materialsRow.sSlaveId = tableDataRow.sSlaveId;
                      materialsData.push(materialsRow);
                    });
                    processData.filter(item => item.sControlId === itemControl.sId && item.sType !== '3').forEach((item) => {
                      const processRow = JSON.parse(JSON.stringify(item));
                      processRow.sId = commonUtils.createSid();
                      processRow.handleType = 'add';
                      processRow.sControlId = tableDataRow.sId;
                      processRow.sPartsName = tableDataRow.sPartsName;
                      processRow.sSlaveId = tableDataRow.sSlaveId;
                      processData.push(processRow);
                    });
                    processData = this.sortData(controlData, processData);
                  });
                }
                if (commonUtils.isNotEmptyArr(materialsData)) { /* 订单从表复制全部 复制成品材料 */
                  materialsData.filter(item => item.sSlaveId === sId && item.sType === '2').forEach((materialsItem) => {
                    const materialsRow = JSON.parse(JSON.stringify(materialsItem));
                    materialsRow.handleType = 'add';
                    materialsRow.sId = commonUtils.createSid();
                    materialsRow.sSlaveId = slaveDataRow.sId;
                    materialsData.push(materialsRow);
                  });
                }

                if (commonUtils.isNotEmptyArr(processData)) { /* 订单从表复制全部 复制成品工序 */
                  processData.filter(item => item.sSlaveId === sId && item.sType === '3').forEach((processItem) => {
                    const processRow = JSON.parse(JSON.stringify(processItem));
                    processRow.handleType = 'add';
                    processRow.sId = commonUtils.createSid();
                    processRow.sSlaveId = slaveDataRow.sId;
                    processData.push(processRow);
                  });
                }
              }
            }
            this.props.onSaveState({
              slaveData,
              [`${name}Pagination`]: { ...tablePagination, total: slaveData.length, current: 9999 },
              controlData,
              materialsData,
              processData,
            });
          }
        }
      } else if (name === 'control') {
        const {
          [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys,
        } = this.props;
        if (commonUtils.isEmptyArr(tableSelectedRowKeys)) {
          message.warn(commonFunc.showMessage(this.props.app.commonConst, 'pleaseChooseCopyData'));/* 请选择复制数据 */
        } else {
          /* 获取复制节点下的所有子节点 */
          if (sModelsType === 'sales/salesOrderPack' && isTree) { /* 树形 */
            const {
              [`${name}SelectedRowKeys`]: treeSelectedKeys,
            } = this.props;
            const controlChildData = tableData.filter(item => item.sAllId.indexOf(treeSelectedKeys[0]) > -1 && item.sId !== treeSelectedKeys[0]);
            if (commonUtils.isNotEmptyArr(tableData)) {
              controlChildData.forEach((itemNew) => {
                tableSelectedRowKeys.push(itemNew.sId);
              });
            }
          }
          const treeCopyNodes = new Map();
          for (const sId of tableSelectedRowKeys) {
            const tableDataIndex = tableData.findIndex(item => item.sId === sId);
            if (tableDataIndex > -1) {
              const tableDataRow = JSON.parse(JSON.stringify(tableData[tableDataIndex]));
              tableDataRow.sId = commonUtils.createSid();
              tableDataRow.handleType = 'add';
              tableDataRow.key = tableDataRow.sId;
              const iOrderArr = [];
              tableData.forEach((item) => {
                const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
                iOrderArr.push(iOrder);
              });
              const iOrderMax = Math.max(...iOrderArr);
              tableDataRow.iOrder = commonUtils.isNotEmptyArr(tableData) ? iOrderMax + 1 : 0;
              if (sModelsType === 'sales/salesOrderPack' && isTree) { /* 树形 */
                const sAllOldId = tableData[tableDataIndex].sAllId;
                const arr = sAllOldId.split(',');
                const newId = commonUtils.createSid();
                tableDataRow.sId = newId;
                let sOldParentId = '';
                let sNewParentAllId = '';
                if (arr.length < 2) { /* 根节点复制 */
                  tableDataRow.sAllId = newId;
                  sOldParentId = newId;
                  sNewParentAllId = newId;
                } else {
                  sOldParentId = arr[arr.length - 2];
                  if (treeCopyNodes.has(sOldParentId)) {
                    sNewParentAllId = treeCopyNodes.get(sOldParentId);
                  } else {
                    const obj = arr[arr.length - 1];
                    sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
                  }
                  const sNewArr = sNewParentAllId.split(',');
                  tableDataRow.sControlParentId = sNewArr[sNewArr.length - 1];
                  sNewParentAllId = `${sNewParentAllId},${newId}`;
                  tableDataRow.sAllId = sNewParentAllId;
                }
                treeCopyNodes.set(sId, sNewParentAllId);
              }
              if (isWait) {
                return tableDataRow;
              } else if (commonUtils.isNotEmptyObject(tableDataRow)) {
                tableData.push(tableDataRow);
                let treeState = [];
                if (sModelsType === 'sales/salesOrderPack') {
                  treeState = this.handleGetControlTreeData(tableData, true);
                }
                /* 部件表复制其材料表、工序表 */
                materialsData.filter(item => item.sControlId === sId && item.sType !== '2').forEach((item) => {
                  const materialsRow = JSON.parse(JSON.stringify(item));
                  materialsRow.sId = commonUtils.createSid();
                  materialsRow.handleType = 'add';
                  materialsRow.sControlId = tableDataRow.sId;
                  materialsRow.sPartsName = tableDataRow.sPartsName;
                  materialsData.push(materialsRow);
                });
                processData.filter(item => item.sControlId === sId && item.sType !== '3').forEach((item) => {
                  const processRow = JSON.parse(JSON.stringify(item));
                  processRow.sId = commonUtils.createSid();
                  processRow.handleType = 'add';
                  processRow.sControlId = tableDataRow.sId;
                  processRow.sPartsName = tableDataRow.sPartsName;
                  processData.push(processRow);
                });
                processData = this.sortData(tableData, processData);
                this.props.onSaveState({
                  [`${name}Data`]: tableData,
                  [`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 },
                  materialsData,
                  processData,
                  ...treeState,
                });
              }
            }
          }
        }
      }
    };

    singlePQtyChange = (tableDataRow) => {
      const bZfZf = tableDataRow.iPrintMode === 2; // 正反版
      const bSample = tableDataRow.dSumPQty >= 4; // 样本
      tableDataRow.iPrintModePo = tableDataRow.iPrintMode <= 2 ? 2 : tableDataRow.iPrintMode === 3 ? 0 : -1;

      if (bSample) {
        if (tableDataRow.dSinglePQty > 0) {
          tableDataRow.dPlateQty = Math.ceil(tableDataRow.dSumPQty / tableDataRow.dSinglePQty);
        }

        if (bZfZf && (tableDataRow.iPrintModePo === 2)) { // 双面样本，正反
          if (tableDataRow.dPlateQty < 2) { // 不管建议放正自翻版了，点方式什么是什么
            tableDataRow.dPlateQty = 2;
            tableDataRow.iStick = Math.ceil(commonUtils.isNull(tableDataRow.dPlateQty, 0) / 2);
            tableDataRow.dSumPlateQty = tableDataRow.iStick * (
              commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
              commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0) +
              commonUtils.isNull(tableDataRow.iOppositeColor, 0) +
              commonUtils.isNull(tableDataRow.iOppositeSpecialColor, 0));
          } else {
            if (tableDataRow.iPrintModePo !== 2) { // 单面样本
              tableDataRow.dPlateQty = (commonUtils.isNull(tableDataRow.dSumPQty, 0) * 0.5) / tableDataRow.dSinglePQty;
              tableDataRow.iStick = Math.ceil(tableDataRow.dPlateQty);
              tableDataRow.dSumPlateQty = tableDataRow.iStick * (commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
                commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0));
            } else {
              tableDataRow.dPlateQty = commonUtils.isNull(tableDataRow.dSumPQty, 0) / commonUtils.isNull(commonUtils.nullIf(tableDataRow.dSinglePQty, 0), 1);
              tableDataRow.iStick = Math.ceil(tableDataRow.dPlateQty / 2);
            }
            tableDataRow.dSumPlateQty = tableDataRow.iStick * (
              commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
              commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0) +
              commonUtils.isNull(tableDataRow.iOppositeColor, 0) +
              commonUtils.isNull(tableDataRow.iOppositeSpecialColor, 0));
          }
        } else {
          if (tableDataRow.iPrintModePo !== 2) { // 单面样本
            tableDataRow.dPlateQty = (commonUtils.isNull(tableDataRow.dSumPQty, 0) * 0.5) / tableDataRow.dSinglePQty;
          } else {
            tableDataRow.dPlateQty = commonUtils.isNull(tableDataRow.dSumPQty, 0) / commonUtils.isNull(commonUtils.nullIf(tableDataRow.dSinglePQty, 0), 1);
          }
          tableDataRow.iStick = Math.ceil(tableDataRow.dPlateQty);
          tableDataRow.dSumPlateQty = tableDataRow.iStick * (
            commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
            commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0));
        }
        if (tableDataRow.iStick > 0 && tableDataRow.dSinglePQty > 0) {
          tableDataRow.dMachineQty = commonUtils.convertFixNum((commonUtils.isNull(tableDataRow.dPartsQty, 0) * commonUtils.isNull(tableDataRow.dSumPQty, 0) * 0.5) / tableDataRow.dSinglePQty / tableDataRow.iStick, 0);
          tableDataRow.dSumMachineQty = tableDataRow.dMachineQty * tableDataRow.iStick;
        }
      } else {
        tableDataRow.iStick = 1;
        tableDataRow.dSumPlateQty = tableDataRow.iStick * (
          commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
          commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0) +
          commonUtils.isNull(tableDataRow.iOppositeColor, 0) +
          commonUtils.isNull(tableDataRow.iOppositeSpecialColor, 0));
        if (bZfZf && tableDataRow.iPrintModePo === 2) {
          tableDataRow.dPlateQty = 2;
          tableDataRow.dSumPlateQty = tableDataRow.iStick * (commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
            commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0) + commonUtils.isNull(tableDataRow.iOppositeColor, 0) +
            commonUtils.isNull(tableDataRow.iOppositeSpecialColor, 0));
        } else {
          tableDataRow.dPlateQty = 1;
          tableDataRow.dSumPlateQty = tableDataRow.iStick * (commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
            commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0));
        }

        if (tableDataRow.dSinglePQty > 0) {
          if (tableDataRow.iPage > 1) { // 笔记本  用 非样本 来做， 倍率是每页都一样才可以用      原先 /2 是指页数， 现在直接按张数
            tableDataRow.dMachineQty = commonUtils.convertFixNum((tableDataRow.dPartsQty * tableDataRow.iPage) / tableDataRow.dSinglePQty, 0);
          } else {
            tableDataRow.dMachineQty = commonUtils.convertFixNum(commonUtils.isNull(tableDataRow.dPartsQty, 0) / tableDataRow.dSinglePQty, 0);
            tableDataRow.dSumMachineQty = tableDataRow.dMachineQty * tableDataRow.iStick;
          }
        }
      }
      return tableDataRow;
    };

    /** 表格数据更改 */
    // name 不写完整的state名称作用为了要用到total // (name, changeValue, sId, dropDownData)
    handleTableChange = async (name, sFieldName, changeValue, sId, dropDownData, isWait) => {
      /*   从CommonBase获取默认参数   */
      const {
        [`${name}Data`]: tableData, sModelsType, sModelsId, token, app, slaveConfig,
      } = this.props;
      if (name === 'control' && sModelsType.includes('sales/salesOrder')) {
        const { [`${name}Data`]: tableData, materialsData: materialsDataOld, processData: processDataOld } = this.props;
        let tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
        if (tableDataRow === undefined) return;
        if (sFieldName === 'dSinglePQty' || sFieldName === 'dSumPQty' || sFieldName === 'iPrintModePo' || sFieldName === 'iPrintMode' || sFieldName === 'iPrintModePo' || sFieldName === 'iPositiveColor' ||
          sFieldName === 'iPositiveSpecialColor' || sFieldName === 'iOppositeColor' || sFieldName === 'iOppositeSpecialColor') {
          if (sFieldName === 'iPrintModePo') {
            if (tableDataRow.iPrintModePo === 0) {
              tableDataRow.iPrintMode = 3;
              if (tableDataRow.iPositiveColor === 0) {
                tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
                tableDataRow.iOppositeColor = 0;
                tableDataRow.iOppositeSpecialColor = 0;
              } else {
                tableDataRow.iOppositeColor = 0;
                tableDataRow.iOppositeSpecialColor = 0;
              }
            } else if (tableDataRow.iPrintModePo === 1) {
              tableDataRow.iPrintMode = 3;
              if (tableDataRow.iPositiveColor === 0) {
                tableDataRow.iPositiveColor = 0;
                tableDataRow.iPositiveSpecialColor = 0;
                tableDataRow.iOppositeColor = tableDataRow.iOppositeColor === 0 ? 4 : tableDataRow.iOppositeColor;
              } else {
                tableDataRow.iPositiveColor = 0;
                tableDataRow.iPositiveSpecialColor = 0;
              }
            } else {
              tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
              tableDataRow.iOppositeColor = tableDataRow.iOppositeColor === 0 ? tableDataRow.iPositiveColor : tableDataRow.iOppositeColor;
            }
          } else if (sFieldName === 'iPrintMode') {
            if (tableDataRow.iPrintMode === 0 || tableDataRow.iPrintMode === 1) {
              tableDataRow.iPositiveColor = commonUtils.isEmpty(tableDataRow.iPositiveColor) || tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
              tableDataRow.iOppositeColor = tableDataRow.iPositiveColor;
              tableDataRow.iOppositeSpecialColor = tableDataRow.iPositiveSpecialColor;
            } else if (tableDataRow.iPrintMode === 2) {
              tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
              tableDataRow.iOppositeColor = tableDataRow.iOppositeColor === 0 ? tableDataRow.iPositiveColor : tableDataRow.iOppositeColor;
            } else if (tableDataRow.iPrintMode === 3) {
              tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
              tableDataRow.iOppositeColor = 0;
              tableDataRow.iOppositeSpecialColor = 0;
            } else if (tableDataRow.iPrintMode === 4) {
              tableDataRow.iPositiveColor = 0;
              tableDataRow.iPositiveSpecialColor = 0;
              tableDataRow.iOppositeColor = 0;
              tableDataRow.iOppositeSpecialColor = 0;
            }
          } else if (sFieldName === 'iPositiveColor' || sFieldName === 'iPositiveSpecialColor') {
            if (tableDataRow.iPrintMode === 0 || tableDataRow.iPrintMode === 1) {
              tableDataRow.iOppositeColor = tableDataRow.iPositiveColor;
              tableDataRow.iOppositeSpecialColor = tableDataRow.iPositiveSpecialColor;
            }
          }
          tableDataRow = this.singlePQtyChange(tableDataRow);
        }
        const materialsData = [];
        const processData = [];
        materialsDataOld.forEach((item) => {
          const itemNew = { ...item };
          if (itemNew.sControlId === sId) {
            itemNew.sPartsName = tableDataRow.sPartsName;
          }
          materialsData.push(itemNew);
        });
        processDataOld.forEach((item) => {
          const itemNew = { ...item };
          if (itemNew.sControlId === sId) {
            itemNew.sPartsName = tableDataRow.sPartsName;
          }
          processData.push(itemNew);
        });
        const materialsDataNew = this.sortData(tableData, materialsData);
        const processDataNew = this.sortData(tableData, processData);
        if (sModelsType === 'sales/salesOrderPack') {
          if (sFieldName === 'sPartsName') { /* 部件名称与子部件同步 */
            const { sPartsName } = tableDataRow;
            const { treeSelectedKeys, treeData } = this.props;
            if (commonUtils.isNotEmptyArr(treeSelectedKeys)) {
              this.handleSearchNodes(treeSelectedKeys[0], treeData, sPartsName);
            }
          } else if (sFieldName === 'dMachineQty') { /* 上机数量改变时,子级部件数量同步改变 */
            const { dMachineQty } = tableDataRow;
            /* 查找该节的所有子节点，将上机数量改为部件数量 */
            tableData.forEach((item, index) => {
              if (commonUtils.isNotEmptyObject(item.sAllId) && item.sAllId.indexOf(tableDataRow.sId) > -1 && item.sId !== tableDataRow.sId) {
                const addstate = {};
                addstate.dPartsQty = dMachineQty;
                tableData[index] = { ...tableData[index], ...addstate };
              }
            });
          }
        }
        const iIndex = tableData.findIndex(item => item.sId === sId);
        tableData[iIndex] = tableDataRow;
        this.props.onSaveState({
          [`${name}Data`]: tableData, materialsData: materialsDataNew, processData: processDataNew,
        });
      } else {
        let { masterData } = this.props;
        const iIndex = tableData.findIndex(item => item.sId === sId);
        // if (sFieldName.substring(0, 1) === 'd' && commonUtils.convertToNum(tableData[iIndex][sFieldName]) === commonUtils.convertToNum(changeValue[sFieldName])) {
        //   if (!(tableData[iIndex][sFieldName] === undefined && commonUtils.convertToNum(changeValue[sFieldName]) === 0)) return;
        // }
        if (sFieldName === 'sProductName' && name === 'slave' && (sModelsType.includes('sales/salesOrder') || sModelsType.includes('manufacture/workOrder') || sModelsType.includes('quotation/quotation'))) {
          if (commonUtils.isNotEmptyObject(changeValue) && Object.keys(changeValue).length === 1 && Object.keys(changeValue)[0] === sFieldName) {
            changeValue.sProductId = changeValue.sProductName;
          }
        }
        let tableDataRow = this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
        /*   添加备货数自动计算  */
        if ((sFieldName === 'dProductQty' || sFieldName === 'dGiveQty') && name === 'slave' && (sModelsType.includes('sales/salesOrderPack') || sModelsType.includes('sales/salesOrder'))) {
          if (commonUtils.isNotEmptyObject(changeValue) && Object.keys(changeValue).length === 1 && Object.keys(changeValue)[0] === sFieldName) {
            const dProductQty = commonUtils.isEmptyNumber(tableDataRow.dProductQty) ? 0 : tableDataRow.dProductQty;
            const dGiveQty = commonUtils.isEmptyNumber(tableDataRow.dGiveQty) ? 0 : tableDataRow.dGiveQty;
            const dStockupRate = commonUtils.isEmptyNumber(masterData.dStockupRate) ? 0 : masterData.dStockupRate;
            if (dStockupRate !== 0) { /* 备货率不为0时,按照备货率计算，否则按照手填的算 */
              tableDataRow.dStockupQty = Math.round((dProductQty + dGiveQty) * dStockupRate);
            }
          }
        }
        if ((sFieldName === 'sProductId' || sFieldName === 'sProductName' || sFieldName === 'sProductStyle' || sFieldName === 'sProductUnit' || sFieldName === 'sProductNo'
          || sFieldName === 'sCustomerProductNo' || sFieldName === 'sProductClassifyId' || sFieldName === 'sProductClassifyName') && !commonUtils.isEmpty(tableDataRow.sProductId)) {
          let productIdDropDown = [];
          if (sFieldName === 'sProductStyle') {
            const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductName');
            if (iIndex > -1) {
              if (this.inputSearch) {
                clearTimeout(this.inputSearch);
              }
              this.inputSearch = setTimeout(async () => {
                const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[iIndex], tableDataRow, tableDataRow.sProductName, 1);
                productIdDropDown = sqlDropDownData.dropDownData;
              }, 500);
            }
          } else {
            productIdDropDown = dropDownData;
          }
          const iProductIdIndex = commonUtils.isEmptyArr(productIdDropDown) ? -1 : productIdDropDown.findIndex(item => item.sId === tableDataRow.sProductId && item.sProductStyle === tableDataRow.sProductStyle);
          if (iProductIdIndex === -1 && !(commonUtils.isNotEmptyObject(sModelsType) && sModelsType.includes('sales/materials'))) {
            tableDataRow.sProductInfo = JSON.stringify({
              sProductId: tableDataRow.sProductName,
              sProductName: tableDataRow.sProductName,
              sProductStyle: tableDataRow.sProductStyle,
              sProductUnit: tableDataRow.sProductUnit,
              sProductNo: tableDataRow.sProductNo,
              sCustomerProductNo: tableDataRow.sCustomerProductNo,
              sProductClassifyId: tableDataRow.sProductClassifyId,
              sProductClassifyName: tableDataRow.sProductClassifyName,
            });
          } else {
            tableDataRow.sProductInfo = '';
          }
          tableDataRow.sMaterialsStyle = tableDataRow.sProductStyle;
          if ((sFieldName === 'sProductId' || sFieldName === 'sProductName' || sFieldName === 'sProductNo') && !commonUtils.isEmpty(changeValue.sProductId) && tableDataRow.sProductId !== tableDataRow.sProductName) {
            const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
            const { sCustomerId } = masterData; /* 增加客户id参数 */
            const value = {
              sProName: 'Sp_Cashier_GetProductPrice',
              paramsMap: {
                sProductGuid: changeValue.sProductId,
                sCustomerId,
              },
            };
            const returnData = (await commonServices.postValueService(app.token, value, url)).data;
            if (returnData.code === 1) {
              tableDataRow.dNProductPrice = returnData.dataset.rows[0].dataSet.outData[0].dPrice; /* 产品单价 */
              const dProofingMoney = commonUtils.convertToNum(tableDataRow.dProofingMoney); /* 打样金额 */
              const dPlateMoney = commonUtils.convertToNum(tableDataRow.dPlateMoney); /* 制版金额 */
              const dKnifeMouldMoney = commonUtils.convertToNum(tableDataRow.dKnifeMouldMoney); /* 刀模金额 */
              const dProductQty = commonUtils.convertToNum(tableDataRow.dProductQty); /* 数量 */
              const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
              const { dNetPrice } = app.decimals;
              if (dProductQty === 0 || (dProofingMoney === 0 && dPlateMoney === 0 && dKnifeMouldMoney === 0)) {
                const dProductForeignPrice = returnData.dataset.rows[0].dataSet.outData[0].dPrice;
                tableDataRow.dProductForeignPrice = dProductForeignPrice;
                tableDataRow.dProductPrice = commonUtils.convertFixNum(dProductForeignPrice * dCurrencyRate, dNetPrice);
              }
            }

            const models = name === 'materials' ? 'Materials' :
              sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
            if (sModelsType.includes('purchase/') || sModelsType.includes('quotation/') || sModelsType.includes('manufacture/') || sModelsType.includes('materialsStock/') || sModelsType.includes('outside/')) {
              tableDataRow = await this.handleMaterialsChange(tableDataRow, sModelsId, masterData, changeValue, 'dProductQty', app, token, models);
            }
            tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dProductQty', masterData, tableDataRow);
            // else {
            //   this.props.getServiceError(returnData);
            // }
          }
        } else if (sModelsType.includes('sales/salesOrder') && (sFieldName === 'sProductClassifyId' || sFieldName === 'sProductClassifyName') && name === 'slave') {
          const { controlData } = this.props;
          if (controlData !== undefined && !commonUtils.isEmpty(tableData.sProductInfo)) {
            const controlDataFilter = controlData.filter(item => item.sSlaveId === tableData[iIndex].sId);
            const tableSelectedRowKeys = [];
            controlDataFilter.forEach((item) => {
              tableSelectedRowKeys.push(item.sId);
            });
            const materialsReturnData = this.otherTableDel('materials', tableSelectedRowKeys);
            const processReturnData = this.otherTableDel('process', tableSelectedRowKeys);
            const controlReturnData = this.props.onDataRowDel('control', true, tableSelectedRowKeys);
            this.props.onSaveState({
              ...materialsReturnData,
              ...processReturnData,
              ...controlReturnData,
            });
          }
        } else if ((sModelsType.includes('cashier/') || sModelsType.includes('sales/salesInvoice') || sModelsType.includes('purchase/purchaseInvoice') || sModelsType.includes('purchase/outsideInvoice')) && (sFieldName === 'dTotalMoney' || sFieldName === 'dRoundingMoney')) { /* 付款单、收款单，从表付款/收款金额改变，会自动汇总到主表付款金额中 */
          const addStata = {};
          let { handleType } = masterData;
          handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
          addStata.handleType = handleType;
          const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
          const { dNetMoney } = app.decimals;
          if (sFieldName === 'dTotalMoney') {
            addStata.dTotalMoney = 0;
            if (iIndex > -1) { /* 选中行 */
              let dMoney = commonUtils.isNotEmptyNumber(tableDataRow.dTotalMoney) ? tableDataRow.dTotalMoney : 0;
              dMoney = commonUtils.convertStrToNumber(dMoney);
              addStata.dTotalMoney = dMoney + commonUtils.convertStrToNumber(addStata.dTotalMoney);
              tableDataRow.dTotalForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? dMoney / dCurrencyRate : 0, dNetMoney);
            }
            // if (commonUtils.isNotEmptyNumber(tableDataRow.dBalanceMoney) && (tableDataRow.dTotalMoney > tableDataRow.dBalanceMoney)) { // 发外发票，采购发票，销售发票 付款单、收款单总金额不能大于余额
            //   const dTotalMoneyName = slaveConfig.gdsconfigformslave.filter(item => item.sName === sFieldName)[0].showName;
            //   const dBalanceMoneyName = slaveConfig.gdsconfigformslave.filter(item => item.sName === 'dBalanceMoney')[0].showName;
            //   message.error(`${dTotalMoneyName}不能大于${dBalanceMoneyName}!`);
            //   tableDataRow = { ...tableDataRow, dTotalMoney: tableDataRow.dBalanceMoney };
            //   // tableDataRow.dTotalMoney = commonUtils.convertStrToNumber(masterData.dTotalMoney);
            //   addStata.dTotalMoney = commonUtils.convertStrToNumber(masterData.dTotalMoney);
            // }
            tableData.forEach((item, index) => { /* 非选中行 */
              if (index !== iIndex) {
                const dMoney = commonUtils.isNotEmptyNumber(item.dTotalMoney) ? item.dTotalMoney : 0;
                addStata.dTotalMoney = commonUtils.convertFixNum(dMoney, 6) + commonUtils.convertFixNum(addStata.dTotalMoney, 6);
              }
            });
            /* 计算外币金额 */
            if (commonUtils.isNotEmptyNumber(addStata.dTotalMoney)) {
              addStata.dProductForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? addStata.dTotalMoney / dCurrencyRate : 0, dNetMoney);
            }
          } else if (sFieldName === 'dRoundingMoney') {
            addStata.dRoundingMoney = 0;
            if (iIndex > -1) { /* 选中行 */
              let dMoney = commonUtils.isNotEmptyNumber(tableDataRow.dRoundingMoney) ? tableDataRow.dRoundingMoney : 0;
              dMoney = commonUtils.convertStrToNumber(dMoney);
              addStata.dRoundingMoney = dMoney + commonUtils.convertStrToNumber(addStata.dRoundingMoney);
            }
            tableData.forEach((item, index) => { /* 非选中行 */
              if (index !== iIndex) {
                const dMoney = commonUtils.isNotEmptyNumber(item.dRoundingMoney) ? item.dRoundingMoney : 0;
                addStata.dRoundingMoney = commonUtils.convertFixNum(dMoney, 6) + commonUtils.convertFixNum(addStata.dRoundingMoney, 6);
              }
            });
          }
          masterData = { ...masterData, ...addStata };
          this.props.onSaveState({ masterData });
        } else if (sModelsType === 'purchase/purchaseOrder' && sFieldName === 'dProcurementCycle') {
          /* 交货周期改变时,交货时间等于制单时间 +交货周期 */
          const dProcurementCycle = commonUtils.isNull(tableDataRow.dProcurementCycle, 0);
          const tCreateDate = commonUtils.isNotEmptyObject(tableDataRow.tCreateDate) ? tableDataRow.tCreateDate : new Date();
          const tDeliverDate = moment(tCreateDate).add(dProcurementCycle, 'days').format(commonUtils.dateFormatA);
          tableDataRow.tDeliverDate = tDeliverDate;
        }
        // 取工艺卡数据
        if (sModelsType.includes('sales/salesOrder') && (sFieldName === 'sProductId' || sFieldName === 'sProductNo' || sFieldName === 'sProductName') && name === 'slave') {
          const {
            controlConfig, materialsConfig, processConfig,
          } = this.props;
          let { controlData, materialsData, processData } = this.props;
          const sId = tableData[iIndex].sId;
          const bCkxCopyFromTechnology = '1'; // app.systemData.filter(item => item.sName === 'CkxCopyFromTechnology')[0].sValue;
          if (bCkxCopyFromTechnology === '1' && tableDataRow.sProductId !== tableDataRow.sProductName) {
            const controlSelectedData = controlData.filter(item => item.sSlaveId === sId);
            if (commonUtils.isNotEmptyObject(controlSelectedData)) {
              const controlSelectedRowKeys = [];
              controlSelectedData.forEach((item) => {
                controlSelectedRowKeys.push(item.sId);
              });
              const materialsReturnData = this.otherTableDel('materials', controlSelectedRowKeys);
              const processReturnData = this.otherTableDel('process', controlSelectedRowKeys);
              const controlReturnData = this.props.onDataRowDel('control', true, controlSelectedRowKeys);
              controlData = controlReturnData.controlData;
              materialsData = materialsReturnData.materialsData;
              processData = processReturnData.processData;
              this.props.onSaveState({
                ...materialsReturnData,
                ...processReturnData,
                ...controlReturnData,
              });
            }
            const sCustomerId = masterData.sCustomerId;
            const sProductId = changeValue.sProductId;
            const sProductIdArray = [];
            sProductIdArray.push(sProductId);
            const sProductIds = sProductIdArray.toString();
            const condition = { sCustomerId, sProductIds };
            const dataUrl = `${commonConfig.server_host}salesorder/getProcessCardDataByCustomIdProductId/?sModelsId=${sModelsId}`;
            const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
            const config = this.props.masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes('BtnCopyFrom.ActProcessCard'));
            if (dataReturn.code === 1) {
              const returnData = dataReturn.dataset.rows[0];
              const copyToControlConfig = config.filter(item => item.sControlName.toLowerCase() === 'BtnCopyFrom.ActProcessCard.Control'.toLowerCase());
              const copyToMaterialsConfig = config.filter(item => item.sControlName.toLowerCase() === 'BtnCopyFrom.ActProcessCard.Materials'.toLowerCase());
              const copyToProcessConfig = config.filter(item => item.sControlName.toLowerCase() === 'BtnCopyFrom.ActProcessCard.Process'.toLowerCase());
              const controlAssignField = commonUtils.isNotEmptyArr(copyToControlConfig) ? copyToControlConfig[0].sAssignField : '';
              const materialsAssignField = commonUtils.isNotEmptyArr(copyToMaterialsConfig) ? copyToMaterialsConfig[0].sAssignField : '';
              const processAssignField = commonUtils.isNotEmptyArr(copyToProcessConfig) ? copyToProcessConfig[0].sAssignField : '';
              const newCopyTo = {};
              newCopyTo.master = masterData;
              newCopyTo.slave = commonUtils.isEmptyArr(tableData) ? {} : tableData;
              if (commonUtils.isNotEmptyArr(returnData.controlData)) {
                const treeCopyNodes = new Map();
                // eslint-disable-next-line no-loop-func
                returnData.controlData.forEach((controlItem) => {
                  newCopyTo.control = controlItem;
                  let controlRow = commonFunc.getDefaultData(controlConfig, newCopyTo); // 取默认值
                  controlRow = { ...controlRow, ...commonFunc.getAssignFieldValue(controlAssignField, controlItem, newCopyTo) }; // 取赋值字段
                  controlRow.handleType = 'add';
                  controlRow.sId = commonUtils.createSid();
                  controlRow.sSlaveId = tableDataRow.sId;
                  controlRow.sParentId = masterData.sId;
                  if (sModelsType === 'sales/salesOrderPack') { /* 树形 */
                    /* CopyTo时sAllId,sControlParentId 设置 */
                    const sAllOldId = controlItem.sAllId;
                    let arr = [];
                    if (commonUtils.isNotEmptyObject(sAllOldId)) {
                      arr = sAllOldId.split(',');
                    }
                    const newId = controlRow.sId;
                    let sOldParentId = '';
                    let sNewParentAllId = '';
                    if (arr.length < 2) { /* 根节点复制 */
                      controlRow.sAllId = newId;
                      sOldParentId = newId;
                      sNewParentAllId = newId;
                    } else {
                      sOldParentId = arr[arr.length - 2];
                      if (treeCopyNodes.has(sOldParentId)) {
                        sNewParentAllId = treeCopyNodes.get(sOldParentId);
                      } else {
                        const obj = arr[arr.length - 1];
                        sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
                      }
                      const sNewArr = sNewParentAllId.split(',');
                      controlRow.sControlParentId = sNewArr[sNewArr.length - 1];
                      sNewParentAllId = `${sNewParentAllId},${newId}`;
                      controlRow.sAllId = sNewParentAllId;
                    }
                    treeCopyNodes.set(controlItem.sId, sNewParentAllId);
                  }
                  controlData.push(controlRow);

                  if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
                    returnData.materialsData.filter(item => item.sControlId === controlItem.sId).forEach((materialsItem) => {
                      newCopyTo.materials = materialsItem;
                      let materialsRow = commonFunc.getDefaultData(materialsConfig, newCopyTo); // 取默认值
                      materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
                      materialsRow.handleType = 'add';
                      materialsRow.sId = commonUtils.createSid();
                      materialsRow.sSlaveId = tableDataRow.sId;
                      materialsRow.sParentId = masterData.sId;
                      materialsRow.sControlId = controlRow.sId;
                      materialsRow.sPartsName = controlRow.sPartsName;

                      materialsData.push(materialsRow);
                    });
                  }

                  if (commonUtils.isNotEmptyArr(returnData.processData)) {
                    returnData.processData.filter(item => item.sControlId === controlItem.sId).forEach((processItem) => {
                      newCopyTo.process = processItem;
                      let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
                      processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                      processRow.handleType = 'add';
                      processRow.sId = commonUtils.createSid();
                      processRow.sSlaveId = tableDataRow.sId;
                      processRow.sParentId = masterData.sId;
                      processRow.sControlId = controlRow.sId;
                      processRow.sPartsName = controlRow.sPartsName;
                      processData.push(processRow);
                    });
                  }
                });
              }
              if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
                // eslint-disable-next-line no-loop-func
                returnData.materialsData.filter(item => item.sType === '2').forEach((materialsItem) => {
                  newCopyTo.materials = materialsItem;
                  let materialsRow = commonFunc.getDefaultData(materialsConfig, newCopyTo); // 取默认值
                  materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
                  materialsRow.handleType = 'add';
                  materialsRow.sId = commonUtils.createSid();
                  materialsRow.sSlaveId = tableDataRow.sId;
                  materialsRow.sParentId = masterData.sId;
                  materialsData.push(materialsRow);
                });
              }
              if (commonUtils.isNotEmptyArr(returnData.processData)) {
                // eslint-disable-next-line no-loop-func
                returnData.processData.filter(item => item.sType === '3').forEach((processItem) => {
                  newCopyTo.process = processItem;
                  let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
                  processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                  processRow.handleType = 'add';
                  processRow.sId = commonUtils.createSid();
                  processRow.sSlaveId = tableDataRow.sId;
                  processRow.sParentId = masterData.sId;
                  processData.push(processRow);
                });
              }
              /* 包装订单 生成树形 */
              let treeState = {};
              if (sModelsType === 'sales/salesOrderPack') {
                treeState = this.handleGetControlTreeData(controlData, true);
              }
              this.props.onSaveState({
                controlData, materialsData, processData, ...treeState,
              });
            }
          }
        } else if (sModelsType.includes('sales/salesOrder') && (sFieldName === 'dProductQty' || sFieldName === 'dGiveQty' || sFieldName === 'dStockupQty') && name === 'slave') {
          const {
            controlData, slaveSelectedRowKeys,
          } = this.props;
          const controlSelectedData = controlData.filter(item => item.sSlaveId === slaveSelectedRowKeys[0]);
          for (const one of controlSelectedData) {
            one.handleType = commonUtils.isEmpty(one.handleType) ? 'update' : one.handleType;
            one.dPartsQty = commonUtils.isNull(tableDataRow.dProductQty, 0) + commonUtils.isNull(tableDataRow.dGiveQty, 0) + commonUtils.isNull(tableDataRow.dStockupQty, 0);
          }
          this.props.onSaveState({ controlData });
        } else if (sModelsType.includes('purchase/') && (sFieldName === 'sMaterialsId' || sFieldName === 'sMaterialsNo' || sFieldName === 'sMaterialsName') && name === 'slave') {
          const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
          const value = {
            sProName: 'Sp_Cashier_GetMaterialsPrice',
            paramsMap: {
              sMaterialsGuid: changeValue.sMaterialsId,
              sSupplyGuid: masterData.sSupplyId,
            },
          };
          const returnData = (await commonServices.postValueService(app.token, value, url)).data;
          if (returnData.code === 1) {
            tableDataRow.dMaterialsPrice = returnData.dataset.rows[0].dataSet.outData[0].dPrice;
          }
          const models = name === 'materials' ? 'Materials' :
            sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
          if (sModelsType.includes('purchase/') || sModelsType.includes('quotation/') || sModelsType.includes('manufacture/') || sModelsType.includes('materialsStock/') || sModelsType.includes('outside/')) {
            tableDataRow = await this.handleMaterialsChange(tableDataRow, sModelsId, masterData, changeValue, 'dAuxiliaryQty', app, token, models);
          }
          tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dAuxiliaryQty', masterData, tableDataRow);

          if (Object.keys(changeValue).length > 0 && Object.keys(changeValue).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
            const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
            const valueMaterialsStock = {
              sProName: 'Sp_Inventory_MaterialsInventoryV56',
              paramsMap: {
                sMaterialsGuid: tableDataRow.sMaterialsId,
                sMaterialsStyle: tableDataRow.sMaterialsStyle,
                sWarehouseGuid: tableDataRow.sWarehouseId,
                sLocationalGuid: tableDataRow.sLocationId,
                sWarehouseLocationGuid: tableDataRow.sWarehouseLocationId,
                sDefine_no: tableDataRow.sDefineNo,
                sDefine_no2: tableDataRow.sDefineNo2,
                iGetQty: 1,
                iHasZero: 1,
              },
            };
            const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
            if (returnDataMaterialsStock.code === 1) {
              tableDataRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
            }
          }
          if (Object.keys(changeValue).length > 0 && Object.keys(changeValue).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
            const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
            const valueMaterialsAvailableQty = {
              sProName: 'Sp_Inventory_MaterialsInventoryV56',
              paramsMap: {
                sMaterialsGuid: tableDataRow.sMaterialsId,
                sMaterialsStyle: tableDataRow.sMaterialsStyle,
                sWarehouseGuid: tableDataRow.sWarehouseId,
                sLocationalGuid: tableDataRow.sLocationId,
                sWarehouseLocationGuid: tableDataRow.sWarehouseLocationId,
                sDefine_no: tableDataRow.sDefineNo,
                sDefine_no2: tableDataRow.sDefineNo2,
                iGetQty: 2,
                iHasZero: 1,
              },
            };
            const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
            if (returnDataMaterialsAvailableQty.code === 1) {
              tableDataRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
            }
          }
          /* 选择材料后 交货周期改变 则交货时间等于制单时间+交货周期 */
          const dProcurementCycle = commonUtils.isNull(tableDataRow.dProcurementCycle, 0);
          const tCreateDate = commonUtils.isNotEmptyObject(tableDataRow.tCreateDate) ? tableDataRow.tCreateDate : new Date();
          const tDeliverDate = moment(tCreateDate).add(dProcurementCycle, 'days').format(commonUtils.dateFormatA);
          tableDataRow.tDeliverDate = tDeliverDate;
          // else {
          //   this.props.getServiceError(returnData);
          // }
        } else if (sModelsType === 'sales/salesCheck' && sFieldName === 'dLossMoney' && name === 'slave') {
          const dPmoney = this.props.getFloatNum('dProductMoney');
          const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
          if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcNoCheckMoney) && commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney)) {
            const dProductForeignMoney = commonUtils.convertFixNum(tableDataRow.dSrcNoCheckMoney - tableDataRow.dLossMoney, dPmoney);
            const dProductMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? dProductForeignMoney * dCurrencyRate : 0, dPmoney); /* 本位币金额 */
            tableDataRow.dProductForeignMoney = dProductForeignMoney;
            tableDataRow.dProductMoney = dProductMoney;
          } else if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcNoCheckMoney) && commonUtils.isEmptyNumber(tableDataRow.dLossMoney)) {
            const dProductForeignMoney = commonUtils.isNull(tableDataRow.dSrcNoCheckMoney, 0);
            const dProductMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? dProductForeignMoney * dCurrencyRate : 0, dPmoney); /* 本位币金额 */
            tableDataRow.dProductForeignMoney = dProductForeignMoney;
            tableDataRow.dProductMoney = dProductMoney;
            tableDataRow.dLossMoney = 0;
          }
        } else if (sModelsType === 'purchase/purchasecheck' && sFieldName === 'dLossMoney' && name === 'slave') {
          const dPmoney = this.props.getFloatNum('dProductMoney');
          if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcNoCheckMoney) && commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney)) {
            const dMoney = commonUtils.convertFixNum(tableDataRow.dSrcNoCheckMoney - tableDataRow.dLossMoney, dPmoney);
            tableDataRow.dMaterialsMoney = dMoney;
          } else if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcNoCheckMoney) && commonUtils.isEmptyNumber(tableDataRow.dLossMoney)) {
            tableDataRow.dMaterialsMoney = commonUtils.isNull(tableDataRow.dSrcNoCheckMoney, 0);
            tableDataRow.dLossMoney = 0;
          }
        } else if (sModelsType === 'cost/cosexpenseshare') { /* 改变费用分摊单据从表成本中心金额，总金额随之改变 */
          if (sFieldName.indexOf('dCostCenter') > -1) {
            const { slaveColumn, app } = this.props;
            const { dNetMoney } = app.decimals;
            let dAllMoney = 0;
            slaveColumn.forEach((item) => {
              const sName = item.dataIndex;
              if (sName.indexOf('dCostCenter') > -1) {
                dAllMoney += commonUtils.isNotEmptyNumber(tableDataRow[sName]) ? commonUtils.convertFixNum(tableDataRow[sName], dNetMoney) : 0;
              }
            });
            tableDataRow.dShareMoney = commonUtils.convertFixNum(dAllMoney, dNetMoney);
          }
        } else if (sModelsType === 'purchase/purchaseInstore' && name === 'slave') { /* 采购入库  材料批次=材料生产日期tSReserve1(此客户手输)+当前日期 */
          if (sFieldName === 'tProductionDate') {
            tableDataRow.sDefineNo = moment(tableDataRow.tProductionDate).format('YYYYMMDDHHmm') + moment(new Date()).format('YYYYMMDDHHmm');
          }
        }
        /* 各种金额，税额，价格计算 */
        let models = name === 'materials' ? 'Materials' :
          sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
        if (sModelsType.includes('purchase/') || sModelsType.includes('quotation/') || sModelsType.includes('manufacture/') || sModelsType.includes('materialsStock/')
          || sModelsType.includes('outside/') || sModelsType.includes('semigoodsStock/') || sModelsType.includes('sales/materials') || sModelsType === 'sales/salesCheck') {
          if (sModelsType.includes('sales/materials') || sModelsType === 'sales/salesCheck') {
            tableDataRow.dAuxiliaryQty = tableDataRow.dProductQty;
          }
          tableDataRow = await this.handleMaterialsChange(tableDataRow, sModelsId, masterData, changeValue, sFieldName, app, token, models);

          if (sModelsType.includes('sales/materials') || sModelsType === 'sales/salesCheck') { /* 如果是材料销售模块/销售对账 如果是材料 则用换算数量*单价  算金额 */
            /* 材料逻辑计算 */
            if (commonUtils.isNotEmptyNumber('dMaterialsQty') && tableDataRow.dMaterialsQty !== 0 && commonUtils.isNotEmptyObject(tableDataRow.sMaterialsUnit)) {
              let modelsNew = '';
              if (models === 'Product') { /* 计算前将Product替换为Materials */
                modelsNew = 'Materials';

                const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
                const { dNetPrice } = app.decimals;
                const dForeignPrice = tableDataRow[`d${models}ForeignPrice`];
                if (commonUtils.isNotEmptyNumber(dForeignPrice)) {
                  /* 只有外币单价情況下 要算本位币单价 */
                  const dProductPrice = commonUtils.convertFixNum(dForeignPrice * dCurrencyRate, dNetPrice);
                  tableDataRow[`d${models}Price`] = dProductPrice;
                }

                tableDataRow[`dN${modelsNew}Price`] = tableDataRow[`d${models}ForeignPrice`];
                tableDataRow[`d${modelsNew}ForeignPrice`] = tableDataRow[`d${models}ForeignPrice`];
                tableDataRow[`d${modelsNew}Price`] = tableDataRow[`d${models}Price`];
                tableDataRow[`dN${modelsNew}Money`] = tableDataRow[`dN${models}Price`];
                tableDataRow[`dN${modelsNew}Money`] = tableDataRow[`d${models}ForeignMoney`];
                tableDataRow[`d${modelsNew}ForeignMoney`] = tableDataRow[`d${models}ForeignMoney`];
                tableDataRow[`d${modelsNew}Money`] = tableDataRow[`d${models}Money`];
                tableDataRow.bSalesMaterials = true;/* 材料销售 销售对账 材料计算 */
                models = 'Materials';
                sFieldName = commonUtils.isNotEmptyObject(sFieldName) ? sFieldName.replace('Product', 'Materials') : sFieldName;
              }
            }
          }
        }
        tableDataRow = commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, tableDataRow);
        let dMaterialsMoney = '';
        if (sModelsType.includes('outside/')) { /* 工序发外 && (sFieldName === 'sSupplyName' || sFieldName === 'sProcessName' || sFieldName === 'dAuxiliaryQty') */
          let sComputeId = {};
          const sSupplyId = masterData.sSupplyId;
          const sProcessId = tableDataRow.sProcessId;
          if (commonUtils.isNotEmptyObject(sProcessId)) {
            /* 根据客户id,工序id获取公式ID */
            sComputeId = await commonBusiness.getOutSideProcessFormula({
              token, sModelsId, sSupplyId, sProcessId,
            });
            if (!commonUtils.isEmpty(sComputeId)) {
              dMaterialsMoney = await commonBusiness.getFormulaValue({
                token, sModelsId, masterData, tableDataRow, sComputeId,
              });
              tableDataRow.dMaterialsMoney = dMaterialsMoney;
              tableDataRow = commonBusiness.getCalculateMoney(app, masterData, tableDataRow, 'Materials');
            }
          }
        }
        if (name === 'slaveChild' || sFieldName === 'dProductQty') {
          const { slaveSelectedRowKeys, slaveData } = this.props;
          if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
            const iIndex = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId));
            if (iIndex > -1) {
              const tableFilterData = tableData.filter(item => item.sDelivergooodSlaveId === slaveData[iIndex].sId);
              if (commonUtils.isNotEmptyArr(tableFilterData)) {
                let dSlaveProductQty = tableDataRow.dProductQty;
                tableFilterData.forEach((item) => {
                  if (item.sId !== tableDataRow.sId) {
                    dSlaveProductQty += commonUtils.isNull(item.dProductQty, 0);
                  }
                });
                if (commonUtils.isNotEmptyNumber(dSlaveProductQty) && dSlaveProductQty !== 0) {
                  const addState = {};
                  addState.dProductQty = dSlaveProductQty;
                  addState.handleType = commonUtils.isEmpty(slaveData[iIndex].handleType) ? 'update' : slaveData[iIndex].handleType;
                  slaveData[iIndex] = { ...slaveData[iIndex], ...addState };
                  this.props.onSaveState({ slaveData });
                }
              }
            }
          }
        }
        if (isWait) {
          return tableDataRow;
        } else {
          tableData[iIndex] = tableDataRow;
          if (name === 'report') { // 报表设计
            this.props.onSaveState({ reportPropsEnabled: true });
          } else {
            this.props.onSaveState({ enabled: true });
          }
          this.props.onSaveState({ [`${name}Data`]: tableData });
        }
      }
    };

    /**   删除表格数据   */
    otherTableDel = (name, tableSelectedRowKeys) => {
      const tableData = this.props[`${name}Data`];
      let tableDelData = this.props[`${name}DelData`];
      tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData;
      for (const sId of tableSelectedRowKeys) {
        /*   看看删除集合和从表中是否都存在该条数据   */
        let tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
        while (tableDataIndex > -1) {
          /*   删除从表中的数据并存入删除集合中   */
          const slaveDataFilter = tableData[tableDataIndex];
          tableData.splice(tableDataIndex, 1);
          slaveDataFilter.handleType = 'del';
          tableDelData.push(slaveDataFilter);
          tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
        }
      }
      return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [] };
    };

    handleMaterialsChange = async (tableDataRow, sModelsId, masterData, changeValue, sFieldName, app, token, models) => {
      const { sComputeId, sConversionComputeId, sReConversionComputeId } = tableDataRow;
      if (sFieldName === 'sMaterialsNo' || sFieldName === 'sMaterialsName' || sFieldName === 'dAuxiliaryQty' || sFieldName === 'dReelAuxiliaryQty' || sFieldName === 'dConversionQty' || sFieldName === 'sMaterialsStyle' || sFieldName === 'dProductQty') {
        if (sFieldName === 'dReelAuxiliaryQty') {
          if (tableDataRow.sMaterialsUnit === '吨' && tableDataRow.bReel && tableDataRow.dGramWeight > 0) {
            tableDataRow = commonBusiness.getMaterialsQty(app, { ...tableDataRow, sMaterialsStyle: tableDataRow.sReelMaterialsStyle }, 'dReelAuxiliaryQty', 'dMaterialsQty');
            tableDataRow.dAuxiliaryQty = tableDataRow.dMaterialsQty;
            tableDataRow.sMaterialsStyle = tableDataRow.sMaterialsStyle !== undefined && tableDataRow.sMaterialsStyle.split('*').length > 1 ? tableDataRow.sMaterialsStyle.split('*')[0] : tableDataRow.sMaterialsStyle;
            tableDataRow.sAuxiliaryUnit = tableDataRow.sMaterialsUnit;
          } else if (tableDataRow.sMaterialsUnit.toUpper() === 'M2' && tableDataRow.bReel) {
            tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, 'dReelAuxiliaryQty', 'dMaterialsQty');
            tableDataRow.dAuxiliaryQty = tableDataRow.dReelAuxiliaryQty;
          } else {
            tableDataRow.dAuxiliaryQty = tableDataRow.dReelAuxiliaryQty;
          }
        }
        if (commonUtils.isEmpty(sComputeId) && sFieldName !== 'dConversionQty') {
          if (sFieldName === 'dProductQty') {
            tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, 'dProductQty', 'dMaterialsQty');
          } else {
            tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, 'dAuxiliaryQty', 'dMaterialsQty');
          }
        } else if (!commonUtils.isEmpty(sComputeId)) {
          tableDataRow.dMaterialsQty = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId,
          });
        }
        if (sFieldName !== 'dConversionQty' && !commonUtils.isEmpty(sConversionComputeId)) {
          tableDataRow.dConversionQty = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId: sConversionComputeId,
          });
        }
      } else if (sFieldName === 'dMaterialsQty') {
        const { sReComputeId } = tableDataRow;
        if (commonUtils.isEmpty(sReComputeId) && tableDataRow.bInverse) {
          tableDataRow = commonBusiness.getAuxiliaryQty(app, tableDataRow, sFieldName, 'dAuxiliaryQty');
        } else if (tableDataRow.bInverse) {
          tableDataRow.dAuxiliaryQty = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId: sReComputeId,
          });
          if (commonUtils.isNotEmptyArr(tableDataRow.dAuxiliaryQty) && tableDataRow.dAuxiliaryQty !== 0) {
            tableDataRow.dProductQty = tableDataRow.dAuxiliaryQty;
          }
        }
        if (!commonUtils.isEmpty(sReConversionComputeId)) {
          tableDataRow.dConversionQty = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId: sReConversionComputeId,
          });
        }
      } else if (sFieldName === 'dAuxiliaryLossQty') {
        if (commonUtils.isEmpty(sComputeId)) {
          tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, sFieldName, 'dLossQty');
        } else {
          tableDataRow.dLossQty = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId,
          });
        }
        if (!commonUtils.isEmpty(tableDataRow.dSrcSurplusAuxiliaryQty)) {
          tableDataRow.dAuxiliaryQty = tableDataRow.dSrcSurplusAuxiliaryQty - tableDataRow.dAuxiliaryLossQty;
          tableDataRow.dMaterialsQty = commonUtils.convertFixNum(tableDataRow.dSrcSurplusQty - tableDataRow.dLossQty, 6);
        }
      } else if (sFieldName === 'dLossQty') {
        const { sReComputeId } = tableDataRow;
        if (commonUtils.isEmpty(sReComputeId)) {
          tableDataRow = commonBusiness.getAuxiliaryQty(app, tableDataRow, sFieldName, 'dAuxiliaryLossQty');
        } else {
          tableDataRow.dAuxiliaryLossQty = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId: sReComputeId,
          });
        }
        if (!commonUtils.isEmpty(tableDataRow.dSrcSurplusAuxiliaryQty)) {
          tableDataRow.dAuxiliaryQty = tableDataRow.dSrcSurplusAuxiliaryQty - tableDataRow.dAuxiliaryLossQty;
          tableDataRow.dMaterialsQty = tableDataRow.dSrcSurplusQty - tableDataRow.dLossQty;
        }
      } else if (sFieldName === 'sProcessId' || sFieldName === 'sProcessNo' || sFieldName === 'sProcessName') {
        const sProcessId = changeValue.sProcessId;
        const url = `${commonConfig.server_host}process/outsideprocess?sModelsId=${sModelsId}&sProcessId=${sProcessId}`;
        const dataReturn = (await commonServices.getService(token, url)).data;
        if (dataReturn.code === 1) {
          if (commonUtils.isNotEmptyArr(dataReturn.dataset.rows)) {
            tableDataRow.dMaterialsPrice = dataReturn.dataset.rows[0].dMaterialsPrice;
          }
          tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dMaterialsPrice', masterData, tableDataRow);
        }
      }
      return tableDataRow;
    }
    /* 材料销售模块金额价格逻辑处理 */
    handleCalculateMaterialsProductMoney= (tableDataRow, sModelsId, masterData, changeValue, sFieldName, app, token, models) => {
      if (sFieldName === `d${models}Qty` || sFieldName === `d${models}Price` || sFieldName === `dN${models}Price` || sFieldName === `d${models}ForeignPrice` || sFieldName === `d${models}ForeignMoney` || sFieldName === `d${models}Money` || sFieldName === 'sTaxId' || sFieldName === 'sTaxName') {
        const { dNetMoney } = app.decimals; /* 设定金额保留的小数位 */
        let modelsNew = models;
        if (models === 'Product') { /* 计算前将Product替换为Materials */
          modelsNew = 'Materials';
        }
        let sFiledNameNew = sFieldName;
        if (sFieldName === 'dProductQty') { /* 材料销售中的订单数量 等同于 dAuxiliaryQty */
          sFiledNameNew = 'dAuxiliaryQty';
        } else if (sFieldName === `d${models}Price`) {
          sFiledNameNew = `d${modelsNew}Price`;
        } else if (sFieldName === `dN${models}Price`) {
          sFiledNameNew = `dN${modelsNew}Price`;
        } else if (sFieldName === `d${models}ForeignPrice`) {
          sFiledNameNew = `d${modelsNew}ForeignPrice`;
        } else if (sFieldName === `d${models}Money`) {
          sFiledNameNew = `d${modelsNew}Money`;
        } else if (sFieldName === `dN${models}Money`) {
          sFiledNameNew = `dN${modelsNew}Money`;
        } else if (sFieldName === `d${models}ForeignMoney`) {
          sFiledNameNew = `d${modelsNew}ForeignMoney`;
        }
        tableDataRow[`dN${modelsNew}Price`] = tableDataRow[`dN${models}Price`];
        tableDataRow[`d${modelsNew}ForeignPrice`] = tableDataRow[`d${models}ForeignPrice`];
        tableDataRow[`d${modelsNew}Price`] = tableDataRow[`d${models}Price`];
        tableDataRow[`dN${modelsNew}Money`] = tableDataRow[`dN${models}Price`];
        tableDataRow[`d${modelsNew}ForeignMoney`] = tableDataRow[`d${models}ForeignMoney`];
        tableDataRow[`d${modelsNew}Money`] = tableDataRow[`d${models}Money`];
        tableDataRow = commonBusiness.getCalculateAllMoney(app, modelsNew, sFiledNameNew, masterData, tableDataRow);

        let dMoney = tableDataRow[`d${modelsNew}Money`]; /* 金额 */
        let dForeignMoney = tableDataRow[`d${modelsNew}ForeignMoney`]; /* 外币金额 */
        let dPrice = tableDataRow[`d${modelsNew}Price`]; /* 单价 */
        const dQty = tableDataRow[`d${modelsNew}Qty`]; /* 换算数量 */
        let dTaxMoney = tableDataRow[`d${modelsNew}TaxMoney`]; /* 税额 */
        let dTaxNoMoney = tableDataRow[`d${modelsNew}NoTaxMoney`]; /* 税额 */
        dMoney = commonUtils.isNotEmptyNumber(dMoney) ? dMoney : 0;
        dForeignMoney = commonUtils.isNotEmptyNumber(dForeignMoney) ? dForeignMoney : 0;
        dPrice = commonUtils.isNotEmptyNumber(dPrice) ? dPrice : 0;
        dTaxMoney = commonUtils.isNotEmptyNumber(dTaxMoney) ? dTaxMoney : 0;
        dTaxNoMoney = commonUtils.isNotEmptyNumber(dTaxNoMoney) ? dTaxNoMoney : 0;

        tableDataRow[`d${models}Money`] = dMoney;
        tableDataRow[`d${models}ForeignMoney`] = dForeignMoney;
        tableDataRow[`d${models}Price`] = dPrice;
        tableDataRow[`d${models}TaxMoney`] = dTaxMoney;
        tableDataRow[`d${models}NoTaxMoney`] = dTaxNoMoney;
        /* 单价计算 */
        let dForeignPrice = tableDataRow[`d${models}Price`];
        if (sFieldName === `d${models}ForeignMoney` || sFieldName === `d${models}Money`) {
          dForeignPrice = commonUtils.isNotEmptyNumber(dQty) && dQty !== 0 ? commonUtils.convertFixNum(dForeignMoney / dQty, dNetMoney) : dPrice;
        }
        tableDataRow[`d${models}ForeignPrice`] = dForeignPrice;
      }
      return tableDataRow;
    }

    handleCustomerChange = (name, changeValue) => {
      if (commonUtils.isNotEmptyObject(changeValue)) {
        if (changeValue.sCustomerId !== this.state.changleCustomerId) {
          const sCustomerId = [];
          sCustomerId.push(changeValue.sCustomerId);
          this.handleTableSelectRowChange(name, sCustomerId, changeValue);
        }
      }
      this.setState({ changleCustomerId: changeValue.sCustomerId });
    }
    handleMasterChange = async (name, sFieldName, changeValue, sId, dropDownData, isWait, masterDataNew) => {
      // this.handleCustomerChange(name, changeValue);
      const {
        sModelsId, sModelsType, masterData: masterDataOld, slaveData, app, masterConfig, slaveConfig, token,
      } = this.props;
      const addState = {};
      const masterData = masterDataNew === undefined ? masterDataOld === undefined ? {} : masterDataOld : masterDataNew;
      let bNewSlaveData = false;
      if (sFieldName === 'sCustomerId' || sFieldName === 'sCustomerNo' || sFieldName === 'sCustomerName') {
        if (commonUtils.isNotEmptyArr(slaveData)) {
          // 从表有数据，请删除后修改客户！不能去掉
          if (slaveData.length === 1 && commonUtils.isEmpty(slaveData[0].sProductId)) {
            bNewSlaveData = true;
          } else {
            message.warn(commonFunc.showMessage(app.commonConst, 'slaveHasDataPleaseDel'));
            return;
          }
        }
        changeValue.tGetPayDate = commonBusiness.getGeyPayDate({ ...masterData, ...changeValue });
        // commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductId', []);
        // commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductNo', []);
        // commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductName', []);
        //
        // commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductId', []);
        // commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductNo', []);
        // commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductName', []);
      } if (sFieldName === 'sSupplyId' || sFieldName === 'sSupplyNo' || sFieldName === 'sSupplyName') {
        changeValue.tGetPayDate = commonBusiness.getGeyPayDate({ ...masterData, ...changeValue });
      } else if (sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName') {
        commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sMaterialsId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sMaterialsNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sMaterialsName', []);
        if (sModelsType === 'materialsStock/materialsCheck' || sModelsType === 'productStock/productCheck') {
          let value = {};
          if (sModelsType === 'materialsStock/materialsCheck') {
            value = {
              sProName: 'Sp_System_AccountSquareCheck',
              paramsMap: {
                iType2: 1,
                sWareHouseGuid: commonUtils.isNotEmptyObject(changeValue.sWareHouseId) ? changeValue.sWareHouseId : '',
              },
            };
          } else if (sModelsType === 'productStock/productCheck') {
            value = {
              sProName: 'Sp_System_AccountSquareCheck',
              paramsMap: {
                iType2: 2,
                sWareHouseGuid: commonUtils.isNotEmptyObject(changeValue.sWareHouseId) ? changeValue.sWareHouseId : '',
              },
            };
          }
          const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
          const returnData = (await commonServices.postValueService(app.token, value, url)).data;
          if (returnData.code === 1) {
            const outData = returnData.dataset.rows[0].dataSet.outData[0];
            if (outData.sCode === -1) {
              message.error(outData.sReturn);
              return;
            }
          } else {
            this.props.getServiceError(returnData);
            return;
          }
        }
      } else if (sModelsType.includes('cashier/') && sFieldName === 'sBillType') {
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerName', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyName', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyId', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyNo', []);
        commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyName', []);
        changeValue.sCustomerId = '';
        const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sCustomerId');
        if (iIndex > -1) {
          masterConfig.gdsconfigformslave[iIndex].bReGetDropDown = true;
        }
        changeValue.sSupplyId = '';
        const iSupplyIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sSupplyId');
        if (iSupplyIndex > -1) {
          masterConfig.gdsconfigformslave[iSupplyIndex].bReGetDropDown = true;
        }
        /* 财务调整中切换调整类型后，对象名称清空 */
        const sBillTypeIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sFamilyName');
        if (sBillTypeIndex > -1) {
          masterData.sFamilyName = '';
        }
        this.props.onSaveState({ masterConfig });
      } else if (sFieldName === 'sGetPayId' || sFieldName === 'sGetPayName') {
        changeValue.tGetPayDate = commonBusiness.getGeyPayDate({ ...masterData, ...changeValue });
      } else if (sFieldName === 'tInvoiceDate') {
        changeValue.tGetPayDate = commonBusiness.getGeyPayDate({ ...masterData, ...changeValue });
      } else if (sFieldName === 'sSettlementId') {
        if (changeValue.sSettlementId === 'cash') {
          const sBankAccountIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankAccount');
          if (sBankAccountIndex > -1) {
            masterConfig.gdsconfigformslave[sBankAccountIndex].iTag = 1;
            masterData.sBankAccount = '';
          }
          const sInvoiceNoIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sInvoiceNo');
          if (sInvoiceNoIndex > -1) {
            masterConfig.gdsconfigformslave[sInvoiceNoIndex].iTag = 1;
            masterData.sInvoiceNo = '';
          }
          const sBankIdIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankId' || item.sName === 'sBankName');
          if (sBankIdIndex > -1) {
            masterConfig.gdsconfigformslave[sBankIdIndex].iTag = 1;
            masterData.sBankId = '';
            masterData.sBankName = '';
          }
        }
        if (changeValue.sSettlementId === 'bank') {
          const sInvoiceNoIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sInvoiceNo');
          if (sInvoiceNoIndex > -1) {
            masterConfig.gdsconfigformslave[sInvoiceNoIndex].iTag = 1;
            masterData.sInvoiceNo = '';
          }
          const sBankAccountIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankAccount');
          if (sBankAccountIndex > -1) {
            masterConfig.gdsconfigformslave[sBankAccountIndex].iTag = 0;
          }
          const sBankIdIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankId' || item.sName === 'sBankName');
          if (sBankIdIndex > -1) {
            masterConfig.gdsconfigformslave[sBankIdIndex].iTag = 0;
          }
        }
        if (changeValue.sSettlementId === 'bill') {
          const sBankAccountIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankAccount');
          if (sBankAccountIndex > -1) {
            masterConfig.gdsconfigformslave[sBankAccountIndex].iTag = 1;
            masterData.sBankAccount = '';
          }
          const sInvoiceNoIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sInvoiceNo');
          if (sInvoiceNoIndex > -1) {
            masterConfig.gdsconfigformslave[sInvoiceNoIndex].iTag = 0;
          }
          const sBankIdIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankId');
          if (sBankIdIndex > -1) {
            masterConfig.gdsconfigformslave[sBankIdIndex].iTag = 0;
          }
          const tDueDateIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'tDueDate');
          if (tDueDateIndex > -1) {
            masterConfig.gdsconfigformslave[tDueDateIndex].iTag = 0;
          }
        }
      }
      let returnData = this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, true, masterData);
      if (sFieldName === 'sSupplyId' || sFieldName === 'sSupplyNo' || sFieldName === 'sSupplyName' || sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName' ||
        sFieldName === 'sLocationId' || sFieldName === 'sLocationNo' || sFieldName === 'sLocationName' ||
        sFieldName === 'sWareHouseLocationId' || sFieldName === 'sWareHouseLocationNo' || sFieldName === 'sWareHouseLocationName' || sFieldName === 'tDeliverDate' ||
        sFieldName === 'sCurrency' || sFieldName === 'dCurrencyRate') {
        const slaveDataNew = [];
        const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
        for (const item of slaveData) {
          let tableDataRow = ((sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName' ||
            sFieldName === 'sLocationId' || sFieldName === 'sLocationNo' || sFieldName === 'sLocationName' ||
            sFieldName === 'sWareHouseLocationId' || sFieldName === 'sWareHouseLocationNo' || sFieldName === 'sWareHouseLocationName') && (sModelsType.includes('materialsStock/productionmaterialsadjust'))) ?
            { ...item } : { ...item, [sFieldName]: changeValue[sFieldName] };

          if (sFieldName === 'sSupplyId' || sFieldName === 'sSupplyNo' || sFieldName === 'sSupplyName') {
            tableDataRow.sTaxId = changeValue.sTaxId;
            tableDataRow.sTaxNo = changeValue.sTaxNo;
            tableDataRow.sTaxName = changeValue.sTaxName;
            tableDataRow.dTaxRate = changeValue.dTaxRate;
            tableDataRow.handleType = commonUtils.isEmpty(tableDataRow.handleType) ? 'update' : tableDataRow.handleType;
            let dMaterialsMoney = '';
            if (sModelsType.includes('outside/')) { /* 工序发外 */
              let sComputeId = '';
              const sSupplyId = changeValue.sSupplyId;
              const sProcessId = tableDataRow.sProcessId;
              /* 根据客户id,工序id获取公式ID */
              if (commonUtils.isNotEmptyObject(sSupplyId) && commonUtils.isNotEmptyObject(sProcessId)) {
                sComputeId = await commonBusiness.getOutSideProcessFormula({
                  token, sModelsId, sSupplyId, sProcessId,
                });
                if (commonUtils.isNotEmptyObject(sComputeId)) {
                  dMaterialsMoney = await commonBusiness.getFormulaValue({
                    token, sModelsId, masterData: returnData.masterData, tableDataRow, sComputeId,
                  });
                  tableDataRow.dMaterialsMoney = dMaterialsMoney;
                  tableDataRow = commonBusiness.getCalculateMoney(app, returnData.masterData, tableDataRow, 'Materials');
                } else {
                  tableDataRow = commonBusiness.getCalculateMoney(app, returnData.masterData, tableDataRow, 'Materials'); /* 没有发外公式情况下 进行计算 */
                }
              }
            } else {
              tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'sTaxId', returnData.masterData, tableDataRow);
            }
          } else if (sFieldName === 'sCurrency' || sFieldName === 'dCurrencyRate') {
            tableDataRow = commonBusiness.getCalculateAllMoney(app, models, `d${models}Money`, returnData.masterData, tableDataRow);
            tableDataRow.handleType = commonUtils.isEmpty(tableDataRow.handleType) ? 'update' : tableDataRow.handleType;
          }
          if ((sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName' ||
            sFieldName === 'sLocationId' || sFieldName === 'sLocationNo' || sFieldName === 'sLocationName' ||
            sFieldName === 'sWareHouseLocationId' || sFieldName === 'sWareHouseLocationNo' || sFieldName === 'sWareHouseLocationName') && (!sModelsType.includes('materialsStock/productionmaterialsadjust'))) {
            if (sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName') {
              tableDataRow.sWareHouseId = changeValue.sWareHouseId;
              tableDataRow.sWareHouseNo = changeValue.sWareHouseNo;
              tableDataRow.sWareHouseName = changeValue.sWareHouseName;
            } else if (sFieldName === 'sLocationId' || sFieldName === 'sLocationNo' || sFieldName === 'sLocationName') {
              tableDataRow.sLocationId = changeValue.sLocationId;
              tableDataRow.sLocationNo = changeValue.sLocationNo;
              tableDataRow.sLocationName = changeValue.sLocationName;
            } else if (sFieldName === 'sWareHouseLocationId' || sFieldName === 'sWareHouseLocationNo' || sFieldName === 'sWareHouseLocationName') {
              tableDataRow.sWareHouseLocationId = changeValue.sWareHouseLocationId;
              tableDataRow.sWareHouseLocationNo = changeValue.sWareHouseLocationNo;
              tableDataRow.sWareHouseLocationName = changeValue.sWareHouseLocationName;
            }
            tableDataRow.handleType = commonUtils.isEmpty(tableDataRow.handleType) ? 'update' : tableDataRow.handleType;
          }
          slaveDataNew.push(tableDataRow);
        }
        addState.slaveData = slaveDataNew;
        // this.props.onSaveState({ slaveData: slaveDataNew });
      } else if ((sFieldName === 'sCustomerId' || sFieldName === 'sCustomerNo' || sFieldName === 'sCustomerName')) {
        if (bNewSlaveData) {
          const slaveDataNew = [];
          const allTableData = {};
          allTableData.master = returnData.masterData;
          const tableDataRowAdd = commonFunc.getDefaultData(slaveConfig, allTableData);
          tableDataRowAdd.handleType = 'add';
          tableDataRowAdd.sId = commonUtils.createSid();
          tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
          tableDataRowAdd.key = tableDataRowAdd.sId;
          tableDataRowAdd.bDefault = false;
          tableDataRowAdd.iOrder = 1;
          slaveDataNew.push(tableDataRowAdd);
          addState.slaveData = slaveDataNew;
          // this.props.onSaveState({ slaveData: slaveDataNew });
        } else if (sModelsType.includes('sales/') || sModelsType.includes('cashier/') || sModelsType.includes('manufacture/')) { // 获取应收款
          if (commonUtils.isNotEmptyObject(masterData)) {
            this.getCustomerReceipt({ masterData: returnData.masterData });
          }
        }
      } else if (sFieldName === 'sTestStandardId' || sFieldName === 'sTestStandardName') {
        const { slaveDelData: slaveDelDataOld, slaveConfig, masterConfig } = this.props;
        const dataUrl = `${commonConfig.server_host}eleteamemployee/getObtainInspectionStandards?sModelsId=${sModelsId}&sParentId=${returnData.masterData.sTestStandardId}`;
        const dataReturn = (await commonServices.getService(this.props.app.token, dataUrl)).data;
        const slaveDelData = commonUtils.isEmptyArr(slaveDelDataOld) ? [] : slaveDelDataOld;
        if (dataReturn.code === 1) {
          const returnSlaveData = dataReturn.dataset.rows;
          slaveData.forEach((item) => {
            item.handleType = 'del';
            slaveDelData.push(item);
          });
          const slaveDataNew = [];
          const newCopyTo = {};
          newCopyTo.master = masterData;
          const iConfigIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'sTestStandardName');
          returnSlaveData.forEach((item, iIndex) => {
            let tableDataRow = commonFunc.getDefaultData(slaveConfig, {});
            tableDataRow.handleType = 'add';
            tableDataRow.sId = commonUtils.createSid();
            tableDataRow.sParentId = masterData && masterData.sId ? masterData.sId : null;
            tableDataRow.key = tableDataRow.sId;
            tableDataRow.iOrder = iIndex;
            if (iConfigIndex > -1) {
              tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(masterConfig.gdsconfigformslave[iConfigIndex].sAssignField, item, newCopyTo) }; // 取赋值字段
            }
            slaveDataNew.push(tableDataRow);
          });
          addState.slaveData = slaveDataNew;
        } else {
          this.props.getServiceError(dataReturn);
        }
      } else if (sFieldName === 'sPeriodID') {
        const master = returnData.masterData;
        let { handleType } = master;
        handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
        if (handleType === 'add') { /* 费用分摊单据新增时，选择不同月份，自动获取从表的数据 */
          const { sModelsId } = this.props;
          let url = `${commonConfig.server_host}costCenter/getCostCenterData?sModelsId=${sModelsId}`;
          const body = {
            sPeriodId: changeValue.sPeriodID,
          };
          /**
           * 修改日期：2021-03-26
           * 修改人：吕杰
           * 区域：以下 4 行
           * BUG：2168
           * 说明：凭证导入表下主表月份切换从后台获取数据
           * 原代码：
           */
          if (sModelsType === 'cashier/voucher') {
            url = `${commonConfig.server_host}costCenter/getCosvoucherImportData?sModelsId=${sModelsId}`;
            body.sWeek = masterDataOld.sWeek;
          }
          const dataReturn = (await commonServices.postValueService(app.token, body, url)).data;
          if (dataReturn.code === 1) {
          /*   获取数据集   */
            const { rows } = dataReturn.dataset;
            const slaveDataNew = [];
            rows.forEach((row) => {
              /**
               * 修改日期：2021-03-26
               * 修改人：吕杰
               * 区域：以下 13 行
               * BUG：2168
               * 说明：凭证导入表下主表月份切换从后台获取数据
               * 原代码：
               */
              let tableDataRowAdd = row;
              if (sModelsType === 'cashier/voucher') {
                // 当主表中配置了转换信息时，对数据字段进行转换
                const index = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'Btnimport');
                if (index > -1) {
                  const newCopyTo = {};
                  newCopyTo.master = masterData;
                  newCopyTo.slave = row;
                  const config = masterConfig.gdsconfigformslave[index];
                  const slaveAssignField = config.sAssignField || '';
                  tableDataRowAdd = { ...row, ...commonFunc.getAssignFieldValue(slaveAssignField, row, newCopyTo) };
                }
              }
              tableDataRowAdd.handleType = handleType;
              tableDataRowAdd.sId = commonUtils.createSid();
              tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
              tableDataRowAdd.key = tableDataRowAdd.sId;
              tableDataRowAdd.bDefault = false;
              slaveDataNew.push(tableDataRowAdd);
            });
            addState.slaveData = slaveDataNew;
          } else { /*   失败   */
            this.props.getServiceError(dataReturn);
            return [];
          }
        }
      } else if (sFieldName === 'sWeek' && sModelsType === 'cashier/voucher') {
        /**
         * 修改日期：2021-03-26
         * 修改人：吕杰
         * 区域：此if内
         * BUG：2168
         * 说明：凭证导入表下主表周期切换从后台获取数据
         * 原代码：
         */
        const master = returnData.masterData;
        let { handleType } = master;
        handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
        if (handleType === 'add') { /* 费用分摊单据新增时，选择不同月份，自动获取从表的数据 */
          const { sModelsId } = this.props;
          const url = `${commonConfig.server_host}costCenter/getCosvoucherImportData?sModelsId=${sModelsId}`;
          const body = {
            sWeek: changeValue.sWeek,
            sPeriodId: masterDataOld.sPeriodId,
          };
          const dataReturn = (await commonServices.postValueService(app.token, body, url)).data;
          if (dataReturn.code === 1) {
          /*   获取数据集   */
            const { rows } = dataReturn.dataset;
            const slaveDataNew = [];
            rows.forEach((row) => {
              let tableDataRowAdd = row;
              // 当主表中配置了转换信息时，对数据字段进行转换
              const index = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'Btnimport');
              if (index > -1) {
                const newCopyTo = {};
                newCopyTo.master = masterData;
                newCopyTo.slave = row;
                const config = masterConfig.gdsconfigformslave[index];
                const slaveAssignField = config.sAssignField || '';
                tableDataRowAdd = { ...row, ...commonFunc.getAssignFieldValue(slaveAssignField, row, newCopyTo) };
              }
              tableDataRowAdd.handleType = handleType;
              tableDataRowAdd.sId = commonUtils.createSid();
              tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
              tableDataRowAdd.key = tableDataRowAdd.sId;
              tableDataRowAdd.bDefault = false;
              slaveDataNew.push(tableDataRowAdd);
            });
            addState.slaveData = slaveDataNew;
          } else { /*   失败   */
            this.props.getServiceError(dataReturn);
            return [];
          }
        }
      }
      const models = name === 'materials' ? 'Materials' :
        sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('print/') || sModelsType.includes('quotation/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
      if (sModelsType.includes('purchase/') || sModelsType.includes('print/') || sModelsType.includes('quotation/') || sModelsType.includes('manufacture/') || sModelsType.includes('materialsStock/') || sModelsType.includes('outside/') || sModelsType.includes('quality/')) {
        let masterData = await this.handleMaterialsChange(returnData.masterData, sModelsId, masterData, changeValue, sFieldName, app, token, models);
        masterData = commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, masterData);
        if (sFieldName !== 'dPackQty') {
          if (changeValue.dPackQty !== this.state.dPackQtyChange && changeValue.dPackQty !== undefined) {
            masterData = commonBusiness.getCalculateAllMoney(app, models, 'dPackQty', masterData, masterData);
            this.setState({ dPackQtyChange: changeValue.dPackQty });
          }
        }
        returnData = { ...returnData, masterData };
      }
      if (isWait) {
        return { ...returnData, ...addState, enabled: true };
      } else {
        this.props.onSaveState({ ...returnData, ...addState, enabled: true });
        return returnData;
      }
    }
    handleBtnPrint = (sActiveId, checked, eKey) => {
      const {
        app, sModelsId, masterConfig, masterData, slaveConfig, sModelsType, reportData, menuChildData, formRoute, controlConfig,
      } = this.props;
      if (sModelsType.includes('manufacture/workOrder')) {
        this.handleUpdateProduction();
      }
      const { token } = app;
      const queryFilter = {};
      queryFilter[masterConfig.sId] = { sId: masterData.sId };
      if (commonUtils.isNotEmptyObject(slaveConfig)) {
        queryFilter[slaveConfig.sId] = { sSqlCondition: { sParentId: masterData.sId } };
      }
      const queryFilterJson = JSON.stringify(queryFilter);
      // const masterDataJson = JSON.stringify(masterData);
      /* 拿到打印报表名称 */
      let printReportName = 'report';
      let printCustomerReportName = 'report';
      if (commonUtils.isNotEmptyArr(reportData)) {
        const iIndex = reportData.findIndex(item => item.sId === sActiveId);
        if (iIndex > -1) {
          printReportName = reportData[iIndex].sReportName;
        }
      }
      if (commonUtils.isNotEmptyArr(menuChildData)) {
        const iIndex = menuChildData.findIndex(item => item.sId === sActiveId);
        if (iIndex > -1) {
          printCustomerReportName = menuChildData[iIndex].sReportName;
        }
      }
      let urlPrint = '';
      if (formRoute === '/indexPage/printlabel') {
        if (commonUtils.isNotEmptyObject(masterData) && masterData.dTrunkQty !== undefined && masterData.dFractionQty !== undefined && masterData.dPackQty !== undefined) { // masterData中必填的三个字段
          // const param = masterDataJson;
          /* 把masterData放在数组中 */
          const ListData = [];
          ListData.push(masterData);
          const param = JSON.stringify(ListData);
          if (eKey.indexOf('BtnPrint.') > -1) {
            urlPrint = `${commonConfig.file_host}printReport/printPdf/${sActiveId}/${printReportName}.pdf?${checked ? 'fileType=.xlsx&' : ''}printType=noquery&sModelsId=${sModelsId}&token=${encodeURIComponent(token)}`;
          } else if (eKey.indexOf('BtnPrintCus.') > -1) {
            urlPrint = `${commonConfig.file_host}printReport/printPdf/${printCustomerReportName}?${checked ? 'fileType=.xlsx&' : ''}printType=noquery&sModelsId=${sModelsId}&token=${encodeURIComponent(token)}`;
          }
          /* Get提交地址栏参数过多,更改Get提交为Post提交 */
          this.handleOpenPost(urlPrint, param);
        } else {
          const dTrunkQtyName = masterConfig.gdsconfigformslave.filter(item => item.sName === 'dTrunkQty');
          const dFractionQtyName = masterConfig.gdsconfigformslave.filter(item => item.sName === 'dFractionQty');
          const dPackQtyName = masterConfig.gdsconfigformslave.filter(item => item.sName === 'dPackQty');
          if (masterData.dTrunkQty === undefined && commonUtils.isNotEmptyObject(dTrunkQtyName)) {
            message.error(`${dTrunkQtyName[0].showName} 必填项！`);
          } else if (masterData.dFractionQty === undefined && commonUtils.isNotEmptyObject(dFractionQtyName)) {
            message.error(`${dFractionQtyName[0].showName} 必填项！`);
          } else if (masterData.dPackQty === undefined && commonUtils.isNotEmptyObject(dPackQtyName)) {
            message.error(`${dPackQtyName[0].showName} 必填项！`);
          }
          return;
        }
      } else if (eKey.indexOf('BtnPrint.') > -1) {
        let { controlSelectedRowKeys } = this.props;
        /* 不出现选择框，则打印全部；出现选择框，则打印勾选的 */
        let bisMutiSelect = false;
        if (commonUtils.isNotEmptyObject(controlConfig) && commonUtils.isNotEmptyArr(controlConfig.gdsconfigformslave)) {
          const filterData = controlConfig.gdsconfigformslave.filter(item => item.sControlName === 'bisMutiSelect');
          if (commonUtils.isNotEmptyArr(filterData)) {
            bisMutiSelect = filterData[0].bVisible;
          }
        }
        if (bisMutiSelect === false || bisMutiSelect === undefined) {
          controlSelectedRowKeys = [];
        }
        urlPrint = `${commonConfig.file_host}printReport/printPdf/${sActiveId}/${printReportName}.pdf?${checked ? 'fileType=.xlsx&' : ''}sModelsId=${sModelsId}&sMaintableId=${masterConfig.sId}&sControlIds=${commonUtils.isNotEmptyArr(controlSelectedRowKeys) ? controlSelectedRowKeys : []}`;
      } else if (eKey.indexOf('BtnPrintCus.') > -1) {
        urlPrint = `${commonConfig.file_host}printReport/printPdf/${printCustomerReportName}?${checked ? 'fileType=.xlsx&' : ''}sModelsId=${sModelsId}&sMaintableId=${masterConfig.sId}`;
      }
      if (formRoute !== '/indexPage/printlabel') {
        window.open(`${encodeURI(`${urlPrint}&queryFilter=${queryFilterJson}`)}&token=${encodeURIComponent(token)}`);
      }
    };
    handleOpenPost= (url, params) => {
      const newWin = window.open();
      let formStr = '';
      formStr = `<form style="visibility:hidden;" method="POST" action="${url}">` +
        `<input type="hidden" name="masterData" value='${params}' />` +
        '</form>';
      newWin.document.body.innerHTML = formStr;
      newWin.document.forms[0].submit();
      return newWin;
    }

    handleUpdateProduction = async () => {
      const { sModelsId, masterData } = this.props;
      const { sBillNo, sId } = masterData || {};
      const dataUrl = `${commonConfig.server_host}business/addUpdateDelBusinessData?sModelsId=${sModelsId}&sBillNo=${sBillNo}&sSysLogSrcId=${sId}`;
      const value = {
        data: [{
          sTable: 'mftworkordermaster',
          column: [{ handleType: 'update', sId: masterData.sId, bProduction: 1 }],
        }],
        sClientType: '1',
      };
      const dataReturn = (await commonServices.postValueService(this.props.app.token, value, dataUrl)).data;
      if (dataReturn.code === 1) {
        message.success(dataReturn.msg);
      } else {
        this.props.getServiceError(dataReturn);
      }
    };

    handleTitleChange = (slavePagination) => {
      this.props.onSaveState({ slavePagination });
    };

    /* 工单、工艺卡、报价单控制表回带图片地址 */
    handleFilfileManageOk= async (controlFilfileData, controlFilfileDelData, sSrcSlaveId) => {
      const {
        controlData: tableData, app, sModelsId, token, controlConfig,
      } = this.props;
      if (commonUtils.isNotEmptyObject(sSrcSlaveId)) {
        if (commonUtils.isNotEmptyArr(controlFilfileDelData)) {
          const addState = {};
          const iIndex = tableData.findIndex(item => item.sId === sSrcSlaveId);
          if (iIndex > -1) {
            const tableDataNewRow = tableData[iIndex];
            const { sMaterialsPicturePath, sMachinePicturePath } = tableDataNewRow;
            const controlsMaterialsPictureDelData = controlFilfileDelData.filter(item => item.sType === '3'); /* 开料 */
            if (commonUtils.isNotEmptyArr(controlsMaterialsPictureDelData)) {
              controlsMaterialsPictureDelData.forEach((slaveItem) => {
                if (slaveItem.sPicturePath === sMaterialsPicturePath) {
                  addState.sMaterialsPicturePath = '';
                }
              });
            }
            const sMachinePictureDelPath = controlFilfileDelData.filter(item => item.sType === '4'); /* 联版 */
            if (commonUtils.isNotEmptyArr(sMachinePictureDelPath)) {
              sMachinePictureDelPath.forEach((slaveItem) => {
                if (slaveItem.sPicturePath === sMachinePicturePath) {
                  addState.sMachinePicturePath = '';
                }
              });
            }
            if (commonUtils.isNotEmptyObject(addState) && (addState.sMachinePicturePath === '' || addState.sMaterialsPicturePath === '')) {
              tableData[iIndex] = { ...tableDataNewRow, ...addState };
              const data = [];
              const updataData = {};
              const updateWhere = {};
              const column = {};
              if (addState.sMaterialsPicturePath === '') {
                column.sMaterialsPicturePath = addState.sMaterialsPicturePath;
              }
              if (addState.sMachinePicturePath === '') {
                column.sMachinePicturePath = addState.sMachinePicturePath;
              }
              if (commonUtils.isNotEmptyObject(tableDataNewRow.sId) && commonUtils.isNotEmptyObject(column)) {
                updateWhere.sId = tableDataNewRow.sId;
                updataData.sTable = controlConfig.sTbName;
                updataData.sWhere = updateWhere;
                updataData.column = column;
                data.push(updataData);
                /* 调用接口将图片地址存入控制表 */
                const configUrl = `${commonConfig.server_host}business/updateBusinessData?sModelsId=${sModelsId}`;
                const value = {
                  data,
                  sClientType: '1',
                };
                const dataReturn = (await commonServices.postValueService(token, value, configUrl)).data;
                if (dataReturn.code === 1) {
                  /* 刷新 */
                  if (this.props.app.currentPane.refresh !== undefined) {
                    this.props.app.currentPane.refresh();
                  }
                } else {
                  this.getServiceError(dataReturn);
                }
              }
            }
          }
        }
        if (commonUtils.isNotEmptyArr(controlFilfileData)) {
          const addState = {};
          const iIndex = tableData.findIndex(item => item.sId === sSrcSlaveId);
          if (iIndex > -1) {
            const tableDataNewRow = tableData[iIndex];
            const { sMaterialsPicturePath, sMachinePicturePath } = tableDataNewRow;
            const controlsMaterialsPictureData = controlFilfileData.filter(item => item.sType === '3');
            if (commonUtils.isNotEmptyArr(controlsMaterialsPictureData)) {
              addState.sMaterialsPicturePath = commonUtils.isNotEmptyObject(controlsMaterialsPictureData[0].sPicturePath) ? controlsMaterialsPictureData[0].sPicturePath : ''; /* 上机默认取上传图片的第一条 */
            }
            const controlsMachinePictureData = controlFilfileData.filter(item => item.sType === '4');
            if (commonUtils.isNotEmptyArr(controlsMachinePictureData)) {
              addState.sMachinePicturePath = commonUtils.isNotEmptyObject(controlsMachinePictureData[0].sPicturePath) ? controlsMachinePictureData[0].sPicturePath : '';
            }
            if (commonUtils.isNotEmptyObject(addState)) {
              tableData[iIndex] = { ...tableDataNewRow, ...addState };
              const data = [];
              const updataData = {};
              const updateWhere = {};
              const column = {};
              if (commonUtils.isNotEmptyObject(addState.sMaterialsPicturePath) && addState.sMaterialsPicturePath !== sMaterialsPicturePath) {
                column.sMaterialsPicturePath = addState.sMaterialsPicturePath;
              }
              if (commonUtils.isNotEmptyObject(addState.sMachinePicturePath) && addState.sMachinePicturePath !== sMachinePicturePath) {
                column.sMachinePicturePath = addState.sMachinePicturePath;
              }
              if (commonUtils.isNotEmptyObject(tableDataNewRow.sId) && commonUtils.isNotEmptyObject(column)) {
                updateWhere.sId = tableDataNewRow.sId;
                updataData.sTable = controlConfig.sTbName;
                updataData.sWhere = updateWhere;
                updataData.column = column;
                data.push(updataData);
                /* 调用接口将图片地址存入控制表 */
                const configUrl = `${commonConfig.server_host}business/updateBusinessData?sModelsId=${sModelsId}`;
                const value = {
                  data,
                  sClientType: '1',
                };
                const dataReturn = (await commonServices.postValueService(token, value, configUrl)).data;
                if (dataReturn.code === 1) {
                  this.props.onSaveState({ tableData });
                  /* 刷新 */
                  if (this.props.app.currentPane.refresh !== undefined) {
                    this.props.app.currentPane.refresh();
                  }
                } else {
                  this.getServiceError(dataReturn);
                }
              }
            }
          }
        }
      } else {
        return message.warning(commonFunc.showMessage(app.commonConst, 'selectedRowKeysNo'));
      }
    }
    // 收付款分摊
    handleShare = () => {
      /* 分摊 */
      const {
        sModelsType, masterData: masterDataOld, slaveData: slaveDataOld, app,
      } = this.props;
      if ((sModelsType.includes('cashier/receipt') && masterDataOld.sBillType !== 'customer') ||
        (sModelsType.includes('cashier/payment') && masterDataOld.sBillType !== 'supply')) {
        return masterDataOld;
      }
      const { dNetMoney } = app.decimals;
      const masterData = { ...masterDataOld };
      const slaveData = [];
      if (commonUtils.isNotEmptyArr(slaveDataOld) && slaveDataOld.length > 0) {
        slaveDataOld.forEach((item) => {
          slaveData.push({ ...item });
        });
      }

      const dTotalMoney = masterData.dTotalMoney !== undefined ? masterData.dTotalMoney : 0;
      let minusSum = 0; /* 负数求和 */
      let minusRoundingSum = 0; /* 负数舍入求和 */
      const minusData = []; /* 负数集 */
      let positiveSum = 0; /* 正数求和 */
      let positiveRoundingSum = 0; /* 正数舍入求和 */
      const positiveData = []; /* 正数集 */
      if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
        slaveData.forEach((child) => {
          child.dTotalMoney = 0;
          child.dRoundingMoney = commonUtils.isNum(child.dRoundingMoney) ? child.dRoundingMoney : 0;
          if (child.dBalanceMoney < 0) {
            minusSum -= Math.abs(child.dBalanceMoney);
            minusRoundingSum -= Math.abs(child.dRoundingMoney);
            minusData.push(child);
          } else {
            const positiveSumTemp = commonUtils.convertFixNum(child.dBalanceMoney, dNetMoney) + commonUtils.convertFixNum(positiveSum, dNetMoney);
            positiveSum = commonUtils.convertFixNum(positiveSumTemp, dNetMoney);
            const positiveRoundingSumTemp = commonUtils.convertFixNum(child.dRoundingMoney, dNetMoney) + commonUtils.convertFixNum(positiveRoundingSum, dNetMoney);
            positiveRoundingSum = commonUtils.convertFixNum(positiveRoundingSumTemp, dNetMoney);
            positiveData.push(child);
          }
        });
      }
      if (commonUtils.convertFixNum(((minusSum - minusRoundingSum) + (positiveSum - positiveRoundingSum)) - dTotalMoney, dNetMoney) <= 0) {
        /* 够扣 */
        positiveSum -= minusRoundingSum;
        positiveSum -= positiveRoundingSum;
        positiveSum -= dTotalMoney; /* 去除分摊金额 */
        if (positiveSum >= 0) {
          for (let i = 0; i < minusData.length; i += 1) {
            /* 负数遍历 */
            const dBalanceMoney = Math.abs(minusData[i].dBalanceMoney); /* 余额正数 */
            const dRoundingMoney = minusData[i].dRoundingMoney !== undefined
              ? minusData[i].dRoundingMoney
              : 0;
            if (positiveSum <= dBalanceMoney) {
              minusData[i].dTotalMoney = commonUtils.convertFixNum(-(positiveSum) - (dRoundingMoney * 1), dNetMoney);
              if (minusData[i].handleType === undefined) {
                minusData[i].handleType = commonUtils.isEmpty(minusData[i].handleType) ? 'update' : minusData[i].handleType;
              }
              break;
            } else {
              minusData[i].dTotalMoney = commonUtils.convertFixNum(-(dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
              positiveSum -= dBalanceMoney - (dRoundingMoney * 1);
              if (minusData[i].handleType === undefined) {
                minusData[i].handleType = commonUtils.isEmpty(minusData[i].handleType) ? 'update' : minusData[i].handleType;
              }
            }
          }
          for (let i = 0; i < positiveData.length; i += 1) {
            /* 正数遍历 */
            const { dBalanceMoney } = positiveData[i]; /* 余额正数 */
            const dRoundingMoney = positiveData[i].dRoundingMoney !== undefined
              ? positiveData[i].dRoundingMoney
              : 0;
            positiveData[i].dTotalMoney = commonUtils.convertFixNum((dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
            if (positiveData[i].handleType === undefined) {
              positiveData[i].handleType = commonUtils.isEmpty(positiveData[i].handleType) ? 'update' : positiveData[i].handleType;
            }
          }
          masterData.dAdvanceMoney = 0;
          masterData.bAdvance = false;
        } else {
          /* 有预收 */
          for (let i = 0; i < positiveData.length; i += 1) {
            /* 正数遍历 */
            const { dBalanceMoney } = positiveData[i]; /* 余额正数 */
            const dRoundingMoney = positiveData[i].dRoundingMoney !== undefined
              ? positiveData[i].dRoundingMoney
              : 0;
            positiveData[i].dTotalMoney = commonUtils.convertFixNum((dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
            positiveData[i].handleType = commonUtils.isEmpty(positiveData[i].handleType) ? 'update' : positiveData[i].handleType;
          }
          for (let i = 0; i < minusData.length; i += 1) {
            /* 负数遍历 */
            minusData[i].dRoundingMoney = 0;
            minusData[i].handleType = commonUtils.isEmpty(minusData[i].handleType) ? 'update' : minusData[i].handleType;
          }
          masterData.dAdvanceMoney = commonUtils.convertFixNum(Math.abs(positiveSum), dNetMoney);
          masterData.bAdvance = true;
        }
        const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
        /* 分摊算外币金额 */
        if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
          slaveData.forEach((item, index) => {
            slaveData[index].dTotalForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? item.dTotalMoney / dCurrencyRate : 0, dNetMoney);
          });
        }
        masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType;
        if (commonUtils.isNotEmptyNumber(masterData.dTotalMoney)) {
          masterData.dProductForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? masterData.dTotalMoney / dCurrencyRate : 0, dNetMoney);
        }
        this.props.onSaveState({ masterData, slaveData });
      } else if (((minusSum - minusRoundingSum) + (positiveSum - positiveRoundingSum)) - dTotalMoney > 0) {
        /* 不够扣情况 */
        minusSum -= minusRoundingSum;
        minusSum -= positiveRoundingSum;
        minusSum -= dTotalMoney; /* 去除分摊金额 */
        for (let i = 0; i < minusData.length; i += 1) {
          /* 负数遍历 */
          const dBalanceMoney = Math.abs(minusData[i].dBalanceMoney); /* 余额正数 */
          const dRoundingMoney = minusData[i].dRoundingMoney !== undefined
            ? minusData[i].dRoundingMoney
            : 0;
          minusData[i].dTotalMoney = commonUtils.convertFixNum(-(dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
          minusData[i].handleType = commonUtils.isEmpty(minusData[i].handleType) ? 'update' : minusData[i].handleType;
        }
        for (let i = 0; i < positiveData.length; i += 1) {
          /* 正数遍历 */
          const { dBalanceMoney } = positiveData[i]; /* 余额正数 */
          const dRoundingMoney = positiveData[i].dRoundingMoney !== undefined
            ? positiveData[i].dRoundingMoney
            : 0;
          if (Math.abs(minusSum) <= dBalanceMoney) {
            positiveData[i].dTotalMoney = commonUtils.convertFixNum(Math.abs(minusSum) - (dRoundingMoney * 1), dNetMoney);
            positiveData[i].handleType = commonUtils.isEmpty(positiveData[i].handleType) ? 'update' : positiveData[i].handleType;
            break;
          } else {
            positiveData[i].dTotalMoney = commonUtils.convertFixNum((dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
            minusSum = -(Math.abs(minusSum) - (dBalanceMoney * 1)); // - (dRoundingMoney * 1)
            positiveData[i].handleType = commonUtils.isEmpty(positiveData[i].handleType) ? 'update' : positiveData[i].handleType;
          }
        }
        const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
        /* 分摊算外币金额 */
        if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
          slaveData.forEach((item, index) => {
            slaveData[index].dTotalForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? item.dTotalMoney / dCurrencyRate : 0, dNetMoney);
          });
        }
        masterData.dAdvanceMoney = 0;
        masterData.bAdvance = false;
        masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType; /* 主表分摊算外币金额 */
        if (commonUtils.isNotEmptyNumber(masterData.dTotalMoney)) {
          masterData.dProductForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? masterData.dTotalMoney / dCurrencyRate : 0, dNetMoney);
        }
        this.props.onSaveState({ masterData, slaveData });
      }
      // let allTotalMoney = 0;
      // let allRoundingMoney = 0;
      // slaveData.forEach((child) => {
      //   if (child.dTotalMoney !== undefined) {
      //     allTotalMoney += child.dTotalMoney * 1;
      //   }
      //   if (child.dRoundingMoney !== undefined) {
      //     allRoundingMoney += child.dRoundingMoney * 1;
      //   }
      // });
      // this.props.onSaveState({ allTotalMoney, allRoundingMoney });
      return masterData;
    };

    handleImport = async (num) => {
      const {
        sModelsId, sModelsType, masterConfig, masterData, slaveData, slaveDelData: slaveDelDataOld, app,
      } = this.props;
      if (commonUtils.isEmpty(masterData.sWareHouseId)) {
        message.error(commonFunc.getConfigShowName(masterConfig, 'sWareHouseId') + commonFunc.showMessage(app.commonConst, 'isNotNull')); // 不能为空！
        return;
      }
      let url;
      if (sModelsType.includes('productStock/')) {
        url = `${commonConfig.server_host}eleProductStock/getEleProductStock?sModelsId=${sModelsId}&sWareHouseId=${masterData.sWareHouseId}&num=${num}`;
      } else {
        url = `${commonConfig.server_host}eleMaterialsStock/getEleMaterialsStock?sModelsId=${sModelsId}&sWareHouseId=${masterData.sWareHouseId}&num=${num}`;
      }

      const dataReturn = (await commonServices.getService(this.props.app.token, url)).data;
      if (dataReturn.code === 1) {
        const returnData = dataReturn.dataset.rows;
        const slaveDelData = commonUtils.isEmptyArr(slaveDelDataOld) ? [] : slaveDelDataOld;
        slaveData.forEach((item) => {
          item.handleType = 'del';
          slaveDelData.push({ ...item });
        });
        returnData.forEach((item, index) => {
          const tableDataRow = this.props.onDataRowAdd('slave', true);
          item.handleType = 'add';
          item.sParentId = masterData.sId;
          item.iOrder = index + 1;
          returnData[index] = { ...tableDataRow, ...item };
        });
        this.props.onSaveState({ slaveData: returnData, slaveDelData });
      } else {
        this.props.getServiceError(dataReturn);
      }
      this.props.onSaveState({ isGetDataVisible: false });
    };

    handleOutTemplate = async () => {
      const {
        token, formData,
      } = this.props;
      const slaveConfig = formData.filter(item => item.sGrd === 'importTemplate')[0];
      window.location.href = `${commonConfig.server_host}import/exportTemplet?gdsconfigformmasterId=${slaveConfig.sId}&token=${token}`;
    };

    /* 导出模版数据 */
    handleOutTemplateData = async () => {
      const {
        slaveConfig, formRoute, masterData, sortedInfo,
      } = this.props;
      const sort = commonUtils.isNotEmptyObject(sortedInfo) ? sortedInfo.order === 'ascend' ? 'asc' : 'desc' : '';
      const slaveOrderBy = commonUtils.isNotEmptyObject(sortedInfo) && Object.keys(sortedInfo).length > 0 ? { [sortedInfo.columnKey]: sort } : ''; //
      const sId = commonUtils.isNotEmptyObject(masterData) ? masterData.sId : '';
      if (commonUtils.isNotEmptyObject(sId)) {
        const sSqlCondition = { sParentId: sId };
        let url = `${commonConfig.server_host}excel/export/${slaveConfig.sId}?sModelsId=${slaveConfig.sParentId}&token=${this.props.app.token}&sName=${formRoute}`;
        if (commonUtils.isNotEmptyObject(sSqlCondition)) {
          url = `${url}&sSqlCondition=${encodeURIComponent(JSON.stringify(sSqlCondition))}`;
        }
        if (slaveOrderBy !== undefined && slaveOrderBy !== '' && Object.keys(slaveOrderBy).length > 0) {
          url = `${url}&sFilterOrderBy=${encodeURIComponent(JSON.stringify(slaveOrderBy))}`;
        }
        window.open(url);
      } else {
        message.warn('没有主表数据！');
      }
    };

    /* 导入未清数据 */
    handleImportFormData = () => {
      const { masterData, sModelsType } = this.props;
      if (commonUtils.isNotEmptyObject(masterData)) {
        let bFilterProValue = '';
        let bFilterProName = '';
        if (sModelsType === 'cashier/payment') { /* 付款单 */
          const { sSupplyName, sSupplyId } = masterData;
          if (commonUtils.isEmptyObject(sSupplyName)) {
            message.error('供应商名称不能为空!');
            return;
          } else {
            bFilterProName = 'sSupplyGuid_pro';
            bFilterProValue = sSupplyId;
          }
        } else if (sModelsType === 'cashier/receipt') { /* 收款单 */
          const { sCustomerName, sCustomerId } = masterData;
          if (commonUtils.isEmptyObject(sCustomerName)) {
            message.error('客户名称不能为空!');
            return;
          } else {
            bFilterProName = 'sCustomerGuid_pro';
            bFilterProValue = sCustomerId;
          }
        }
        this.props.onSaveState({ importFormDataVisible: true, bFilterProName, bFilterProValue });
      }
    }
    handleDesignFunction = () => {
      this.props.onSaveState({ visibleStatement: true });
    };
    handleBatchPriceUpdate = () => {
      const { slaveData, slaveSelectedRowKeys, app } = this.props;
      if (slaveSelectedRowKeys === undefined || slaveSelectedRowKeys.length !== 1) {
        return message.warning(commonFunc.showMessage(app.commonConst, 'selectedRowKeysNo'));/* 请选择一条数据进行操作 */
      } else {
        const batchPriceUpdateData = slaveData.filter(item => item.sId === slaveSelectedRowKeys[0]);
        this.props.onSaveState({ batchPriceUpdateData, visibleBatchPriceUpdate: true });
      }
    };
    /* 有外币时，配置BtnBatchNPriceUpdate， 会调用这个方法 */
    handleBatchNPriceUpdate = () => {
      const { slaveData, slaveSelectedRowKeys, app } = this.props;
      if (slaveSelectedRowKeys === undefined || slaveSelectedRowKeys.length !== 1) {
        return message.warning(commonFunc.showMessage(app.commonConst, 'selectedRowKeysNo'));/* 请选择一条数据进行操作 */
      } else {
        const batchNPriceUpdateData = slaveData.filter(item => item.sId === slaveSelectedRowKeys[0]);
        this.props.onSaveState({ batchNPriceUpdateData, visibleBatchNPriceUpdate: true });
      }
    };

    /** 按钮操作事件 */
    handleButtonClick = (name) => {
      if (name === 'BtnDesignFunction') {
        this.handleDesignFunction();
      } else if (name === 'BtnBatchPriceUpdate') {
        this.handleBatchPriceUpdate();
      } else if (name === 'BtnBatchNPriceUpdate') {
        this.handleBatchNPriceUpdate();
      } else if (name === 'BtnOutTemplate') {
        this.handleOutTemplate();
      } else if (name === 'BtnOutTemplateData') { /* 导出模版数据 */
        this.handleOutTemplateData();
      }
      const { sModelsType } = this.props;
      // 收付款分摊
      if (sModelsType.includes('cashier/') || sModelsType.includes('sales/') || sModelsType.includes('purchase/')) {
        if (name === 'BtnShare') {
          this.handleShare();
        }
        if (sModelsType.includes('cashier/') && name === 'BtnImportFormData') { /* 导入未清数据 */
          this.handleImportFormData(name);
        }
      } else if (sModelsType.includes('materialsStock/') || sModelsType.includes('productStock/')) {
        if (name === 'BtnImport') {
          this.props.onSaveState({ isGetDataVisible: true });
        }
      }
    };

    handleBtnChoose = async (name, sControlName, chooseConfig, recordIndex, tableName) => {
      const { token } = this.props;
      const url = `${commonConfig.server_host}/gdsmodule/getGdsmoduleById/${chooseConfig.sActiveId}?sModelsId=${chooseConfig.sActiveId}`;
      const dataReturn = (await commonServices.getService(token, url)).data;
      if (dataReturn.code === 1) {
        const [returnData] = dataReturn.dataset.rows;
        this.props.onSaveState({
          [`${name}ChooseVisible`]: true, [`${name}ChooseData`]: returnData, slaveSelectedIndex: recordIndex, tableName,
        });
      } else {
        this.props.getServiceError(dataReturn);
      }
    };

    handleSelect = (name, selectConfig, selectData) => {
      const {
        [`${name}Data`]: tableData, [`${name}Config`]: tableConfig, masterData, slaveSelectedIndex,
      } = this.props;
      if (commonUtils.isNotEmptyArr(selectData)) {
        selectData.forEach((item, index) => {
          const newCopyTo = {};
          newCopyTo.master = masterData;
          // newCopyTo.slave = item;
          let tableDataRow = commonFunc.getDefaultData(tableConfig, newCopyTo); // 取默认值
          tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段
          tableDataRow.handleType = 'add';
          tableDataRow.sId = commonUtils.createSid();
          tableDataRow.sParentId = masterData.sId;
          if (name === 'slave' && selectConfig.sControlName === 'BtnChooseMaterials' && index === 0 && (commonUtils.isEmpty(tableData[slaveSelectedIndex].sProductName) || tableData[slaveSelectedIndex].sProductName === '')) {
            tableData[slaveSelectedIndex] = { ...tableData[slaveSelectedIndex], ...tableDataRow };
          } else {
            tableData.push(tableDataRow);
          }
        });
      }
      this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}ChooseVisible`]: false });
    };

    handleSelectCancel = (name) => {
      this.props.onSaveState({ [`${name}ChooseVisible`]: false });
    };
    /* 双击弹出Memo */
    // handleGetMemo = (name, sValue, sMemoFiled, sRecord) => {
    //   const { sCurrMemoProps } = this.props;
    //   let { [`${name}Data`]: tableData } = this.props;
    //   const addStata = { [`${sMemoFiled}`]: sValue };
    //   if (name !== 'master') {
    //     const iIndex = tableData.findIndex(item => item.sId === sRecord.sId);
    //     let handleType = tableData[iIndex].handleType;/* 获取操作类型 */
    //     handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
    //     addStata.handleType = handleType;
    //     tableData[iIndex] = { ...tableData[iIndex], ...addStata };
    //   } else {
    //     let handleType = tableData.handleType;/* 获取操作类型 */
    //     handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
    //     addStata.handleType = handleType;
    //     tableData = { ...tableData, ...addStata };
    //   }
    //   sCurrMemoProps.bVisibleMemo = false;
    //   this.props.onSaveState({ ...sCurrMemoProps, [`${name}Data`]: tableData });
    // };
    // handleGetMemoCancel = () => {
    //   const { sCurrMemoProps } = this.props;
    //   sCurrMemoProps.bVisibleMemo = false;
    //   this.props.onSaveState({ ...sCurrMemoProps });
    // };
    // async await
    handleEleMaterialsStoreCurrQty = async (slaveData) => {
      const { sModelsId, app } = this.props;
      let flag = true;
      const InsufficientInventory = commonFunc.showMessage(app.commonConst, 'InsufficientInventory');/* 库存不足，不能领料 */
      const MateriaTransferQuantityVerificationFailed = commonFunc.showMessage(app.commonConst, 'MateriaTransferQuantityVerificationFailed');/* 材料调拨数量校验失败，请稍后操作 */
      const url = `${commonConfig.server_host}eleMaterialsStock/getEleMaterialsStoreCurrQty?sModelsId=${sModelsId}`;
      for (const item of slaveData) {
        const body = {
          sMaterialsId: item.sMaterialsId, /*   查询条件   */
          sMaterialsStyle: item.sMaterialsStyle,
          sWareHouseId: item.sWareHouseId,
        };
        if (commonUtils.isNotEmptyStr(item.sLocationId)) {
          body.sLocationId = item.sLocationId;
        }
        if (commonUtils.isNotEmptyStr(item.sWarehouseLocationId)) {
          body.sWarehouseLocationId = item.sWarehouseLocationId;
        }
        if (commonUtils.isNotEmptyStr(item.sDefineNo)) {
          body.sDefineNo = item.sDefineNo;
        }
        if (commonUtils.isNotEmptyStr(item.sDefineNo2)) {
          body.sDefineNo2 = item.sDefineNo2;
        }
        const dataReturn = (await commonServices.postValueService(this.props.app.token, body, url)).data;
        if (dataReturn.code === 1) {
          if (commonUtils.isNotEmptyArr(dataReturn.dataset.rows)) {
            const materials = dataReturn.dataset.rows[0];
            if (materials.dAuxiliaryQty < item.dAuxiliaryQty) {
              const sMaterialsName = commonUtils.isEmpty(item.sMaterialsName) ? item.sMaterialsName1 : item.sMaterialsName;
              message.error(`[${sMaterialsName}${item.sMaterialsStyle}], ${InsufficientInventory}`);
              flag = false;
              break;
            }
          } else {
            const sMaterialsName = commonUtils.isEmpty(item.sMaterialsName) ? item.sMaterialsName1 : item.sMaterialsName;
            message.error(`[${sMaterialsName}${item.sMaterialsStyle}], ${InsufficientInventory}`);
            flag = false;
            break;
          }
        } else {
          message.error(MateriaTransferQuantityVerificationFailed);
          flag = false;
          break;
        }
      }
      return flag;
    }
    handleTableSelectRowChange = async (name, selectedRowKeys, changeValue) => {
      if (name === 'slave' || name === 'master') {
        const { token, sModelsId, [`${name}Data`]: tableData } = this.props;
        if (commonUtils.isNotEmptyArr(tableData) && commonUtils.isNotEmptyArr(selectedRowKeys)) {
          let url = '';
          let sCustomerId = '';
          if (sModelsId === '192116810113315228246447250' || sModelsId === '101251240115015952245193980') {
            if (name === 'master') {
              sCustomerId = changeValue.sCustomerId;
            } else if (name === 'slave') {
              const sCustomerIdIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
              if (sCustomerIdIndex > -1) {
                sCustomerId = tableData[sCustomerIdIndex].sCustomerId;
              }
            }
            if (commonUtils.isNotEmptyObject(sCustomerId)) {
              url = `${commonConfig.file_host_ebc}printReport/getReportByCustomerId/${sCustomerId}?sModelsId=${sModelsId}`;
              const values = {};
              const masterReturn = (await commonServices.postValueService(token, values, url)).data;
              if (masterReturn.code === 1) {
                const menuChildData = masterReturn.dataset.rows;
                this.props.onSaveState({ menuChildData });
              }
            }
          } else {
            let sProcessId = '';
            if (name === 'master') {
              sProcessId = changeValue.sProcessClassifyId;
            } else if (name === 'slave') {
              const sProcessIdIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
              if (sProcessIdIndex > -1) {
                sProcessId = tableData[sProcessIdIndex].sProcessClassifyId;
              }
            }
            if (commonUtils.isNotEmptyObject(sProcessId)) {
              url = `${commonConfig.file_host_ebc}printReport/getReportByProcessId/${sProcessId}?sModelsId=${sModelsId}`;
              const values = {};
              const masterReturn = (await commonServices.postValueService(token, values, url)).data;
              if (masterReturn.code === 1) {
                const menuChildData = masterReturn.dataset.rows;
                this.props.onSaveState({ menuChildData });
              }
            }
          }
        }
      } else if (name === 'control') {
        const { treeData, sModelsType } = this.props; /* 赋值给树组件节点 */
        if (sModelsType === 'sales/salesOrderPack') {
          let { treeSelectedKeys } = this.props; /* 赋值给树组件节点 */
          if (treeData !== undefined) {
            treeSelectedKeys = selectedRowKeys; /* 把树形选中节点赋值给表格部件选中节点 */
            this.props.onSaveState({ treeSelectedKeys });
          }
        }
      }
      /* 点按钮删除时，会触发行点击事件 导致selectedRowKeys为删除行的sId */
      const { [`${name}Data`]: tableData } = this.props;
      if (Array.isArray(tableData) && tableData.length > 0 && selectedRowKeys.length) {
        const iIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
        if (iIndex === -1) {
          if (commonUtils.isNotEmptyArr(tableData) && tableData.length > 0) {
            selectedRowKeys = commonUtils.isNotEmptyArr(tableData) ? [tableData[0].sId] : [];
          }
        }
      }
      this.props.onTableSelectRowChange(name, selectedRowKeys);
    }
    // 获取重量
    handleGetWeight = async () => {
      const { masterConfig, app } = this.props;
      const url = app.rxtx.sUrl;
      const returnData = (await commonServices.getService(app.token, url)).data;
      if (returnData.code === 1) {
        const iConfigIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnGetWeight');
        const sAssignField = masterConfig.gdsconfigformslave[iConfigIndex].sAssignField;
        const sAssignFieldStr = sAssignField.split(':')[0];
        const sAssignFieldName = sAssignFieldStr.split('.')[0];
        const sAssignFieldKey = sAssignFieldStr.split('.')[1];
        const dWeight = returnData.dataset.rows[0].dWeight;
        if (commonUtils.isNotEmptyObject([`${sAssignFieldName}Data`])) {
          const { [`${sAssignFieldName}Data`]: tableData } = this.props;
          tableData[tableData.length - 1][sAssignFieldKey] = dWeight;
          this.props.onSaveState({ tableData: [`${sAssignFieldName}Data`] });
        }
      } else {
        this.props.getServiceError(returnData);
      }
    }
    handleViewClick = (name, sName, record) => {
      if (name === 'process' && sName === 'sProcessParamStr') { // process sProcessParam
        const { processConfig, enabled, sModelsType } = this.props;
        const slaveSelectOneData = record;
        let modalVisible = false;
        const sProcessParamsSelects = [];
        let paramType = '';
        if (commonUtils.isNotEmptyObject(slaveSelectOneData)) {
          if (sModelsType.includes('manufacture/')) {
            paramType = slaveSelectOneData.sWorkOrderParam;
          } else if (sModelsType.includes('quotation/')) {
            paramType = slaveSelectOneData.sProcessParam;
          }
        }
        if (commonUtils.isNotEmptyObject(paramType) && enabled) {
          const sProcessParam = JSON.parse(paramType);
          modalVisible = true;
          // eslint-disable-next-line no-plusplus
          for (let i = 1; i < 7; i++) {
            const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
            if (iIndex > -1 && !commonUtils.isEmpty(sProcessParam[`sParam${i.toString()}`])) {
              processConfig.gdsconfigformslave[iIndex].showName = sProcessParam[`sParam${i.toString()}`];
              processConfig.gdsconfigformslave[iIndex].bVisible = !sProcessParam[`sParam${i.toString()}`].includes('参数值');
              record[`sParam${i.toString()}`] = sProcessParam[`sParam${i.toString()}`];
              sProcessParamsSelects.push(processConfig.gdsconfigformslave[iIndex]);
            } else if (iIndex > -1) {
              // processConfig.gdsconfigformslave[iIndex].showName = `sParamValue${i.toString()}`;
              processConfig.gdsconfigformslave[iIndex].bVisible = true;
            }
          }
        } else {
          modalVisible = false;
          // eslint-disable-next-line no-plusplus
          for (let i = 1; i < 7; i++) {
            const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
            if (iIndex > -1) {
              processConfig.gdsconfigformslave[iIndex].bVisible = true;
            }
          }
        }
        this.props.onSaveState({
          processRecord: record,
          sProcessParamsSelects,
          sProcessParamsModalVisible: modalVisible,
        });
      } else {
        this.props.onViewClick(name, sName, record);
      }
    };
    /* 选择基础颜色 */
    handleSelectSisColor = async (name, selectConfig, selectData) => {
      const { enabled, processData, processSelectedRowId } = this.props;
      if (enabled) {
        let sColorSerialMemoStr = '';
        const jsonData = [];
        if (commonUtils.isNotEmptyArr(selectData)) {
          selectData.forEach((item) => {
            const {
              sId, sName, dColor, CreateDate, sMakePerson,
            } = item;
            const jsonObj = {};
            jsonObj.sId = sId;
            jsonObj.sName = sName; /* 名称 */
            jsonObj.dColor = dColor; /* 色序 */
            jsonObj.CreateDate = CreateDate;
            jsonObj.sMakePerson = sMakePerson;
            sColorSerialMemoStr += `${sName}-${dColor},`;
            jsonData.push(jsonObj);
          });
          if (commonUtils.isNotEmptyObject(sColorSerialMemoStr)) {
            sColorSerialMemoStr = commonUtils.isNotEmptyArr(jsonData) ? JSON.stringify(jsonData) : ''; /* JSON对象转换为字符串存放到合版信息中 */
          }
        }
        const iIndex = processData.findIndex(item => item.sId === processSelectedRowId);
        if (iIndex > -1) {
          const addState = {};
          let { handleType } = processData[iIndex];
          handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
          addState.handleType = handleType;
          addState.sColorSerialMemo = sColorSerialMemoStr;
          processData[iIndex] = { ...processData[iIndex], ...addState };
        }
      }
      this.props.onSaveState({
        sisColorChooseVisible: false,
      });
    }
    handleViewChoose= (name, sName, record) => {
      const { sId } = record; /* 控制表主键 */
      const { enabled } = this.props;
      const sisColorSelectedRowKeys = [];
      let jsonData = [];
      if (name === 'process' && sName === 'sColorSerialMemo') {
        const { [`${name}Data`]: tableData } = this.props;
        const iIndex = tableData.findIndex(item => item.sId === sId);
        if (iIndex > -1) {
          const sColorSerialMemo = tableData[iIndex].sColorSerialMemo;

          if (commonUtils.isNotEmptyObject(sColorSerialMemo)) {
            try {
              jsonData = JSON.parse(sColorSerialMemo);
              jsonData.forEach((item) => {
                sisColorSelectedRowKeys.push(item.sId);
              });
            } catch (ex) {
              console.log('ex', ex);
            }
          }
        }
        this.props.onSaveState({
          sisColorChooseVisible: true,
          processSelectedRowId: sId, /* 工序表选中行sId */
          enabled,
          sisColorSelectedRowKeys,
          sisColorSelectedData: jsonData,
        });
      }
    }
    handleCancelModal = (modelVisible) => {
      this.props.onSaveState({
        [modelVisible]: false,
      });
    }

    /* 根据上机长、上机宽，材料长，材料宽 计算自动排版数 */
    handleResolveMachineComposing = (productLength, productWidth, maxMachineLength, maxMachineWidth) => {
      let result1 = {};
      const productLengthTemp = commonUtils.convertStrToNumber(commonUtils.isNull(productLength, 0)); /* 产品长 */
      const productWidthTemp = commonUtils.convertStrToNumber(commonUtils.isNull(productWidth, 0)); /* 产品宽 */
      const maxMachineLengthTemp = commonUtils.convertStrToNumber(commonUtils.isNull(maxMachineLength, 0)); /* 材料长 */
      const maxMachineWidthTemp = commonUtils.convertStrToNumber(commonUtils.isNull(maxMachineWidth, 0)); /* 材料宽 */
      if (isNaN(productLengthTemp) || productLengthTemp === 0 || isNaN(productWidthTemp) || productWidthTemp === 0 || isNaN(maxMachineLengthTemp) || maxMachineLengthTemp === 0 || isNaN(maxMachineWidthTemp) || maxMachineWidthTemp === 0) {
        return result1;
      }
      const vh = this.handleDescVerticalComposing(productLength, productWidth, maxMachineLength, maxMachineWidth);
      const hv = this.handleDescHorizonalComposing(productLength, productWidth, maxMachineLength, maxMachineWidth);
      const totalNumVH = vh.totalNum;
      const totalNumHV = hv.totalNum;
      if (totalNumVH === totalNumHV) {
        if (vh.remaining === 0) {
          result1 = vh;
        } else {
          result1 = hv;
        }
      } else if (totalNumVH > totalNumHV) {
        result1 = vh;
      } else {
        result1 = hv;
      }
      return result1;
    };

    handleDescHorizonalComposing = (productLength, productWidth, maxMachineLength, maxMachineWidth) => {
      let horizonalWWNum = 0;
      let horizonalLWNum = 0;
      let verticalLLNum = 0;
      let verticalLWNum = 0;
      let totalNum = 0;// 总的排列数目
      let totalLength = 0;// 上机长，即最大排列占据的长度
      let totalWidth = 0;// 上机宽，即最大排列占据的宽度

      let mLength = 0;
      let mWidth = 0;
      let horizonalRemaining = 0;
      // let fTempmarginW = 0;
      // let fTempmarginL = 0;
      // const mTemp = 0;
      const dmargin = 0;

      const result1 = {};

      if (maxMachineLength > maxMachineWidth || maxMachineLength === maxMachineWidth) {
        mLength = maxMachineLength;
      } else {
        mLength = maxMachineWidth;
      }

      if (maxMachineLength < maxMachineWidth || maxMachineLength === maxMachineWidth) {
        mWidth = maxMachineLength;
      } else {
        mWidth = maxMachineWidth;
      }
      maxMachineLength = mLength;
      maxMachineWidth = mWidth;

      // 按机器优先横排--竖向横排数量，即上述竖向横排一共排几行
      verticalLLNum = Math.floor(maxMachineLength / this.handleZeroToOne(productWidth + commonUtils.convertFixNum(dmargin, 2)));
      // 按机器优先横排--横向横排数量，即横向排列的时候，一行最多能排几个
      verticalLWNum = Math.floor(maxMachineWidth / this.handleZeroToOne(productLength + commonUtils.convertFixNum(dmargin, 2)));

      totalNum += verticalLLNum * verticalLWNum;

      // 画册类，不能混排，而且只能是偶数，如果是奇数，则首选在长方向去掉一列，
      horizonalRemaining = 0;
      // fTempmarginW = 0;// 宽方向 需减少的出血
      // fTempmarginL = 0;// 长方向 需减少的出血
      horizonalWWNum = 0;
      horizonalLWNum = 0;

      if (totalNum > 0) {
        // 上述横排完成之后，剩余的右边宽度，用于竖向排列
        horizonalRemaining = maxMachineWidth - (verticalLWNum * (productLength + commonUtils.convertFixNum(dmargin, 2)));
        // 按机器优先长排--竖向横排一行能排的数量，即排完竖向之后，剩余的排横向的，看一行能排多少个

        // / 剩余空间  横向 排数量
        horizonalWWNum = Math.floor(horizonalRemaining / (productWidth + commonUtils.convertFixNum(dmargin, 2)));
        // 剩余空间  竖向 排数量
        horizonalLWNum = Math.floor(maxMachineLength / (productLength + commonUtils.convertFixNum(dmargin, 2)));
      }

      if (horizonalWWNum * horizonalLWNum === 0) {
        // 不是混排的情况
        totalLength = verticalLLNum * (productWidth + commonUtils.convertFixNum(dmargin, 2));
        totalWidth = verticalLWNum * (productLength + commonUtils.convertFixNum(dmargin, 2));
      } else {
        totalNum += horizonalWWNum * horizonalLWNum;
        // 有可能是左边横向排列占用的长度更长，也有可能是剩余右侧的竖向排列方式占用的长度更长，最终更长的那个作为上机尺寸
        if (verticalLLNum * (productWidth + dmargin) > horizonalLWNum * (productLength + commonUtils.convertFixNum(dmargin, 2))) {
          totalLength = verticalLLNum * (productWidth + dmargin);
        } else {
          totalLength = horizonalLWNum * (productLength + dmargin);
        }
        // 最终宽度是所有左侧横向排列占据的宽度以及右侧剩余空间竖向排列占据的宽度之和
        totalWidth = (verticalLWNum * (productLength + dmargin)) + (horizonalWWNum * (productWidth + commonUtils.convertFixNum(dmargin, 2)));
      }

      result1.remaining = horizonalLWNum * horizonalWWNum;
      result1.iLengthComposing = verticalLLNum;
      result1.iWidthComposing = verticalLWNum;


      result1.sMethod = `W#${commonUtils.convertNumberToStr(verticalLLNum)}*${commonUtils.convertNumberToStr(verticalLWNum)}+L#${commonUtils.convertNumberToStr(horizonalWWNum)}*${commonUtils.convertNumberToStr(horizonalLWNum)}`;
      result1.sMaterialMethod = `W#${commonUtils.convertNumberToStr(verticalLLNum)}*${commonUtils.convertNumberToStr(verticalLWNum)}+L#${commonUtils.convertNumberToStr(horizonalWWNum)}*${commonUtils.convertNumberToStr(horizonalLWNum)}`;
      // 最终要保存排列之后的长和宽，按机器排的时候获取的是上机尺寸;按材料排的时候，就是最优材料排版
      if (totalLength > totalWidth) {
        result1.totalLength = totalLength;
        result1.totalWidth = totalWidth;
      } else {
        result1.totalLength = totalWidth;
        result1.totalWidth = totalLength;
      }
      // 最终保存最大数目，以便比较最优排版数
      result1.totalNum = totalNum;
      return result1;
    };
    handleDescVerticalComposing = (productLength, productWidth, maxMachineLength, maxMachineWidth) => {
      let horizonalWWNum = 0;
      let horizonalLWNum = 0;
      let verticalLLNum = 0;
      let verticalLWNum = 0;
      let mLength = 0;
      let mWidth = 0;
      let verticalRemaining = 0;
      // eslint-disable-next-line no-unused-vars
      let fTempmarginW = 0;
      // eslint-disable-next-line no-unused-vars
      let fTempmarginL = 0;
      const result1 = {};
      // eslint-disable-next-line no-unused-vars
      const TYHLLookupList = 0;
      const dmargin = 0;
      let totalNum = 0;// 总的排列数目
      let totalLength = 0;// 上机长，即最大排列占据的长度
      let totalWidth = 0; // 上机宽，即最大排列占据的宽度
      if (maxMachineLength >= maxMachineWidth) {
        mLength = maxMachineLength;
      } else {
        mLength = maxMachineWidth;
      }

      if (maxMachineLength <= maxMachineWidth) {
        mWidth = maxMachineLength;
      } else {
        mWidth = maxMachineWidth;
      }
      maxMachineLength = mLength;
      maxMachineWidth = mWidth;
      // 画册类，不能混排，而且只能是偶数，如果是奇数，则首选在长方向去掉一列，
      verticalRemaining = 0;

      fTempmarginW = 0;// 宽方向 需减少的出血
      fTempmarginL = 0;// 长方向 需减少的出血

      horizonalWWNum = 0;
      horizonalLWNum = 0;

      // 按机器优先长排--竖排竖方向排多少个
      verticalLLNum = Math.floor(maxMachineLength / this.handleZeroToOne(commonUtils.convertFixNum(productLength, 2) + commonUtils.convertFixNum(dmargin, 2)));
      // 竖排横方向排多少个
      verticalLWNum = Math.floor(maxMachineWidth / this.handleZeroToOne(commonUtils.convertFixNum(productWidth, 2) + commonUtils.convertFixNum(dmargin, 2)));
      totalNum += verticalLLNum * verticalLWNum;

      if (totalNum > 0) {
        // 上述竖排完成之后，剩余的长度
        verticalRemaining = maxMachineLength - (verticalLLNum * (commonUtils.convertFixNum(productLength, 2) + commonUtils.convertFixNum(dmargin, 2)));
        // 剩余下面 竖向 排数量
        horizonalLWNum = Math.floor(verticalRemaining / this.handleZeroToOne(productWidth + commonUtils.convertFixNum(dmargin, 2)));
        // 剩余下面 横向 排数量
        horizonalWWNum = Math.floor(maxMachineWidth / this.handleZeroToOne(productLength + commonUtils.convertFixNum(dmargin, 2)));
      }

      if (horizonalWWNum * horizonalLWNum === 0) {
        totalLength = verticalLLNum * (productLength + commonUtils.convertFixNum(dmargin, 2));
        totalWidth = verticalLWNum * (productWidth + commonUtils.convertFixNum(dmargin, 2));
      } else {
        totalNum += horizonalLWNum * horizonalWWNum;
        totalLength = (verticalLLNum * (productLength + commonUtils.convertFixNum(dmargin, 2))) + ((productWidth + commonUtils.convertFixNum(dmargin, 2)) * horizonalLWNum);
        // 最终宽度是所有左侧横向排列占据的宽度以及右侧剩余空间竖向排列占据的宽度之和
        if (verticalLWNum * (productWidth + dmargin) > horizonalWWNum * (productLength + commonUtils.convertFixNum(dmargin, 2))) {
          totalWidth = verticalLWNum * (productWidth + commonUtils.convertFixNum(dmargin, 2));
        } else {
          totalWidth = horizonalWWNum * (productLength + commonUtils.convertFixNum(dmargin, 2));
        }
      }
      result1.remaining = horizonalLWNum * horizonalWWNum;
      result1.iLengthComposing = verticalLLNum;
      result1.iWidthComposing = verticalLWNum;
      result1.sMethod = `L#${commonUtils.convertNumberToStr(verticalLLNum)}*${commonUtils.convertNumberToStr(verticalLWNum)}+W#${commonUtils.convertNumberToStr(horizonalLWNum)}*${commonUtils.convertNumberToStr(horizonalWWNum)}`;
      result1.sMaterialMethod = `L#${commonUtils.convertNumberToStr(verticalLLNum)}*${commonUtils.convertNumberToStr(verticalLWNum)}+W#${commonUtils.convertNumberToStr(horizonalWWNum)}*${commonUtils.convertNumberToStr(horizonalLWNum)}`;
      // 最终要保存排列之后的长和宽，按机器排的时候获取的是上机尺寸;按材料排的时候，就是最优材料排版
      if (totalLength > totalWidth) {
        result1.totalLength = totalLength;
        result1.totalWidth = totalWidth;
      } else {
        result1.totalLength = totalWidth;
        result1.totalWidth = totalLength;
      }
      // 最终保存最大数目，以便比较最优排版数
      result1.totalNum = Math.floor(totalNum);
      return result1;
    };
    handleZeroToOne = (num) => {
      if (commonUtils.isEmptyNumber(num) && num === 0) {
        num = 1;
      }
      return num;
    };

    /* 单据字段单击右键全部更新，弹出窗选择后，更新此列所有数据。（只更新非只读字段） */
    handleContextMenuOk=(contextMenuValue, contextMenuData, contextMenuType) => {
      const {
        contextMenuConfig, contextMenuTbName, [`${contextMenuTbName}Data`]: tableData, [`${contextMenuTbName}SelectedRowKeys`]: selectedRowKeys,
      } = this.props;
      if (commonUtils.isNotEmptyObject(contextMenuTbName) && commonUtils.isNotEmptyArr(tableData)) {
        if (commonUtils.isNotEmptyArr(contextMenuConfig) && commonUtils.isNotEmptyObject(contextMenuConfig[0])) {
          const tableConfig = contextMenuConfig[0];
          const tableFilterData = tableData.filter(item => selectedRowKeys.includes(item.sId));
          if (commonUtils.isNotEmptyArr(tableFilterData)) {
            let changeData = [];
            const chooseType = commonUtils.isNotEmptyNumber(contextMenuType) ? contextMenuType : 1;
            if (chooseType === 1) {
              changeData = tableData;
            } else if (chooseType === 2) {
              changeData = tableData.filter(item => item.iRowNum === tableFilterData[0].iRowNum || item.iRowNum > tableFilterData[0].iRowNum);
            }
            // const tableDataRow = tableFilterData[0];
            if (commonUtils.isNotEmptyArr(changeData) && commonUtils.isNotEmptyObject(tableConfig.sName) && !commonUtils.isEmpty(contextMenuValue)) {
              const sName = tableConfig.sName;
              changeData.forEach((child) => {
                const addState = {};
                addState[sName] = contextMenuValue;
                const iIndex = tableData.findIndex(row => row.sId === child.sId);
                if (iIndex > -1) {
                  addState.handleType = commonUtils.isEmpty(tableData[iIndex].handleType) ? 'update' : tableData[iIndex].handleType;
                  tableData[iIndex] = { ...tableData[iIndex], ...addState, ...contextMenuData };
                  const changeValue = { ...contextMenuData };
                  changeValue[sName] = contextMenuValue;
                  /* 手动触发改变事件 */
                  this.handleTableChange(contextMenuTbName, sName, changeValue, child.sId, [], false);
                }
              });
            }
          }
        }
      }
      this.props.onSaveState({
        [`${contextMenuTbName}Data`]: tableData,
        contextMenuModalVisible: false, /* 右击全部更新弹窗 */
      });
    }

    /* 工单、工艺卡、报价单上移下移排序 */
    orderNum = (tableData, controlSelectedRowKeys) => {
      /* 部件工序排序 */
      const tableFilterData = tableData.filter(item => controlSelectedRowKeys.includes(item.sControlId));
      if (commonUtils.isNotEmptyArr(tableFilterData)) {
        tableFilterData.forEach((item, index) => {
          item.iOrder = index + 1;
          item.handleType = commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType;
          const index1 = tableData.findIndex(item1 => item1.sId === item.sId);
          if (index1 > -1) {
            tableData[index1] = { ...tableData[index1], ...item };
          }
        });
      }
      /* 成品工序 */
      const tableFilterCPData = tableData.filter(item => item.sType === '3');
      if (commonUtils.isNotEmptyArr(tableFilterCPData)) {
        let num = 1001;
        tableFilterCPData.forEach((item) => {
          item.iOrder = num;
          item.handleType = commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType;
          const index1 = tableData.findIndex(item1 => item1.sId === item.sId);
          num += 1;
          if (index1 > -1) {
            tableData[index1] = { ...tableData[index1], ...item };
          }
        });
      }
      return tableData;
    };

    /* 送货单个性化弹窗 选择数据带到从表字表 */
    handleSelectCommonPopup = (currentPaneName, selectConfig, selectData, tbName) => {
      const {
        [`${tbName}Data`]: tableData, [`${tbName}SelectedRowKeys`]: tableSelectedRowKeys, masterData,
      } = this.props;
      let { slaveChildData } = this.props;
      const iIndex = commonUtils.isNotEmptyArr(tableSelectedRowKeys) ? tableData.findIndex(item => item.sId === tableSelectedRowKeys[0]) : -1;
      let dProductQty = 0;
      if (commonUtils.isNotEmptyArr(selectData)) {
        // eslint-disable-next-line no-unused-vars
        selectData.forEach((item, index) => {
          if (commonUtils.isEmpty(slaveChildData)) {
            slaveChildData = [];
          }
          const newCopyTo = {};
          newCopyTo.master = masterData;
          if (iIndex > -1) {
            newCopyTo.slaveChild = item;
          }
          /* 库存数量叠加到从表的送货数量中 */
          dProductQty += commonUtils.isNull(item.dProductQty, 0); /* 赠送数量叠加 */
          let tableDataRowAdd = this.handleTableAdd('slaveChild', true);
          item.handleType = 'add';
          tableDataRowAdd = { ...tableDataRowAdd, ...item }; // 取赋值字段
          tableDataRowAdd.sId = commonUtils.createSid();
          tableDataRowAdd.sParentId = masterData.sId;
          tableDataRowAdd.sDelivergooodSlaveId = tableData[iIndex].sId; /* 选中从表的sId */
          slaveChildData.push(tableDataRowAdd);
        });
        if (commonUtils.isNotEmptyNumber(dProductQty) && dProductQty !== 0) {
          const addState = {};
          addState.dProductQty = dProductQty;
          addState.handleType = commonUtils.isEmpty(tableData[iIndex].handleType) ? 'update' : tableData[iIndex].handleType;
          tableData[iIndex] = { ...tableData[iIndex], ...addState };
        }
        this.props.onSaveState({ [`${tbName}Data`]: tableData, slaveChildData });
      }
    };

    render() {
      const { masterData, sModelsType, app } = this.props;
      const imgSrc = commonBusiness.handleAddIcon(masterData, sModelsType, app);
      return (
        <ChildComponent
          {...this.props}
          {...this.state}
          /*
            修改日期：2021-03-18
            修改人：吕杰
            区域：以下一行
            说明：添加keyDown事件透传
          */
          onKeyDown={this.onKeyDown}
          onContextMenu={this.onContextMenu}
          onAdd={this.handleAdd}
          onEdit={this.handleEdit}
          onSubmit={this.handleValidateSave}
          onSaveData={this.handleSaveData}
          onSelectRowChange={this.handleSelectRowChange}
          onTableSelectRowChange={this.handleTableSelectRowChange}
          onReturnForm={this.handleForm}
          onChangeInvalid={this.handleInvalid}
          onBtnExamine={this.handleAudit.bind(this, 1)}
          onBtnCancelExamine={this.handleAudit.bind(this, 0)}
          onCopyTo={this.handleCopyTo}
          onCopyFrom={this.handleCopyFrom}
          onSearchData={this.handleSearchData}
          onNext={this.handleSearchData.bind(this, 'next')}
          onBtnPrior={this.handleSearchData.bind(this, 'up')}
          onBtnFirst={this.handleSearchData.bind(this, 'first')}
          onBtnLast={this.handleSearchData.bind(this, 'end')}
          onSearchUpDown={this.handleSearchUpDown}
          onGetData={this.handleGetData}
          onCancel={this.handleCancel}
          onDel={this.handleDel}
          onSearchUpDownThird={this.handleSearchUpDownThird}
          onDataRowAdd={this.handleTableAdd}
          onDataRowCopy={this.handleTableCopy}
          onDataRowCopyAll={this.handleTableCopyAll}
          onDataChange={this.handleTableChange}
          onBtnPrint={this.handleBtnPrint}
          onChange={this.handleMasterChange}
          onTitleChange={this.handleTitleChange}
          onButtonClick={this.handleButtonClick}
          onBtnChoose={this.handleBtnChoose}
          onSelect={this.handleSelect}
          onSelectCancel={this.handleSelectCancel}
          // onGetMemo={this.handleGetMemo}
          // onGetMemoCancel={this.handleGetMemoCancel}
          onDelDataSuccess={this.handleDelDataSuccess}
          onMaterialsChange={this.handleMaterialsChange}
          onDataAudit={this.dataAudit}
          imgSrc={imgSrc}
          onFilfileManageOk={this.handleFilfileManageOk}
          onGetWeight={this.handleGetWeight}
          onDataImport={this.handleImport}
          onGetControlTreeData={this.handleGetControlTreeData}
          onViewClick={this.handleViewClick}
          onViewChoose={this.handleViewChoose}
          onSelectSisColor={this.handleSelectSisColor}
          onCancelModal={this.handleCancelModal}
          onResolveMachineComposing={this.handleResolveMachineComposing}
          onContextMenuOk={this.handleContextMenuOk}
          orderNum={this.orderNum}
          onSelectCommonPopup={this.handleSelectCommonPopup} /* 送货单个性化放大镜弹窗 */
        />
      );
    }
  };
};
