/* eslint-disable */
/* eslint-disable prefer-destructuring,no-await-in-loop,radix,,no-loop-func */
/**
 * Created by mar105 on 2019-01-08.
 */
import React, { Component } from 'react';
import { Toast,Modal } from 'antd-mobile-v2';
import * as commonUtils from '../../utils/utils';
import * as commonFunc from '../../components/Common/commonFunc';
import * as commonBusiness from '../../components/Common/commonBusiness';
import commonConfig from '../../utils/config';
import * as commonServices from '../../services/services';
import BarCodeUtil from './BarCodeUtil';

export default (ChildComponent) => {
  return class extends Component {
    constructor(props) {
      super(props);
      this.state = {};
      this.isOutsourcedProcesses = this.props.sModelsType?.includes('utside/outsideinstorePDA');
    }

    async componentWillReceiveProps(nextProps) {
      const {
        formData, currentId, masterConfig: masterConfigOld, sModelsId,
      } = nextProps;
      if (commonUtils.isEmptyObject(masterConfigOld) && formData.length > 0) {
        const sId = currentId || nextProps.masterData?.sId || '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        const slaveConfig = formData.filter(item => item.bGrd)[0];
        /* 判断是否有汇总表 */
        const slaveSumConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.bGrd && item.sGrd && item.sGrd.includes('sumTable') )) ? formData.filter(item => item.bGrd && item.sGrd && item.sGrd.includes('sumTable')  )[0] : {};
       /* 加载子从表 */
        const filterData = formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult' && item.bGrdVisible);
        let slaveChildConfig = {};
        if (commonUtils.isNotEmptyArr(filterData) && filterData.length > 1) {
          slaveChildConfig = filterData[1];
        }
        const otherConfig = {};
        if (this.isOutsourcedProcesses) {
          otherConfig.slave0Config = formData.filter(item => item.bGrd && item.sGrd && item.sGrd.includes('slave0'))[0] || {};
        }
        let addStateMaster = {};
        let userEntrustData = []; /* 委托人 */
        let addState = {};
        let addStateSum = {};
        if (sId === '') {
          const config = {};
          config.masterConfig = masterConfig;
          config.slaveConfig = slaveConfig;
          config.slaveSumConfig = slaveSumConfig;
          config.slaveChildConfig = slaveChildConfig;
          config.slave0Config = otherConfig.slave0Config || {};
          addState = await this.handleAdd(config, nextProps.copyTo, true);
        } else {
          addStateMaster = await this.props.handleGetDataOne({
            name: 'master',
            configData: masterConfig,
            condition: { sId, pageSize: '', pageNum: '' },
            isWait: true,
          });
          if (location.pathname === '/indexMobile/examine') {
            const masterDataNew = addStateMaster.masterData;
            const sParamsArr = commonUtils.isNotEmptyObject(masterDataNew) && commonUtils.isNotEmptyObject(masterDataNew.sTableParams) ? JSON.parse(masterDataNew.sTableParams) : '';
            const sParamsValueArr = commonUtils.isNotEmptyObject(masterDataNew) && commonUtils.isNotEmptyObject(masterDataNew.sTableParamsValue) ? JSON.parse(masterDataNew.sTableParamsValue) : '';
            /* 塞入配置 */
            if (commonUtils.isNotEmptyObject(sParamsArr) && commonUtils.isNotEmptyObject(masterDataNew) && commonUtils.isNotEmptyObject(masterConfig) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave)) {
              /* 移除最后一位元素 */
              for (const key of Object.keys(sParamsArr)) {
                const newConfig = {
                  iOrder: 300, sId: commonUtils.createSid(), bVisible: true, sParamsArr: key, showName: sParamsArr[key], sName: key,
                };
                const len = masterConfig.gdsconfigformslave.length;
                masterConfig.gdsconfigformslave.splice(len - 1, 0, newConfig);
                if (commonUtils.isNotEmptyArr(sParamsValueArr)) {
                  masterDataNew[key] = sParamsValueArr[key];
                }
              }
            }
            /* 拉委托人员的下拉数据源 */
            const iUserIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName && item.sControlName.includes('BtnEntrust'));
            if (iUserIndex > -1) {
              userEntrustData = await this.props.getSqlDropDownData(sModelsId, 'master', masterConfig.gdsconfigformslave[iUserIndex], masterDataNew);
            }
          }
          addState = await this.props.handleGetDataSet({
            name: 'slave', configData: slaveConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
          });
          if(commonUtils.isNotEmptyObject(slaveSumConfig) && slaveSumConfig.sGrd && slaveSumConfig.sGrd.includes('sumTableSelect')) {
            addStateSum = await this.props.handleGetDataSet({
              name: 'slaveSum', configData: slaveSumConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
            });
          }
          if (commonUtils.isNotEmptyArr(addState.slaveData)) {
            if (commonUtils.isNotEmptyObject(addState.slaveData[0].sReportParam)) {
              addState.slaveData[0] = { ...addState.slaveData[0], ...commonUtils.convertStrToObj(addState.slaveData[0].sReportParam) };
              // eslint-disable-next-line no-plusplus
              for (let i = 1; i < 7; i++) {
                const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
                if (iIndex > -1 && !commonUtils.isEmpty(addState.slaveData[0][`sParam${i.toString()}`])) {
                  slaveConfig.gdsconfigformslave[iIndex].showName = addState.slaveData[0][`sParam${i.toString()}`];
                  slaveConfig.gdsconfigformslave[iIndex].bVisible = !addState.slaveData[0][`sParam${i.toString()}`].includes('参数值');
                } else if (iIndex > -1) {
                  slaveConfig.gdsconfigformslave[iIndex].bVisible = false;
                }
              }
            } else {
              // eslint-disable-next-line no-plusplus
              for (let i = 1; i < 7; i++) {
                const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
                if (iIndex > -1) {
                  slaveConfig.gdsconfigformslave[iIndex].bVisible = false;
                }
              }
            }
          }
        }
        this.props.onSaveState({
          masterConfig, slaveConfig, sId, pageLoading: false, ...addState, ...addStateMaster, userEntrustData, slaveSumConfig, ...addStateSum, slaveChildConfig,
          ...otherConfig,
        });
      }
    }

    shouldComponentUpdate(nextProps) {
      const { masterConfig } = nextProps;
      return commonUtils.isNotEmptyObject(masterConfig);
    }

    /**  点击新增按钮   */
    handleAdd = async (config, copyTo, isWait) => {
      /*   外置处理业务   */
      const {
        sModelsId, token, sModelsType, formRoute, peopleInfosId, peopleInfoData, app,
      } = this.props;
      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;
      if (commonUtils.isNotEmptyObject(masterConfig)) {
        masterData = commonFunc.getDefaultData(masterConfig);
      }
      masterData.handleType = 'add';
      masterData.sId = commonUtils.createSid();
      masterData.sFormId = sModelsId;
      masterData.maxBillNo = 'sBillNo';
      if (formRoute === '/contactsInfo') {
        if (commonUtils.isNotEmptyArr(peopleInfoData) && peopleInfosId !== '') {
          const peopleInfo = peopleInfoData.filter(item => item.sId === peopleInfosId);
          masterData = { ...masterData, ...peopleInfo[0] };
        }
      }
      let slaveData = [];
      const slaveSumData = [];
      let slaveChildData = [];
      const employeeData = [];
      let slave0Data = []; // 外发发货登记

      // const slaveTotal = [];
      // const tableDataTotal = {};
      let slaveAssignField = '';
      let slaveChildAssignField = '';
      console.log('copyTo', copyTo);
      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) };

        const copyToSlaveConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slave`.toLowerCase());
        slaveAssignField = commonUtils.isNotEmptyArr(copyToSlaveConfig) ? copyToSlaveConfig[0].sAssignField : '';
        if (sModelsType === 'production/productionReport') {
          copyTo.slaveData = commonUtils.isEmptyArr(copyTo.slaveData) ? [] : [copyTo.slaveData[0]];
        }
        if (slaveAssignField !== '') {
          for (const slaveItem of copyTo.slaveData) {
            const newCopyTo = {};
            newCopyTo.master = copyTo.masterData;
            newCopyTo.slave = slaveItem;
            const newSid = commonUtils.createSid();
            let slaveRow = commonFunc.getDefaultData(config.slaveConfig, newCopyTo, { newSid }); // 取默认值
            slaveRow = { ...slaveRow, ...commonFunc.getAssignFieldValue(slaveAssignField, slaveItem, newCopyTo) }; // 取赋值字段
            slaveRow.handleType = 'add';
            slaveRow.sId = newSid;
            slaveRow.sParentId = masterData.sId;
            slaveRow.sSqlConditionId = slaveRow.sId;

            if (sModelsType === 'production/productionReport') {
              if (!commonUtils.isEmpty(slaveRow.sWageId)) {
                slaveRow.dWageMoney = await commonBusiness.getFormulaValue({
                  token, sModelsId, masterData, tableDataRow: slaveRow, sComputeId: slaveRow.sWageId,
                });
              }
              if (!commonUtils.isEmpty(slaveRow.sConversionFormulaId)) {
                slaveRow.dConversionQty = await commonBusiness.getFormulaValue({
                  token, sModelsId, masterData, tableDataRow: slaveRow, sComputeId: slaveRow.sConversionFormulaId,
                });
              }
              if (commonUtils.isNotEmptyObject(slaveRow.sReportParam)) {
                slaveRow = { ...slaveRow, ...commonUtils.convertStrToObj(slaveRow.sReportParam) };
                // eslint-disable-next-line no-plusplus
                for (let i = 1; i < 7; i++) {
                  const iIndex = configNew.slaveConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
                  if (iIndex > -1 && !commonUtils.isEmpty(slaveRow[`sParam${i.toString()}`])) {
                    configNew.slaveConfig.gdsconfigformslave[iIndex].showName = slaveRow[`sParam${i.toString()}`];
                    configNew.slaveConfig.gdsconfigformslave[iIndex].bVisible = !slaveRow[`sParam${i.toString()}`].includes('参数值');
                  } else if (iIndex > -1) {
                    configNew.slaveConfig.gdsconfigformslave[iIndex].bVisible = false;
                  }
                }
              } else {
                // eslint-disable-next-line no-plusplus
                for (let i = 1; i < 7; i++) {
                  const iIndex = configNew.slaveConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
                  if (iIndex > -1) {
                    configNew.slaveConfig.gdsconfigformslave[iIndex].bVisible = false;
                  }
                }
              }
              const sMachineId = app.sMachineId;
              if (sMachineId) {
                const sSessionTeamId = localStorage.getItem(`${commonConfig.prefix}mobile_${sMachineId}`);
                if (sSessionTeamId) {
                  slaveRow.sTeamId = sSessionTeamId;
                }
              }
              let returnData = JSON.parse(localStorage.getItem(`${commonConfig.prefix}employeeData`));
              if (!commonUtils.isEmpty(slaveRow.sTeamId)) {
                if (commonUtils.isEmptyArr(returnData)) {
                  const url = `${commonConfig.server_host}eleteamemployee/getEleteamemployee?sModelsId=${sModelsId}&sTeamId=${slaveRow.sTeamId}&sSlaveId=${slaveRow.sId}&sParentId=${slaveRow.sParentId}`;
                  const dataReturn = (await commonServices.getService(token, url)).data;
                  if (dataReturn.code === 1) {
                    returnData = dataReturn.dataset.rows;
                  } else { /*   失败   */
                    this.props.getServiceError(dataReturn);
                  }
                }
                returnData.forEach((child) => {
                  employeeData.push({
                    sId: commonUtils.createSid(),
                    sParentId: masterData.sId,
                    sSlaveId: slaveRow.sId,
                    sEmployeeId: child.sEmployeeId,
                    sEmployeeName: child.sEmployeeName,
                    dProportion: child.dProportion !== 0 ? child.dProportion : commonUtils.convertFixNum(1 / returnData.length, 6),
                    handleType: 'add',
                  });
                });
                /* 班组变化时，算每个工作人员计件工资 */
                const dWageMoneyTotal = slaveRow.dWageMoney;
                if (commonUtils.isNotEmptyNumber(dWageMoneyTotal)) {
                  let dProportionTotal = 0;
                  employeeData.forEach((item) => {
                    if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
                      item.dProportion = parseFloat(item.dProportion);
                      dProportionTotal += commonUtils.convertFixNum(item.dProportion, 6);
                      dProportionTotal = commonUtils.convertFixNum(dProportionTotal, 6);
                    }
                  });
                  employeeData.forEach((item) => {
                    if (commonUtils.isNotEmptyNumber(item.dProportion)) {
                      const index1 = employeeData.findIndex(item1 => item1.sId === item.sId);
                      employeeData[index1] = {
                        ...item,
                        dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * dWageMoneyTotal, 6),
                        handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
                      };
                    }
                  });
                }


                const dWageMoney = commonUtils.isNotEmptyNumber(slaveRow.dWageMoney) ? commonUtils.convertFixNum(slaveRow.dWageMoney, 6) : 0;
                const dTimeMoney = commonUtils.isNotEmptyNumber(slaveRow.dTimeMoney) ? commonUtils.convertFixNum(slaveRow.dTimeMoney, 6) : 0;
                const dLossMoney = commonUtils.isNotEmptyNumber(slaveRow.dLossMoney) ? commonUtils.convertFixNum(slaveRow.dLossMoney, 6) : 0;
                slaveRow.dAllMoney = commonUtils.convertFixNum((dWageMoney + dTimeMoney) - dLossMoney, 6);
              }
            }
            slaveData.push(slaveRow);
          }
        }

        const copyToSlaveChildConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slaveChild`.toLowerCase());
        slaveChildAssignField = commonUtils.isNotEmptyArr(copyToSlaveChildConfig) ? copyToSlaveChildConfig[0].sAssignField : '';

        if (slaveChildAssignField !== '' && commonUtils.isNotEmptyArr(copyTo.slaveChildData)) {
          for (const slaveChildItem of copyTo.slaveChildData) {
            const newCopyTo = {};
            newCopyTo.master = copyTo.masterData;
            newCopyTo.slaveChild = slaveChildItem;

            let slaveChildRow = commonFunc.getDefaultData(config.slaveChildConfig, newCopyTo); // 取默认值
            slaveChildRow = {...slaveChildRow, ...commonFunc.getAssignFieldValue(slaveChildAssignField, slaveChildItem, newCopyTo)}; // 取赋值字段
            slaveChildRow.handleType = 'add';
            slaveChildRow.sId = commonUtils.createSid();
            slaveChildRow.sParentId = masterData.sId;
            slaveChildRow.sSqlConditionId = commonUtils.isNotEmptyArr(slaveData) ? slaveData[0].sId :'';
            slaveChildData.push(slaveChildRow);
          }
          masterData = this.props.handleMasterDefaultData(slaveChildData, this.isOutsourcedProcesses, 0, masterData, config);
        }

        /**
         * 外发工序处理
         */
        if (this.isOutsourcedProcesses) {
          let slave0AssignField = '';
          const copyToSlave0Config = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slave0`.toLowerCase());
          slave0AssignField = commonUtils.isNotEmptyArr(copyToSlave0Config) ? copyToSlave0Config[0].sAssignField : '';
          if (slave0AssignField !== '' && commonUtils.isNotEmptyArr(copyTo.slave0Data)) {
            for (const slave0Item of copyTo.slave0Data) {
              const newCopyTo = {};
              newCopyTo.master = copyTo.masterData;
              newCopyTo.slave0 = slave0Item;

              let slave0Row = commonFunc.getDefaultData(config.slave0Config, newCopyTo); // 取默认值
              slave0Row = {...slave0Row, ...commonFunc.getAssignFieldValue(slave0AssignField, slave0Item, newCopyTo)}; // 取赋值字段
              slave0Row.handleType = 'add';
              slave0Row.sId = commonUtils.createSid();
              slave0Row.sParentId = masterData.sId;
              slave0Data.push(slave0Row);
            }
            masterData = this.props.handleMasterDefaultData(slave0Data, this.isOutsourcedProcesses, 1, masterData, config);
          }
        }

        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');
            const slaveConfig = commonUtils.isEmptyObject(config) ? {} : config.slaveConfig;
            if (!isWait) {
              masterConfig = this.props.slaveConfig;
            }
            const iSqlIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sActValue');
            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) }; // 取赋值字段
                // tableDataRow.sTestReference = '15S|20S';
                const sTestReference = tableDataRow.sTestReference;
                const sParamObj = {};
                if (commonUtils.isNotEmptyObject(sTestReference)) { /* 若数据有值 渲染下拉框 */
                  if (sTestReference.indexOf('|') >= 0) {
                    sTestReference.split('|').forEach((itemField) => {
                      sParamObj[itemField] = itemField;
                    });
                    tableDataRow.sParamDropDownsActValue = sParamObj;
                    if (iSqlIndex > -1) {
                      slaveConfig.gdsconfigformslave[iSqlIndex].sDropDownType = 'sql';
                    } else {
                      slaveConfig.gdsconfigformslave[iSqlIndex].sDropDownType = '';
                    }
                  }
                } else { /* 若数据没有值 则渲染文本框 */
                  tableDataRow.isText = true;
                }
              }
              slaveData.push(tableDataRow);
            });
          }
        }
      }

      const iUserIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName && item.sControlName.includes('sTeamMachine'));
      if (iUserIndex > -1) {
        const sTeamMachineData = await this.props.getSqlDropDownData(sModelsId, 'master', masterConfig.gdsconfigformslave[iUserIndex], masterData);
        if(commonUtils.isNotEmptyArr(sTeamMachineData)) {
          masterData.sTeamId = sTeamMachineData[0].sTeamId;
          masterData.sTeamName = sTeamMachineData[0].sTeamName;
          masterData.sMachineId = sTeamMachineData[0].sMachineId;
          masterData.sMachineName = sTeamMachineData[0].sMachineName;
        }
      }

      /* 剔除订单到收款单新增空行（2022.7.8朱总要求)) */
      if (slaveData.length === 0 && commonUtils.isNotEmptyObject(slaveAssignField)) {
        const allTableData = {};
        allTableData.master = masterData;
        allTableData.slave = slaveData;
        let tableDataRowAdd = {};
        if (commonUtils.isNotEmptyObject(configNew.slaveConfig)) {
          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 = 0;
          slaveData.push(tableDataRowAdd);
        }
      }
      if (!commonUtils.isNotEmptyObject(config.slaveChildConfig)) {
        if (Array.isArray(slaveData)) {
          masterData = this.props.handleMasterDefaultData(slaveData, this.isOutsourcedProcesses, undefined, masterData, config);
        }
      }

      const state = {
        masterData,
        slaveData,
        slave0Data, // 外发工序
        slaveSumData:slaveData,
        slaveChildData,
        employeeData,
        slaveTotal: [],
        slaveSelectedRowKeys: [],
        searchUpDownData: {},
        enabled: true,
      };
      state.sUseInfo = '';
      if (isWait) {
        return state;
      } else {
        this.props.onSaveState(state);
        return true;
      }
    };

    baseSuccessFn = async() => {
      const {
        currentId, masterData, billnosetting, app, sModelsType, copyTo, dispatch,
      } = this.props;
      const { userinfo } = app;
      const onSendSocketMessage = this.props.handleSendSocketMessage;
      Toast.hide();

      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,
      });

      let bSucess = true;
      if (billnosetting.bAutoCheck && bSucess) {
        Toast.loading('正在审核单据,如果长期未响应,请到EBC中操作 ...', 5);
        await this.handleAudit(1);
      } else {
        /* 通过onRouterMobile路由跳转 */
        if (sModelsType === 'production/productionReport' && commonUtils.isNotEmptyObject(copyTo) && commonUtils.isNotEmptyObject(copyTo.listModelsId) && copyTo.listUrl && copyTo.listUrl.includes('commobileList')) {
          const sModelsId = copyTo.listModelsId;
          const sModelsType = copyTo.listModelsType;
          const url = '/indexMobile/commobileList';
          const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sModelsId}?sModelsId=${sModelsId}`;
          dispatch({
            type: 'content/onRouterMobile',
            payload: {
              url, /*   接口地址   */
              urlKey: sNameUrl,
              sModelsId,
              sModelsType,
              copyTo,
              listFilterCondition: copyTo.listFilterCondition,
            },
          });
        } else {
          window.history.back(-1);
        }
      }
      this.props.onSaveState({
        loading: false,
      });
    }

    /**   toolbar保存   */
    handleSaveData = async (params) => {
      const {
        token, sModelsId, app,
      } = this.props;
      const BtnSave = commonFunc.showMessage(app.commonConst, 'BtnSave');/* 保存 */
      params.optName = BtnSave;
      const returnData = await commonBusiness.saveData({ token, value: params, sModelsId, baseSuccessFn: this.baseSuccessFn });
      if (commonUtils.isNotEmptyObject(returnData)) {
       if (returnData.code !== 2) {
        await this.baseSuccessFn();
       }
       return true;
      } else {
        this.props.onSaveState({
          loading: false,
        });
        return false;
      }
    };

    /**   toolbar校验保存   */
    handleValidateSave = async () => {
      const {
        masterConfig, masterData, slaveConfig, slaveDelData, sModelsType, employeeConfig, employeeData, employeeDelData, token, sModelsId, app,
        slaveSumConfig, slaveSumData, slaveSumDelData, slaveChildConfig, slaveChildData, slaveChildDelData, slave0Config, slave0Data,
      } = this.props;
      let { slaveData } = this.props;
      if (!commonBusiness.validateMaster(masterConfig, masterData, this.props) || !commonBusiness.validateTable(slaveConfig, slaveData, this.props)) {
        this.props.onSaveState({
          loading: false,
        });
        return;
      }
      if(commonUtils.isNotEmptyObject(slave0Config)) {
        if (!commonBusiness.validateTable(slave0Config, slave0Data, this.props)) {
          this.props.onSaveState({
            loading: false,
          });
          return;
        }
      }
      if(commonUtils.isNotEmptyObject(slaveChildConfig)) {
        if (!commonBusiness.validateTable(slaveChildConfig, slaveChildData, this.props)) {
          this.props.onSaveState({
            loading: false,
          });
          return;
        }
      }
      if (slaveConfig && slaveConfig.bNotCanEmpty && commonUtils.isEmptyArr(slaveData)) {
        Toast.info(commonFunc.showMessage(app.commonConst, 'slaveNotNull')); // 从表不能为空！
        this.props.onSaveState({
          loading: false,
        });
        return;
      }
      const params = {
        sFieldName: 'dAuxiliaryQty',
        tableDataRow: commonUtils.isNotEmptyArr(slaveChildData) ? slaveChildData[0] : {},
      }
      // 汇总到从表方法
      const slaveNewData = await this.handleWriteBack(params, true);
      if(commonUtils.isNotEmptyArr(slaveNewData)) {
        slaveData = await this.handleWriteBack(params, true);
        console.log('汇总从表：', slaveData);
      }
      const data = [];
      data.push(commonBusiness.mergeData('master', masterConfig.sTbName, [masterData]));

      if (sModelsType === 'production/productionReport') {
        for (const tableDataRow of slaveData) {
          const sWageId = tableDataRow.sWageId;
          tableDataRow.dWageMoney = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId: sWageId,
          });
          const dWageMoneyTotal = tableDataRow.dWageMoney;
          let dProportionTotal = 0;
          const employeeSlaveData = employeeData.filter(item => item.sSlaveId === tableDataRow.sId);
          employeeSlaveData.forEach((item) => {
            if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
              dProportionTotal += commonUtils.convertFixNum(item.dProportion, 6);
            }
          });
          employeeSlaveData.forEach((item) => {
            if (commonUtils.isNotEmptyNumber(item.dProportion)) {
              const index1 = employeeData.findIndex(item1 => item1.sId === item.sId);
              employeeData[index1] = {
                ...item,
                dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dWageMoney, 0), 6),
                dTimeMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dTimeMoney, 0), 6),
                dLossMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dLossMoney, 0), 6),
                dOtherMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dOtherMoney, 0), 6),
                dJobMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dJobMoney, 0), 6),
                handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
              };
            }
          });
          /* 选择计件方案后 算总金额 */
          const dWageMoney = commonUtils.isNotEmptyNumber(dWageMoneyTotal) ? commonUtils.convertFixNum(dWageMoneyTotal, 6) : 0;
          const dTimeMoney = commonUtils.isNotEmptyNumber(tableDataRow.dTimeMoney) ? commonUtils.convertFixNum(tableDataRow.dTimeMoney, 6) : 0;
          const dLossMoney = commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney) ? commonUtils.convertFixNum(tableDataRow.dLossMoney, 6) : 0;
          tableDataRow.dAllMoney = commonUtils.convertFixNum((dWageMoney + dTimeMoney) - dLossMoney, 6);
          tableDataRow.handleType = commonUtils.isEmpty(tableDataRow.handleType) ? 'update' : tableDataRow.handleType;
        }
      }
      data.push(commonBusiness.mergeData('slave', slaveConfig.sTbName, slaveData, slaveDelData));

      if(commonUtils.isNotEmptyObject(slaveChildConfig)) {
        data.push(commonBusiness.mergeData('slaveChild', slaveChildConfig.sTbName, slaveChildData, slaveChildDelData));
      }
      // 外发工序
      if(commonUtils.isNotEmptyObject(this.props.slave0Config) && this.isOutsourcedProcesses) {
        data.push(commonBusiness.mergeData('slave0', this.props.slave0Config.sTbName, this.props.slave0Data, this.props.slave0DelData));
      }

      if (sModelsType === 'production/productionReport' && !commonUtils.isEmpty(employeeConfig)) {
        data.push(commonBusiness.mergeData('employee', employeeConfig.sTbName, employeeData, employeeDelData));
        localStorage.setItem(`${commonConfig.prefix}sTeamId`, slaveData[0].sTeamId);
        localStorage.setItem(`${commonConfig.prefix}employeeData`, JSON.stringify(employeeData));
        /* 手机端报产选了机台后，进去报产，选了班组，确认之后，在返回去报第二个的时候，默认班组 */
        if (commonUtils.isNotEmptyObject(slaveData[0])) {
          const sMachineId = slaveData[0].sMachineId;
          const sTeamId = slaveData[0].sTeamId;
          if (sMachineId && sTeamId) {
            localStorage.setItem(`${commonConfig.prefix}mobile_${sMachineId}`, sTeamId);
          }
        }
      }
      if(commonUtils.isNotEmptyObject(slaveSumConfig) && slaveSumConfig.sGrd && slaveSumConfig.sGrd.includes('sumTableSelect')) {
        data.push(commonBusiness.mergeData('slaveSum', slaveSumConfig.sTbName, slaveSumData, slaveSumDelData));
      }
      console.log('data', data);
      Toast.loading('正在保存数据,请稍后 ...', 0);
      this.handleSaveData({ data, sClientType: '1', sSysLogSrcId: masterData.sId }).finally(() => {
        Toast.hide();
      });
    };

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

    /**   数据审核   */
    dataAudit = async (flag, tmpCheck, isWait) => {
      /*   待用数据声明   */
      const {
        sModelsId, masterData, app, masterConfig, slaveConfig, token, sModelsType, slaveData, employeeConfig, copyTo, dispatch, slave0Config,
        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 : '',
        },
      };
      /*   数据审核   */
      const url = `${commonConfig.server_host}business/doExamine?sModelsId=${sModelsId}`;
      const returnData = (await commonServices.postValueService(app.token, value, url)).data;
      if (isWait) {
        return returnData;
      } else {
        /*   接收返回值   */
        await this.handleGetData(masterConfig, slaveConfig);
        const check = commonFunc.showMessage(app.commonConst, 'BtnExamine');/* 审核 */
        const BtnCancelExamine = commonFunc.showMessage(app.commonConst, 'BtnCancelExamine');/* 销审 */
        if (sModelsType === 'production/productionReport' && !commonUtils.isEmpty(employeeConfig)) {
          await this.handleGetMemoData(employeeConfig);
        }
        if(commonUtils.isNotEmptyObject(slave0Config) && this.isOutsourcedProcesses) {
          await this.handleGetMemoData(slave0Config);
        }
        if(commonUtils.isNotEmptyObject(slaveChildConfig) ) {
          await this.handleGetMemoData(slave0Config);
        }
        if (this.props.refresh !== undefined) {
          this.props.refresh();
        }
        if (returnData.code === 1) { /*   成功   */
          this.props.onSaveState({
            loading: false,
          });
          if (flag === 1) {
            /*   审核   */
            const { outData } = returnData.dataset.rows[0].dataSet;
            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();
                // }
                Toast.fail(check + outData[0].sReturn);
                return;
              }
              const checkConditions = [];
              let checkPersonData = {};
              sReturnArray.forEach((item) => {
                const checkCondition = item.split('-')[2];
                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,
                  });
                } else { /*   失败   */
                  this.props.getServiceError({ msg: check + dataReturn });
                }
              }
            } else {
              Toast.success(check + returnData.msg);
              if (sModelsType === 'production/productionReport' && commonUtils.isNotEmptyObject(copyTo) && commonUtils.isNotEmptyObject(copyTo.listModelsId) && copyTo.listUrl && copyTo.listUrl.includes('commobileList')) {
                const sModelsId = copyTo.listModelsId;
                const sModelsType = copyTo.listModelsType;
                const url = '/indexMobile/commobileList';
                const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sModelsId}?sModelsId=${sModelsId}`;
                dispatch({
                  type: 'content/onRouterMobile',
                  payload: {
                    url, /*   接口地址   */
                    urlKey: sNameUrl,
                    sModelsId,
                    sModelsType,
                    copyTo,
                    returnFilterCondition: copyTo.listFilterCondition,
                  },
                });
              } else {
                window.history.back(-1);
              }
            }
          } else {
            /*   消审   */
            const { outData } = returnData.dataset.rows[0].dataSet;
            if (commonUtils.isNotEmptyStr(outData[0].sReturn)) {
              Toast.fail(outData[0].sReturn);
            } else {
              // if (this.props.app.currentPane.refresh !== undefined) {
              //   this.props.app.currentPane.refresh();
              // }
              Toast.success(BtnCancelExamine + returnData.msg);
              window.history.back(-1);
            }
          }
        } else { /*   失败   */
          this.props.getServiceError(returnData);
          this.props.onSaveState({
            loading: false,
          });
        }
        return true;
      }
    };
    handleGetMsg = (str) => {
      const msgArr = commonUtils.isNotEmptyObject(str) ? str.split('xpm'): '';
      const divStr = [];
      if(commonUtils.isNotEmptyArr(msgArr)) {
        for (let i = 0; i < msgArr.length; i ++) {
          divStr.push(<p>{msgArr[i]}</p>);
        }
      }
      return divStr;
    }
    /* 调用后台配置的接口 */
    handleThirdInterfaceCall = async (obj, showTip, key, sListSlaveId) => {
      let bResult = false;
      const {
        app, sModelsId, masterData, slaveSelectedRowKeys,
      } = this.props;
      const sInterfaceName = obj.sInterfaceName;
      const value = { sId: commonUtils.isNotEmptyObject(sListSlaveId) ? sListSlaveId : masterData.sId, userInfo: app.userinfo };
      const url = `${commonConfig.interface_host}interfaceDefine/callthirdparty/${sInterfaceName}?sModelsId=${sModelsId}`;
      const returnData = (await commonServices.postValueService(app.token, value, url, app)).data;
      if (returnData.code === 1) {
        bResult = true;
      } else if (returnData.code === -8) {
        Modal.info({
          title: '温馨提示:',
          width: 200,
          content: (
            <div>
              {this.handleGetMsg(returnData.msg)}
            </div>
          ),
          okText: '确认',
          onOk() {},
        });
        bResult = true;
      } else {
        bResult = false;
        this.props.getServiceError(returnData);
      }
      return bResult;
    }

    handleWriteBack = async (params, isWait) => {
      const {
        sFieldName,
        tableDataRow,
      } = params;
      const {
        slaveSelectedRowKeys,
        slaveData,
        slaveChildConfig,
        slaveChildData,
      } = this.props;
      if (commonUtils.isEmptyArr(slaveData) || commonUtils.isEmptyArr(slaveChildData)) {
        return;
      }
      const sId = slaveSelectedRowKeys[0] || slaveData[0].sId;
      const iSlaveIndex = slaveData.findIndex(item => item.sId === sId);
      const slaveDataRow = slaveData[iSlaveIndex];
      const slaveChildFilter = slaveChildData.filter(item => item.sSqlConditionId === slaveDataRow.sSqlConditionId);

      // 需要汇总的字段
      const writeBackFields = ['dAuxiliaryQty', 'dProductQty', 'dArrivalQty', 'sBarcode', 'sDefineNo'];

      const bHasiType = slaveChildConfig.gdsconfigformslave.find(item => ['itype', 'iType'].includes(item.sName));

      if (bHasiType && ['dAuxiliaryQty', 'itype', 'iType', 'dProductQty'].includes(sFieldName)) {
        // 需要汇总到从表的字段 1:dAuxiliaryQty，2:dEscrowQty，3:dGiveAuxiliaryQty
        let dAuxiliaryQty = 0;
        let dEscrowAuxiliaryQty = 0;
        let dGiveAuxiliaryQty = 0;
        let dProductQty = 0;
        slaveChildFilter.forEach(item => {
          const dataRow = item.sId === params.tableDataRow.sId ? params.tableDataRow : item;
          const { itype, iType } = dataRow;
          const type = itype !== undefined ? itype : iType !== undefined ? iType : 11;
          console.log('s', dataRow.sId, type);
          if (type === 1) {
            dAuxiliaryQty +=  commonUtils.convertToNum(commonUtils.isNull(dataRow.dAuxiliaryQty, 0), 2);
          } else if (type === 2) {
            dEscrowAuxiliaryQty +=  commonUtils.convertToNum(commonUtils.isNull(dataRow.dAuxiliaryQty, 0), 2);
          } else if (type === 3) {
            dGiveAuxiliaryQty +=  commonUtils.convertToNum(commonUtils.isNull(dataRow.dAuxiliaryQty, 0), 2);
          } else if (type === 10) {
            dAuxiliaryQty +=  commonUtils.convertToNum(commonUtils.isNull(dataRow.dProductQty, 0), 2);
          } else if (type === 11) {
            dProductQty +=  commonUtils.convertToNum(commonUtils.isNull(dataRow.dAuxiliaryQty, 0), 2);
          } else if (type === 12) {
            dProductQty +=  commonUtils.convertToNum(commonUtils.isNull(dataRow.dProductQty, 0), 2);
          }
        });

        const iIndex = slaveData.findIndex(item => item.sId === sId);
        let tableDataRow = {};
        tableDataRow = await this.handleTableChange('slave', 'dEscrowAuxiliaryQty', { dEscrowAuxiliaryQty }, sId, [], true);
        slaveData[iIndex] = tableDataRow;
        window.tmpSlaveData = slaveData;
        tableDataRow = await this.handleTableChange('slave', 'dGiveAuxiliaryQty', { dGiveAuxiliaryQty }, sId, [], true);
        slaveData[iIndex] = tableDataRow;
        window.tmpSlaveData = slaveData;
        tableDataRow = await this.handleTableChange('slave', 'dAuxiliaryQty', { dAuxiliaryQty }, sId, [], true);
        slaveData[iIndex] = tableDataRow;
        if (slaveChildFilter.some(item => item.itype === 11 || item.iType === 11 || item.itype === 12 || item.iType === 12)) {
          window.tmpSlaveData = slaveData;
          tableDataRow = await this.handleTableChange('slave', 'dProductQty', { dProductQty }, sId, [], true);
          slaveData[iIndex] = tableDataRow;
        }
        window.tmpSlaveData = null;
        console.log('切换从表：', slaveData);
        if(isWait) {
          return  slaveData;
        } else {
          this.props.onSaveState({ slaveData });
        }
      } else if (bHasiType && writeBackFields.includes(sFieldName)) {
        let dQty = 0;
        slaveChildFilter.forEach(item => {
          const dataRow = item.sId === tableDataRow.sId ? tableDataRow : item;
          dQty += commonUtils.isNull(dataRow[sFieldName], 0);
        });
        this.props.onDataChange('slave', sFieldName, { [sFieldName]: dQty }, sId, [], false);
      }
    }

    handleForm = (form) => {
      this.form = form;
    };
    /**   点击修改按钮操作  */
    handleEdit = () => {
      const {
        slaveConfig, masterConfig, app, dispatch, currentId, slaveChildConfig, slave0Config,
      } = this.props;
      const { userinfo } = app;

      this.props.app.webSocket.onmessageTmp = (msg) => {
        const rtmsg = JSON.parse(msg.data);
        if (rtmsg.action === 'showMsg') {
          Toast.info(rtmsg.msg);
          this.props.onSaveState({ loading: false });
        } else if (rtmsg.action === 'update') {
          this.handleGetData(masterConfig, slaveConfig);
          if(commonUtils.isNotEmptyObject(slave0Config) && this.isOutsourcedProcesses) {
              this.handleGetMemoData(slave0Config);
          }
          if(commonUtils.isNotEmptyObject(slaveChildConfig) ) {
              this.handleGetMemoData(slaveChildConfig);
          }
          //
          this.props.onSaveState({ enabled: true, loading: false });
        }
      };
      this.props.handleSendSocketMessage('update', 'showMsg', currentId, userinfo.sId, null, null);
    };

    /**   获取主表、从表、审核表数据   */
    handleGetData = async (masterConfig, slaveConfig) => {
      const { currentId, masterData } = this.props; /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : masterData?.sId;
      await this.props.handleGetDataOne({ name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' } });
      if (!commonUtils.isEmptyObject(slaveConfig) && slaveConfig.sSqlStr !== "noQuery") {
        this.props.handleGetDataSet({
          name: 'slave', configData: slaveConfig, condition: { sSqlCondition: { sParentId: sId } },
        });
      }
    };

    handleGetMemoData = async (tableConfig,sTableName) => {
      const { currentId,masterData } = this.props; /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : masterData?.sId;
      this.props.handleGetDataSet({
        name: sTableName, configData: tableConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
    };

    handleMasterChange = async (name, sFieldName, changeValue, sId, dropDownData, isWait, masterDataNew) => {
      // this.handleCustomerChange(name, changeValue);
      const {
        sModelsId, sModelsType: sModelsTypeOld, masterData: masterDataOld, slaveData, app, masterConfig, slaveConfig, token,
      } = this.props;
      const addState = {};
      const sModelsType = commonUtils.isEmpty(sModelsTypeOld) ? '' : sModelsTypeOld;
      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 {
            Toast.info(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', []);
      } else 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) {
              Toast.fail(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') {
        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 = '';
          }
          const tDueDateIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'tDueDate');
          if (tDueDateIndex > -1) {
            masterConfig.gdsconfigformslave[tDueDateIndex].iTag = 1;
            delete masterData.tDueDate;
          }
        }
        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;
          }
          const tDueDateIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'tDueDate');
          if (tDueDateIndex > -1) {
            masterConfig.gdsconfigformslave[tDueDateIndex].iTag = 1;
            delete masterData.tDueDate;
          }
        }
        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);
      const masterDataAfter = commonBusiness.getKeyUpEvent(name, sFieldName, masterConfig, returnData.masterData, {}, true);
      if (commonUtils.isNotEmptyObject(masterDataAfter)) {
        returnData.masterData = masterDataAfter;
      }
      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') {
        const slaveDataNew = [];
        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;
            const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';

            tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'sTaxId', masterData, tableDataRow);
            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, tableDataRow, sComputeId,
                  });
                  tableDataRow.dMaterialsMoney = dMaterialsMoney;
                  tableDataRow = commonBusiness.getCalculateMoney(app, masterData, tableDataRow, 'Materials');
                }
              }
            }
          }
          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.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');
          const iSqlIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sActValue');
          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) }; // 取赋值字段
              // tableDataRow.sTestReference = '15S|20S';
              const sTestReference = tableDataRow.sTestReference;
              const sParamObj = {};
              if (commonUtils.isNotEmptyObject(sTestReference)) {
                if (sTestReference.indexOf('|') >= 0) {
                  sTestReference.split('|').forEach((itemField) => {
                    sParamObj[itemField] = itemField;
                  });
                  tableDataRow.sParamDropDownsActValue = sParamObj;
                  if (iSqlIndex > -1) {
                    slaveConfig.gdsconfigformslave[iSqlIndex].sDropDownType = 'sql';
                  } else {
                    slaveConfig.gdsconfigformslave[iSqlIndex].sDropDownType = '';
                  }
                }
              } else { /* 若数据没有值 则渲染文本框 */
                tableDataRow.isText = true;
              }
            }
            slaveDataNew.push(tableDataRow);
          });
          addState.slaveData = slaveDataNew;
        } else {
          Toast.fail(dataReturn.msg);
        }
      }
      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;
      }
    }

    handleFocus = (showConfig) => {
      this.props.onSaveState({
        currentConfig:showConfig
      });
    }
    handleBlur = (showConfig) => {

    }


    /** 表格数据更改 */
    // name 不写完整的state名称作用为了要用到total // (name, changeValue, sId, dropDownData)
    handleTableChange = async (name, sFieldName, changeValue, sId, dropDownData, isWait) => {
      /*   从CommonBase获取默认参数   */
      const {
        [`${name}Data`]: tableData, sModelsType, sModelsId, token, app,
      } = this.props;
      if (name === 'control' && sModelsType === '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);

        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 === 'sProductId' || sFieldName === 'sProductName' || sFieldName === 'sProductStyle' || sFieldName === 'sProductUnit' || sFieldName === 'sProductNo'
          || sFieldName === 'sCustomerProductNo' || sFieldName === 'sProductClassifyId' || sFieldName === 'sProductClassifyName') && !commonUtils.isEmpty(tableDataRow.sProductId)) {
          const productIdDropDown = commonUtils.getStoreDropDownData(sModelsId, 'slave', sFieldName);
          const iProductIdIndex = commonUtils.isEmptyArr(productIdDropDown) ? -1 : productIdDropDown.findIndex(item => item.sId === tableDataRow.sProductId);
          if (iProductIdIndex === -1) {
            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 = '';
          }
          if ((sFieldName === 'sProductId' || sFieldName === 'sProductName' || sFieldName === 'sProductNo') && !commonUtils.isEmpty(changeValue.sProductId)) {
            const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
            const value = {
              sProName: 'Sp_Cashier_GetProductPrice',
              paramsMap: {
                sProductGuid: changeValue.sProductId,
              },
            };
            const returnData = (await commonServices.postValueService(app.token, value, url)).data;
            if (returnData.code === 1) {
              tableDataRow.dProductPrice = 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, 'dProductQty', app, token, models);
            }
            tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dProductQty', masterData, tableDataRow);
            // else {
            //   this.props.getServiceError(returnData);
            // }
          }
        } else if (sModelsType === '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/') && sFieldName === 'dTotalMoney') { /* 付款单、收款单，从表付款/收款金额改变，会自动汇总到主表付款金额中 */
          const addStata = {};
          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);
          }
          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);
            }
          });
          masterData = { ...masterData, ...addStata };
          this.props.onSaveState({ masterData });
        }
        // 取工艺卡数据
        if (sModelsType === '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 materialsReturnData = this.otherTableDel('materials', controlSelectedData);
              const processReturnData = this.otherTableDel('process', controlSelectedData);
              const controlReturnData = this.props.onDataRowDel('control', true, controlSelectedData);
              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)) {
                // 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;
                  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);
                });
              }
              this.props.onSaveState({ controlData, materialsData, processData });
            }
          }
        } else if (sModelsType === '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);
          }
          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;
            }
          }
          // else {
          //   this.props.getServiceError(returnData);
          // }
        } else if (sModelsType === 'sales/salesCheck' && sFieldName === 'dLossMoney' && name === 'slave') {
          if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcMoney) && commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney)) {
            const dPprice = this.props.getFloatNum('dProductPrice'); /* 获取系统设定小数位 */
            tableDataRow.dProductMoney = commonUtils.convertFixNum(tableDataRow.dSrcMoney - tableDataRow.dLossMoney, dPprice);
          } else if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcMoney) && commonUtils.isEmptyNumber(tableDataRow.dLossMoney)) {
            tableDataRow.dProductMoney = tableDataRow.dSrcMoney;
            tableDataRow.dLossMoney = 0;
          }
        }
        /* 各种金额，税额，价格计算 */
        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, sFieldName, app, token, models);
        }
        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;
          /* 根据客户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');
          }
        }
        const otherData = {};
        if (this.isOutsourcedProcesses && sFieldName === 'dAuxiliaryQty' && name === 'slaveChild') {
          const { slaveChildData, slaveData } = this.props;
          const originData = slaveChildData.find(i => i && i.sId === sId)?.dAuxiliaryQty || 0;
          if (Array.isArray(slaveChildData) && Array.isArray(slaveData)) {
            const value = (Number(slaveData?.[0]?.dAuxiliaryQty) +
              Number(changeValue[sFieldName] || 0) -
              Number(originData)).toFixed(2) || slaveData?.[0]?.dAuxiliaryQty;
            otherData.slaveData = [{...slaveData?.[0] || {}, dAuxiliaryQty: value }];
          }
        }
        if (name === 'slaveChild') {
          const params = {
            sFieldName: 'dAuxiliaryQty',
            tableDataRow,
          }
          // 汇总到从表方法
         await this.handleWriteBack(params);
        }

       const tabPage = this.handleNameToIndex(name);
       if ((typeof tabPage !== 'undefined') || !commonUtils.isNotEmptyObject(this.props.slaveChildConfig)) {
        const data = [ ...tableData ];
        data[iIndex] = tableDataRow;
        const master = this.props.handleMasterDefaultData(data, this.isOutsourcedProcesses, tabPage, masterData);
        this.props.onSaveState({ masterData: master });
       }


        if (isWait) {
          return tableDataRow;
        } else {
          tableData[iIndex] = tableDataRow;
          this.props.onSaveState({ [`${name}Data`]: tableData, enabled: true, ...otherData });
        }
      }
    };

    handleNameToIndex = (name) => {
      return ({
        slaveChild: 0,
        slave0: 1,
        slave: undefined,
      }[name]);
    }

    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.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.bInverse) {
          tableDataRow = commonBusiness.getAuxiliaryQty(app, tableDataRow, sFieldName, 'dAuxiliaryLossQty');
        } else if (tableDataRow.bInverse) {
          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;
    }

    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 });
    }

    handleMobileScan = (fieldConfig, tbName, record) => {
      if (commonUtils.isNotEmptyObject(fieldConfig)) {
        const sFieldName = fieldConfig.sName;
        const newTableName = 'master';
        BarCodeUtil.startScan(async (type, code) => {
          const {
            slaveConfig, sModelsId, masterData, slaveData, sModelsType, masterConfig,
          } = this.props;
          /* 规则定义
          材料
          sDefineNo: codeArr[0],  --唯一码
          sMaterialsName: codeArr[1], --材料名称
          sMaterialsStyle: codeArr[2], --材料规格
          dAuxiliaryQty: codeArr[3],  --数量
          sWareHouseName: codeArr[4], --仓库名称
          sLocationName: codeArr[5], --名称
          sDefineNo2: codeArr[6], --二维码
          tInStoreDate: codeArr[7], --入库日期
          sMaterialsId: codeArr[8], --材料ID
          sWareHouseId: codeArr[9], --仓库ID
          sLocationId: codeArr[10], --sLocationId
          成品
          sDefineNo: codeArr[0],  --唯一码
          sProductName: codeArr[1], --产品名称
          sProductStyle: codeArr[2], --产品规格
          dProductQty: codeArr[3], --产品数量
          sWarehouseName: codeArr[4], --仓库名称
          sLocationName: codeArr[5], --仓库名称
          sDefineNo2: codeArr[6], --二维码
          tInStoreDate: codeArr[7], --入库日期
          sProductId: codeArr[8], --产品ID
          sWareHouseId: codeArr[9], --仓库ID
          sLocationId: codeArr[10],
          sCustomerName: codeArr[11], --客户名称
          sCustomerShort: codeArr[12],
          sOrderNo: codeArr[13], --订单号
          sWorkOrderNo: codeArr[14], --工单号
          sCustomerOrderNo: codeArr[15], --客户编号
          sCustomerProductNo: codeArr[16], --客户产品编号
          */
          // const slaveData = [];
          let slaveDataObj = {};
          let masterdataObj = {};
          let slaveDataObjAdd = {};
          const masterDataObjAdd = {};
          if (commonUtils.isEmptyObject(code)) {
            Toast.fail('二维码扫码失败！', 1);
            return;
          }
          const codeArr = code.split('|');
          let models = '';
          if (codeArr.length === 12) { /* 材料 */
            models = 'Materials';
          } else if (codeArr.length === 17) { /* 成品 */
            models = 'Product';
          } else {
            models = 'Single'; /* 单一的 */
          }
          if (models === 'Single') { /* sModelsType === 'purchase/purchaseInstore' 扫码入库、扫码领料(唯一码) */
            /* 取第一条码 */
            const sCode = codeArr.length > 0 ? codeArr[0] : '';
            /* 如果条码已存在，提示 */
            // const iIndex = slaveData.findIndex(item => commonUtils.isNotEmptyObject(item.sDefineNo) && item.sDefineNo === sDefineNo);
            // if (iIndex > -1) {
            //   Toast.fail('条码已存在!!!', 1);
            //   return;
            // }
            if (tbName === 'master') {
              masterData[sFieldName] = sCode;
            }
            if (tbName === 'master') {
              masterdataObj = {
                ...masterData, [sFieldName]: sCode,
              };
            } else if(tbName === 'slave')  {
              if(commonUtils.isNotEmptyArr(slaveData)) {
                /* 如果是从表的字段配置了扫码 那么则将值赋值到字段上 */
                const iIndex = commonUtils.isNotEmptyArr(slaveData) ? slaveData.findIndex(item => item.sId === record.sId) : -1;
                if (iIndex > -1) {
                  const newType =   commonUtils.isEmpty(slaveData[iIndex].handleType) ? 'update' : slaveData[iIndex].handleType;
                  slaveData[iIndex] = { ...slaveData[iIndex], [sFieldName]: sCode, handleType :newType };
                }
              }
            }



            /* 读取扫码配置 */
            // const btnScanConfigs = masterConfig.gdsconfigformslave.filter(item => item.sName === '' && item.sControlName.indexOf('BtnScan') > -1);
            // const AssignField = commonUtils.isNotEmptyArr(btnScanConfigs) ? btnScanConfigs[0].sAssignField : '';
            // /* 唯一码调接口 */
            // let sqlDataRow ={};
            // if(commonUtils.isNotEmptyArr(btnScanConfigs)) {
            //   const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', btnScanConfigs[0], masterdataObj);
            //   if(commonUtils.isNotEmptyArr(sqlDropDownData)) {
            //     sqlDataRow = sqlDropDownData[0];
            //   }
            // }
            // slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, masterdataObj) }; // 取主表赋值字段
            // if(commonUtils.isNotEmptyObject(sqlDataRow)) {
            //   slaveDataObj = { ...slaveDataObj, ...commonFunc.getAssignFieldValue(AssignField, sqlDataRow) }; // 取接口数据源赋值字段
            // }
            // slaveDataObj.sParentId = masterdataObj.sId;
            // if (commonUtils.isNotEmptyArr(slaveData)) {
            //   const len = slaveData.length;
            //   const sDefineNoNew = slaveData[len - 1].sDefineNo;
            //   const { handleType } = slaveData[len - 1];
            //   /* 若slaveData 最后一条数据没有条形码，则赋值条形码；否则新增一条数据 */
            //   if (commonUtils.isEmptyArr(sDefineNoNew)) {
            //     slaveDataObj.handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
            //     // slaveData[len - 1] = slaveDataObj;
            //     slaveData[len - 1] = { ...slaveData[len-1], ...slaveDataObj};
            //   } else {
            //     slaveDataObj.sId = commonUtils.createSid();
            //     slaveDataObj.handleType = 'add';
            //     slaveData.push(slaveDataObj);
            //   }
            // } else {
            //   slaveDataObj.sId = commonUtils.createSid();
            //   slaveDataObj.handleType = 'add';
            //   slaveData.push(slaveDataObj);
            // }
            if (sModelsType === 'scan/productionmaterials') { /* 只有扫码领料连续扫码 */
              this.handleClick('slave', 'scan'); /* 连续扫码 */
            }
          } else {
            Toast.fail('二维码不存在!!!', 1);
          }
          if (models !== 'Single') {
            slaveData.push(slaveDataObj);
          }
          this.props.onSaveState({ slaveData, masterData: masterdataObj });
        });
      }
    }

    handleButtonClick = async (name ) => {
      if(name === 'BtnRefresh') {
        const { sModelsType, slaveConfig, masterConfig, employeeConfig, slave0Config, slaveChildConfig}= this.props;
        await this.handleGetData(masterConfig, slaveConfig);
        if (sModelsType === 'production/productionReport' && !commonUtils.isEmpty(employeeConfig)) {
          await this.handleGetMemoData(employeeConfig);
        }
        if(commonUtils.isNotEmptyObject(slave0Config) && this.isOutsourcedProcesses) {
          await this.handleGetMemoData(slave0Config, 'slave0Child');
        }
        if(commonUtils.isNotEmptyObject(slaveChildConfig) ) {
          await this.handleGetMemoData(slaveChildConfig, 'slaveChild');
        }
        // if (this.props.refresh !== undefined) {
        //   this.props.refresh();
        // }
      }

    }
    render() {
      return (
        <ChildComponent
          {...this.props}
          {...this.state}
          onAdd={this.handleAdd}
          onSubmit={this.handleValidateSave}
          onSaveData={this.handleSaveData}
          onReturnForm={this.handleForm}
          onChange={this.handleMasterChange}
          onFocus ={ this.handleFocus}
          onBlur ={ this.handleBlur}
          onDataChange={this.handleTableChange}
          onMaterialsChange={this.handleMaterialsChange}
          onAudit={this.handleAudit}
          onEdit={this.handleEdit}
          isOutsourcedProcesses={this.isOutsourcedProcesses}
          onMobileScan={this.handleMobileScan}
          handleNameToIndex={this.handleNameToIndex}
          onButtonClick = {this.handleButtonClick}
        />
      );
    }
  };
};
