/* eslint-disable prefer-destructuring,no-loop-func */
/**
 * Created by mar105 on 2019-01-04.
 */

import React, { Component } from 'react';
import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import { Modal, Layout, Spin, Avatar, Select, message, Button } from 'antd-v4';
import ProcessUp from '../../../assets/processUp.svg';
import ProcessDown from '../../../assets/processDown.svg';
import DisableProcessUp from '../../../assets/disableprocessUp.svg';
import DisableProcessDown from '../../../assets/disableprocessDown.svg';
import ProcessTop from '../../../assets/processTop.svg';
import DisableProcessTop from '../../../assets/disableprocessTop.svg';
import ProcessBottom from '../../../assets/processBottom.svg';
import DisableProcessBottom from '../../../assets/disableprocessBottom.svg';
import CommonSales from '../../Common/CommonBillEvent';/* 继承销售模块业务功能 */
import * as commonFunc from '../../Common/commonFunc';/* 通用单据方法 */ /* 通用单据方法 */
import Toolbar from '../../Common/ToolBar/ToolBarNew';
import StaticEditTable from '../../Common/CommonTable';/* 可编辑表格 */
import styles from '../../../index.less';
import selfstyles from '../index.less';
import CommonView from '../../Common/CommonView';
import CommonBase from '../../Common/CommonBase';/* 获取配置及数据 */
import * as commonUtils from '../../../utils/utils';/* 通用方法 */
import * as commonBusiness from '../../Common/commonBusiness';/* 单据业务功能 */
import commonConfig from '../../../utils/config';
import * as commonServices from '../../../services/services';/*   服务类   */
import CommonListSelect from '../../Common/CommonListSelect';
import CommonListSelectFlex from '../../Common/CommonListSelectFlex';/* 可编辑的选择界面 */
import CommonListSelectTree from '../../Common/CommonListSelectTree';/* 树形选择界面 */
// import SlaveMemo from '../../Common/SlaveMemo';
import SplitPaste from '../WorkOrder/SplitPaste';/* 选择界面 */
import AntdDraggableModal from '../../Common/AntdDraggableModal';
import ShowType from '../../Common/CommonComponent';
import ContextMenuModal from '../../Common/ContextMenuModal';
import SvgIcon from '../../SvgIcon';

const { Header, Content, Sider } = Layout;
const { Option } = Select;
const { confirm } = Modal;

class ProcessCard extends Component {
  constructor(props) {
    super(props);
    this.state = {
      fastOrderModalVisible: false,
    };
  }

  async componentWillReceiveProps(nextProps) {
    let {
      controlColumn, materialsColumn, processColumn, dailyColumn, colorColumn,
    } = nextProps;
    const { formData, currentId } = nextProps;
    if (commonUtils.isEmptyArr(controlColumn) && formData.length > 0) {
      const sId = currentId || nextProps.masterData?.sId || '';
      /* 数据Id */
      const masterConfig = formData.filter(item => !item.bGrd)[0];
      /* bGrd代表是否是表格 */
      const slaveConfig = formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult')[0];
      const slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
      const checkConfig = formData.filter(item => item.bGrd && item.sTbName === 'sysbillcheckresult')[0];
      const checkColumn = commonFunc.getHeaderConfig(checkConfig);

      const controlConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductcontrol'.toUpperCase())[0];
      controlColumn = commonFunc.getHeaderConfig(controlConfig, controlColumn);

      const materialsConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductmaterials'.toUpperCase())[0];
      materialsColumn = commonFunc.getHeaderConfig(materialsConfig, materialsColumn);

      const processConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductprocess'.toUpperCase())[0];
      const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sMachineId');
      if (iIndex > -1) {
        processConfig.gdsconfigformslave[iIndex].bReGetDropDown = true;
      }
      processColumn = commonFunc.getHeaderConfig(processConfig, processColumn);
      let colorConfigGrdVisible;
      const colorConfigTrue = formData.filter(item => item.sTbName.toUpperCase() === 'mftProductparam'.toUpperCase())[0];
      if (commonUtils.isNotEmptyObject(colorConfigTrue)) {
        colorConfigGrdVisible = colorConfigTrue.bGrdVisible;
        if (colorConfigGrdVisible) {
          colorColumn = commonFunc.getHeaderConfig(colorConfigTrue, colorColumn);
        }
      }
      let dailyConfigGrdVisible;
      const dailyConfigTrue = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductchange'.toUpperCase())[0];
      if (commonUtils.isNotEmptyObject(dailyConfigTrue)) {
        dailyConfigGrdVisible = dailyConfigTrue.bGrdVisible;
        if (dailyConfigGrdVisible) {
          dailyColumn = commonFunc.getHeaderConfig(dailyConfigTrue, dailyColumn);
        }
      }


      let addState = {};
      const dailyConfig = dailyConfigGrdVisible ? dailyConfigTrue : '';
      const colorConfig = colorConfigGrdVisible ? colorConfigTrue : '';
      if (sId === '') {
        const config = {};
        config.masterConfig = masterConfig;
        config.slaveConfig = slaveConfig;
        config.controlConfig = controlConfig;
        config.materialsConfig = materialsConfig;
        config.processConfig = processConfig;
        config.colorConfig = colorConfig;
        config.dailyConfig = dailyConfig;
        addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
      } else {
        this.props.onGetData(masterConfig, slaveConfig, checkConfig);
        this.handleGetData(controlConfig, materialsConfig, processConfig, colorConfig, dailyConfig);
      }
      this.props.onSaveState({
        masterConfig,
        slaveConfig,
        slaveColumn,
        checkConfig,
        checkColumn,
        sId,
        pageLoading: false,
        controlConfig,
        controlColumn,
        materialsConfig,
        materialsColumn,
        processConfig,
        processColumn,
        colorConfig,
        colorColumn,
        dailyConfig,
        dailyColumn,
        ...addState,
        dailyConfigGrdVisible,
        colorConfigGrdVisible,
      });
    }

    // // 未清复制到时，产品ID需要再获取动态部件
    // const sId = currentId || nextProps.masterData?.sId || '';
    // if (sId === '' && commonUtils.isNotEmptyObject(this.props.masterData) && !this.props.bGetPartsData) {
    //   const { sAllPartsName } = this.props.masterData;
    //   if (sAllPartsName !== undefined) {
    //     const allPartsName = sAllPartsName.split(',');
    //     const sPartsName = allPartsName[0];
    //     if (commonUtils.isEmptyObject(this.props.masterConfig[`dSumPQty${sPartsName}`])) {
    //       this.handleMasterChange('master', 'sProductClassifyName');
    //       this.props.onSaveState({ bGetPartsData: true });
    //     }
    //   }
    // }
  }

  shouldComponentUpdate(nextProps) {
    const { controlColumn, slaveConfig } = nextProps;
    return typeof slaveConfig === 'object' && Object.keys(slaveConfig).length > 0 && commonUtils.isNotEmptyArr(controlColumn);
  }

  getMenuStatus = (menu) => {
    if (menu.sControlName === 'BtnCalculation' || menu.sControlName === 'BtnChooseProcess' || menu.sControlName === 'BtnChooseMaterials') {
      return !this.props.enabled;
    }
  };

  /* 获取表数据 */
  handleGetData = async (controlConfig, materialsConfig, processConfig, colorConfig, dailyConfig, extraState = {}) => {
    const { currentId } = this.props; /* 当前页签数据 */
    const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */
    const addStateControl = await this.props.handleGetDataSet({
      name: 'control', configData: controlConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
    });
    this.props.handleGetDataSet({
      name: 'materials', configData: materialsConfig, condition: { sSqlCondition: { sParentId: sId } },
    });
    const addStateProcess = await this.props.handleGetDataSet({
      name: 'process', configData: processConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
    });
    if (addStateProcess) {
      if (Array.isArray(addStateProcess.processData)) {
        // eslint-disable-next-line array-callback-return
        addStateProcess.processData.map((itemProcess) => {
          if (commonUtils.isNotEmptyObject(itemProcess.sWorkOrderParam)) {
            itemProcess.sProcessParamStr = '';
            // eslint-disable-next-line no-plusplus
            for (let i = 1; i < 7; i++) {
              const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
              if (iIndex > -1 && !commonUtils.isEmpty(itemProcess[`sParam${i.toString()}`])) {
                itemProcess.sProcessParamStr += `${itemProcess[`sParam${i.toString()}`]}:${itemProcess[`sParamValue${i.toString()}`]},`;
              }
            }
            if (itemProcess.sProcessParamStr === '') {
              itemProcess.sProcessParamStr = '工艺参数';
            }
          }
        });
        addStateProcess.processData = this.sortData(addStateControl.controlData, addStateProcess.processData);
      }
    }
    let addStateColor = {};
    if (colorConfig) {
      addStateColor = await this.props.handleGetDataSet({
        name: 'color', configData: colorConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
      });
    }

    let addStateDaily = {};
    if (dailyConfig) {
      addStateDaily = await this.props.handleGetDataSet({
        name: 'daily', configData: dailyConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
      });
    }
    this.props.onSaveState({
      pageLoading: false, ...addStateControl, ...addStateProcess, ...addStateColor, ...addStateDaily, ...extraState,
    });
  };

  handleBackProcessData = async (config, isWait) => {
    const { token } = this.props.app;
    const { sModelsId, sBackProcessData } = this.props;
    const masterConfig = commonUtils.isEmpty(config) ? this.props.masterConfig : config.masterConfig;
    if (sBackProcessData === undefined || sBackProcessData === '') {
      const sBackProcess = masterConfig.gdsconfigformslave.filter(item => item.sName === 'sBackProcess')[0];
      const url = `${commonConfig.server_host}business/getSelectDataBysControlId/${sBackProcess.sId}?sModelsId=${sModelsId}`;
      const values = { sKeyUpFilterName: '', sSqlCondition: {} };

      const masterReturn = (await commonServices.postValueService(token, values, url)).data;
      if (masterReturn.code === 1) {
        const sBackProcessDataValue = masterReturn.dataset.rows;
        if (isWait) {
          return { sBackProcessData: sBackProcessDataValue };
        } else {
          this.props.onSaveState({ sBackProcessData: sBackProcessDataValue });
        }
      } else {
        message.warn(masterReturn.msg);
      }
    }
  }

  handleForm = (form) => {
    this.form = form;
  };

  /* 非列表联动下拉 */
  handleMasterChange = async (name, sFieldName, changeValue, sId, dropDownData, config, isWait) => {
    /* 数据集类型，对象型为Map 数组型为List */
    const {
      sModelsId, app,
    } = this.props;
    const masterData = commonUtils.isEmpty(config) ? this.props.masterData : config.masterData;
    const masterConfig = commonUtils.isEmpty(config) ? this.props.masterConfig : config.masterConfig;
    const { token } = app;
    let { sBackProcessClassifyData } = this.props;
    let { sAllPartsName } = masterData;
    let backProcessData;
    if (sFieldName === 'sProductClassifyId' || sFieldName === 'sProductId' || sFieldName === 'sProductClassifyName' || sFieldName === 'sProductName') {
      backProcessData = await this.handleBackProcessData(config, true);
      let allPartsName = [];
      if (sAllPartsName !== undefined) {
        allPartsName = sAllPartsName.split(',');
      }

      if (allPartsName.length > 0 && masterConfig.gdsconfigformslave.filter(item => item.sName === `sMaterialsName${allPartsName[0]}`).length > 0 &&
        (sBackProcessClassifyData !== undefined && sBackProcessClassifyData !== '' && sBackProcessClassifyData.length > 0 &&
          masterConfig.gdsconfigformslave.filter(item => item.sName === `${sBackProcessClassifyData[0].sId}${allPartsName[0]}`).length > 0)) {
        let iIndex;
        allPartsName.forEach((sPartsName) => {
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === `dSumPQty${sPartsName}`);
          if (iIndex > -1) {
            masterConfig.gdsconfigformslave.splice(iIndex, 1);
          }
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === `sMaterialsName${sPartsName}`);
          if (iIndex > -1) {
            masterConfig.gdsconfigformslave.splice(iIndex, 1);
          }
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === `iPrintModePo${sPartsName}`);
          if (iIndex > -1) {
            masterConfig.gdsconfigformslave.splice(iIndex, 1);
          }
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === `iPositiveColor${sPartsName}`);
          if (iIndex > -1) {
            masterConfig.gdsconfigformslave.splice(iIndex, 1);
          }

          if (sBackProcessClassifyData !== '') {
            sBackProcessClassifyData.filter(processClassify => processClassify.sType !== '3').forEach((processClassify) => {
              iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === processClassify.sId + sPartsName);
              if (iIndex > -1) {
                masterConfig.gdsconfigformslave.splice(iIndex, 1);
              }
            });
          }
        });
        if (sBackProcessClassifyData !== '') {
          sBackProcessClassifyData.filter(processClassify => processClassify.sType === '3').forEach((processClassify) => {
            iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === processClassify.sId);
            if (iIndex > -1) {
              masterConfig.gdsconfigformslave.splice(iIndex, 1);
            }
          });
        }
      }


      let sProductClassifyId;
      if (changeValue !== null && changeValue !== undefined) {
        sProductClassifyId = commonUtils.isEmpty(changeValue.sProductClassifyId) ? masterData.sProductClassifyId : changeValue.sProductClassifyId;
        sAllPartsName = commonUtils.isEmpty(changeValue.sAllPartsName) ? masterData.sAllPartsName : changeValue.sAllPartsName;
      } else {
        sProductClassifyId = masterData.sProductClassifyId;
      }
      if (commonUtils.isEmpty(sProductClassifyId)) {
        return;
      }
      const sBackProcessClassify = masterConfig.gdsconfigformslave.filter(item => (item.sName.toLowerCase() === 'sbackprocessclassify'))[0];

      const values = { sKeyUpFilterName: '', sSqlCondition: { sProductClassifyId } };
      const dataReturn = (await commonServices.postValueService(token, values, `${commonConfig.server_host}business/getSelectDataBysControlId/${sBackProcessClassify.sId}?sModelsId=${sModelsId}`)).data;
      /*   接收返回值   */
      /*   成功的话刷新页面(同步主表和从表数据),不成功就弹出错误提示   */
      if (dataReturn.code === 1) { /*   成功   */
        const { rows } = dataReturn.dataset;

        allPartsName = [];
        if (sAllPartsName !== undefined) {
          allPartsName = sAllPartsName.split(',');
        }

        sBackProcessClassifyData = rows;
        if (allPartsName.length > 0 && masterConfig.gdsconfigformslave.filter(item => item.sName === `sMaterialsName${allPartsName[0]}`).length <= 0 &&
          sBackProcessClassifyData !== undefined && sBackProcessClassifyData !== '' && sBackProcessClassifyData.length > 0 &&
          masterConfig.gdsconfigformslave.filter(item => item.sName === `${sBackProcessClassifyData[0].sId}${allPartsName[0]}`).length <= 0) {
          const sumPQtyConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'dSumPQty').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'dSumPQty')[0] : [];
          const materialsNameConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'sMaterialsName').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'sMaterialsName')[0] : [];
          const printModePoConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'iPrintModePo').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'iPrintModePo')[0] : [];
          const positiveColorConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'iPositiveColor').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'iPositiveColor')[0] : [];
          const processNameConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'sProcessName').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'sProcessName')[0] : [];

          let ConfigNew;
          allPartsName.forEach((item) => {
            ConfigNew = { ...sumPQtyConfig };
            ConfigNew.sName = `dSumPQty${item}`;
            ConfigNew.sAssignField = commonUtils.isEmpty(ConfigNew.sAssignField) ? '' : ConfigNew.sAssignField.replace(/:/g, `${item}:`);
            masterConfig.gdsconfigformslave.push(ConfigNew);

            ConfigNew = { ...materialsNameConfig };
            ConfigNew.sName = `sMaterialsName${item}`;
            ConfigNew.sAssignField = commonUtils.isEmpty(ConfigNew.sAssignField) ? '' : ConfigNew.sAssignField.replace(/:/g, `${item}:`);
            masterConfig.gdsconfigformslave.push(ConfigNew);

            ConfigNew = { ...printModePoConfig };
            ConfigNew.sName = `iPrintModePo${item}`;
            ConfigNew.sAssignField = commonUtils.isEmpty(ConfigNew.sAssignField) ? '' : ConfigNew.sAssignField.replace(/:/g, `${item}:`);
            masterConfig.gdsconfigformslave.push(ConfigNew);

            ConfigNew = { ...positiveColorConfig };
            ConfigNew.sName = `iPositiveColor${item}`;
            ConfigNew.sAssignField = commonUtils.isEmpty(ConfigNew.sAssignField) ? '' : ConfigNew.sAssignField.replace(/:/g, `${item}:`);
            masterConfig.gdsconfigformslave.push(ConfigNew);
            if (sBackProcessClassifyData !== '') {
              sBackProcessClassifyData.filter(processClassify => processClassify.sType !== '3').forEach((processClassify) => {
                ConfigNew = { ...processNameConfig };
                ConfigNew.sName = processClassify.sId + item;
                masterConfig.gdsconfigformslave.push(ConfigNew);
              });
            }
          });
          if (sBackProcessClassifyData !== '') {
            sBackProcessClassifyData.filter(processClassify => processClassify.sType === '3').forEach((processClassify) => {
              ConfigNew = { ...processNameConfig };
              ConfigNew.sName = processClassify.sId;
              masterConfig.gdsconfigformslave.push(ConfigNew);
            });
          }
        }
        const returnChange = await this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, true, masterData);
        const masterDataDefault = commonFunc.getDefaultData(masterConfig, {});
        returnChange.masterData = { ...returnChange.masterData, ...masterDataDefault };
        if (isWait) {
          return {
            ...returnChange, sBackProcessClassifyData, masterConfig, ...backProcessData,
          };
        } else {
          this.props.onSaveState({
            ...returnChange, sBackProcessClassifyData, masterConfig, ...backProcessData,
          });
        }
      } else { /*   失败   */
        this.props.getServiceError(dataReturn);
      }
    } else if (sFieldName === 'sCustomerId' || sFieldName === 'sCustomerNo' || sFieldName === 'sCustomerName') {
      const returnChange = await this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, true);
      if (returnChange !== undefined && returnChange.masterData !== undefined) {
        returnChange.masterData.sProductId = '';
        returnChange.masterData.sProductNo = '';
        returnChange.masterData.sProductName = '';
      }
      this.props.onSaveState({ ...returnChange });
    } else {
      this.props.onChange(name, sFieldName, changeValue, sId, dropDownData);
    }
  };

  /* 数据生成按钮 */
  handleDataCreate= async () => {
    let { checkProcessClassifyData } = this.props;
    const {
      masterData, slaveConfig, materialsConfig, processConfig, sModelsId, app,
    } = this.props;
    const { token } = this.props.app;
    const paramMap = {};
    const { sAllPartsName } = masterData;
    let allPartsName = [];
    if (sAllPartsName !== undefined) {
      allPartsName = sAllPartsName.split(',');
    }
    let cpProcessName = '';
    checkProcessClassifyData = commonUtils.isEmptyArr(checkProcessClassifyData) ? [] : checkProcessClassifyData;
    // paramMap.modelName = masterData.modelName;
    paramMap.sCustomerId = masterData.sCustomerId;
    paramMap.sCustomerName = masterData.sCustomerName;
    paramMap.sProductClassifyId = masterData.sProductClassifyId;
    paramMap.sProductId = masterData.sProductId;
    paramMap.sProductName = masterData.sProductName;
    paramMap.sProductStyleId = masterData.sProductStyleId;
    paramMap.sProductStyle = masterData.sProductStyle;
    paramMap.dProductWidth = !commonUtils.isEmpty(masterData.sProductStyle) && masterData.sProductStyle.split('*').length > 0 ? masterData.sProductStyle.split('*')[1] : 0;
    paramMap.dProductLength = !commonUtils.isEmpty(masterData.sProductStyle) && masterData.sProductStyle.split('*').length > 0 ? masterData.sProductStyle.split('*')[0] : 0;
    paramMap.dProductHeight = 0;
    paramMap.dProductQty = masterData.dProductQty;
    const partsInfo = [];
    allPartsName.forEach((item) => {
      const partInfo = {};
      partInfo.sPartsName = item;
      partInfo.dPartsQty = masterData.dProductQty;
      partInfo.dSumPQty = masterData[`dSumPQty${item}`];
      const materialsInfo = [];
      const material = {};
      material.sMaterialsId = masterData[`sMaterialsId${item}`];
      material.sMaterialsNo = masterData[`sMaterialsNo${item}`];
      material.sMaterialsName = masterData[`sMaterialsName${item}`] !== undefined && masterData[`sMaterialsName${item}`].split('[-]').length > 1 ? masterData[`sMaterialsName${item}`].split('[-]')[1] : masterData[`sMaterialsName${item}`];
      materialsInfo.push(material);
      partInfo.materialsInfo = materialsInfo;
      partInfo.iPositiveColor = masterData[`iPositiveColor${item}`];
      partInfo.iPrintModePo = masterData[`iPrintModePo${item}`];
      if (material.sMaterialsId !== undefined && material.sMaterialsId !== '') {
        const processInfo = [];
        checkProcessClassifyData.filter(card => card.sPartsName === item && card.sType !== '3').forEach((card) => {
          if (!commonUtils.isEmpty(masterData[card.sId + item])) {
            if (commonUtils.isEmpty(partInfo.sPrintProcessId) && card.sType === '1') {
              partInfo.sPrintProcessId = masterData[card.sId + item];
            } else {
              const process = {};
              process.sProductClassifyId = card.sId;
              process.sProcessId = masterData[card.sId + item];
              if (masterData[card.sId + card.sName + item] !== undefined) {
                process.sProcessName = masterData[card.sId + card.sName + item];
                process.sType = masterData[card.sId + card.sType + item];
                processInfo.push(process);
              }
            }
          }
        });
        partInfo.processInfo = processInfo;
        partsInfo.push(partInfo);
      }
    });
    const productProcess = [];
    checkProcessClassifyData.filter(card => card.sType === '3').forEach((card) => {
      if (!commonUtils.isEmpty(masterData[card.sId])) {
        const process = {};
        process.sProductClassifyId = card.sId;
        process.sProcessId = masterData[card.sId];
        process.sProcessName = masterData[card.sId + card.sName];
        if (masterData[card.sId + card.sName] !== undefined) {
          cpProcessName = cpProcessName === '' ? masterData[card.sId + card.sName] : `${cpProcessName},${masterData[card.sId + card.sName]}`;
          productProcess.push(process);
        }
      }
    });
    paramMap.cpProcessName = cpProcessName;
    paramMap.productProcessInfo = productProcess;
    paramMap.partsInfo = partsInfo;

    if (commonUtils.isEmpty(paramMap.sProductName) || commonUtils.isEmpty(paramMap.sProductStyle) || commonUtils.isEmpty(paramMap.dProductWidth) ||
      commonUtils.isEmpty(paramMap.dProductLength) || commonUtils.isEmpty(paramMap.dProductQty)) {
      // this.props.onSaveState({ fastOrderModalVisible: false });
      message.error(commonFunc.showMessage(app.commonConst, 'ProductError'));/* 产品信息不正确 */
      return;
    }
    /* 验证产品规格是否 符合数字*数字格式 */
    const sProductStyle = paramMap.sProductStyle;
    if (commonUtils.isNotEmptyObject(sProductStyle) && sProductStyle.indexOf('*') > -1) { /* 首先查看产品规格输入是否有*号 */
      const arr = sProductStyle.split('*');
      const numCheck = /^(-?\d+)(\.?)(\d{1,6})?$/;
      if (commonUtils.isNotEmptyArr(arr) && arr.length > 0) {
        for (let i = 0; i < arr.length; i += 1) {
          if (!numCheck.test(arr[i])) { /* 验证是否数字 */
            message.error(commonFunc.showMessage(app.commonConst, 'sProductStyleErr'));
            return;
          }
        }
      } else {
        message.error(commonFunc.showMessage(app.commonConst, 'sProductStyleErr'));
        return;
      }
      /* 验证*两边是否是数字 */
    } else {
      message.error(commonFunc.showMessage(app.commonConst, 'sProductStyleErr'));
      return;
    }
    const url = `${commonConfig.server_host}calculationStd/countMoney?sModelsId=${sModelsId}`;
    const dataReturn = (await commonServices.postValueService(token, paramMap, url)).data;
    if (dataReturn.code === 1) {
      const {
        productClassify, partsNewInfo, productProcessInfo, partsInfo: partsOldInfo,
      } = dataReturn.dataset.rows[0];
      const slaveData = [];
      const controlData = [];
      const materialsData = [];
      let processData = [];
      const tableDataRow = {};
      for (const item of slaveConfig.gdsconfigformslave) {
        tableDataRow[item.sName] = masterData[item.sName];
      }
      tableDataRow.sId = commonUtils.createSid();
      tableDataRow.handleType = 'add';
      tableDataRow.iOrder = 1;
      tableDataRow.sParentId = masterData.sId;
      // const productIdDropDown = commonUtils.getStoreDropDownData(sModelsId, 'slave', 'sProductName');
      let productIdDropDown;
      const slaveIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductName');
      if (slaveIndex > -1) {
        const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[slaveIndex], tableDataRow);
        productIdDropDown = sqlDropDownData.dropDownData;
      }
      const iProductIdIndex = commonUtils.isEmptyArr(productIdDropDown) ? -1 : productIdDropDown.findIndex(item => item.sId === tableDataRow.sProductId);
      if (iProductIdIndex === -1) {
        tableDataRow.sProductId = tableDataRow.sProductName;
        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 = '';
      }
      slaveData.push(tableDataRow);
      if (!commonUtils.isEmptyArr(partsOldInfo)) {
        partsOldInfo.forEach((item) => {
          if (commonUtils.isNotEmptyObject(item) && !commonUtils.isEmpty(item.errorFlag)) {
            this.props.getServiceError({ msg: `${item.sPartsName}  ${item.errorFlag}` });
          }
        });
      }
      const bProcessAssort = true;
      let returnProcessAssort = [];
      let processAssignAssort = '';
      let dropDownDataProcessName;
      if (bProcessAssort) {
        const dataUrl = `${commonConfig.server_host}salesorder/getProcessAssort?sModelsId=${sModelsId}`;
        const dataProcessAssort = (await commonServices.postValueService(token, {}, dataUrl)).data;
        if (dataProcessAssort.code === 1) {
          returnProcessAssort = dataProcessAssort.dataset.rows[0].processassort;
          const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProcessName');
          if (iIndex > -1) {
            const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', processConfig.gdsconfigformslave[iIndex]);
            dropDownDataProcessName = sqlDropDownData.dropDownData;
            processAssignAssort = processConfig.gdsconfigformslave[iIndex].sAssignField;
          }
        }
      }
      const newCopyTo = {};
      newCopyTo.master = masterData;
      newCopyTo.slave = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
      partsNewInfo.forEach((partInfo, iIndex) => {
        const partsDataRow = {};
        for (const child of Object.keys(partInfo)) {
          partsDataRow[child] = partInfo[child];
        }
        partsDataRow.handleType = 'add';
        partsDataRow.iOrder = iIndex + 1;/* 快速下单编号从1开始 */
        partsDataRow.sId = commonUtils.createSid();
        partsDataRow.sParentId = masterData.sId;
        if (partsDataRow.iPrintMode !== 3) {
          partsDataRow.iOppositeColor = partsDataRow.iPositiveColor;
        }
        delete partsDataRow.dMaterialsKQty;
        delete partsDataRow.dMaterialsLength;
        delete partsDataRow.dMaterialsWidth;
        if (productClassify.bSpecialRules) {
          partsDataRow.dMachineLength = partsDataRow.dMaxMachineLength;
          partsDataRow.dMachineWidth = partsDataRow.dMaxMachineWidth;
        }
        controlData.push(partsDataRow);
        // 材料信息
        partInfo.materialsInfo.forEach((materialInfo, iOrder) => {
          const materialDataRow = {};
          for (const item of materialsConfig.gdsconfigformslave) {
            materialDataRow[item.sName] = materialInfo[item.sName];
          }
          materialDataRow.handleType = 'add';
          materialDataRow.sType = '0';
          materialDataRow.iPartOrder = iIndex;
          materialDataRow.iOrder = iOrder + 1;
          materialDataRow.sPartsName = partsDataRow.sPartsName;
          materialDataRow.sId = commonUtils.createSid();
          materialDataRow.sParentId = masterData.sId;
          materialDataRow.sControlId = partsDataRow.sId;
          materialDataRow.dMaterialsKQty = partsDataRow.iNumberofMaterial;
          materialsData.push(materialDataRow);
        });
        // 工序信息
        let processPrintDataRow = {};
        processPrintDataRow.handleType = 'add';
        processPrintDataRow.sProcessId = partInfo.sProcessId;
        const iProcessPrintIndex = dropDownDataProcessName.findIndex(item => item.sId === processPrintDataRow.sProcessId);
        if (iProcessPrintIndex > -1) {
          processPrintDataRow = { ...processPrintDataRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iProcessPrintIndex], newCopyTo) }; // 取赋值字段
        }
        processPrintDataRow.sType = partInfo.sType;
        processPrintDataRow.iPartOrder = iIndex;
        processPrintDataRow.iOrder = 1;
        processPrintDataRow.sProcessName = partInfo.sProcessName;
        processPrintDataRow.sPartsName = partsDataRow.sPartsName;
        processPrintDataRow.dProcessInQty = partInfo.dProcessInQty;
        processPrintDataRow.dLossQty = partInfo.dLossQty;
        processPrintDataRow.dProcessOutQty = partInfo.dProcessOutQty;
        processPrintDataRow.sId = commonUtils.createSid();
        processPrintDataRow.sParentId = masterData.sId;
        processPrintDataRow.sControlId = partsDataRow.sId;
        processData.push(processPrintDataRow);
        // 配套工序
        if (bProcessAssort) {
          returnProcessAssort.filter(item => item.sParentId === processPrintDataRow.sProcessId).forEach(((itemProcessAssort) => {
            const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
            const iProcessIndex = -1;
            const iNewProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === partsDataRow.sId);
            if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
              let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
              processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
              processRow.handleType = 'add';
              processRow.sId = commonUtils.createSid();
              processRow.sParentId = masterData.sId;
              processRow.sControlId = partsDataRow.sId;
              processRow.sPartsName = partsDataRow.sPartsName;
              processRow.sType = dropDownDataProcessName[iIndex].sType;
              processData.push(processRow);
            }
          }));
        }

        partInfo.processInfo.forEach((process, iOrder) => {
          let processAfterDataRow = {};
          for (const item of processConfig.gdsconfigformslave) {
            processAfterDataRow[item.sName] = process[item.sName];
          }
          for (const child of Object.keys(process)) {
            processAfterDataRow[child] = process[child];
          }
          processAfterDataRow.handleType = 'add';
          processAfterDataRow.sProcessId = process.sProcessId;
          const iProcessAfterIndex = dropDownDataProcessName.findIndex(item => item.sId === processAfterDataRow.sProcessId);
          if (iProcessAfterIndex > -1) {
            processAfterDataRow = { ...processAfterDataRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iProcessAfterIndex], newCopyTo) }; // 取赋值字段
          }
          processAfterDataRow.sType = process.sType;
          processAfterDataRow.iPartOrder = iIndex;
          processAfterDataRow.iOrder = iOrder + 1;
          processAfterDataRow.sPartsName = partsDataRow.sPartsName;
          processAfterDataRow.sId = commonUtils.createSid();
          processAfterDataRow.sParentId = masterData.sId;
          processAfterDataRow.sControlId = partsDataRow.sId;
          processData.push(processAfterDataRow);
          // 配套工序
          if (bProcessAssort) {
            returnProcessAssort.filter(item => item.sParentId === processPrintDataRow.sProcessId).forEach(((itemProcessAssort) => {
              const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
              const iProcessIndex = -1;
              const iNewProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === partsDataRow.sId);
              if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
                let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
                processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                processRow.handleType = 'add';
                processRow.sId = commonUtils.createSid();
                processRow.sParentId = masterData.sId;
                processRow.sControlId = partsDataRow.sId;
                processRow.sPartsName = partsDataRow.sPartsName;
                processRow.sType = dropDownDataProcessName[iIndex].sType;
                processData.push(processRow);
              }
            }));
          }
        });
      });
      productProcessInfo.forEach((process, iOrder) => {
        let processProductDataRow = {};
        for (const item of processConfig.gdsconfigformslave) {
          processProductDataRow[item.sName] = process[item.sName];
        }
        for (const child of Object.keys(process)) {
          processProductDataRow[child] = process[child];
        }
        const iProductProcessIndex = dropDownDataProcessName.findIndex(item => item.sId === processProductDataRow.sProcessId);
        if (iProductProcessIndex > -1) {
          processProductDataRow = { ...processProductDataRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iProductProcessIndex], newCopyTo) }; // 取赋值字段
        }
        processProductDataRow.handleType = 'add';
        processProductDataRow.sType = '3';
        processProductDataRow.sPartsName = '';
        processProductDataRow.iPartOrder = 999;
        processProductDataRow.iOrder = iOrder + 1;
        processProductDataRow.sId = commonUtils.createSid();
        processProductDataRow.sParentId = masterData.sId;
        processData.push(processProductDataRow);
        // 配套工序
        if (bProcessAssort) {
          returnProcessAssort.filter(item => item.sParentId === processProductDataRow.sProcessId).forEach(((itemProcessAssort) => {
            const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
            const iProcessIndex = -1;
            const iNewProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId);
            if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
              let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
              processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
              processRow.handleType = 'add';
              processRow.sId = commonUtils.createSid();
              processRow.sParentId = masterData.sId;
              processRow.sType = dropDownDataProcessName[iIndex].sType;
              processData.push(processRow);
            }
          }));
        }
      });
      processData = this.sortData(controlData, processData);
      this.props.onSaveState({
        materialsConfig, slaveData, controlData, materialsData, processData, fastOrderModalVisible: false, materialsSelectedRowKeys: [],
      });
    } else {
      this.props.getServiceError(dataReturn);
    }
  };

  /* 勾选工序分类 */
  handleProcessChange=(e, value, sPartsName) => {
    let { checkProcessClassifyData } = this.props;
    let index = -1;
    if (commonUtils.isNotEmptyArr(checkProcessClassifyData)) {
      index = checkProcessClassifyData.findIndex(item => (item.sId === value.sId && item.sPartsName === sPartsName));
    } else {
      checkProcessClassifyData = [];
    }
    if (e.target.checked) {
      if (index <= -1) {
        const newvalue = { ...value };
        newvalue.sPartsName = sPartsName;
        checkProcessClassifyData.push(newvalue);
      }
    } else if (index > -1) {
      checkProcessClassifyData.splice(index, 1);
    }
    this.props.onSaveState({ checkProcessClassifyData });
  };

  handleSelectChangeProcess = (sAssignField, value, option) => {
    const { masterData, sBackProcessClassifyData } = this.props;
    let { checkProcessClassifyData } = this.props;
    if (sAssignField !== undefined) {
      // 这一段是处理工序的赋值字段，原因工序是动态生成，没用showtype
      const sAssignFields = sAssignField.split(',');
      const recordRow = option.props['data-recordrow'];
      sAssignFields.forEach((item, iAssignIndex) => {
        const itemsplits = item.split(':');
        masterData[`${itemsplits[0]}`] = recordRow[itemsplits[1]];
        if (iAssignIndex === 0) {
          let index = -1;
          const sPartsName = itemsplits[0].replace(recordRow.sParentId, '');
          if (commonUtils.isNotEmptyArr(checkProcessClassifyData)) {
            index = checkProcessClassifyData.findIndex(item => (item.sId === recordRow.sParentId && item.sPartsName === sPartsName));
          } else {
            checkProcessClassifyData = [];
          }
          if (index <= -1) {
            const iBackProcessIndex = sBackProcessClassifyData.findIndex(item => item.sId === recordRow.sParentId);
            if (iBackProcessIndex > -1) {
              const newvalue = { ...sBackProcessClassifyData[iBackProcessIndex] };
              newvalue.sPartsName = sPartsName;
              checkProcessClassifyData.push(newvalue);
            }
          }
        }
      });
      this.props.onSaveState({ masterData, checkProcessClassifyData });
    }
  }

  handleA = (sId) => {
    const { sBackProcessData } = this.props;
    const data = sBackProcessData.filter(item => item.sParentId === sId);
    const optionProcess = [];
    data.forEach((item) => {
      optionProcess.push(<Option key={item.sId} value={item.sId} data-recordrow={item}>{item.sProcessName}</Option>);
    });
    return optionProcess;
  }

  handleSave = async () => {
    this.form.validateFields((err) => {
      /*   验证通过与不通过走不同的流程   */
      if (err) { /*   验证失败   */
        /*   直接渲染显示错误提示   */
        for (const key of Object.keys(err)) {
          message.warning(err[key].errors[0].message);
        }
        this.props.onSaveState({
          loading: false,
        });
      } else { /*   验证成功   */
        const {
          masterConfig, masterData, slaveConfig, slaveData, slaveDelData, controlConfig, controlData, controlDelData,
          materialsConfig, materialsData, materialsDelData, processConfig, processData, processDelData, colorConfig,
          colorData, colorDelData, dailyConfig, dailyData, dailyDelData, app,
        } = this.props;
        if (commonUtils.isEmptyArr(slaveData)) {
          message.warning(`从表${commonFunc.showMessage(this.props.app.commonConst, 'isNotNull')}`);
          this.props.onSaveState({
            loading: false,
          });
          return;
        }
        if (!commonBusiness.validateTable(slaveConfig, slaveData, this.props) || !commonBusiness.validateTable(controlConfig, controlData, this.props) ||
          (!commonBusiness.validateTable(materialsConfig, materialsData, this.props)) || !commonBusiness.validateTable(processConfig, processData, this.props) ||
          !commonBusiness.validateTable(colorConfig, colorData, this.props) || !commonBusiness.validateTable(dailyConfig, dailyData, this.props)) {
          this.props.onSaveState({
            loading: false,
          });
          return;
        }
        if (commonUtils.isNotEmptyArr(materialsData)) {
          let flag = true;
          for (const item of materialsData) {
            if (commonUtils.isNotEmptyObject(item.sMaterialsType) && item.sMaterialsType === 'paper' && commonUtils.isEmptyObject(item.sMaterialsStyle)) {
              message.error(item.sMaterialsName + commonFunc.showMessage(app.commonConst, 'NoStyle'));/* 请填写"${item.sMaterialsName}"的规格 */
              flag = false;
              break;
            }
          }
          if (!flag) {
            this.props.onSaveState({
              loading: false,
            });
            return;
          }
        }
        const data = [];
        data.push(commonBusiness.mergeData('master', masterConfig.sTbName, [masterData]));
        data.push(commonBusiness.mergeData('slave', slaveConfig.sTbName, slaveData, slaveDelData));
        data.push(commonBusiness.mergeData('control', controlConfig.sTbName, controlData, controlDelData));
        data.push(commonBusiness.mergeData('materials', materialsConfig.sTbName, materialsData, materialsDelData));
        data.push(commonBusiness.mergeData('process', processConfig.sTbName, processData, processDelData));
        data.push(commonBusiness.mergeData('color', colorConfig.sTbName, colorData, colorDelData));
        data.push(commonBusiness.mergeData('daily', dailyConfig.sTbName, dailyData, dailyDelData));
        this.props.onSaveData({
          data, sClientType: '1', loading: false, sSysLogSrcId: masterData.sId,
        });
      }
    });
  };

  /**   处理选择行发生改变   */
  handleTableSelectRowChange = (name, selectedRowKeys) => {
    /*   外置处理业务   */
    if (name === 'slave') {
      const { controlData } = this.props;
      const addState = this.props.onTableSelectRowChange(name, selectedRowKeys, true);
      if (!commonUtils.isEmptyArr(controlData) && controlData.length === 1) {
        addState.controlSelectedRowKeys = [controlData[0].sId];
      } else {
        addState.controlSelectedRowKeys = [];
      }
      this.props.onSaveState(addState);
    } else if (name === 'materials' || name === 'process') {
      const { [`${name}Data`]: tableData, enabled } = this.props;
      const addState = this.props.onTableSelectRowChange(name, selectedRowKeys, true);
      if (commonUtils.isNotEmptyArr(selectedRowKeys)) {
        const iIndex = tableData.findIndex(item => item.sId === selectedRowKeys.toString());
        if (enabled && iIndex > -1 && !commonUtils.isEmpty(tableData[iIndex].sControlId)) {
          addState.controlSelectedRowKeys = [tableData[iIndex].sControlId];
        }
      }
      this.props.onSaveState(addState);
    } else {
      this.props.onTableSelectRowChange(name, selectedRowKeys);
    }
  };

  /** 控制选择控制表时，显示部件工序与成品工序 */
  handleFilterData = (name, dataIndex, value, record) => {
    if (value === undefined) {
      return true;
    }
    if (name === 'process') {
      return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '3') ||
        (commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()));
    } else {
      return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '2') ||
        (commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()));
    }
  };
  /** 控制选择控制表时，显示部件工序与成品工序 */
  handleGetFilterData = (name) => {
    const { [`${name}Data`]: data, controlSelectedRowKeys } = this.props;
    if (data !== undefined && commonUtils.isNotEmptyArr(controlSelectedRowKeys)) {
      const newArr = data.filter((item) => {
        return (commonUtils.isNotEmptyStr(item.sControlId) && item.sControlId.toString().toLowerCase().includes(controlSelectedRowKeys.toString()));
      });
      return newArr.length;
    }
  };
  handleKeyDown = (e, record, sName, name) => {
    /* 生产施工单，当印刷方式是“自翻”时，反面颜色不应该可输入 */
    if (commonUtils.isNotEmptyObject(record) && sName === 'iOppositeColor' && record.iPrintMode === 0) {
      if (e.key !== 'F12') {
        e.preventDefault();
      }
    } else {
      this.props.onKeyDown(e, record, sName, name);
    }
  }

  /**   添加表格空行   */
  handleTableAdd = (name, flag) => {
    /*   外置处理业务   */
    const {
      gdsformconst, controlData, controlSelectedRowKeys, [`${name}Data`]: tableData,
    } = this.props;
    if (name === 'control') {
      const tableDataRow = this.props.onDataRowAdd(name, true);
      // let dPartsQty = 0;
      // if (commonUtils.isNotEmptyArr(slaveData)) {
      //   slaveData.forEach((item) => {
      //     dPartsQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0);
      //   });
      //   const productIdDropDown = commonUtils.getStoreDropDownData(sModelsId, 'slave', 'sProductName');
      //   if (productIdDropDown) {
      //     const iProductIdIndex = productIdDropDown.findIndex(item => item.sId === slaveData[0].sProductId);
      //     if (iProductIdIndex > -1) {
      //       tableDataRow.sPartsName = productIdDropDown[iProductIdIndex].sProductName;
      //     }
      //   }
      // }
      // tableDataRow.dPartsQty = dPartsQty;
      tableData.push(tableDataRow);
      this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId] });
    } else if (name === 'materials' || name === 'process') {
      const tableDataRow = this.props.onDataRowAdd(name, true);
      if (commonUtils.isEmptyArr(controlSelectedRowKeys)) {
        message.warn(commonFunc.showMessage(gdsformconst, 'pleaseChooseParts')); // 请选择部件
        return;
      }
      const iIndex = controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]);
      if (iIndex > -1) {
        if (commonUtils.isEmpty(controlData[iIndex].sPartsName) === '') {
          message.warn(commonFunc.showMessage(gdsformconst, 'partsNameNotNull')); // 部件名称不能为空
          return;
        }
        tableDataRow.sControlId = controlData[iIndex].sId;
        tableDataRow.sPartsName = controlData[iIndex].sPartsName;
      }
      tableData.push(tableDataRow);
      this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId] });
    } else {
      return this.props.onDataRowAdd(name, flag);
    }
  };
  /**   删除表格数据   */
  otherTableDel = async (name, tableSelectedRowKeys) => {
    const tableData = this.props[`${name}Data`];
    let tableDelData = this.props[`${name}DelData`];
    tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData;
    for (const sId of tableSelectedRowKeys) {
      /*   看看删除集合和从表中是否都存在该条数据   */
      let tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
      while (tableDataIndex > -1) {
        /*   删除从表中的数据并存入删除集合中   */
        const slaveDataFilter = tableData[tableDataIndex];
        tableData.splice(tableDataIndex, 1);
        slaveDataFilter.handleType = 'del';
        tableDelData.push(slaveDataFilter);
        tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
      }
    }
    return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [] };
  }
  /**   删除表格数据   */
  handleTableDel = async (name, flag, tableSelectedRowKeys) => {
    if (name === 'control') {
      if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) {
        const materialsReturnData = this.otherTableDel('materials', tableSelectedRowKeys);
        const processReturnData = this.otherTableDel('process', tableSelectedRowKeys);
        const controlReturnData = this.props.onDataRowDel(name, true, tableSelectedRowKeys);
        this.props.onSaveState({
          ...materialsReturnData,
          ...processReturnData,
          ...controlReturnData,
        });
        return true;
      } else {
        return false;
      }
    } else if (name === 'process') {
      const {
        sModelsId, [`${name}Data`]: tableData, materialsConfig, materialsData, token,
      } = this.props;
      const iIndex = tableData.findIndex(item => item.sId === tableSelectedRowKeys.toString());

      const dataUrl = `${commonConfig.server_host}salesorder/getProcessAssort?sModelsId=${sModelsId}`;
      const dataProcessAssort = (await commonServices.postValueService(token, {}, dataUrl)).data;
      const tableDelData = [];
      let returnProcessAssort = [];
      if (dataProcessAssort.code === 1) {
        returnProcessAssort = dataProcessAssort.dataset.rows[0].processassort;
      }

      let iMaterialsIndex = -1;
      const sProcessId = tableData[iIndex].sProcessId;
      const sControlId = tableData[iIndex].sControlId;
      iMaterialsIndex = materialsData.findIndex(item => item.sControlId === tableData[iIndex].sControlId && item.sProcessId === tableData[iIndex].sProcessId);
      const processReturnData = this.props.onDataRowDel(name, true, tableSelectedRowKeys);

      returnProcessAssort.filter(item => item.sParentId === sProcessId).forEach(((itemProcessAssort) => {
        const iProcessIndex = processReturnData.processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === sControlId);
        if (iProcessIndex > -1) {
          const slaveDataFilter = processReturnData.processData[iProcessIndex];
          tableData.splice(iProcessIndex, 1);
          slaveDataFilter.handleType = 'del';
          tableDelData.push(slaveDataFilter);
        }
      }));
      processReturnData.processDelData.concat(tableDelData);
      if (iMaterialsIndex > -1) {
        materialsData[iMaterialsIndex].sProcessId = '';
        materialsData[iMaterialsIndex].sProcessTbId = '';
        materialsData[iMaterialsIndex].sMaterialsProcessName = '';
      }
      this.props.onSaveState({
        ...processReturnData,
        materialsConfig,
        materialsSelectedRowKeys: [],
      });
      return true;
    } else {
      return this.props.onDataRowDel(name, flag, tableSelectedRowKeys);
    }
  };

  handleCalculation = async () => {
    const dataUrl = `${commonConfig.server_host}business/addWorksheet?sModelsId=${this.props.sModelsId}`;
    const {
      masterConfig, slaveConfig, controlConfig, materialsConfig, processConfig, app,
    } = this.props;
    let {
      slaveData, controlData, materialsData, processData, masterData,
    } = this.props;
    const data = [];
    data.push(commonBusiness.mergeData('master', `${masterConfig.sTbName.toLowerCase()}_Tmp`, [masterData], [], true));
    data.push(commonBusiness.mergeData('slave', `${slaveConfig.sTbName.toLowerCase()}_tmp`, slaveData, [], true));
    data.push(commonBusiness.mergeData('control', `${controlConfig.sTbName.toLowerCase()}_tmp`, controlData, [], true));
    data.push(commonBusiness.mergeData('materials', `${materialsConfig.sTbName.toLowerCase()}_tmp`, materialsData, [], true));
    data.push(commonBusiness.mergeData('process', `${processConfig.sTbName.toLowerCase()}_tmp`, processData, [], true));
    const value = { data, sClientType: '1', sGuid: masterData.sId };
    const dataReturn = (await commonServices.postValueService(this.props.app.token, value, dataUrl)).data;
    if (dataReturn.code === 1) { /*   成功   */
      const valueReturn = dataReturn.dataset.rows[0];
      const masterDataArr = valueReturn[`${masterConfig.sTbName.toLowerCase()}_tmp`];
      if (commonUtils.isNotEmptyArr(masterDataArr)) {
        masterData = masterDataArr[0];
      }
      slaveData = valueReturn[`${slaveConfig.sTbName.toLowerCase()}_tmp`];
      controlData = valueReturn[`${controlConfig.sTbName.toLowerCase()}_tmp`];
      materialsData = valueReturn[`${materialsConfig.sTbName.toLowerCase()}_tmp`];
      processData = valueReturn[`${processConfig.sTbName.toLowerCase()}_tmp`];
      processData = this.sortData(controlData, processData);
      this.props.onSaveState({
        slaveData, controlData, materialsData, processData, masterData, loading: false,
      });

      message.success(commonFunc.getConfigShowName(masterConfig, 'BtnCalculation') + commonFunc.showMessage(app.commonConst, 'handleSuccess'));
    } else { /*   失败   */
      this.props.onSaveState({
        loading: false,
      });
      this.props.getServiceError(dataReturn);
    }
  }

  /** 按钮操作事件 */
  handleButtonClick = async (name) => {
    if (name === 'BtnCalculation') {
      this.props.onSaveState({
        loading: true,
      });
      this.handleCalculation();
    } else if (name === 'BtnChooseProcess') {
      const {
        slaveData, controlData, slaveSelectedRowKeys, masterConfig, app,
      } = this.props;
      if (commonUtils.isEmptyArr(slaveData)) {
        message.error(commonFunc.showMessage(app.commonConst, 'NoSlaveData'));/* 请填写从表数据 */
        return;
      }
      const slaveSelectedData = slaveData.filter(item => item.sId === slaveSelectedRowKeys[0]);
      if (commonUtils.isEmptyArr(slaveSelectedData)) {
        message.error(commonFunc.showMessage(app.commonConst, 'pleaseChooseSlaveData'));/* 请选择从表数据 */
        return;
      }
      if (commonUtils.isEmptyStr(slaveSelectedData[0].sProductId)) {
        message.error(commonFunc.showMessage(app.commonConst, 'pleaseChooseProduct'));/* 请选择产品 */
        return;
      }
      if (commonUtils.isEmptyObject(controlData)) {
        message.error(commonFunc.showMessage(app.commonConst, 'NoControlData'));/* 请填写控制表数据 */
        return;
      }
      const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === name);
      if (iIndex > -1) {
        this.props.onBtnChoose('process', name, masterConfig.gdsconfigformslave[iIndex]);
      }
    } else if (name === 'BtnChooseMaterials') {
      const {
        slaveData, controlData, slaveSelectedRowKeys, masterConfig, app,
      } = this.props;
      if (commonUtils.isEmptyArr(slaveData)) {
        message.error(commonFunc.showMessage(app.commonConst, 'NoSlaveData'));/* 请填写从表数据 */
        return;
      }
      const slaveSelectedData = slaveData.filter(item => item.sId === slaveSelectedRowKeys[0]);
      if (commonUtils.isEmptyArr(slaveSelectedData)) {
        message.error(commonFunc.showMessage(app.commonConst, 'pleaseChooseSlaveData'));/* 请选择从表数据 */
        return;
      }
      if (commonUtils.isEmptyStr(slaveSelectedData[0].sProductId)) {
        message.error(commonFunc.showMessage(app.commonConst, 'pleaseChooseProduct'));/* 请选择产品 */
        return;
      }
      if (commonUtils.isEmptyObject(controlData)) {
        message.error(commonFunc.showMessage(app.commonConst, 'NoControlData'));/* 请填写控制表数据 */
        return;
      }
      const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === name);
      if (iIndex > -1) {
        this.props.onBtnChoose('materials', name, masterConfig.gdsconfigformslave[iIndex]);
      }
    } else {
      this.props.onButtonClick(name);
    }
  };

  /*  上一条、下一条、首条、末条 */
  handleSearchData = async (handleType) => {
    const {
      controlConfig, materialsConfig, processConfig,
    } = this.props;
    const bReturn = await this.props.onSearchData(handleType);
    if (bReturn) {
      this.handleGetData(controlConfig, materialsConfig, processConfig);
    }
  };

  /**   点击修改按钮操作   */
  handleEdit = () => {
    const {
      controlConfig, materialsConfig, processConfig, colorConfig, dailyConfig,
    } = this.props;
    this.props.onEdit(() => {
      this.handleGetData(controlConfig, materialsConfig, processConfig, colorConfig, dailyConfig, { loading: false, enabled: true });
    });
  };

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

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

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

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

  /* 确定要删除 */
  handleOkDel = async (props) => {
    /*   数据参数   */
    const {
      token, sModelsId, masterConfig, masterData, slaveConfig, checkConfig, controlConfig, materialsConfig, processConfig,
    } = props;
    const value = {
      sClientType: '1',
      data: {
        sMasterTable: masterConfig.sTbName,
        sId: [masterData.sId],
        sSlaveTable: [
          {
            tableName: slaveConfig.sTbName,
            relationName: 'sParentId',
          }, {
            tableName: checkConfig.sTbName,
            relationName: 'sBillId',
          }, {
            tableName: controlConfig.sTbName,
            relationName: 'sParentId',
          }, {
            tableName: materialsConfig.sTbName,
            relationName: 'sParentId',
          }, {
            tableName: processConfig.sTbName,
            relationName: 'sParentId',
          }],
      },
    };
    const { sBillNo, sId } = masterData || {};
    const url = `${commonConfig.server_host}business/delMasSlaBusinessData?sModelsId=${sModelsId}&sBillNo=${sBillNo}&sSysLogSrcId=${sId}`;
    /*   接收返回值   */
    const { data } = await commonServices.postValueService(token, value, url);
    if (data.code === 1) {
      /*   数据删除成功   */
      if (this.props.app.currentPane.refresh !== undefined) {
        this.props.app.currentPane.refresh();
      }
      this.props.onDelDataSuccess(props);
    } else { /*   失败   */
      this.props.getServiceError(data);
    }
  };

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

  /*   取消操作  */
  handleCancel = (obj) => {
    /*   待用数据声明   */
    const {
      masterConfig, slaveConfig, checkConfig, controlConfig, materialsConfig, processConfig, app,
    } = this.props;
    const onGetData = this.props.onGetData;
    const onGetDataOk = this.handleGetData;
    const onSaveStateOk = this.props.onSaveState;
    const onSendSocketMessage = this.props.handleSendSocketMessage;
    const { copyTo } = app.currentPane;
    const { userinfo } = app;
    confirm({
      title: obj.title,
      onOk() {
        onGetData(masterConfig, slaveConfig, checkConfig);
        onGetDataOk(controlConfig, materialsConfig, processConfig);
        onSaveStateOk({ enabled: false });
        if (commonUtils.isNotEmptyObject(copyTo)) {
          const { slaveData } = copyTo;
          const sIdArray = [];
          slaveData.forEach((item) => {
            const redisKey = item.sSlaveId;
            sIdArray.push(redisKey);
          });
          const sId = sIdArray.toString();
          onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
        }
      },
      onCancel() {
      },
    });
  };

  /**  点击新增按钮   */
  handleAdd = async (config, copyTo, isWait) => {
    if (commonUtils.isEmptyObject(config)) {
      const {
        masterConfig, slaveConfig, controlConfig, processConfig, materialsConfig, colorConfig,
      } = this.props;
      config = config === undefined ? {} : config;
      config.masterConfig = masterConfig;
      config.slaveConfig = slaveConfig;
      config.materialsConfig = materialsConfig;
      config.controlConfig = controlConfig;
      config.processConfig = processConfig;
      config.colorConfig = colorConfig;
    }
    let state = await this.props.onAdd(config, copyTo, true);
    const { masterData, slaveData } = state;
    const controlData = [];
    const materialsData = [];
    let processData = [];
    const colorData = [];
    if (commonUtils.isNotEmptyObject(copyTo)) {
      const {
        sModelsId, token,
      } = this.props;
      const bCkxCopyFromTechnology = '0'; // 工艺卡不用再取工艺卡。 app.systemData.filter(item => item.sName === 'CkxCopyFromTechnology')[0].sValue;
      if (bCkxCopyFromTechnology === '1') {
        const sCustomerId = commonUtils.isEmptyStr(copyTo.masterData.sCustomerId) ? copyTo.slaveData[0].sCustomerId : copyTo.masterData.sCustomerId;
        const sProductIdArray = [];
        copyTo.slaveData.forEach((slaveItem) => {
          const sProductId = slaveItem.sProductId;
          if (commonUtils.isNotEmptyStr(sProductId)) {
            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;
        if (dataReturn.code === 1) {
          const returnData = dataReturn.dataset.rows[0];
          const copyToControlConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.control`.toLowerCase());
          const copyToMaterialsConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.materials`.toLowerCase());
          const copyToProcessConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.process`.toLowerCase());
          const copyToColorConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.param`.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 colorAssignField = commonUtils.isNotEmptyArr(copyToColorConfig) ? copyToColorConfig[0].sAssignField : '';

          const bProcessAssort = true;
          let returnProcessAssort = [];
          let processAssignAssort = '';
          let dropDownDataProcessName;
          if (bProcessAssort) {
            const dataUrl = `${commonConfig.server_host}salesorder/getProcessAssort?sModelsId=${sModelsId}`;
            const dataProcessAssort = (await commonServices.postValueService(token, {}, dataUrl)).data;
            if (dataProcessAssort.code === 1) {
              returnProcessAssort = dataProcessAssort.dataset.rows[0].processassort;
              const iIndex = config.processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProcessName');
              if (iIndex > -1) {
                const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', config.processConfig.gdsconfigformslave[iIndex]);
                dropDownDataProcessName = sqlDropDownData.dropDownData;
                processAssignAssort = config.processConfig.gdsconfigformslave[iIndex].sAssignField;
              }
            }
          }
          const newCopyTo = {};
          newCopyTo.master = copyTo.masterData;
          newCopyTo.slave = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
          if (commonUtils.isNotEmptyArr(returnData.controlData)) {
            let dProductQty = 0;
            slaveData.forEach((item) => {
              dProductQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
            });
            returnData.controlData.forEach((controlItem) => {
              newCopyTo.control = controlItem;
              let controlRow = commonFunc.getDefaultData(config.controlConfig, newCopyTo); // 取默认值
              controlRow = { ...controlRow, ...commonFunc.getAssignFieldValue(controlAssignField, controlItem, newCopyTo) }; // 取赋值字段
              controlRow.handleType = 'add';
              controlRow.sId = commonUtils.createSid();
              controlRow.sParentId = masterData.sId;
              controlRow.dPartsQty = dProductQty;
              controlData.push(controlRow);

              if (commonUtils.isNotEmptyArr(returnData.processData)) {
                returnData.processData.filter(item => item.sControlId === controlItem.sId && item.sType !== '3').forEach((processItem) => {
                  newCopyTo.process = processItem;
                  let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                  processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                  processRow.handleType = 'add';
                  processRow.sId = commonUtils.createSid();
                  processRow.sParentId = masterData.sId;
                  processRow.sControlId = controlRow.sId;
                  processRow.sPartsName = controlRow.sPartsName;
                  processData.push(processRow);
                  // 配套工序
                  if (bProcessAssort) {
                    returnProcessAssort.filter(item => item.sParentId === processRow.sProcessId).forEach(((itemProcessAssort) => {
                      const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
                      const iProcessIndex = returnData.processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlItem.sId);
                      const iNewProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlRow.sId);
                      if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
                        let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                        processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                        processRow.handleType = 'add';
                        processRow.sId = commonUtils.createSid();
                        processRow.sParentId = masterData.sId;
                        processRow.sControlId = controlRow.sId;
                        processRow.sPartsName = controlRow.sPartsName;
                        processRow.sType = dropDownDataProcessName[iIndex].sType;
                        processData.push(processRow);
                      }
                    }));
                  }
                });
              }

              if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
                returnData.materialsData.filter(item => item.sControlId === controlItem.sId && item.sType !== '2').forEach((materialsItem) => {
                  newCopyTo.materials = materialsItem;
                  let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo); // 取默认值
                  materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
                  materialsRow.handleType = 'add';
                  materialsRow.sId = commonUtils.createSid();
                  materialsRow.sParentId = masterData.sId;
                  materialsRow.sControlId = controlRow.sId;
                  materialsRow.sPartsName = controlRow.sPartsName;
                  // 材料对应工序的ID要变化
                  if (commonUtils.isNotEmptyArr(returnData.processData)) {
                    const iProcessIndex = processData.findIndex(item => item.sControlId === controlRow.sId && item.sSrcProcessTbId === materialsItem.sProcessTbId);
                    if (iProcessIndex > -1) {
                      materialsRow.sProcessTbId = processData[iProcessIndex].sId;
                    }
                  }
                  materialsData.push(materialsRow);
                });
              }
            });
          }
          if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
            returnData.materialsData.filter(item => item.sType === '2').forEach((materialsItem) => {
              newCopyTo.materials = materialsItem;
              let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo); // 取默认值
              materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
              materialsRow.handleType = 'add';
              materialsRow.sId = commonUtils.createSid();
              materialsRow.sParentId = masterData.sId;
              materialsData.push(materialsRow);
            });
          }

          if (commonUtils.isNotEmptyArr(returnData.processData)) {
            returnData.processData.filter(item => item.sType === '3').forEach((processItem) => {
              newCopyTo.process = processItem;
              let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
              processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
              processRow.handleType = 'add';
              processRow.sId = commonUtils.createSid();
              processRow.sParentId = masterData.sId;
              processData.push(processRow);
              // 成品配套工序
              if (bProcessAssort) {
                returnProcessAssort.filter(item => item.sParentId === processRow.sProcessId).forEach(((itemProcessAssort) => {
                  const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
                  const iProcessIndex = returnData.processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId);
                  const iNewProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId);
                  if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
                    if (itemProcessAssort.sType === 'single') {
                      let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                      processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                      processRow.handleType = 'add';
                      processRow.sId = commonUtils.createSid();
                      processRow.sParentId = masterData.sId;
                      processRow.sType = dropDownDataProcessName[iIndex].sType;
                      processData.push(processRow);
                    } else if (itemProcessAssort.sType === 'all') {
                      controlData.forEach((controlItem) => {
                        let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                        processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                        processRow.handleType = 'add';
                        processRow.sId = commonUtils.createSid();
                        processRow.sParentId = masterData.sId;
                        processRow.sControlId = controlItem.sId;
                        processRow.sPartsName = controlItem.sPartsName;
                        processRow.sType = dropDownDataProcessName[iIndex].sType;
                        processData.push(processRow);
                      });
                    }
                  }
                }));
              }
            });
          }
          if (commonUtils.isNotEmptyArr(returnData.colorData)) {
            if (commonUtils.isNotEmptyObject(config.colorConfig)) {
              returnData.colorData.forEach((colorItem) => {
                newCopyTo.color = colorItem;
                let colorRow = commonFunc.getDefaultData(config.colorConfig, newCopyTo); // 取默认值
                colorRow = { ...colorRow, ...commonFunc.getAssignFieldValue(colorAssignField, colorItem, newCopyTo) }; // 取赋值字段
                colorRow.handleType = 'add';
                colorRow.sId = commonUtils.createSid();
                colorRow.sParentId = masterData.sId;
                colorData.push(colorRow);
              });
            }
          }
        } else {
          this.props.getServiceError(dataReturn.msg);
        }
      } else {
        const copyToControlConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.control`.toLowerCase());
        const copyToMaterialsConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.materials`.toLowerCase());
        const copyToProcessConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.process`.toLowerCase());
        const copyToColorConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.param`.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 colorAssignField = commonUtils.isNotEmptyArr(copyToColorConfig) ? copyToColorConfig[0].sAssignField : '';

        const newCopyTo = {};
        newCopyTo.master = copyTo.masterData;
        newCopyTo.slave = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
        const bProcessAssort = true;
        if (commonUtils.isEmptyArr(copyTo.controlData) && commonUtils.isNotEmptyArr(copyTo.slaveData)) {
          const { token } = this.props;
          const sSlaveId = commonUtils.isNotEmptyStr(copyTo.slaveData[0].sSlaveId) ? copyTo.slaveData[0].sSlaveId : copyTo.slaveData[0].sId;
          // const condition = { sSlaveId: copyTo.slaveData[0].sSlaveId };
          const condition = { sSlaveId };
          const dataUrl = `${commonConfig.server_host}salesorder/getPartsInfo?sModelsId=${sModelsId}`;
          const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
          // bProcessAssort = false;
          if (dataReturn.code === 1) {
            const returnData = dataReturn.dataset.rows[0];
            copyTo.controlData = returnData.controlData;
            copyTo.materialsData = returnData.materialsData;
            copyTo.processData = returnData.processData;
            copyTo.colorData = returnData.colorData;
          } else {
            this.props.getServiceError(dataReturn);
          }
        }

        let returnProcessAssort = [];
        let processAssignAssort = '';
        let dropDownDataProcessName;
        if (bProcessAssort) {
          const dataUrl = `${commonConfig.server_host}salesorder/getProcessAssort?sModelsId=${sModelsId}`;
          const dataProcessAssort = (await commonServices.postValueService(token, {}, dataUrl)).data;
          if (dataProcessAssort.code === 1) {
            returnProcessAssort = dataProcessAssort.dataset.rows[0].processassort;
            const iIndex = config.processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProcessName');
            if (iIndex > -1) {
              const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', config.processConfig.gdsconfigformslave[iIndex]);
              dropDownDataProcessName = sqlDropDownData.dropDownData;
              processAssignAssort = config.processConfig.gdsconfigformslave[iIndex].sAssignField;
            }
          }
        }
        if (commonUtils.isNotEmptyArr(copyTo.controlData)) {
          let dProductQty = 0;
          slaveData.forEach((item) => {
            dProductQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
          });
          copyTo.controlData.forEach((controlItem) => {
            newCopyTo.control = controlItem;
            let controlRow = commonFunc.getDefaultData(config.controlConfig, newCopyTo); // 取默认值
            controlRow = { ...controlRow, ...commonFunc.getAssignFieldValue(controlAssignField, controlItem, newCopyTo) }; // 取赋值字段
            controlRow.handleType = 'add';
            controlRow.sId = commonUtils.createSid();
            controlRow.sParentId = masterData.sId;
            controlRow.dPartsQty = dProductQty;
            controlData.push(controlRow);

            if (commonUtils.isNotEmptyArr(copyTo.processData)) {
              copyTo.processData.filter(item => item.sControlId === controlItem.sId && item.sType !== '3').forEach((processItem) => {
                newCopyTo.process = processItem;
                let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                processRow.handleType = 'add';
                processRow.sId = commonUtils.createSid();
                processRow.sParentId = masterData.sId;
                processRow.sControlId = controlRow.sId;
                processRow.sPartsName = controlRow.sPartsName;
                processRow.sType = processItem.sType;
                processData.push(processRow);
                if (bProcessAssort) {
                  returnProcessAssort.filter(item => item.sParentId === processRow.sProcessId).forEach(((itemProcessAssort) => {
                    const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
                    const iProcessIndex = copyTo.processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlItem.sId);
                    const iNewProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlRow.sId);
                    if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
                      let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                      processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                      processRow.handleType = 'add';
                      processRow.sId = commonUtils.createSid();
                      processRow.sParentId = masterData.sId;
                      processRow.sControlId = controlRow.sId;
                      processRow.sPartsName = controlRow.sPartsName;
                      processRow.sType = dropDownDataProcessName[iIndex].sType;
                      processData.push(processRow);
                    }
                  }));
                }
              });
            }

            if (commonUtils.isNotEmptyArr(copyTo.materialsData)) {
              copyTo.materialsData.filter(item => item.sControlId === controlItem.sId && item.sType !== '2').forEach((materialsItem) => {
                newCopyTo.materials = materialsItem;
                let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo); // 取默认值
                materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
                materialsRow.handleType = 'add';
                materialsRow.sId = commonUtils.createSid();
                materialsRow.sParentId = masterData.sId;
                materialsRow.sControlId = controlRow.sId;
                materialsRow.sPartsName = controlRow.sPartsName;
                materialsRow.sType = materialsItem.sType;
                // 材料对应工序的ID要变化
                if (commonUtils.isNotEmptyArr(copyTo.processData)) {
                  const iProcessIndex = processData.findIndex(item => item.sControlId === controlRow.sId && item.sSrcProcessTbId === materialsItem.sProcessTbId);
                  if (iProcessIndex > -1) {
                    materialsRow.sProcessTbId = processData[iProcessIndex].sId;
                  }
                }
                materialsData.push(materialsRow);
              });
            }
          });
        }

        if (commonUtils.isNotEmptyArr(copyTo.materialsData)) {
          copyTo.materialsData.filter(item => item.sType === '2').forEach((materialsItem) => {
            newCopyTo.materials = materialsItem;
            let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo); // 取默认值
            materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
            materialsRow.handleType = 'add';
            materialsRow.sId = commonUtils.createSid();
            materialsRow.sParentId = masterData.sId;
            materialsRow.sType = materialsItem.sType;
            materialsData.push(materialsRow);
          });
        }

        if (commonUtils.isNotEmptyArr(copyTo.processData)) {
          copyTo.processData.filter(item => item.sType === '3').forEach((processItem) => {
            newCopyTo.process = processItem;
            let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
            processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
            processRow.handleType = 'add';
            processRow.sId = commonUtils.createSid();
            processRow.sParentId = masterData.sId;
            processRow.sType = processItem.sType;
            processData.push(processRow);

            if (bProcessAssort) {
              returnProcessAssort.filter(item => item.sParentId === processRow.sProcessId).forEach(((itemProcessAssort) => {
                const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
                const iProcessIndex = copyTo.processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId);
                const iNewProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId);
                if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
                  if (itemProcessAssort.sType === 'single') {
                    let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                    processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                    processRow.handleType = 'add';
                    processRow.sId = commonUtils.createSid();
                    processRow.sParentId = masterData.sId;
                    processRow.sType = dropDownDataProcessName[iIndex].sType;
                    processData.push(processRow);
                  } else if (itemProcessAssort.sType === 'all') {
                    controlData.forEach((controlItem) => {
                      let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                      processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                      processRow.handleType = 'add';
                      processRow.sId = commonUtils.createSid();
                      processRow.sParentId = masterData.sId;
                      processRow.sControlId = controlItem.sId;
                      processRow.sPartsName = controlItem.sPartsName;
                      processRow.sType = dropDownDataProcessName[iIndex].sType;
                      processData.push(processRow);
                    });
                  }
                }
              }));
            }
          });
        }
        if (commonUtils.isNotEmptyArr(copyTo.colorData)) {
          if (commonUtils.isNotEmptyObject(config.colorConfig)) {
            copyTo.colorData.forEach((colorItem) => {
              newCopyTo.color = colorItem;
              let colorRow = commonFunc.getDefaultData(config.colorConfig, newCopyTo); // 取默认值
              colorRow = { ...colorRow, ...commonFunc.getAssignFieldValue(colorAssignField, colorItem, newCopyTo) }; // 取赋值字段
              colorRow.handleType = 'add';
              colorRow.sId = commonUtils.createSid();
              colorRow.sParentId = masterData.sId;
              colorData.push(colorRow);
            });
          }
        }
      }
      if (controlData.length === 0) {
        if (!commonUtils.isEmpty(slaveData[0].sProductId)) {
          const iIndex = config.slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductName');
          if (iIndex > -1) {
            const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', config.slaveConfig.gdsconfigformslave[iIndex]);
            const dropDownData = sqlDropDownData.dropDownData;
            const [changeData] = dropDownData.filter(item => item.sProductId === slaveData[0].sProductId);
            const sParentId = commonUtils.isEmpty(changeData) ? '' : changeData.sParentId;
            if (!commonUtils.isEmpty(sParentId)) {
              const iIndex = config.masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductClassifyName');
              if (iIndex > -1) {
                let dProductQty = 0;
                slaveData.forEach((item) => {
                  dProductQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
                });
                const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', config.masterConfig.gdsconfigformslave[iIndex]);
                const dropDownData = sqlDropDownData.dropDownData;
                const [changeData] = dropDownData.filter(item => item.sId === sParentId);
                const sAllPartsName = commonUtils.isEmpty(changeData) ? '' : changeData.sAllPartsName;
                if (commonUtils.isNotEmptyStr(sAllPartsName)) {
                  const sAssignFieldObj = sAllPartsName.split(',');
                  for (const child of sAssignFieldObj) {
                    let allTableData = {};
                    allTableData = {};
                    allTableData.master = masterData;
                    allTableData.slave = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
                    const tableDataRow = commonFunc.getDefaultData(config.controlConfig, allTableData);
                    tableDataRow.handleType = 'add';
                    tableDataRow.sId = commonUtils.createSid();
                    tableDataRow.sParentId = masterData && masterData.sId ? masterData.sId : null;
                    tableDataRow.key = tableDataRow.sId;
                    tableDataRow.bDefault = false;
                    tableDataRow.iOrder = 0;
                    tableDataRow.sPartsName = child;
                    tableDataRow.dPartsQty = dProductQty;
                    controlData.push(tableDataRow);
                  }
                }
              }
            }
          }
        }
      } else {
        processData = this.sortData(controlData, processData);
      }
    } else {
      state.fastOrderModalVisible = this.props.bFastOrderView;
      const { sModelsId } = this.props;
      if (commonUtils.isEmpty(masterData.sProductClassifyId)) {
        const iIndex = config.masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductClassifyName');
        if (iIndex > -1) {
          const returnValue = {};
          const { sAssignField } = config.masterConfig.gdsconfigformslave[iIndex];
          const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', config.masterConfig.gdsconfigformslave[iIndex]);
          const dropDownData = sqlDropDownData.dropDownData;
          const [changeData] = dropDownData.filter(item => item.sType === 'huace');
          if (!commonUtils.isEmpty(sAssignField)) {
            /* 赋值数组 */
            const sAssignFieldObj = sAssignField.split(',');
            if (commonUtils.isNotEmptyObject(changeData)) {
              for (const child of sAssignFieldObj) {
                if (child.indexOf(':') > -1) {
                  const sFieldName = child.split(':')[0].trim();
                  const sValueName = child.split(':')[1].trim();
                  returnValue[sFieldName] = changeData[sValueName];
                }
              }
            }
          }
          const addState = await this.handleMasterChange('master', 'sProductClassifyName', { ...masterData, ...returnValue }, masterData.sId, null, { masterData, masterConfig: config.masterConfig }, true);
          state = { ...state, ...addState };
        }
      }
    }
    if (controlData.length === 0) {
      const allTableData = {};
      allTableData.master = masterData;
      allTableData.slave = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
      const tableDataRow = commonFunc.getDefaultData(config.controlConfig, allTableData);
      tableDataRow.handleType = 'add';
      tableDataRow.sId = commonUtils.createSid();
      tableDataRow.sParentId = masterData && masterData.sId ? masterData.sId : null;
      tableDataRow.key = tableDataRow.sId;
      tableDataRow.bDefault = false;
      tableDataRow.iOrder = 1; /* 序号从1开始 */
      let dProductQty = 0;
      slaveData.forEach((item) => {
        dProductQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
      });
      tableDataRow.dPartsQty = dProductQty;
      controlData.push(tableDataRow);
    }
    const stateNew = {
      ...state,
      controlData,
      controlSelectedRowKeys: [],
      materialsData,
      materialsSelectedRowKeys: [],
      processData,
      colorData,
      processSelectedRowKeys: [],
      checkProcessClassifyData: [],
    };
    if (isWait) {
      return stateNew;
    } else {
      this.props.onSaveState(stateNew);
    }
  };

  handleSelect = async (name, selectConfig, selectData) => {
    const {
      [`${name}Data`]: tableData, [`${name}Config`]: tableConfig, masterConfig, slaveSelectedRowKeys, controlSelectedRowKeys, sModelsId, token,
      slaveConfig, controlConfig, materialsConfig, processConfig, colorConfig, slaveData, controlData: controlDataOld, materialsData: materialsDataOld, processData: processDataOld, colorData: colorDataOld,
      controlDelData: controlDelDataOld, materialsDelData: materialsDelDataOld, processDelData: processDelDataOld, colorDelData: colorDelDataOld,
    } = this.props;
    let { masterData } = this.props;
    if (name === 'productProcessInfo') {
      if (commonUtils.isNotEmptyArr(selectData)) {
        const controlData = [];
        const materialsData = [];
        const processData = [];
        const colorData = [];
        const addState = {};
        const controlDelData = commonUtils.isEmptyArr(controlDelDataOld) ? [] : controlDelDataOld;
        const materialsDelData = commonUtils.isEmptyArr(materialsDelDataOld) ? [] : materialsDelDataOld;
        const processDelData = commonUtils.isEmptyArr(processDelDataOld) ? [] : processDelDataOld;
        const colorDelData = commonUtils.isEmptyArr(colorDelDataOld) ? [] : colorDelDataOld;
        controlDataOld.forEach((item) => {
          item.handleType = 'del';
          controlDelData.push(item);
        });
        addState.controlDelData = controlDelData;
        materialsDataOld.forEach((item) => {
          item.handleType = 'del';
          materialsDelData.push(item);
        });
        addState.materialsDelData = materialsDelData;
        processDataOld.forEach((item) => {
          item.handleType = 'del';
          processDelData.push(item);
        });
        addState.processDelData = processDelData;
        if (commonUtils.isNotEmptyArr(colorDataOld) && colorDataOld.length > 0) {
          colorDataOld.forEach((item) => {
            item.handleType = 'del';
            colorDelData.push(item);
          });
        }
        addState.colorDelData = colorDelData;
        const config = {};
        config.masterConfig = masterConfig;
        config.slaveConfig = slaveConfig;
        config.controlConfig = controlConfig;
        config.materialsConfig = materialsConfig;
        config.processConfig = processConfig;
        config.colorConfig = colorConfig;
        let iSlaveIndex = -1;
        if (!commonUtils.isEmpty(slaveSelectedRowKeys)) {
          iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys.toString());
        }
        const condition = { sCardId: selectData[0].sId };
        const dataUrl = `${commonConfig.server_host}salesorder/getProcessCardDataByCustomIdProductId/?sModelsId=${sModelsId}`;
        const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
        if (dataReturn.code === 1) {
          const copyTo = { config: masterConfig.gdsconfigformslave, name: selectConfig.sControlName };
          const returnData = dataReturn.dataset.rows[0];
          const copyToMasterDetailConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}`.toLowerCase());
          const copyToSlaveDetailConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slave`.toLowerCase());
          const copyToControlConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.control`.toLowerCase());
          const copyToMaterialsConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.materials`.toLowerCase());
          const copyToProcessConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.process`.toLowerCase());
          const copyToColorConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.param`.toLowerCase());
          const masterDetailAssignField = commonUtils.isNotEmptyArr(copyToMasterDetailConfig) ? copyToMasterDetailConfig[0].sAssignField : '';
          const slaveDetailAssignField = commonUtils.isNotEmptyArr(copyToSlaveDetailConfig) ? copyToSlaveDetailConfig[0].sAssignField : '';
          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 colorAssignField = commonUtils.isNotEmptyArr(copyToColorConfig) ? copyToColorConfig[0].sAssignField : '';
          const newCopyTo = {};
          newCopyTo.master = copyTo.masterData;
          newCopyTo.slave = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];

          if (iSlaveIndex > -1) {
            slaveData[iSlaveIndex] = { ...slaveData[iSlaveIndex], ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, selectData[0], newCopyTo) }; // 取赋值字段
          }

          const bProcessAssort = true;
          let returnProcessAssort = [];
          let processAssignAssort = '';
          let dropDownDataProcessName;
          if (bProcessAssort) {
            const dataUrl = `${commonConfig.server_host}salesorder/getProcessAssort?sModelsId=${sModelsId}`;
            const dataProcessAssort = (await commonServices.postValueService(token, {}, dataUrl)).data;
            if (dataProcessAssort.code === 1) {
              returnProcessAssort = dataProcessAssort.dataset.rows[0].processassort;
              const iIndex = config.processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProcessName');
              if (iIndex > -1) {
                const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', config.processConfig.gdsconfigformslave[iIndex]);
                dropDownDataProcessName = sqlDropDownData.dropDownData;
                processAssignAssort = config.processConfig.gdsconfigformslave[iIndex].sAssignField;
              }
            }
          }

          if (commonUtils.isNotEmptyArr(returnData.controlData)) {
            let dProductQty = 0;

            if (commonUtils.isNotEmptyArr(returnData.slaveData)) {
              masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, returnData.slaveData[0], newCopyTo) }; // 取赋值字段
            }

            slaveData.forEach((item, iSlaveIndex) => {
              if (commonUtils.isNotEmptyArr(returnData.slaveData)) {
                item = { ...item, ...commonFunc.getAssignFieldValue(slaveDetailAssignField, returnData.slaveData[0], newCopyTo) }; // 取赋值字段
              }
              slaveData[iSlaveIndex] = item;
              dProductQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
            });
            returnData.controlData.forEach((controlItem) => {
              newCopyTo.control = controlItem;
              let controlRow = commonFunc.getDefaultData(config.controlConfig, newCopyTo); // 取默认值
              controlRow = { ...controlRow, ...commonFunc.getAssignFieldValue(controlAssignField, controlItem, newCopyTo) }; // 取赋值字段
              controlRow.handleType = 'add';
              controlRow.sId = commonUtils.createSid();
              controlRow.sParentId = masterData.sId;
              controlRow.dPartsQty = dProductQty;
              controlData.push(controlRow);

              if (commonUtils.isNotEmptyArr(returnData.processData)) {
                returnData.processData.filter(item => item.sControlId === controlItem.sId && item.sType !== '3').forEach((processItem) => {
                  newCopyTo.process = processItem;
                  let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                  processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                  processRow.handleType = 'add';
                  processRow.sId = commonUtils.createSid();
                  processRow.sParentId = masterData.sId;
                  processRow.sControlId = controlRow.sId;
                  processRow.sPartsName = controlRow.sPartsName;
                  processData.push(processRow);

                  // 配套工序
                  if (bProcessAssort) {
                    returnProcessAssort.filter(item => item.sParentId === processRow.sProcessId).forEach(((itemProcessAssort) => {
                      const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
                      const iProcessIndex = returnData.processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlItem.sId);
                      const iNewProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlRow.sId);
                      if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
                        let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                        processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                        processRow.handleType = 'add';
                        processRow.sId = commonUtils.createSid();
                        processRow.sParentId = masterData.sId;
                        processRow.sControlId = controlRow.sId;
                        processRow.sPartsName = controlRow.sPartsName;
                        processRow.sType = dropDownDataProcessName[iIndex].sType;
                        processData.push(processRow);
                      }
                    }));
                  }
                });
              }

              if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
                returnData.materialsData.filter(item => item.sControlId === controlItem.sId && item.sType !== '2').forEach((materialsItem) => {
                  newCopyTo.materials = materialsItem;
                  let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo); // 取默认值
                  materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
                  materialsRow.handleType = 'add';
                  materialsRow.sId = commonUtils.createSid();
                  materialsRow.sParentId = masterData.sId;
                  materialsRow.sControlId = controlRow.sId;
                  materialsRow.sPartsName = controlRow.sPartsName;
                  // 材料对应工序的ID要变化
                  if (commonUtils.isNotEmptyArr(returnData.processData)) {
                    const iProcessIndex = processData.findIndex(item => item.sControlId === controlRow.sId && item.sSrcProcessTbId === materialsItem.sProcessTbId);
                    if (iProcessIndex > -1) {
                      materialsRow.sProcessTbId = processData[iProcessIndex].sId;
                    }
                  }
                  materialsData.push(materialsRow);
                });
              }
            });
          }
          if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
            returnData.materialsData.filter(item => item.sType === '2').forEach((materialsItem) => {
              newCopyTo.materials = materialsItem;
              let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo); // 取默认值
              materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
              materialsRow.handleType = 'add';
              materialsRow.sId = commonUtils.createSid();
              materialsRow.sParentId = masterData.sId;
              materialsData.push(materialsRow);
            });
          }

          if (commonUtils.isNotEmptyArr(returnData.processData)) {
            returnData.processData.filter(item => item.sType === '3').forEach((processItem) => {
              newCopyTo.process = processItem;
              let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
              processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
              processRow.handleType = 'add';
              processRow.sId = commonUtils.createSid();
              processRow.sParentId = masterData.sId;
              processData.push(processRow);

              // 成品配套工序
              if (bProcessAssort) {
                returnProcessAssort.filter(item => item.sParentId === processRow.sProcessId).forEach(((itemProcessAssort) => {
                  const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
                  const iProcessIndex = returnData.processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId);
                  const iNewProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId);
                  if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
                    if (itemProcessAssort.sType === 'single') {
                      let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                      processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                      processRow.handleType = 'add';
                      processRow.sId = commonUtils.createSid();
                      processRow.sParentId = masterData.sId;
                      processRow.sType = dropDownDataProcessName[iIndex].sType;
                      processData.push(processRow);
                    } else if (itemProcessAssort.sType === 'all') {
                      controlData.forEach((controlItem) => {
                        let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                        processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                        processRow.handleType = 'add';
                        processRow.sId = commonUtils.createSid();
                        processRow.sParentId = masterData.sId;
                        processRow.sControlId = controlItem.sId;
                        processRow.sPartsName = controlItem.sPartsName;
                        processRow.sType = dropDownDataProcessName[iIndex].sType;
                        processData.push(processRow);
                      });
                    }
                  }
                }));
              }
            });
          }
          if (commonUtils.isNotEmptyArr(returnData.colorData)) {
            returnData.colorData.forEach((colorItem) => {
              newCopyTo.color = colorItem;
              let colorRow = commonFunc.getDefaultData(config.colorConfig, newCopyTo); // 取默认值
              colorRow = { ...colorRow, ...commonFunc.getAssignFieldValue(colorAssignField, colorItem, newCopyTo) }; // 取赋值字段
              colorRow.handleType = 'add';
              colorRow.sId = commonUtils.createSid();
              colorRow.sParentId = masterData.sId;
              colorData.push(colorRow);
            });
          }
          this.props.onSaveState({
            [`${name}ChooseVisible`]: false,
            processData,
            materialsData,
            controlData,
            colorData,
            masterData,
            controlSelectedRowKeys: [],
            materialsSelectedRowKeys: [],
            processSelectedRowKeys: [],
            ...addState,
          });
        } else {
          this.props.getServiceError(dataReturn.msg);
        }
      }
    } else {
      const { controlData } = this.props;
      const iControlIndex = commonUtils.isNotEmptyArr(controlSelectedRowKeys) ? controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]) : -1;
      if (commonUtils.isNotEmptyArr(selectData)) {
        for (const item of selectData) {
          const newCopyTo = {};
          newCopyTo.master = masterData;
          if (iControlIndex > -1) {
            newCopyTo.control = controlData[iControlIndex];
          }
          let tableDataRow = commonFunc.getDefaultData(tableConfig, newCopyTo); // 取默认值
          tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段
          tableDataRow.handleType = 'add';
          tableDataRow.sId = commonUtils.createSid();
          tableDataRow.sParentId = masterData.sId;
          if (name === 'process') {
            /* 设置工单参数下拉 */
            if (commonUtils.isNotEmptyObject(tableDataRow.sWorkOrderParam)) {
              tableDataRow = { ...tableDataRow, ...commonUtils.convertStrToObj(tableDataRow.sWorkOrderParam) };
            }
            const value = { sSqlCondition: { sParentId: item.sId } };
            const configDataId = '11811781131121915166093023980';
            const dataUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${configDataId}?sModelsId=${sModelsId}`;
            const returnData = (await commonServices.postValueService(token, value, dataUrl)).data;
            if (returnData.code === 1) {
              const eleprocessmachineData = returnData.dataset.rows[0].dataSet;
              const newData = eleprocessmachineData.filter(item => item.bDefault);
              if (commonUtils.isNotEmptyArr(newData)) {
                tableDataRow.sMachineId = newData[0].sMachineId;
              }
            }
            const bProcessAssort = true;
            let returnProcessAssort = [];
            let processAssignAssort = '';
            let dropDownDataProcessName;
            if (bProcessAssort) {
              const dataUrl = `${commonConfig.server_host}salesorder/getProcessAssort?sModelsId=${sModelsId}`;
              const dataProcessAssort = (await commonServices.postValueService(token, {}, dataUrl)).data;
              if (dataProcessAssort.code === 1) {
                returnProcessAssort = dataProcessAssort.dataset.rows[0].processassort;
                const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProcessName');
                if (iIndex > -1) {
                  const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', processConfig.gdsconfigformslave[iIndex]);
                  dropDownDataProcessName = sqlDropDownData.dropDownData;
                  processAssignAssort = processConfig.gdsconfigformslave[iIndex].sAssignField;
                }
              }
            }
            // 配套工序
            if (bProcessAssort) {
              returnProcessAssort.filter(item => item.sParentId === tableDataRow.sProcessId).forEach(((itemProcessAssort) => {
                const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
                if (iIndex > -1) {
                  const iProcessIndex = selectData.findIndex(item => item.sId === itemProcessAssort.sProcessId);
                  const iNewProcessIndex = dropDownDataProcessName[iIndex].sType === '3' ?
                    tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId) :
                    tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlData[iControlIndex].sId);
                  if (iIndex > -1 && iProcessIndex < 0 && iNewProcessIndex < 0) {
                    let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
                    processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                    processRow.handleType = 'add';
                    processRow.sId = commonUtils.createSid();
                    processRow.sParentId = masterData.sId;
                    processRow.sType = dropDownDataProcessName[iIndex].sType;
                    if (iControlIndex > -1 && processRow.sType !== '3') {
                      processRow.sControlId = controlData[iControlIndex].sId;
                      processRow.sPartsName = controlData[iControlIndex].sPartsName;
                    }
                    tableData.push(processRow);

                    if (itemProcessAssort.sType === 'all') {
                      controlData.filter(item => item.sId !== controlData[iControlIndex].sId).forEach((controlTableRow) => {
                        const iNewProcessIndex = dropDownDataProcessName[iIndex].sType === '3' ?
                          tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId) :
                          tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlTableRow.sId);
                        if (iNewProcessIndex < 0) {
                          let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
                          processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                          processRow.handleType = 'add';
                          processRow.sId = commonUtils.createSid();
                          processRow.sParentId = masterData.sId;
                          processRow.sType = dropDownDataProcessName[iIndex].sType;
                          if (iControlIndex > -1 && processRow.sType !== '3') {
                            processRow.sControlId = controlTableRow.sId;
                            processRow.sPartsName = controlTableRow.sPartsName;
                          }
                          tableData.push(processRow);
                        }
                      });
                    }
                  }
                }
              }));
            }
          }
          if (iControlIndex > -1 && tableDataRow.sType !== '3') {
            tableDataRow.sControlId = controlData[iControlIndex].sId;
            tableDataRow.sPartsName = controlData[iControlIndex].sPartsName;
            tableData.push(tableDataRow);
          } else if (tableDataRow.sType === '3') {
            tableData.push(tableDataRow);
          }
        }
      }
      const tableDataNew = this.sortData(controlData, tableData);
      this.props.onSaveState({
        [`${name}Data`]: tableDataNew, [`${name}ChooseVisible`]: false, materialsSelectedRowKeys: [],
      });
    }
  };

  sortData = (tableData, processData) => {
    processData.sort((g1, g2) => {
      const iIndex1 = tableData.findIndex(item => item.sId === g1.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g1.sControlId);
      if (g1.iOrder === undefined) {
        g1.iOrder = '';
      }
      if (g2.iOrder === undefined) {
        g2.iOrder = '';
      }
      let sPartOrder1 = `0000${iIndex1}`;
      sPartOrder1 = sPartOrder1.substring(sPartOrder1.length - 3);
      let sOrder1 = `00000${g1.iOrder.toString()}`;
      sOrder1 = sOrder1.indexOf('.') > -1 ? sOrder1 : `${sOrder1}.00`;
      sOrder1 = sOrder1.replace('.', '');
      sOrder1 = sOrder1.substring(sOrder1.length - 5);
      const iIndex2 = tableData.findIndex(item => item.sId === g2.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g2.sControlId);
      let sPartOrder2 = `0000${iIndex2}`;
      sPartOrder2 = sPartOrder2.substring(sPartOrder2.length - 3);
      let sOrder2 = `00000${g2.iOrder.toString()}`;
      sOrder2 = sOrder2.indexOf('.') > -1 ? sOrder2 : `${sOrder2}.00`;
      sOrder2 = sOrder2.replace('.', '');
      sOrder2 = sOrder2.substring(sOrder2.length - 5);
      return parseFloat(sPartOrder1 + g1.sType + sOrder1) - parseFloat(sPartOrder2 + g2.sType + sOrder2);
    });
    return processData;
  };
  /* 控制排序 */
  orderData = (e, name, type) => {
    const {
      [`${name}SelectedRowKeys`]: tableselectedRowKeys, controlData, controlSelectedRowKeys, app,
    } = this.props;
    let { [`${name}Data`]: processData } = this.props;
    if (name === 'process') {
      if (commonUtils.isEmptyArr(tableselectedRowKeys)) {
        message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseMoveData'));/* 请勾选要移动数据 */
        return;
      }
      if (commonUtils.isEmptyArr(processData)) {
        message.warn(commonFunc.showMessage(app.commonConst, 'NoProcessData'));/* 请填写工序表数据 */
        return;
      }
      const processNew = processData.filter((item) => { /* 获取勾选数据集 */
        return tableselectedRowKeys.indexOf(item.sId) > -1;
      });
      if (commonUtils.isEmptyArr(processNew)) {
        message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseMoveData'));/* 请选择要移动数据 */
        return;
      }
      const len = processData.length;
      const newLen = processNew.length;
      let num = 0.01;/* 循环增加体 */
      let targetiOrder = -1;
      if (type === 1) { /*  上移 */
        const iIndex = processData.findIndex(item => item.sId === processNew[0].sId);/* 选中第一个节点的下标 */
        if (iIndex === 0) {
          message.warn(commonFunc.showMessage(app.commonConst, 'NoUp'));/* 无需上移 */
          return;
        } else {
          targetiOrder = processData[iIndex - 1].iOrder - 1; /* 目标排序号 */
        }
      } else if (type === 2) { /*  下移 */
        const iIndex = processData.findIndex(item => item.sId === processNew[newLen - 1].sId);/* 选中最后一个节点的下标 */
        if (iIndex === len - 1) {
          message.warn(commonFunc.showMessage(app.commonConst, 'NoDown')); /* 无需下移 */
          return;
        } else {
          targetiOrder = processData[iIndex + 1].iOrder;
        }
      } else if (type === 0) { /*  置顶 */
        const iIndex = processData.findIndex(item => item.sId === processNew[0].sId);/* 选中第一个节点的下标 */
        if (iIndex === 0) {
          message.warn(commonFunc.showMessage(app.commonConst, 'NoTop')); /* 无需置顶 */
          return;
        } else {
          targetiOrder = processData[0].iOrder - 1;
        }
      } else if (type === 3) { /*  置底 */
        const iIndex = processData.findIndex(item => item.sId === processNew[newLen - 1].sId);/* 选中最后一个节点的下标 */
        if (iIndex === len - 1) {
          message.warn(commonFunc.showMessage(app.commonConst, 'NoBottom')); /* 无需置底 */
          return;
        } else {
          targetiOrder = processData[len - 1].iOrder + 1;
        }
      }
      processNew.forEach((item) => {
        if (commonUtils.isEmptyObject(item.sType)) {
          message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseProcessType'));/* 请选择工序名称 */
          return;
        }
        const index1 = processData.findIndex(item1 => item1.sId === item.sId);
        processData[index1] = { ...item, iOrder: targetiOrder + num };
        num += 0.01;
      });
      processData = this.sortData(controlData, processData);
      const processSortData = this.props.orderNum(processData, controlSelectedRowKeys);
      if (commonUtils.isNotEmptyArr(processSortData)) {
        processData = processSortData;
      }
      this.props.onSaveState({ [`${name}Data`]: processData });
    }
  };

  /** 表格数据更改 */
  // name 不写完整的state名称作用为了要用到total // (name, changeValue, sId, dropDownData)
  handleTableChange = async (name, sFieldName, changeValue, sId, dropDownData) => {
    /*   从CommonBase获取默认参数   */
    if (name === 'slave') {
      const {
        sModelsId, [`${name}Data`]: tableData, masterConfig, controlConfig, controlData: controlDataOld, masterData, sModelsType,
      } = this.props;
      const tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
      if (tableDataRow === undefined) return;
      const iIndex = tableData.findIndex(item => item.sId === sId);
      tableData[iIndex] = tableDataRow;
      const addState = {};
      if (sFieldName === 'dProductQty' || sFieldName === 'dGiveQty' || sFieldName === 'dStockupQty') {
        let dPartsQty = 0;
        tableData.forEach((item) => {
          dPartsQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
        });
        const controlData = [];
        controlDataOld.forEach((item) => {
          const itemNew = { ...item };
          itemNew.dPartsQty = dPartsQty;
          controlData.push(itemNew);
        });
        addState.controlData = controlData;
      }
      if (sFieldName === 'sCustomerId' || sFieldName === 'sCustomerNo' || sFieldName === 'sCustomerName') {
        // commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductId', []);
        // commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductNo', []);
        // commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductName', []);
        tableDataRow.sProductId = '';
        tableDataRow.sProductNo = '';
        tableDataRow.sProductName = '';
        tableData[iIndex] = tableDataRow;
      } else if ((sFieldName === 'sProductId' || sFieldName === 'sProductNo' || sFieldName === 'sProductName') && tableDataRow.handleType === 'add') {
        // const productIdDropDown = commonUtils.getStoreDropDownData(sModelsId, 'slave', sFieldName);
        const iProductIdIndex = dropDownData.findIndex(item => item.sId === tableData[0].sProductId);
        if (iProductIdIndex > -1 && tableDataRow.sProductId !== tableDataRow.sProductName && commonUtils.isEmptyArr(controlDataOld)) {
          const changeData = dropDownData[iProductIdIndex];
          const sParentId = commonUtils.isEmpty(changeData) ? '' : changeData.sParentId;
          if (!commonUtils.isEmpty(sParentId)) {
            const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductClassifyName');
            if (iIndex > -1) {
              let dProductQty = 0;
              tableData.forEach((item) => {
                dProductQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
              });
              const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', masterConfig.gdsconfigformslave[iIndex]);
              const dropDownData = sqlDropDownData.dropDownData;
              const [changeData] = dropDownData.filter(item => item.sId === sParentId);
              const sAllPartsName = commonUtils.isEmpty(changeData) ? '' : changeData.sAllPartsName;
              if (commonUtils.isNotEmptyStr(sAllPartsName)) {
                const sAssignFieldObj = sAllPartsName.split(',');
                const controlData = [];
                for (const child of sAssignFieldObj) {
                  let allTableData = {};
                  allTableData = {};
                  allTableData.master = masterData;
                  allTableData.slave = commonUtils.isEmptyArr(tableData) ? {} : tableData[0];
                  const tableDataRow = commonFunc.getDefaultData(controlConfig, allTableData);
                  tableDataRow.handleType = 'add';
                  tableDataRow.sId = commonUtils.createSid();
                  tableDataRow.sParentId = masterData && masterData.sId ? masterData.sId : null;
                  tableDataRow.key = tableDataRow.sId;
                  tableDataRow.bDefault = false;
                  tableDataRow.iOrder = controlData.length + 1;
                  tableDataRow.sPartsName = child;
                  tableDataRow.dPartsQty = dProductQty;
                  controlData.push(tableDataRow);
                }
                addState.controlData = controlData;
              }
            }
          }
        }
      }
      /* 膜内工艺卡算法逻辑  */
      if (sModelsType === 'manufacture/workOrder3' || sModelsId === '101251240115016046551448370') {
        const controlData = addState.controlData;
        if (sFieldName === 'dProductLength' || sFieldName === 'dProductWidth' || sFieldName === 'dCombineCoefficient') {
          if (commonUtils.isNotEmptyArr(tableData) && tableData.length > 1 && commonUtils.isNotEmptyArr(controlData)) {
            let sumTotal = 0;
            tableData.forEach((item) => {
              const singleSum = item.dProductLength * item.dProductWidth * item.dCombineCoefficient;
              sumTotal += singleSum;
            });
            /* 计算多产品合拼的折算率 */
            const dConversionRate = ((controlData[0].dMaterialsLength * controlData[0].dMaterialsWidth) *
              (tableDataRow.dProductLength * tableDataRow.dProductWidth * tableDataRow.dCombineCoefficient)) / sumTotal / tableDataRow.dCombineCoefficient / 1000000;
            tableDataRow.dConversionRate = commonUtils.convertFixNum(dConversionRate, 6);
            tableData[iIndex] = tableDataRow;
            tableData.forEach((item, index) => {
              if (item.sId !== sId) {
                const addSata = {};
                const dConversionRate = ((controlData[0].dMaterialsLength * controlData[0].dMaterialsWidth) *
                  (item.dProductLength * item.dProductWidth * item.dCombineCoefficient)) / sumTotal / item.dCombineCoefficient / 1000000;
                addSata.dConversionRate = commonUtils.convertFixNum(dConversionRate, 6);
                tableData[index] = { ...item, ...addSata };
              }
            });
          }
        }
      }
      this.props.onSaveState({ [`${name}Data`]: tableData, ...addState });
    } else if (name === 'control') {
      const {
        [`${name}Data`]: tableData, materialsData: materialsDataOld, processData: processDataOld, sModelsId, sModelsType, slaveData,
      } = this.props;
      let { masterData } = 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);
      }
      /* 膜内工艺卡算法逻辑  */
      if (sModelsType === 'manufacture/workOrder3' && sModelsId === '101251240115016046551448370') {
        /* 排版数dSinglePQty=列数iCol*iRow个数 */
        const iCol = commonUtils.isNull(tableDataRow.iCol, 0);
        const iRow = commonUtils.isNull(tableDataRow.iRow, 0);
        const dMachineWidth = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMachineWidth, 0));
        const dMachineLength = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMachineLength, 0));
        const dCutEdge = commonUtils.isNull(tableDataRow.dCutEdge, 0);
        const dColGap = commonUtils.isNull(tableDataRow.dColGap, 0);
        const dRowGap = commonUtils.isNull(tableDataRow.dRowGap, 0);
        const dScraperGap = commonUtils.isNull(tableDataRow.dScraperGap, 0);
        const dMaterialsLength = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMaterialsLength, 0));
        const dMaterialsWidth = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMaterialsWidth, 0));
        const dSinglePQty = commonUtils.isNull(tableDataRow.dSinglePQty, 0);
        if (sFieldName === 'iCol' || sFieldName === 'iRow') {
          tableDataRow.dSinglePQty = iCol * iRow;
        }
        /* 膜宽dMaterialsWidth =图文尺寸dMachineWidth*列数iCol+图文到膜边尺寸 dCutEdge*2+图文到图文的尺寸dColGap*（列数iCol-1） */
        if (sFieldName === 'dMachineWidth' || sFieldName === 'iCol' || sFieldName === 'dCutEdge' || sFieldName === 'dColGap') {
          tableDataRow.dMaterialsWidth = (dMachineWidth * iCol) + (dCutEdge * 2) + (dColGap * (iCol - 1));
        }
        /* 版周长 dMaterialsLength=（版周长图文尺寸dMachineLength+图文到图文尺寸dRowGap）*版周长个数iRow+dScraperGap刮刀距离 */
        if (sFieldName === 'dMachineLength' || sFieldName === 'dRowGap' || sFieldName === 'iRow' || sFieldName === 'dScraperGap') {
          tableDataRow.dMaterialsLength = ((dMachineLength + dRowGap) * iRow) + dScraperGap;
        }
        if (sFieldName === 'dMachineLength' || sFieldName === 'dRowGap' || sFieldName === 'iRow' || sFieldName === 'dScraperGap' || sFieldName === 'dMaterialsLength') {
          let dPlatediameter = dMaterialsLength / Math.PI;
          dPlatediameter = commonUtils.convertFixNum(dPlatediameter, 2);
          const addState = {};
          addState.dPlatediameter = dPlatediameter;
          addState.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType;
          masterData = { ...masterData, ...addState };
        }
        /* 1款拼版 从表产品折算率=版周长*膜宽/1000000 */
        if (commonUtils.isNotEmptyArr(slaveData)) {
          if (slaveData.length === 1) { /* 只有一条从表数据  */
            const addState = {};
            addState.dConversionRate = (dMaterialsLength * dMaterialsWidth) / 1000000;
            addState.dCombineCoefficient = dSinglePQty;
            addState.handleType = commonUtils.isEmpty(slaveData[0].handleType) ? 'update' : slaveData[0].handleType;
            slaveData[0] = { ...slaveData[0], ...addState };
          } else if (slaveData.length > 1) { /* 多款产品合拼的 折算率  */
            let sumTotal = 0;
            slaveData.forEach((itemNew) => {
              const singleSum = itemNew.dProductLength * itemNew.dProductWidth * itemNew.dCombineCoefficient;
              sumTotal += singleSum;
            });
            slaveData.forEach((item, index) => {
              const addState = {};
              /* 多产品折算率 */
              const dConversionRate = ((dMaterialsLength * dMaterialsWidth) *
                (item.dProductLength * item.dProductWidth * item.dCombineCoefficient)) / sumTotal / item.dCombineCoefficient / 1000000;
              addState.dConversionRate = commonUtils.convertFixNum(dConversionRate, 6);
              addState.handleType = commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType;
              slaveData[index] = { ...item, ...addState };
            });
          }
        }
      }
      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, slaveData, masterData,
      });
    } else if (name === 'materials') {
      const {
        [`${name}Data`]: tableData, controlData, controlSelectedRowKeys,
      } = this.props;
      const tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
      if (tableDataRow === undefined) return;
      const iIndex = tableData.findIndex(item => item.sId === sId);
      if (iIndex > -1) {
        tableData[iIndex] = tableDataRow;
      }
      if (sFieldName === 'sType') {
        if (tableData[iIndex].sType === '2') {
          tableData[iIndex].sControlId = '';
          tableData[iIndex].sPartsName = '';
        } else {
          const iControlIndex = commonUtils.isEmptyArr(controlSelectedRowKeys) ? -1 : controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]);
          if (iControlIndex > -1) {
            tableData[iIndex].sControlId = controlData[iControlIndex].sId;
            tableData[iIndex].sPartsName = controlData[iControlIndex].sPartsName;
          }
        }
      }
      this.props.onSaveState({ [`${name}Data`]: tableData });
    } else if (name === 'process') {
      const {
        [`${name}Data`]: tableData, sModelsId, masterData, slaveData, controlData, controlSelectedRowKeys, materialsData, processConfig, token,
      } = this.props;
      let { processDelData, materialsDelData } = this.props;
      const tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
      if (tableDataRow === undefined) return;
      let iIndex = tableData.findIndex(item => item.sId === sId);
      let tableDataRowOld = {};
      let iMaterialsIndex = -1;
      let sControlId = '';
      if (iIndex > -1) {
        iMaterialsIndex = materialsData.findIndex(item => item.sControlId === tableData[iIndex].sControlId && item.sProcessId === tableData[iIndex].sProcessId);
        tableDataRowOld = tableData[iIndex];
        tableData[iIndex] = tableDataRow;
        sControlId = tableData[iIndex].sControlId;
      }
      const addState = {};
      if (sFieldName === 'sProcessId' || sFieldName.includes('sProcessName')) {
        const bProcessAssort = true;
        let returnProcessAssort = [];
        let processAssignAssort = '';
        let dropDownDataProcessName;
        const sProcessParamStriIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProcessParamStr' && item.bVisible);
        if (sProcessParamStriIndex > -1 && commonUtils.isNotEmptyObject(tableData[iIndex].sWorkOrderParam)) {
          tableData[iIndex].sProcessParamStr = '工艺参数';
        } else if (sProcessParamStriIndex > -1) {
          tableData[iIndex].sProcessParamStr = '';
        }
        if (commonUtils.isNotEmptyObject(tableData[iIndex].sWorkOrderParam)) {
          tableData[iIndex] = { ...tableData[iIndex], ...commonUtils.convertStrToObj(tableData[iIndex].sWorkOrderParam) };
        }
        if (bProcessAssort) {
          const dataUrl = `${commonConfig.server_host}salesorder/getProcessAssort?sModelsId=${sModelsId}`;
          const dataProcessAssort = (await commonServices.postValueService(token, {}, dataUrl)).data;
          if (dataProcessAssort.code === 1) {
            returnProcessAssort = dataProcessAssort.dataset.rows[0].processassort;
            const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProcessName');
            if (iIndex > -1) {
              const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', processConfig.gdsconfigformslave[iIndex]);
              dropDownDataProcessName = sqlDropDownData.dropDownData;
              processAssignAssort = processConfig.gdsconfigformslave[iIndex].sAssignField;
            }
          }
        }
        const iControlIndex = commonUtils.isEmptyArr(controlSelectedRowKeys) ? -1 : controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]);
        // 配套工序
        if (bProcessAssort) {
          const newCopyTo = {};
          newCopyTo.master = masterData;
          if (commonUtils.isNotEmptyArr(slaveData)) {
            newCopyTo.slave = slaveData[0];
          }
          /* 切换工序时 先删除原工序配套工序 */
          if (commonUtils.isEmptyArr(processDelData)) {
            processDelData = [];
          }
          if (commonUtils.isEmptyArr(materialsDelData)) {
            materialsDelData = [];
          }
          returnProcessAssort.filter(item => item.sParentId === tableDataRowOld.sProcessId).forEach(((itemProcessAssort) => {
            const iProcessIndex = tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === sControlId);
            if (iProcessIndex > -1) {
              const processDataRow = tableData[iProcessIndex];
              tableData.splice(iProcessIndex, 1);
              processDataRow.handleType = 'del';
              processDelData.push(processDataRow);
              /* 删除配套材料 */
              const iMaterialsIndex = materialsData.findIndex(item => item.sMaterialsName === processDataRow.sProcessName && item.sControlId === sControlId);
              if (iMaterialsIndex > -1) {
                const materialsDataRow = materialsData[iMaterialsIndex];
                materialsData.splice(iMaterialsIndex, 1);
                materialsDataRow.handleType = 'del';
                materialsDelData.push(materialsDataRow);
              }
            }
          }));
          if (commonUtils.isNotEmptyArr(processDelData)) {
            addState.processDelData = processDelData;
          }
          if (commonUtils.isNotEmptyArr(materialsDelData)) {
            addState.materialsDelData = materialsDelData;
          }
          iIndex = tableData.findIndex(item => item.sId === tableDataRow.sId);
          returnProcessAssort.filter(item => item.sParentId === tableDataRow.sProcessId).forEach(((itemProcessAssort) => {
            const iIndex = dropDownDataProcessName.findIndex(item => item.sId === itemProcessAssort.sProcessId);
            if (iIndex > -1) {
              const iNewProcessIndex = dropDownDataProcessName[iIndex].sType === '3' ?
                tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId) :
                tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlData[iControlIndex].sId);
              if (iNewProcessIndex < 0) {
                let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
                processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                processRow.handleType = 'add';
                processRow.sId = commonUtils.createSid();
                processRow.sParentId = masterData.sId;
                processRow.sType = dropDownDataProcessName[iIndex].sType;
                if (iControlIndex > -1 && processRow.sType !== '3') {
                  processRow.sControlId = controlData[iControlIndex].sId;
                  processRow.sPartsName = controlData[iControlIndex].sPartsName;
                }
                tableData.push(processRow);

                if (itemProcessAssort.sType === 'all') {
                  controlData.filter(item => item.sId !== controlData[iControlIndex].sId).forEach((controlTableRow) => {
                    const iNewProcessIndex = dropDownDataProcessName[iIndex].sType === '3' ?
                      tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId) :
                      tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlTableRow.sId);
                    if (iNewProcessIndex < 0) {
                      let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
                      processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignAssort, dropDownDataProcessName[iIndex], newCopyTo) }; // 取赋值字段
                      processRow.handleType = 'add';
                      processRow.sId = commonUtils.createSid();
                      processRow.sParentId = masterData.sId;
                      processRow.sType = dropDownDataProcessName[iIndex].sType;
                      if (iControlIndex > -1 && processRow.sType !== '3') {
                        processRow.sControlId = controlTableRow.sId;
                        processRow.sPartsName = controlTableRow.sPartsName;
                      }
                      tableData.push(processRow);
                    }
                  });
                }
              }
            }
          }));
        }
        if (tableData[iIndex].sType === '3') {
          tableData[iIndex].sControlId = '';
          tableData[iIndex].sPartsName = '';
        } else if (iControlIndex > -1) {
          tableData[iIndex].sControlId = controlData[iControlIndex].sId;
          tableData[iIndex].sPartsName = controlData[iControlIndex].sPartsName;
          if (iMaterialsIndex > -1) {
            materialsData[iMaterialsIndex].sProcessId = tableData[iIndex].sProcessId;
            materialsData[iMaterialsIndex].sProcessTbId = tableData[iIndex].sId;
            materialsData[iMaterialsIndex].sMaterialsProcessName = tableData[iIndex].sProcessName;
          }
        }
      }
      this.props.onSaveState({ [`${name}Data`]: tableData, materialsSelectedRowKeys: [], ...addState });
    } else {
      this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData);
    }
  };

  handleCancelFastOrderModal = () => {
    this.props.onSaveState({ fastOrderModalVisible: false });
  };
  handleCancelProcessChooseModal = () => {
    this.props.onSaveState({ processChooseVisible: false });
  };
  handleCancelMaterialsChooseModal = () => {
    this.props.onSaveState({ materialsChooseVisible: false });
  };
  handleCancelProductProcessInfoChooseModal = () => {
    this.props.onSaveState({ productProcessInfoChooseVisible: false });
  };

  /**   复制全部   */
  handleTableCopyAll = (name, isWait) => {
    const {
      [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys, materialsData, app,
    } = this.props;
    let { processData } = this.props;
    if (name === 'control') {
      if (commonUtils.isEmptyArr(tableSelectedRowKeys)) {
        message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseCopyData'));/* 请选择复制数据 */
      } else {
        for (const sId of tableSelectedRowKeys) {
          const tableDataIndex = tableData.findIndex(item => item.sId === sId);
          if (tableDataIndex > -1) {
            const tableDataRow = JSON.parse(JSON.stringify(tableData[tableDataIndex]));
            tableDataRow.sId = commonUtils.createSid();
            tableDataRow.handleType = 'add';
            tableDataRow.key = tableDataRow.sId;
            tableDataRow.sPartsName = `${tableData[tableDataIndex].sPartsName}new`;
            tableDataRow.sAllId = tableDataRow.sId;
            const iOrderArr = [];
            tableData.forEach((item) => {
              const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
              iOrderArr.push(iOrder);
            });
            const iOrderMax = Math.max(...iOrderArr);
            tableDataRow.iOrder = commonUtils.isNotEmptyArr(tableData) ? iOrderMax + 1 : 0;
            if (isWait) {
              return tableDataRow;
            } else if (commonUtils.isNotEmptyObject(tableDataRow)) {
              tableData.push(tableDataRow);
              processData.filter(item => item.sControlId === sId && item.sType !== '3').forEach((item) => {
                const processRow = JSON.parse(JSON.stringify(item));
                processRow.sId = commonUtils.createSid();
                processRow.handleType = 'add';
                processRow.sControlId = tableDataRow.sId;
                processRow.sPartsName = tableDataRow.sPartsName;
                processRow.sSrcProcessTbId = item.sId;
                processData.push(processRow);
              });
              processData = this.sortData(tableData, processData);
              materialsData.filter(item => item.sControlId === sId && item.sType !== '2').forEach((materialsItem) => {
                const materialsRow = JSON.parse(JSON.stringify(materialsItem));
                materialsRow.sId = commonUtils.createSid();
                materialsRow.handleType = 'add';
                materialsRow.sControlId = tableDataRow.sId;
                materialsRow.sPartsName = tableDataRow.sPartsName;
                // 材料对应工序的ID要变化
                if (commonUtils.isNotEmptyArr(processData)) {
                  const iProcessIndex = processData.findIndex(item => item.sControlId === tableDataRow.sId && item.sSrcProcessTbId === materialsItem.sProcessTbId);
                  if (iProcessIndex > -1) {
                    materialsRow.sProcessTbId = processData[iProcessIndex].sId;
                  }
                }
                materialsData.push(materialsRow);
              });
              this.props.onSaveState({
                [`${name}Data`]: tableData,
                [`${name}Pagination`]: { total: tableData.length, current: 9999 },
                materialsSelectedRowKeys: [],
                materialsData,
                processData,
              });
            }
          }
        }
      }
    }
  };

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

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

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

      if (tableDataRow.dSinglePQty > 0) {
        if (tableDataRow.iPage > 1) { // 笔记本  用 非样本 来做， 倍率是每页都一样才可以用      原先 /2 是指页数， 现在直接按张数
          tableDataRow.dMachineQty = commonUtils.convertFixNum((tableDataRow.dPartsQty * tableDataRow.iPage) / tableDataRow.dSinglePQty, 0);
        } else {
          tableDataRow.dMachineQty = commonUtils.convertFixNum(commonUtils.isNull(tableDataRow.dPartsQty, 0) / tableDataRow.dSinglePQty, 0);
          tableDataRow.dSumMachineQty = tableDataRow.dMachineQty * tableDataRow.iStick;
        }
      }
    }
    return tableDataRow;
  };
  // ---
  handleCancelProcessParamsModalVisible = () => { // 工艺参数弹窗消失
    this.props.onSaveState({
      sProcessParamsModalVisible: false,
    });
  }
  handleProcessParamsOk = () => { // 工艺参数弹窗确定按钮
    const {
      processData,
      processRecord,
      processConfig,
    } = this.props;
    if (commonUtils.isNotEmptyArr(processData) && commonUtils.isNotEmptyObject(processRecord)) {
      const processSelectDataIndex = processData.findIndex(item => item.sId === processRecord.sId);
      if (processSelectDataIndex > -1) {
        let sProcessParamStr = '';
        // eslint-disable-next-line no-plusplus
        for (let i = 1; i < 7; i++) {
          const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
          if (iIndex > -1 && !commonUtils.isEmpty(processData[processSelectDataIndex][`sParam${i.toString()}`])) {
            sProcessParamStr += `${processData[processSelectDataIndex][`sParam${i.toString()}`]}:${processData[processSelectDataIndex][`sParamValue${i.toString()}`] === undefined ? '' : processData[processSelectDataIndex][`sParamValue${i.toString()}`]},`;
          }
        }
        processData[processSelectDataIndex] = { ...processData[processSelectDataIndex], sProcessParamStr };
      }
    }
    this.props.onSaveState({
      processData,
      sProcessParamsModalVisible: false,
    });
  }

  render() {
    const { pageLoading, masterData, fastOrderModalVisible, sModelsType, app  } = this.props;
    const imgSrc = commonBusiness.handleAddIcon(masterData, sModelsType, app);
    return (
      <Spin spinning={pageLoading}>
        <ProcessCardComponent
          {...this.props}
          {...this.state}
          onReturnForm={this.handleForm}
          onSubmit={this.handleSave}
          onMasterChange={this.handleMasterChange}
          handleDataCreate={this.handleDataCreate}
          handleProcessChange={this.handleProcessChange}
          handleSelectChangeProcess={this.handleSelectChangeProcess}
          handleA={this.handleA}
          onEdit={this.handleEdit}
          onCopyTo={this.handleCopyTo}
          onAdd={this.handleAdd}
          onDel={this.handleDel}
          onCancel={this.handleCancel}
          onFilterData={this.handleFilterData}
          onDataRowAdd={this.handleTableAdd}
          onDataRowDel={this.handleTableDel}
          getMenuStatus={this.getMenuStatus}
          onButtonClick={this.handleButtonClick}
          onNext={this.handleSearchData.bind(this, 'next')}
          onBtnPrior={this.handleSearchData.bind(this, 'up')}
          onBtnFirst={this.handleSearchData.bind(this, 'first')}
          onBtnLast={this.handleSearchData.bind(this, 'end')}
          onSelect={this.handleSelect}
          onDataChange={this.handleTableChange}
          imgSrc={imgSrc}
          fastOrderModalVisible={fastOrderModalVisible}
          onCancelFastOrderModal={this.handleCancelFastOrderModal}
          onCancelProcessChooseModal={this.handleCancelProcessChooseModal}
          onCancelMaterialsChooseModal={this.handleCancelMaterialsChooseModal}
          onCancelProductProcessInfoChooseModal={this.handleCancelProductProcessInfoChooseModal}
          onDataRowCopyAll={this.handleTableCopyAll}
          // onRowClick={this.onRowClick}
          // onDoubleClick={this.onDoubleClick}
          // onRowMouseEnter={this.onRowMouseEnter}
          onDataRowModal={this.handleTableModal}
          OnGetFilterData={this.handleGetFilterData}
          onTableSelectRowChange={this.handleTableSelectRowChange}
          onKeyDown={this.handleKeyDown}
          orderData={this.orderData}
          /* --- */
          onProcessParamsOk={this.handleProcessParamsOk}
          onCancelProcessParamsModalVisible={this.handleCancelProcessParamsModalVisible}
        />
      </Spin>
    );
  }
}

const ProcessCardComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form);
    return obj;
  },
})((props) => {
  const {
    form, onReturnForm, masterConfig: masterConfigOld, slaveData, slavePagination, sModelsId, sTabId, app, colorConfigGrdVisible, dailyConfigGrdVisible, sisColorChooseVisible,
  } = props;
  /*   回带表单   */
  onReturnForm(form);
  const addProps = {};
  if (commonUtils.isNotEmptyObject(masterConfigOld)) {
    const masterConfig = JSON.parse(JSON.stringify(masterConfigOld));
    let iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'dProductQty');
    if (iIndex > -1) {
      masterConfig.gdsconfigformslave.splice(iIndex, 1);
    }
    iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sCustomerName');
    if (iIndex > -1) {
      masterConfig.gdsconfigformslave.splice(iIndex, 1);
    }
    iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductClassifyName');
    if (iIndex > -1) {
      masterConfig.gdsconfigformslave.splice(iIndex, 1);
    }
    iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductName');
    if (iIndex > -1) {
      masterConfig.gdsconfigformslave.splice(iIndex, 1);
    }
    iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductStyle');
    if (iIndex > -1) {
      masterConfig.gdsconfigformslave.splice(iIndex, 1);
    }
    addProps.masterConfig = masterConfig;
  }

  const propsType = {
    ...props,
    ...addProps,
    onChange: props.onMasterChange,
  };
  const pagination = {
    total: commonUtils.isEmptyArr(slaveData) ? 0 : slaveData.length,
    current: commonUtils.isEmptyObject(slavePagination) ? 1 : slavePagination.current,
    size: 'large',
    pageSize: commonConfig.pageSize,
    showQuickJumper: true,
    hideOnSinglePage: true,
  };
  const width = '18px';
  const height = '18px';
  const setAdd = {
    title: '增加',
    img: <SvgIcon iconClass="plus" fill="#8c949e" size="14" offsetY="3" alt="添加" />,
    disableimg: <SvgIcon iconClass="plus" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="添加" />,
  };
  const setCopy = {
    title: '复制',
    img: <SvgIcon iconClass="copy" fill="#8c949e" size="14" offsetY="3" alt="复制" />,
    disableimg: <SvgIcon iconClass="copy" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="复制" />,
  };
  const setCopyAll = {
    title: '复制部件',
    img: <SvgIcon iconClass="copyall" fill="#8c949e" size="14" offsetY="3" alt="复制部件" />,
    disableimg: <SvgIcon iconClass="copyall" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="复制部件" />,
  };
  const setDelete = {
    title: '删除',
    img: <SvgIcon iconClass="close" fill="#8c949e" size="14" offsetY="3" alt="删除" />,
    disableimg: <SvgIcon iconClass="close" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="删除" />,
  };
  const setProcess = {
    title: '工序',
    img: <SvgIcon iconClass="process" fill="#8c949e" size="14" offsetY="3" alt="选择工序" />,
    disableimg: <SvgIcon iconClass="process" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="选择工序" />,
  };
  const setMaterial = {
    title: '材料',
    img: <SvgIcon iconClass="material" fill="#8c949e" size="14" offsetY="3" alt="选择材料" />,
    disableimg: <SvgIcon iconClass="material" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="选择材料" />,
  };
  const processUp = {
    title: '上移',
    width: { width },
    height: { height },
    img: <img src={ProcessUp} alt="上移" width="16px" height="16px" />,
    disableimg: <img src={DisableProcessUp} alt="上移" width="16px" height="16px" />,
  };
  const processDown = {
    title: '下移',
    width: { width },
    height: { height },
    img: <img src={ProcessDown} alt="下移" width="16px" height="16px" />,
    disableimg: <img src={DisableProcessDown} alt="下移" width="16px" height="16px" />,
  };
  const processTop = {
    title: '置顶',
    width: { width },
    height: { height },
    img: <img src={ProcessTop} alt="置顶" width="16px" height="16px" />,
    disableimg: <img src={DisableProcessTop} alt="置顶" width="16px" height="16px" />,
  };
  const processBottom = {
    title: '置底',
    width: { width },
    height: { height },
    img: <img src={ProcessBottom} alt="置底" width="16px" height="16px" />,
    disableimg: <img src={DisableProcessBottom} alt="置底" width="16px" height="16px" />,
  };
  let chooseProcessConfigRow;
  let onChooseProcessIndex;
  /* 获取toolbar 选择工序 */
  if (commonUtils.isNotEmptyObject(masterConfigOld)) {
    onChooseProcessIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProcess');
    if (onChooseProcessIndex > -1) {
      chooseProcessConfigRow = props.masterConfig.gdsconfigformslave[onChooseProcessIndex];
    }
  }
  /* 获取toolbar 选择材料 */
  let chooseMaterialsConfigRow;
  if (commonUtils.isNotEmptyObject(masterConfigOld)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseMaterials');
    if (iIndex > -1) {
      chooseMaterialsConfigRow = props.masterConfig.gdsconfigformslave[iIndex];
    }
  }
  const slaveTableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    onKeyDown: props.onKeyDown,
    tableProps: {
      rowSelection: null, pagination, onChange: props.onTitleChange, setAdd, setCopy, setDelete, AutoTableHeight: '100%',
    },
  };
  // const mProps = { ...commonBusiness.createMemoProps('slave', props) };
  const controlPropsType = {
    ...commonBusiness.getTableTypes('control', props),
    onKeyDown: props.onKeyDown,
    tableProps: {
      // rowSelection: null,
      setAdd,
      setCopyAll,
      setDelete,
      setProcess,
      setMaterial,
      chooseProcessConfigRow,
      chooseMaterialsConfigRow,
      AutoTableHeight: 132,
      // onRow: (record) => {
      //   return {
      //     onClick: () => { props.onRowClick('control', record); },
      //     onDoubleClick: () => { props.onDoubleClick('control', record); },
      //     onMouseEnter: () => { props.onRowMouseEnter('control', record); },
      //   };
      // },
    },
  };
  const materialsPropsType = {
    ...commonBusiness.getTableTypes('materials', props),
    filteredValue: props.controlSelectedRowKeys,
    onFilterData: props.onFilterData,
    OnGetFilterData: props.OnGetFilterData,
    onKeyDown: props.onKeyDown,
    tableProps: {
      rowSelection: null, setAdd, setCopy, setDelete, AutoTableHeight: '100%',
    },
  };
  const processPropsType = {
    ...commonBusiness.getTableTypes('process', props),
    filteredValue: props.controlSelectedRowKeys,
    onFilterData: props.onFilterData,
    OnGetFilterData: props.OnGetFilterData,
    onKeyDown: props.onKeyDown,
    tableProps: {
      rowSelection: null, setAdd, setCopy, setDelete, AutoTableHeight: '100%',
    },
    isDragAndDrop: props.enabled && true,
  };
  let colorTableProps = {};
  // let cProps = {};
  if (colorConfigGrdVisible) {
    colorTableProps = {
      ...commonBusiness.getTableTypes('color', props),
      onKeyDown: props.onKeyDown,
      tableProps: {
        rowSelection: null, setAdd, setCopy, setDelete, AutoTableHeight: '100%',
      },
    };
    // cProps = { ...commonBusiness.createMemoProps('color', props) };
  }

  let dailyRecordTableProps = {};
  if (dailyConfigGrdVisible) {
    dailyRecordTableProps = {
      ...commonBusiness.getTableTypes('daily', props),
      onKeyDown: props.onKeyDown,
      tableProps: {
        rowSelection: null, pagination, onChange: props.onTitleChange, setAdd, setCopy, setDelete, AutoTableHeight: '100%',
      },
    };
  }
  let searchProcessType = {};
  let chooseProcessConfig = {};
  if (commonUtils.isNotEmptyObject(props.processChooseData)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProcess');
    if (iIndex > -1) {
      chooseProcessConfig = props.masterConfig.gdsconfigformslave[iIndex];
    }

    searchProcessType = {
      app: {
        ...props.app,
        currentPane: {
          name: 'process',
          config: chooseProcessConfig,
          conditonValues: props.getSqlCondition(chooseProcessConfig),
          title: props.processChooseData.sMenuName,
          route: props.processChooseData.sName,
          formId: props.processChooseData.sId,
          key: sModelsId + props.processChooseData.sId,
          sModelsType: props.processChooseData.sModelType,
          select: props.onSelect,
          selectCancel: props.onSelectCancel,
        },
      },
      dispatch: props.dispatch,
      fatherModelsType: props.sModelsType,
      content: props.content,
      id: new Date().getTime().toString(),
    };
  }

  let searchMaterialsType = {};
  let chooseMaterialsConfig = {};
  if (commonUtils.isNotEmptyObject(props.materialsChooseData)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseMaterials');
    if (iIndex > -1) {
      chooseMaterialsConfig = props.masterConfig.gdsconfigformslave[iIndex];
    }

    searchMaterialsType = {
      app: {
        ...props.app,
        currentPane: {
          name: 'materials',
          config: chooseMaterialsConfig,
          conditonValues: props.getSqlCondition(chooseMaterialsConfig),
          title: props.materialsChooseData.sMenuName,
          route: props.materialsChooseData.sName,
          formId: props.materialsChooseData.sId,
          key: sModelsId + props.materialsChooseData.sId,
          sModelsType: props.materialsChooseData.sModelType,
          select: props.onSelect,
          // ----
          selectCancel: props.onSelectCancel,
        },
      },
      dispatch: props.dispatch,
      content: props.content,
      id: new Date().getTime().toString(),
    };
  }

  let productProcessInfoType = {};
  let productProcessInfoConfig = {};
  let processCardSearchResult = commonFunc.showMessage(app.commonConst, 'processCardSearchResult');/* 复制从工艺卡查询结果 */
  if (commonUtils.isNotEmptyObject(props.productProcessInfoChooseData)) {
    const productProcessInfoCopyFromKey = props.productProcessInfoCopyFromKey;
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === productProcessInfoCopyFromKey);
    if (iIndex > -1) {
      productProcessInfoConfig = props.masterConfig.gdsconfigformslave[iIndex];
      processCardSearchResult = commonUtils.isNotEmptyObject(productProcessInfoConfig) && commonUtils.isNotEmptyObject(productProcessInfoConfig.sActiveName) ? productProcessInfoConfig.sActiveName : processCardSearchResult;
    }

    productProcessInfoType = {
      app: {
        ...props.app,
        currentPane: {
          name: 'productProcessInfo',
          config: productProcessInfoConfig,
          conditonValues: props.getSqlCondition(productProcessInfoConfig),
          title: props.productProcessInfoChooseData.sMenuName,
          route: props.productProcessInfoChooseData.sName,
          formId: props.productProcessInfoChooseData.sId,
          key: sModelsId + props.productProcessInfoChooseData.sId,
          sModelsType: props.productProcessInfoChooseData.sModelType,
          select: props.onSelect,
          selectCancel: props.onSelectCancel,
        },
      },
      dispatch: props.dispatch,
      content: props.content,
      id: new Date().getTime().toString(),
    };
  }

  /* 工序表选择颜色 */
  let chooseColorsConfig = {};
  let searchColorsType = {};
  if (commonUtils.isNotEmptyObject(props) && commonUtils.isNotEmptyObject(props.processConfig)) {
    const iIndex = props.processConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseColors');
    if (iIndex > -1) {
      chooseColorsConfig = props.processConfig.gdsconfigformslave[iIndex];
    }
    searchColorsType = {
      app: {
        ...props.app,
        currentPane: {
          name: 'sisColor',
          config: chooseColorsConfig,
          conditonValues: props.getSqlCondition(chooseColorsConfig),
          title: '选择颜色',
          route: '/indexPage/commonList',
          formRoute: '/indexPage/commonList',
          formId: chooseColorsConfig.sActiveId,
          key: sModelsId + chooseColorsConfig.sId,
          sModelsType: 'search/sisColor',
          select: props.onSelectSisColor,
          selectCancel: props.onSelectCancel,
        },
      },
      enabled: props.enabled,
      sisColorSelectedData: props.sisColorSelectedData,
      slaveSelectedRowKeys: props.sisColorSelectedRowKeys,
      dispatch: props.dispatch,
      content: props.content,
      id: new Date().getTime().toString(),
    };
    searchColorsType.app = {
      ...searchColorsType.app,
      ...props.showCacheData(props.isSColorSerialMemo?.current, props.processData, props.processSelectedRowId) || {},
    };
  }

  const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
  const productInfo = commonFunc.showMessage(app.commonConst, 'productInfo');/* 产品信息 */
  const controlInfo = commonFunc.showMessage(app.commonConst, 'controlInfo');/* 部件信息 */
  const materialsInfo = commonFunc.showMessage(app.commonConst, 'materialsInfo');/* 材料信息 */
  const processInfo = commonFunc.showMessage(app.commonConst, 'processInfo');/* 工序信息 */
  const colorInfo = commonFunc.showMessage(app.commonConst, 'colorInfo');/* 颜色信息 */
  const dailyInfo = commonFunc.showMessage(app.commonConst, 'dailyInfo');/* 日志信息 */
  const setMaterialTitle = commonFunc.showMessage(app.commonConst, 'setMaterial');/* 选择材料标题 */
  const setProcessTitle = commonFunc.showMessage(app.commonConst, 'setProcess');/* 选择工序标题 */
  const setSisColorTitle = commonFunc.showMessage(app.commonConst, 'setSisColor');/* 选择颜色标题 */

  const fastOrder = commonFunc.showMessage(app.commonConst, 'fastOrder');/* 快速下单 */
  const comfirmOrder = commonFunc.showMessage(app.commonConst, 'comfirmOrder');/* 确认下单 */
  const setUp = commonFunc.showMessage(app.commonConst, 'setUp');/* 上移 */
  const setDown = commonFunc.showMessage(app.commonConst, 'setDown');/* 下移 */
  const setTop = commonFunc.showMessage(app.commonConst, 'setTop');/* 置顶 */
  const setBottom = commonFunc.showMessage(app.commonConst, 'setBottom');/* 置底 */
  // --------
  const sProcessParams = commonFunc.showMessage(app.commonConst, 'sProcessParams');/* 选择工艺参数标题 */
  return (
    <Form>
      <Layout className="xly-workorder-list">
        <Header className={styles.header}>
          <Toolbar {...props} className="billBtnGroup" style={{ backgroundColor: '#646464', color: 'rgb(255,255,255)' }} />
        </Header>
        <Layout className={styles.clayout}>
          <div className={styles.content}>
            <div id="slaveTabs" className={`${styles.bShow} slaveTabsFlex`} style={{ paddingRight: '10px', overflow: 'auto', maxHeight: 'calc(100vh - 130px)' }} >
              <div>
                <Avatar src={props.imgSrc} />
              </div>
              <CommonView {...propsType} />
              <div className={styles.slaveTabs} style={{ marginLeft: '10px' }}>
                <Layout>
                  <Sider className={selfstyles.product}>
                    {productInfo}
                  </Sider>
                  <Content>
                    <StaticEditTable {...slaveTableProps} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                  </Content>
                </Layout>
              </div>
              <div style={{ marginLeft: '10px', marginTop: 10 }}>
                <Layout className="processList">
                  <Sider className="control">
                    {controlInfo}
                  </Sider>
                  <Content>
                    <StaticEditTable {...controlPropsType} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                  </Content>
                </Layout>
              </div>
              <div style={{ marginLeft: '10px', marginTop: 10 }}>
                <Layout>
                  <Sider className="materials">
                    {materialsInfo}
                  </Sider>
                  <Content>
                    <StaticEditTable {...materialsPropsType} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                  </Content>
                </Layout>
              </div>
              {
                colorConfigGrdVisible ?
                  <div className={styles.slaveTabs} style={{ marginLeft: '10px', marginTop: 10 }}>
                    <Layout>
                      <Sider className={selfstyles.product}>
                        {colorInfo}
                      </Sider>
                      <Content>
                        <StaticEditTable {...colorTableProps} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                      </Content>
                    </Layout>
                  </div> : ''
              }
              <div style={{ marginLeft: '10px', marginTop: 10 }}>
                <Layout className="processList">
                  <Sider className="process">
                    <a title={setTop} {...addProps} onClick={props.enabled ? e => props.orderData(e, 'process', 0) : null}>{ props.enabled ? processTop.img : processTop.disableimg}</a>
                    <a title={setUp} {...addProps} onClick={props.enabled ? e => props.orderData(e, 'process', 1) : null}>{ props.enabled ? processUp.img : processUp.disableimg }</a>
                    <a title={setDown} {...addProps} onClick={props.enabled ? e => props.orderData(e, 'process', 2) : null}>{props.enabled ? processDown.img : processDown.disableimg }</a>
                    <a title={setBottom} {...addProps} onClick={props.enabled ? e => props.orderData(e, 'process', 3) : null}>{props.enabled ? processBottom.img : processBottom.disableimg }</a>
                    {processInfo}
                  </Sider>
                  <Content style={{ minHeight: '273px' }}>
                    <StaticEditTable {...processPropsType} setOpterationColumn="Y" selfTableHeight={330} noVlist />
                  </Content>
                </Layout>
              </div>
              {
                dailyConfigGrdVisible ?
                  <div className={styles.slaveTabs} style={{ marginLeft: '10px', marginTop: 10 }}>
                    <Layout>
                      <Sider className={selfstyles.product}>
                        {dailyInfo}
                      </Sider>
                      <Content>
                        <StaticEditTable {...dailyRecordTableProps} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                      </Content>
                    </Layout>
                  </div> : ''
              }
            </div>
          </div>
        </Layout>
        {
          (pane.notCurrentPane ? false : props.processChooseVisible) ?
            <AntdDraggableModal
              width={1300}
              title={setProcessTitle}
              visible={pane.notCurrentPane ? false : props.processChooseVisible}
              onCancel={props.onCancelProcessChooseModal}
              footer={null}
            >
              <CommonListSelectTree {...searchProcessType} />
            </AntdDraggableModal>
            : ''
        }

        {
          sisColorChooseVisible ?
            <AntdDraggableModal
              width={1300}
              title={setSisColorTitle}
              visible={pane.notCurrentPane ? false : props.sisColorChooseVisible}
              onCancel={props.onCancelModal.bind(this, 'sisColorChooseVisible')}
              footer={null}
            >
              <CommonListSelectFlex {...searchColorsType} />
            </AntdDraggableModal>
            : ''
        }

        {
          (pane.notCurrentPane ? false : props.materialsChooseVisible) ?
            <AntdDraggableModal
              width={1300}
              title={setMaterialTitle}
              visible={pane.notCurrentPane ? false : props.materialsChooseVisible}
              onCancel={props.onCancelMaterialsChooseModal}
              wrapClassName="worker-order-pack-modal"
              className="modalMaterials"
              footer={null}
            >
              <CommonListSelect {...searchMaterialsType} />
            </AntdDraggableModal>
            : ''
        }

        {
          props.productProcessInfoChooseVisible ?
            <AntdDraggableModal
              width={1200}
              title={processCardSearchResult}
              visible={props.productProcessInfoChooseVisible}
              onCancel={props.onCancelProductProcessInfoChooseModal}
              footer={null}
            >
              <CommonListSelect {...productProcessInfoType} />
            </AntdDraggableModal>
            : ''
        }
        {
          (pane.notCurrentPane ? false : props.fastOrderModalVisible) ?
            <AntdDraggableModal
              className="workorder-modal"
              title={fastOrder}
              visible={pane.notCurrentPane ? false : props.fastOrderModalVisible}
              width={1200}
              bodyStyle={{
                padding: 0, maxHeight: 600, overflow: 'auto', backgroundColor: '#ffffff', paddingTop: -4,
              }}
              maskStyle={{ backgroundColor: 'rgba(0, 0, 0, 0.4)' }}
              okText={comfirmOrder}
              cancelText=""
              maskCloseable
              footer={<Button type="primary" onClick={props.handleDataCreate}>确认下单</Button>}
              onCancel={props.onCancelFastOrderModal}
            >
              <SplitPaste {...props} />
            </AntdDraggableModal>
            : ''
        }
        {
          props.sProcessParamsModalVisible ?
            <AntdDraggableModal
              width="33%"
              title={sProcessParams}
              visible={props.sProcessParamsModalVisible}
              onOk={props.onProcessParamsOk}
              onCancel={props.onCancelProcessParamsModalVisible}
              // footer={null}
            >
              <div className="sProcessParamsModal" style={{ height: '80%', overflowY: 'auto' }}>
                { commonUtils.isNotEmptyArr(props.sProcessParamsSelects) ?
                  props.sProcessParamsSelects.map((child) => {
                    const sMemo = child.sName.toLowerCase().endsWith('memo');
                    let enabledNew = !child.bReadonly;
                    if (child.iTag === 1) {
                      enabledNew = false;
                    } else if (child.iTag === 3) {
                      enabledNew = true;
                    }
                    // const slaveSelectOneDataIndex = slaveData.findIndex(item => item.sId === selectedRowKeys[selectedRowKeys.length - 1]); // 多选选择最后一个
                    const showTypeProps = {
                      name: 'process',
                      form: props.form,
                      record: props.processRecord,
                      sId: props.processRecord.sId,
                      getSqlDropDownData: props.getSqlDropDownData,
                      getSqlCondition: props.getSqlCondition,
                      handleSqlDropDownNewRecord: props.handleSqlDropDownNewRecord,
                      getFloatNum: props.getFloatNum,
                      onChange: props.onDataChange,
                      showConfig: child,
                      formItemLayout: {},
                      textArea: sMemo,
                      enabled: enabledNew,
                      dataValue: props.processRecord[child.sName],
                      bTable: true,
                      formRoute: props.formRoute,
                    };
                    return (
                      <div className="sProcessParamsModalType">
                        <span>{`${child.showName} : `}</span>
                        <ShowType {...showTypeProps} />
                      </div>
                    );
                  }) : ''
                }
              </div>
            </AntdDraggableModal>
            : ''
        }
        {
          props.contextMenuModalVisible ?
            <ContextMenuModal {...props} />
            : ''
        }
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonSales(ProcessCard));
