/* eslint-disable */
/* eslint-disable prefer-destructuring,no-loop-func */
import React, { Component } from 'react';
import moment from 'moment';
import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import {
  Modal,
  Layout,
  Spin,
  Select,
  message,
  Button,
  Table,
  Checkbox,
  Row,
  Col,
  Avatar,
  Slider,
  Tabs
} from 'antd-v4';
import AddIcon from '@/assets/add.svg';
import AddChildIcon from '@/assets/addChild.svg';
import DisableAddIcon from '@/assets/disableadd.svg';
import DisableAddChildIcon from '@/assets/disableaddChild.svg';
import DelIcon from '@/assets/delete.svg';
import DisableDelIcon from '@/assets/disabledelete.svg';
import CopyIcon from '@/assets/copy.svg';
import CopyAllIcon from '@/assets/copyall.svg';
import DisableCopyIcon from '@/assets/disablecopy.svg';
import DisableCopyAllIcon from '@/assets/disablecopyall.svg';
import MateriallIcon from '@/assets/material.svg';
import DisableMateriallIcon from '@/assets/disablematerial.svg';
import ProcessIcon from '@/assets/process.svg';
import DisableProcessIcon from '@/assets/disableprocess.svg';
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 '@/components/Common/CommonBillEvent';/* 继承销售模块业务功能 */
import * as commonFunc from '@/components/Common/commonFunc';/* 通用单据方法 */ /* 通用单据方法 */
import Toolbar from '@/components/Common/ToolBar/ToolBarNew';
import StaticEditTable from '@/components/Common/CommonTable';/* 可编辑表格 */
import styles from '@/index.less';
import CommonView from '@/components/Common/CommonView';
import CommonBase from '@/components/Common/CommonBase';/* 获取配置及数据 */
import * as commonUtils from '@/utils/utils';/* 通用方法 */
import * as commonBusiness from '@/components/Common/commonBusiness';/* 单据业务功能 */
import commonConfig from '@/utils/config';
import * as commonServices from '@/services/services';/*   服务类   */
import CommonListSelect from '@/components/Common/CommonListSelect';/* 选择界面 */
import CommonListSelectFlex from '@/components/Common/CommonListSelectFlex';
/* 可编辑的选择界面 */
import CommonListSelectTree from '@/components/Common/CommonListSelectTree';
/* 树形选择界面 */
import CommonListSelectProductProcess from '@/components/Common/CommonListSelectAssignment';
import CommonListSelectProductMaterial from '@/components/Common/CommonListSelectProductMaterial';
/* 选择成品工序 */
// import SlaveMemo from '../../Common/SlaveMemo';
import SlavesInfo from '@/components/Common/SlavesInfo';
import AntdDraggableModal from '@/components/Common/AntdDraggableModal';
import AntdDraggableDiv from '@/components/Common/AntdDraggableDiv';
import StaticEditTree from '@/components/Common/Tree/StaticTree';
import Eject from '@/assets/ejectleft.svg';
import Close from '@/assets/closeleft.svg';
import ShowType from '@/components/Common/CommonComponent';
import ContextMenuModal from '@/components/Common/ContextMenuModal';
import SplitPaste from '@/components/Manufacture/WorkOrder/SplitPaste';/* 选择界面 */
import SvgIcon from "../../SvgIcon";

import selfstyles from '../index.less';

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

const isQianCai = false;

class WorkOrderPack extends Component {
  constructor(props) {
    super(props);
    this.state = {
      currentTab: 1,
    };
  }

  async componentWillReceiveProps(nextProps) {
    let {
      controlColumn, materialsColumn, processColumn, colorColumn, packColumn,
    } = 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() === 'MftWorkOrderControl'.toUpperCase())[0];
      controlColumn = commonFunc.getHeaderConfig(controlConfig, controlColumn);

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

      const finishedMaterialsConfig = formData.filter(item => item.sTbName.toUpperCase() === 'MftWorkOrderMaterials'.toUpperCase() && item.showName === '成品材料')[0];
      const finishedMaterialsColumn = finishedMaterialsConfig ? commonFunc.getHeaderConfig(finishedMaterialsConfig) : false;

      const processConfig = formData.filter(item => item.sTbName.toUpperCase() === 'MftWorkOrderProcess'.toUpperCase())[0];
      const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sMachineId');

      const finishedProcessConfig = formData.filter(item => item.sTbName.toUpperCase() === 'MftWorkOrderProcess'.toUpperCase() && item.showName === '成品工序')[0];
      const finishedProcessColumn = finishedProcessConfig ? commonFunc.getHeaderConfig(finishedProcessConfig) : false;
      if (iIndex > -1) {
        processConfig.gdsconfigformslave[iIndex].bReGetDropDown = true;
      }
      processColumn = commonFunc.getHeaderConfig(processConfig, processColumn);
      /* 合版信息表s */
      const packConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftworkordercontrolcombine'.toUpperCase())[0];
      const slaveChooseConfig = slaveConfig.gdsconfigformslave.filter(item => (item.sName === 'sCustomerName'
        || item.sName === 'sProductId'
        || item.sName === 'sCustomerId'
        || item.sName === 'sProductNo'
        || item.sName === 'sProductName'
        || item.sName === 'dProductQty'
        || item.sName === 'sProductStyle'
        || item.sName === 'sProductUnit')); /* 拼接从表配置,客户名称 ，产品名称，生产数  */
      const salveChooseConfigFilter = [];
      if (commonUtils.isNotEmptyArr(slaveChooseConfig)) {
        slaveChooseConfig.forEach((item) => {
          const iIndex = packConfig.gdsconfigformslave.findIndex(itemNew => itemNew.sName === item.sName);
          if (iIndex === -1) {
            const itemNew = Object.assign({}, item);
            itemNew.bNotEmpty = false;
            salveChooseConfigFilter.push(itemNew);
          }
        });
      }
      /* 拼接排序 */
      if (commonUtils.isNotEmptyArr(salveChooseConfigFilter)) {
        let packFilter = packConfig.gdsconfigformslave.filter(item => item.sName === 'iOrder');
        packFilter = packFilter.concat(salveChooseConfigFilter);
        const packFilterOther = packConfig.gdsconfigformslave.filter(item => item.sName !== 'iOrder');
        packFilter = packFilter.concat(packFilterOther);
        packConfig.gdsconfigformslave = packFilter;
      }
      packColumn = commonFunc.getHeaderConfig(packConfig, packColumn);
      let colorConfigGrdVisible;
      const colorConfigTrue = formData.filter(item => item.sTbName.toUpperCase() === 'mftworkorderparam'.toUpperCase())[0];
      if (commonUtils.isNotEmptyObject(colorConfigTrue)) {
        colorConfigGrdVisible = colorConfigTrue.bGrdVisible;
        if (colorConfigGrdVisible) {
          colorColumn = commonFunc.getHeaderConfig(colorConfigTrue, colorColumn);
        }
      }
      let addState = {};
      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.packConfig = packConfig;
        addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
      } else {
        this.props.onGetData(masterConfig, slaveConfig, checkConfig);
        this.handleGetData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig);
      }
      this.props.onSaveState({
        masterConfig,
        slaveConfig,
        slaveColumn,
        checkConfig,
        checkColumn,
        sId,
        pageLoading: false,
        controlConfig,
        controlColumn,
        materialsConfig,
        materialsColumn,
        finishedMaterialsColumn,
        finishedMaterialsConfig,
        finishedProcessColumn,
        finishedProcessConfig,
        processConfig,
        processColumn,
        colorConfig,
        colorColumn,
        packConfig,
        packColumn,
        ...addState,
        colorConfigGrdVisible,
      });
    }
    if(nextProps.treeData && this.props.treeData && nextProps.treeData.length !== 0 && this.props.treeData.length !== 0) {
      if ((nextProps.treeData.length > this.props.treeData.length) && (nextProps.treeData[nextProps.treeData.length - 1].key !== this.props.treeData[this.props.treeData.length - 1].key)) {
        this.handleTreeScrollToBottom();
      }
    }
  }

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

  /**   行选择   */
  // onRowClick = (name, record) => {
  //   if (name === 'control') {
  //     this.props.onTableSelectRowChange(name, [record.sId]);
  //   }
  // };
  //
  // onRowMouseEnter = (name, record) => {
  //   if (this.props.enabled && name === 'control') {
  //     this.props.onTableSelectRowChange(name, [record.sId]);
  //   }
  // }
  //
  // onDoubleClick = (name, record) => {
  //   if (this.props.onDoubleClick !== undefined) {
  //     this.props.onDoubleClick(record);
  //   }
  // };
  onChange1 = (checkedValues) => {
    this.props.onSaveState({
      dataPersonArray: checkedValues,
    });
  };


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

  handleTreeScrollToBottom = () => {
    const { currentPane, panes } = this.props.app;
    if (commonUtils.isNotEmptyArr(panes) && commonUtils.isNotEmptyObject(currentPane)) {
      const index = panes.findIndex(item => item.formId === currentPane.formId && item.key === currentPane.key && item.notCurrentPane === currentPane.notCurrentPane && item.route === currentPane.route && item.title === currentPane.title && item.sModelsType === currentPane.sModelsType && item.sProcName === currentPane.sProcName);
      let currentTab = document.getElementById('navTabWrap').children[index];
      if (commonUtils.isEmpty(currentTab)) {
        const oChildren = document.getElementById('navTabWrap').getElementsByClassName('ant-tabs-content')[0].children;
        for (const child of oChildren) {
          if (child.nodeName === 'DIV' && index !== undefined && child.getAttribute('id') === `navTabWrap-panel-${panes[index].key}`) {
            currentTab = child;
          }
        }
      }
      const treeNode = currentTab.getElementsByClassName('xly-control-tree')[0];
      if (treeNode) {
        setTimeout(() => {
          treeNode.scrollTop = treeNode.scrollHeight;
        }, 0)
      }
    }
  };

  handleEject = () => {
    const { currentPane, panes } = this.props.app;
    if (commonUtils.isNotEmptyArr(panes) && commonUtils.isNotEmptyObject(currentPane)) {
      const index = panes.findIndex(item => item.formId === currentPane.formId && item.key === currentPane.key && item.notCurrentPane === currentPane.notCurrentPane && item.route === currentPane.route && item.title === currentPane.title && item.sModelsType === currentPane.sModelsType && item.sProcName === currentPane.sProcName);
      /* 当前页签 */
      let currentTab = document.getElementById('navTabWrap').children[index];
      if (commonUtils.isEmpty(currentTab)) {
        const oChildren = document.getElementById('navTabWrap').getElementsByClassName('ant-tabs-content')[0].children;
        for (const child of oChildren) {
          if (child.nodeName === 'DIV' && index !== undefined && child.getAttribute('id') === `navTabWrap-panel-${panes[index].key}`) {
            currentTab = child;
          }
        }
      }
      // const currentTab = document.getElementById('tabs').getElementsByClassName('ant-tabs-content-no-animated')[0].children[index];
      if (!commonUtils.isEmpty(currentTab)) {
        const filterTreeArr = currentTab.getElementsByClassName('xly-filter-tree');/* 获取当前页签下的树组件 */
        if (commonUtils.isNotEmptyArr(filterTreeArr)) {
          const filterTree = filterTreeArr[0];
          if (filterTree.style.display === 'block') {
            filterTree.style.display = 'none';
          } else {
            filterTree.style.display = 'block';
          }
        }
      }
    }
  };

  /* 获取表数据 */
  handleGetData = async (controlConfig, materialsConfig, processConfig, colorConfig, packConfig, extraState = {}) => {
    const { currentId, slaveData, sModelsType } = this.props; /* 当前页签数据 */
    const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */
    const addStateControl = await this.props.handleGetDataSet({
      name: 'control', configData: controlConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
    });
    const { controlData, controlSelectedRowKeys } = addStateControl; /* 同步树选中节点与部件选中节点 */
    const treeState = this.handleGetControlTreeData(controlData, true);

    const addStateMaterials = await this.props.handleGetDataSet({
      name: 'materials', configData: materialsConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
    });
    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 = '工艺参数';
            }
            if (commonUtils.isNotEmptyObject(itemProcess.sWorkOrderParam)) {
              let iIndex = -1;
              iIndex = addStateProcess.processData.findIndex(item => item.sId === itemProcess.sId);
              if (iIndex > -1) {
                addStateProcess.processData[iIndex] = { ...itemProcess, ...commonUtils.convertStrToObj(itemProcess.sWorkOrderParam) };
              }
            }
          }
        });
        addStateProcess.processData = this.sortData(addStateControl.controlData, addStateProcess.processData);
      }
    }
    const addStatePack = await this.props.handleGetDataSet({
      name: 'pack', configData: packConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
    });
    let addStateColor = {};
    if (colorConfig) {
      addStateColor = await this.props.handleGetDataSet({
        name: 'color', configData: colorConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
      });
    }
    /* 合版表合并产品信息 */
    if (commonUtils.isNotEmptyArr(slaveData)) {
      const { packData } = addStatePack;
      slaveData.forEach((itemSlave) => {
        const packDataFilter = packData.filter(itemNew => itemNew.sSlaveId === itemSlave.sId);
        if (commonUtils.isNotEmptyArr(packDataFilter)) {
          packDataFilter.forEach((itemPack) => {
            const iIndex = packData.findIndex(child => child.sId === itemPack.sId);
            if (iIndex > -1) {
              const packRowAdd = this.handlePackDataAdd(itemSlave);
              if (commonUtils.isNotEmptyObject(packRowAdd)) {
                packData[iIndex] = { ...packData[iIndex], ...packRowAdd };
              }
            }
          });
        }
      });
      addStatePack.packData = packData;
    }
    /**
     * 修改日期：2021-03-26
     * 修改人：吕杰
     * 区域：以下 3 行
     * BUG：2173
     * 说明：通用工单刷新后 需显示所有部件的工序
     * 原代码：
     */
    const noSelected = sModelsType === 'manufacture/workOrderPack';
    this.props.onSaveState({
      pageLoading: false, ...addStateControl,...addStateMaterials, ...addStateProcess, ...addStateColor, ...addStatePack, ...treeState, treeSelectedKeys: noSelected ? [] : controlSelectedRowKeys, ...extraState,
    });
  };

  /**   获取部件树   */
  handleGetControlTreeData= (controlData, isWait) => {
    /* 生成部件树结构 */
    let treeData = [];
    const expandedKeys = [];
    let { treeSelectedKeys } = this.props;
    if (commonUtils.isNotEmptyArr(controlData)) {
      const rootData = commonUtils.isNotEmptyArr(controlData) ? controlData.filter(item => commonUtils.isEmpty(item.sControlParentId)) : []; /* 找到所有一级树结构 */
      rootData.forEach((item) => {
        const treeDataRow = {};
        const { sId, sPartsName } = item;
        treeDataRow.key = sId;
        treeDataRow.showName = sPartsName;
        treeDataRow.sAllId = item.sAllId;
        const children = this.handleGetControlTreeChildData(sId, controlData);
        let sChildren = '1'; /* 树形结构最后一个节点设置为1 */
        if (commonUtils.isNotEmptyArr(children)) {
          sChildren = '0'; /* 树形结构其他节点设置为0 */
        }
        treeDataRow.sChildren = sChildren;
        /* 添加sChildren,sAllId 值 */
        const iIndex = controlData.findIndex(item => item.sId === sId);
        if (iIndex > -1) {
          // controlData[iIndex].sAllId = sAllId;
          controlData[iIndex].sChildren = sChildren;
        }
        treeDataRow.children = commonUtils.isNotEmptyArr(children) ? children : [];
        treeData.push(treeDataRow);
      });
      if (commonUtils.isEmptyArr(treeSelectedKeys)) {
        expandedKeys.push(treeData[treeData.length - 1].key);
      }
    } else {
      treeSelectedKeys = [];
      treeData = [];
    }
    if (isWait) {
      return { treeData };
    } else {
      this.props.onSaveState({
        treeData,
        // expandedKeys,
      });
    }
  };

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

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

  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 = {  ...masterDataDefault, ...returnChange.masterData };
        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, dispatch,
    } = this.props;
    const { token } = this.props.app;
    const paramMap = {};
    const { sAllPartsName } = masterData;
    let allPartsName = [];
    if (sAllPartsName !== undefined) {
      allPartsName = sAllPartsName.split(',');
    }
    this.props.app.webSocket.onmessageTmp = (msg) => {
      const rtmsg = JSON.parse(msg.data);
      if (rtmsg.action === 'workOrderAllprogress') {
        this.props.onSaveState({
          workOrderAllprogress: rtmsg.msg,
        });
      }
    };
    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;
    let numErr = false;
    let numName = '';
    let num = 0;

    // eslint-disable-next-line array-callback-return
    paramMap.partsInfo.map((item) => {
      if (masterData.sProductClassifyId === '15736273370008507016374163380000' && item.dSumPQty < 4) {
        num = item.dSumPQty;
        numName = item.sPartsName;
      }
      if (item.dSumPQty % 2 !== 0 && item.dSumPQty !== undefined) {
        numErr = true;
        numName = item.sPartsName;
      }
    });
    if (numErr) {
      message.error(`${numName}P数必须是2的倍数！`);
      return;
    }
    if (num === 2) {
      message.error(`${numName}P数必须大于4P！`);
      return;
    }


    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;
    }
    this.props.onSaveState({
      Loading: true,
    });
    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);
      const sInfoArr = [];
      if (!commonUtils.isEmptyArr(partsOldInfo)) {
        partsOldInfo.forEach((item) => {
          if (commonUtils.isNotEmptyObject(item) && !commonUtils.isEmpty(item.errorFlag)) {
            this.props.getServiceError({ msg: `${item.sPartsName}  ${item.errorFlag}` });
          }
        });
      }
      if (this.props.app.userinfo.sType === 'sysadmin') { /* 超级管理员，弹窗显示接口返回的sInfo  */
        partsNewInfo.forEach((item) => {
          const { sPartsName, sInfo } = item;
          const sInfoObj = {};
          sInfoObj.sPartsName = sPartsName;
          sInfoObj.sInfo = sInfo;
          sInfoArr.push(sInfoObj);
        });
      }
      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);
      const addState = {};
      if (!commonUtils.isEmptyArr(controlData) && controlData.length === 1) {
        addState.controlSelectedRowKeys = [controlData[0].sId];
      } else {
        addState.controlSelectedRowKeys = [];
      }
      this.props.onSaveState({
        materialsConfig,
        slaveData,
        controlData,
        materialsData,
        processData,
        fastOrderModalVisible: false,
        workOrderAllprogress: 0,
        ...addState,
        materialsSelectedRowKeys: [],
        sInfoArr,
        bVisiblesInfo: !!commonUtils.isNotEmptyArr(sInfoArr),
        Loading: false,
      });
    } else {
      this.props.getServiceError(dataReturn);
      this.props.onSaveState({
        Loading: false,
      });
    }
  };

  /* 勾选工序分类 */
  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(async (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, packConfig, packData, packDelData, app, calculated, sModelsType,
        } = 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(packConfig, packData, 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 calculating = commonFunc.showLocalMessage(this.props, 'calculating', '自动计算中，请稍后再试。');

        if (['manufacture/workOrder'].includes(sModelsType) && !calculated) {
          message.warning(calculating);
          await this.handleCalculation(true);
        } else {
          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('pack', packConfig.sTbName, packData, packDelData));
          this.props.onSaveData({
            data, sClientType: '1', loading: false, sSysLogSrcId: masterData.sId,
          });
        }
      }
    });
  };

  /**   处理选择行发生改变   */
  handleTableSelectRowChange = (name, selectedRowKeys) => {
    /*   外置处理业务   */
    if (name === 'slave') {
      const {
        slaveData, controlData, materialsData, enabled,
        app,
      } = this.props;
      const addState = this.props.onTableSelectRowChange(name, selectedRowKeys, true);
      if (commonUtils.isNotEmptyArr(selectedRowKeys)) {
        const iIndex = slaveData.findIndex(item => item.sId === selectedRowKeys.toString());
        if (iIndex > -1) {
          /* 若从表相关联的材料表被物料需求计划使用或是生产领料使用，则进行提示,阻止编辑 */
          if (materialsData) {
            materialsData.filter(item => item.sParentId === slaveData[iIndex].sParentId).forEach((itemNew) => {
              const sOrderdetailUsed = itemNew.sOrderdetailUsed;
              const sProductionUsed = itemNew.sProductionUsed;
              if (enabled && (commonUtils.isNotEmptyObject(sOrderdetailUsed))) {
                message.error(commonFunc.showMessage(app.commonConst, 'OrderdetailUsed') + sOrderdetailUsed);
                return;
              }
              if (enabled && (commonUtils.isNotEmptyObject(sProductionUsed))) {
                message.error(commonFunc.showMessage(app.commonConst, 'sProductionUsed') + sProductionUsed);
              }
            });
          }
        }
      }
      if (!commonUtils.isEmptyArr(controlData) && controlData.length === 1) {
        addState.controlSelectedRowKeys = [controlData[0].sId];
        addState.treeSelectedKeys = [controlData[0].sId];
      } else {
        addState.controlSelectedRowKeys = [];
        addState.treeSelectedKeys = [];
      }
      this.props.onSaveState(addState);
    } else if (name === 'control') {
      const {
        [`${name}Data`]: tableData, materialsData, app, 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 (iIndex > -1) {
          /* 若此条控制表中材料表被物料需求计划使用或是生产领料使用，则进行提示,阻止编辑 */
          materialsData.filter(item => item.sControlId === tableData[iIndex].sId).forEach((itemNew) => {
            const sOrderdetailUsed = itemNew.sOrderdetailUsed;
            const sProductionUsed = itemNew.sProductionUsed;
            if (enabled && (commonUtils.isNotEmptyObject(sOrderdetailUsed))) {
              message.error(commonFunc.showMessage(app.commonConst, 'OrderdetailUsed') + sOrderdetailUsed);
              return;
            }
            if (enabled && (commonUtils.isNotEmptyObject(sProductionUsed))) {
              message.error(commonFunc.showMessage(app.commonConst, 'sProductionUsed') + sProductionUsed);
            }
          });
        }
        if (iIndex > -1 && !commonUtils.isEmpty(tableData[iIndex].sControlId)) {
          addState.controlSelectedRowKeys = [tableData[iIndex].sControlId];
        }
        const { treeData } = this.props; /* 赋值给树组件节点 */
        let { treeSelectedKeys } = this.props; /* 赋值给树组件节点 */
        if (treeData !== undefined) {
          treeSelectedKeys = selectedRowKeys; /* 把树形选中节点赋值给表格部件选中节点 */
          addState.treeSelectedKeys = treeSelectedKeys;
        }
      }
      this.props.onSaveState(addState);
    } else if (name === 'materials' || name === 'process') {
      const { [`${name}Data`]: tableData, app, 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 (iIndex > -1) {
          /* 工单中材料或工序，若该条数据被物料需求计划使用或是生产领料使用，则进行提示,阻止编辑 */
          const sOrderdetailUsed = tableData[iIndex].sOrderdetailUsed;
          const sProductionUsed = tableData[iIndex].sProductionUsed;
          if (enabled && (commonUtils.isNotEmptyObject(sOrderdetailUsed))) {
            message.error(commonFunc.showMessage(app.commonConst, 'OrderdetailUsed') + sOrderdetailUsed);
            return;
          }
          if (enabled && (commonUtils.isNotEmptyObject(sProductionUsed))) {
            message.error(commonFunc.showMessage(app.commonConst, 'sProductionUsed') + sProductionUsed);
            return;
          }
        }
        if (enabled && iIndex > -1 && !commonUtils.isEmpty(tableData[iIndex].sControlId)) {
          addState.controlSelectedRowKeys = [tableData[iIndex].sControlId];
        }
      }
      this.props.onSaveState(addState);
    } else if (name === 'pack') {
      const { [`${name}Data`]: tableData } = this.props;
      const addState = this.props.onTableSelectRowChange(name, selectedRowKeys, true);
      if (commonUtils.isNotEmptyArr(selectedRowKeys)) {
        this.handleGetdFactProductQty(selectedRowKeys, tableData);
      }
      this.props.onSaveState(addState);
    } else {
      this.props.onTableSelectRowChange(name, selectedRowKeys);
    }
  };

  /** 控制选择控制表时，显示部件工序与成品工序 */
  handleFilterData = (name, dataIndex, value, record) => {
    if (value === undefined) {
      return true;
    }
    this.handleTableRowLock(name, record);
    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()));
    }
  };
  /** 控制选择控制表时，显示成品材料与成品工序 */
  handleFilterProductData = (name, dataIndex, value, record) => {
    const { slaveSelectedRowKeys } = this.props;
    if (value === undefined) {
      return true;
    }
    this.handleTableRowLock(name, record);
    if (name === 'process') {
      return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '3') &&
        ((commonUtils.isNotEmptyStr(record.sCombinePartsName) && record.sCombinePartsName === slaveSelectedRowKeys[0]) || !record.sCombinePartsName);
    } else {
      return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '2') ||
        ((commonUtils.isNotEmptyStr(record.sCombinePartsName) && record.sCombinePartsName === slaveSelectedRowKeys[0]) || !record.sCombinePartsName);
    }
  };
  /** 控制选择控制表时，显示部件工序与成品工序 */
  handleGetFilterData = (name, bFinished) => {
    const { [`${name}Data`]: data, controlSelectedRowKeys, slaveSelectedRowKeys } = this.props;
    if (data !== undefined && ((commonUtils.isNotEmptyArr(controlSelectedRowKeys) && !bFinished) || bFinished)) {
      if (name === 'materials' && bFinished) { /*  新增成品材料 */
        return data.filter(item => item.sType === '2' && (item.sCombinePartsName === slaveSelectedRowKeys[0] || !item.sCombinePartsName)).length;
      } else if (name === 'process' && bFinished) { /*  新增成品工序s */
        return data.filter(item => item.sType === '3' && (item.sCombinePartsName === slaveSelectedRowKeys[0] || !item.sCombinePartsName)).length;
      } else {
        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, bchild, bFinished, bModalAdd) => {
    const { masterConfig } = this.props;
    if(bModalAdd === true) {
      if(name === 'materials') {
        const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "BtnChooseProductMaterials");
        if (iIndex > -1) {
          this.props.onBtnChoose('productMaterials', 'materials', masterConfig.gdsconfigformslave[iIndex]);
        }
      }
      if(name === 'process') {
        const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "BtnChooseProductProcess");
        if (iIndex > -1) {
          this.props.onBtnChoose('productProcess', 'process', masterConfig.gdsconfigformslave[iIndex]);
        }
      }
      return;
    }
    /*   外置处理业务   */
    const {
      gdsformconst, slaveData, controlData, controlSelectedRowKeys, slaveSelectedRowKeys, [`${name}Data`]: tableData,
    } = this.props;
    if (name === 'control') {
      /* 增加子部件 */
      const {
        [`${name}SelectedRowKeys`]: treeSelectedKeys,
      } = this.props;
      if ((bchild === 'childNode' || bchild === 'sameNode') && (commonUtils.isEmptyArr(treeSelectedKeys) || commonUtils.isEmptyArr(controlSelectedRowKeys))) {
        message.warn('请选择部件！'); // 请选择部件
        return;
      }
      const tableDataRow = this.props.onDataRowAdd(name, true);
      if (bchild === 'sameNode') { /* 添加同级 */
        const iIndex = controlData.findIndex(item => item.sId === treeSelectedKeys[0]);
        /* 找到同级子元素的sControlParentId */
        if (iIndex > -1) {
          tableDataRow.sControlParentId = controlData[iIndex].sControlParentId;
          /* 找到同级父级sAllId */
          const pId = controlData[iIndex].sControlParentId;
          const sControlParentId = controlData.findIndex(item => item.sId === pId);
          if (sControlParentId > -1) {
            const sAllId = controlData[sControlParentId].sAllId;
            if (commonUtils.isEmptyObject(sAllId)) {
              message.warn('部件数据生成错误！[sAllId为空]');
              return;
            }
            tableDataRow.sAllId = `${controlData[sControlParentId].sAllId},${tableDataRow.sId}`;
          } else {
            tableDataRow.sAllId = tableDataRow.sId;
          }
        }
      }
      if (bchild === 'childNode') { /* 添加子级 */
        tableDataRow.sControlParentId = treeSelectedKeys[0];
        const iIndex = controlData.findIndex(item => item.sId === treeSelectedKeys[0]);
        if (iIndex > -1) {
          const sAllId = controlData[iIndex].sAllId;
          if (commonUtils.isEmptyObject(sAllId)) {
            message.warn('子部件数据生成错误！[sAllId为空]'); // 获取父节点的sAllId
            return;
          }
          tableDataRow.sAllId = `${controlData[iIndex].sAllId},${tableDataRow.sId}`;
        }
      }
      let dPartsQty = 0;
      /* 主表配置bProductQtyAdd 则代表产品数量不叠加备货数 赠送数 */
      let bProductQtySelf = false;
      if (commonUtils.isNotEmptyObject(this.props.masterConfig) && commonUtils.isNotEmptyArr(this.props.masterConfig.gdsconfigformslave)) {
        const iIndex = this.props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bProductQtySelf');
        if (iIndex > -1) {
          bProductQtySelf = true;
        }
      }
      if (commonUtils.isNotEmptyArr(slaveData)) {
        slaveData.forEach((item) => {
          if (bProductQtySelf) {
            dPartsQty += commonUtils.isNull(item.dProductQty, 0);
          } else {
            dPartsQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
          }
        });
      }
      tableDataRow.dPartsQty = dPartsQty;
      tableData.push(tableDataRow);
      const treeState = this.handleGetControlTreeData(tableData, true);
      this.props.onSaveState({
        ...treeState, [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId], treeSelectedKeys: [tableDataRow.sId],
      });
    } else if (name === 'materials' || name === 'process') {
      const tableDataRow = this.props.onDataRowAdd(name, true);
      if (commonUtils.isEmptyArr(controlSelectedRowKeys) && !bFinished) {
        message.warn(commonFunc.showMessage(gdsformconst, 'pleaseChooseParts')); // 请选择部件
        return;
      }
      if(bFinished) {
        const iIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
        if (iIndex > -1) {
          tableDataRow.sCombinePartsNameNew = `${slaveData[iIndex].sCustomerName}-${slaveData[iIndex].sProductName}`;
          tableDataRow.sCombinePartsName = slaveData[iIndex].sId;
          if (name === 'materials') { /*  新增成品材料 */
            tableDataRow.sType = '2';
          }
          if (name === 'process') { /*  新增成品工序 */
            tableDataRow.sType = '3';
          }
        }
      } else {
        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;
          // tableDataRow.iOrder = controlData[iIndex];
        }
      }

      tableData.push(tableDataRow);
      this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId] });
    } else if (name === 'slave') {
      const { [`${name}SelectedRowKeys`]: tableSelectedRowKeys, app, packData } = this.props;
      const tableDataRow = this.props.onDataRowAdd(name, true);
      if (commonUtils.isNotEmptyArr(slaveData) && commonUtils.isEmptyArr(tableSelectedRowKeys)) {
        message.warning(commonFunc.showMessage(app.commonConst, 'selectedRowKeysNo'));
        return;
      }
      if (commonUtils.isNotEmptyArr(controlData)) {
        controlData.forEach((item) => {
          /* 合版信息表增加一条从表数据  */
          const packDataRow = this.handlePackDataAdd(tableDataRow, slaveData.length, item.sId, 'add');
          if (commonUtils.isNotEmptyObject(packDataRow)) {
            // packDataRow.dCombineQty = 1;
            packData.push(packDataRow);
          }
        });
      }
      tableData.push(tableDataRow);
      this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId] }, packData);
    } else {
      return this.props.onDataRowAdd(name, flag);
    }
  };
  /**   删除表格数据   */
  otherTableDel = (name, tableSelectedRowKeys, sField) => {
    const tableData = this.props[`${name}Data`];
    let tableDelData = this.props[`${name}DelData`];
    tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData;
    const sFieldName = commonUtils.isEmpty(sField) ? 'sControlId' : sField;
    for (const sId of tableSelectedRowKeys) {
      /*   看看删除集合和从表中是否都存在该条数据s   */
      let tableDataIndex = tableData.findIndex(item => item[sFieldName] === sId);
      while (tableDataIndex > -1) {
        /*   删除从表中的数据并存入删除集合中   */
        const slaveDataFilter = tableData[tableDataIndex];
        tableData.splice(tableDataIndex, 1);
        slaveDataFilter.handleType = 'del';
        tableDelData.push(slaveDataFilter);
        tableDataIndex = tableData.findIndex(item => item[sFieldName] === sId);
      }
    }
    return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [] };
  }
  /**   删除表格数据   */
  handleTableDel = async (name, flag, tableSelectedRowKeys) => {
    if (name === 'slave') {
      /* 删除sSlaveId关联的合版表 */
      const { [`${name}SelectedRowKeys`]: tableSelectedRowKeys } = this.props;
      if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) {
        const packReturnData = this.otherTableDel('pack', tableSelectedRowKeys, 'sSlaveId');
        const materielReturnData = this.otherTableDel('materials', tableSelectedRowKeys, 'sCombinePartsName'); /* 删除成品材料 */
        const processReturnData = this.otherTableDel('process', tableSelectedRowKeys, 'sCombinePartsName'); /* 删除成品工序 */
        const slaveReturnData = this.props.onDataRowDel(name, true, tableSelectedRowKeys);
        this.props.onSaveState({
          ...materielReturnData,
          ...processReturnData,
          ...packReturnData,
          ...slaveReturnData,
        });
        return true;
      } else {
        message.warn('请选择要删除的部件！');
        return false;
      }
    } else if (name === 'control') {
      const { controlData, treeSelectedKeys, [`${name}SelectedRowKeys`]: tableSelectedRowKeys } = this.props;
      if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) {
        const iIndex = controlData.findIndex(item => tableSelectedRowKeys.includes(item.sId) && item.rowTag === 1);
        if (iIndex > -1) {
          /* 如果行被锁定不可更改删除时 */
          return false;
        }
        /* 删除该节点及所有子节点 */
        const controlChildData = controlData.filter(item => commonUtils.isNotEmptyObject(item.sAllId) && item.sAllId.indexOf(treeSelectedKeys[0]) > -1 && item.sId !== treeSelectedKeys[0]);
        if (commonUtils.isNotEmptyArr(controlData)) {
          controlChildData.forEach((itemNew) => {
            tableSelectedRowKeys.push(itemNew.sId);
          });
        }
        const materialsReturnData = this.otherTableDel('materials', tableSelectedRowKeys);
        const processReturnData = this.otherTableDel('process', tableSelectedRowKeys);
        const packReturnData = this.otherTableDel('pack', tableSelectedRowKeys);
        const controlReturnData = this.props.onDataRowDel(name, true, tableSelectedRowKeys);
        const treeState = this.handleGetControlTreeData(controlReturnData.controlData, true);
        this.props.onSaveState({
          ...treeState,
          ...materialsReturnData,
          ...processReturnData,
          ...packReturnData,
          ...controlReturnData,
        });
        return true;
      } else {
        message.warn('请选择要删除的部件！');
        return false;
      }
    } else if (name === 'process') {
      const {
        sModelsId, [`${name}Data`]: tableData, materialsConfig, materialsData, token,
      } = this.props;
      let { materialsDelData } = this.props;
      if (commonUtils.isEmptyArr(materialsDelData)) {
        materialsDelData = [];
      }
      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;
      iMaterialsIndex = materialsData.findIndex(item => item.sControlId === tableData[iIndex].sControlId && item.sProcessId === tableData[iIndex].sProcessId);

      const sProcessId = tableData[iIndex].sProcessId;
      const sControlId = tableData[iIndex].sControlId;
      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);

          /* 删除配套材料 */
          const iMaterialsIndex = materialsData.findIndex(item => item.sMaterialsName === slaveDataFilter.sProcessName && item.sControlId === sControlId);
          if (iMaterialsIndex > -1) {
            const materialsDataRow = materialsData[iMaterialsIndex];
            materialsData.splice(iMaterialsIndex, 1);
            materialsDataRow.handleType = 'del';
            materialsDelData.push(materialsDataRow);
          }
        }
      }));

      processReturnData.processDelData.concat(tableDelData);
      if (iMaterialsIndex > -1) {
        materialsData[iMaterialsIndex].sProcessId = '';
        materialsData[iMaterialsIndex].sProcessTbId = '';
        materialsData[iMaterialsIndex].sMaterialsProcessName = '';
      }
      this.props.onSaveState({
        ...processReturnData,
        materialsDelData,
        materialsConfig,
        materialsSelectedRowKeys: [],
      });
      return true;
    } else {
      return this.props.onDataRowDel(name, flag, tableSelectedRowKeys);
    }
  };
  /**   材料被使用锁定表格数据行   */
  handleTableRowLock = async (name, record) => {
    const { slaveData, controlData, enabled } = this.props;
    if (commonUtils.isNotEmptyObject(record) && enabled) {
      if (name === 'materials' || name === 'process') {
        const { sOrderdetailUsed, sProductionUsed } = record;
        if (commonUtils.isNotEmptyObject(sOrderdetailUsed) || commonUtils.isNotEmptyObject(sProductionUsed)) {
          record.rowTag = 1;
          controlData.filter(item => item.sId === record.sControlId).forEach((itemNew) => {
            itemNew.rowTag = 1;
          });
          slaveData.filter(item => item.sParentId === record.sParentId).forEach((itemNew) => {
            itemNew.rowTag = 1;
          });
        }
      }
    }
  }

  handleCalculation = async (bSave) => {
    const dataUrl = `${commonConfig.server_host}business/addWorksheet?sModelsId=${this.props.sModelsId}`;
    const {
      app, masterConfig, slaveConfig, packConfig, controlConfig, materialsConfig, processConfig, colorConfig, sModelsType, colorData, slaveDelData, controlDelData, materialsDelData, processDelData, colorDelData, packDelData,
    } = this.props;
    let {
      slaveData, packData, controlData, materialsData, processData, masterData,
    } = this.props;
    const sMakePerson = masterData.sMakePerson;
    const dataCalculation = [];
    if ((masterData.sFormId === '101251240115015840916341460' || sModelsType.includes('manufacture/workOrderSupple')) && commonUtils.isNotEmptyArr(colorData)) {
      controlData.forEach((item) => {
        item.iPositiveColor = colorData.filter(item => !item.bNotColor).length;
      });
    }
    dataCalculation.push(commonBusiness.mergeData('master', `${masterConfig.sTbName.toLowerCase()}_Tmp`, [masterData], [], true));
    dataCalculation.push(commonBusiness.mergeData('slave', `${slaveConfig.sTbName.toLowerCase()}_tmp`, slaveData, [], true));
    dataCalculation.push(commonBusiness.mergeData('control', `${controlConfig.sTbName.toLowerCase()}_tmp`, controlData, [], true));
    dataCalculation.push(commonBusiness.mergeData('pack', `${packConfig.sTbName.toLowerCase()}_tmp`, packData, [], true));
    dataCalculation.push(commonBusiness.mergeData('materials', `${materialsConfig.sTbName.toLowerCase()}_tmp`, materialsData, [], true));
    dataCalculation.push(commonBusiness.mergeData('process', `${processConfig.sTbName.toLowerCase()}_tmp`, processData, [], true));
    const value = { data: dataCalculation, 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];
      }
      if (masterData.handleType === 'update' && !commonUtils.isEmpty(sMakePerson)) {
        masterData.sMakePerson = sMakePerson;
      }
      slaveData = valueReturn[`${slaveConfig.sTbName.toLowerCase()}_tmp`];
      packData = valueReturn[`${packConfig.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);

      /* 计算成功后自动调用保存 */
      if (bSave) {
        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('pack', packConfig.sTbName, packData, packDelData));
        this.props.onSaveData({
          data, sClientType: '1', loading: false, sSysLogSrcId: masterData.sId,
        });
      } else {
        this.props.onSaveState({
          slaveData, packData, controlData, materialsData, processData, masterData, loading: false, calculated: true,
        });

        message.success(commonFunc.getConfigShowName(masterConfig, 'BtnCalculation') + commonFunc.showMessage(app.commonConst, 'handleSuccess'));
      }
    } else { /*   失败   */
      this.props.onSaveState({
        loading: false,
        calculated: 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 if (name === 'BtnCombine') {
      const { slaveData: slaveDataOld, controlData: controlDataOld } = this.props;
      let dMaxQty = 0;
      let dSumMachineQty = 0;
      slaveDataOld.forEach((item) => {
        if (commonUtils.isEmpty(item.dCombineQty) || item.dCombineQty === 0 ? 0 : item.dSrcQty / item.dCombineQty > dMaxQty) {
          dMaxQty = Math.ceil(commonUtils.isEmpty(item.dCombineQty) || item.dCombineQty === 0 ? 0 : item.dSrcQty / item.dCombineQty);
        }
      });
      const controlData = [];
      if (commonUtils.isNotEmptyArr(controlDataOld)) {
        controlDataOld.forEach((item) => {
          let controlRow = { ...item, dPartsQty: dMaxQty };
          controlRow = this.singlePQtyChange(controlRow);
          controlData.push(controlRow);
        });
        dSumMachineQty = controlData[0].dSumMachineQty;
      }
      const slaveData = [];
      slaveDataOld.forEach((item) => {
        slaveData.push({ ...item, dProductQty: dSumMachineQty * item.dCombineQty });
      });
      this.props.onSaveState({ slaveData, controlData });
    } else if (name === 'BtnDraft') {
      const {
        masterConfig, masterData, slaveConfig, slaveData, slaveDelData, controlConfig, controlData, controlDelData,
        materialsConfig, materialsData, materialsDelData, processConfig, processData, processDelData, colorConfig,
        colorData, colorDelData,
      } = this.props;
      const data = [];
      slaveConfig.gdsconfigformslave.forEach((itemConfig) => {
        slaveData.filter(itemData => itemData.handleType === 'add' || itemData.handleType === 'update').forEach((itemData) => {
          itemData.NoVerify = 'NoVerify';
          const firstDataIndex = itemConfig.sName.substring(0, 1);
          if (commonUtils.isEmpty(itemData[itemConfig.sName])) {
            itemData[itemConfig.sName] = firstDataIndex === 's' ? '' :
              firstDataIndex === 'd' || firstDataIndex === 'i' ? 0 :
                firstDataIndex === 'b' ? false :
                  firstDataIndex === 't' ? moment(new Date()).format(this.props.app.dateFormat) : undefined;
          }
        });
      });
      controlConfig.gdsconfigformslave.forEach((itemConfig) => {
        controlData.filter(itemData => itemData.handleType === 'add' || itemData.handleType === 'update').forEach((itemData) => {
          itemData.NoVerify = 'NoVerify';
          const firstDataIndex = itemConfig.sName.substring(0, 1);
          if (commonUtils.isEmpty(itemData[itemConfig.sName])) {
            itemData[itemConfig.sName] = firstDataIndex === 's' ? '' :
              firstDataIndex === 'd' || firstDataIndex === 'i' ? 0 :
                firstDataIndex === 'b' ? false :
                  firstDataIndex === 't' ? moment(new Date()).format(this.props.app.dateFormat) : undefined;
          }
        });
      });

      materialsConfig.gdsconfigformslave.forEach((itemConfig) => {
        materialsData.filter(itemData => itemData.handleType === 'add' || itemData.handleType === 'update').forEach((itemData) => {
          itemData.NoVerify = 'NoVerify';
          const firstDataIndex = itemConfig.sName.substring(0, 1);
          if (commonUtils.isEmpty(itemData[itemConfig.sName])) {
            itemData[itemConfig.sName] = firstDataIndex === 's' ? '' :
              firstDataIndex === 'd' || firstDataIndex === 'i' ? 0 :
                firstDataIndex === 'b' ? false :
                  firstDataIndex === 't' ? moment(new Date()).format(this.props.app.dateFormat) : undefined;
          }
        });
      });

      processConfig.gdsconfigformslave.forEach((itemConfig) => {
        processData.filter(itemData => itemData.handleType === 'add' || itemData.handleType === 'update').forEach((itemData) => {
          itemData.NoVerify = 'NoVerify';
          const firstDataIndex = itemConfig.sName.substring(0, 1);
          if (commonUtils.isEmpty(itemData[itemConfig.sName])) {
            itemData[itemConfig.sName] = firstDataIndex === 's' ? '' :
              firstDataIndex === 'd' || firstDataIndex === 'i' ? 0 :
                firstDataIndex === 'b' ? false :
                  firstDataIndex === 't' ? moment(new Date()).format(this.props.app.dateFormat) : undefined;
          }
        });
      });

      if (commonUtils.isNotEmptyObject(colorConfig)) {
        colorConfig.gdsconfigformslave.forEach((itemConfig) => {
          colorData.filter(itemData => itemData.handleType === 'add' || itemData.handleType === 'update').forEach((itemData) => {
            itemData.NoVerify = 'NoVerify';
            const firstDataIndex = itemConfig.sName.substring(0, 1);
            if (commonUtils.isEmpty(itemData[itemConfig.sName])) {
              itemData[itemConfig.sName] = firstDataIndex === 's' ? '' :
                firstDataIndex === 'd' || firstDataIndex === 'i' ? 0 :
                  firstDataIndex === 'b' ? false :
                    firstDataIndex === 't' ? moment(new Date()).format(this.props.app.dateFormat) : undefined;
            }
          });
        });
      }

      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));
      if (commonUtils.isNotEmptyObject(colorConfig)) {
        data.push(commonBusiness.mergeData('color', colorConfig.sTbName, colorData, colorDelData));
      }
      this.props.onSaveData({
        data, sClientType: '1', loading: false, sSysLogSrcId: masterData.sId, bIsUnCcg: false,
      });
    } else {
      this.props.onButtonClick(name);
    }
  };

  /*  上一条、下一条、首条、末条 */
  handleSearchData = async (handleType) => {
    const {
      controlConfig, materialsConfig, processConfig, colorConfig, packConfig,
    } = this.props;
    const bReturn = await this.props.onSearchData(handleType);
    if (bReturn) {
      this.handleGetData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig);
    }
  };
  /**   点击修改按钮操作   */
  handleEdit = () => {
    const {
      controlConfig, materialsConfig, processConfig, colorConfig, packConfig,
    } = this.props;
    this.props.onEdit(() => {
      this.handleGetData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig, { loading: false, enabled: true });
    });
  };

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

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

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

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

  /* 确定要删除 */
  handleOkDel = async (props) => {
    /*   数据参数   */
    const {
      token, sModelsId, masterConfig, masterData, slaveConfig, checkConfig, controlConfig, materialsConfig, processConfig, app,
    } = props;
    const { userinfo, systemData } = app;
    const { sMakePerson } = masterData; /* 本单据制单人 */
    const { sUserName, sType } = userinfo;/* 登录用户 */
    const iIndex = systemData.findIndex(item => item.sName === 'CkxModifyBillNoMakePerson');
    if (iIndex > -1) {
      const sValue = systemData[iIndex].sValue;
      if (sValue === '0') { /* 系统未启用非制单人修改单据，普通用户非制单人不可以修改制单人的单据 */
        if (sType !== 'sysadmin' && sUserName !== sMakePerson) {
          message.error(commonFunc.showMessage(app.commonConst, 'NoDelByNoMakePerson'));
          return;
        }
      }
    }
    const value = {
      sClientType: '1',
      data: {
        sMasterTable: masterConfig.sTbName,
        sId: [masterData.sId],
        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, colorConfig, packConfig, 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, colorConfig, packConfig);
        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);
    let { slaveData, masterData } = state;
    let controlData = [];
    let packData = [];
    let materialsData = [];
    let processData = [];
    const colorData = [];
    /* 主表配置bProductQtyAdd 则代表产品数量不叠加备货数 赠送数 */
    let bProductQtySelf = false;
    if (commonUtils.isNotEmptyObject(this.props.masterConfig) && commonUtils.isNotEmptyArr(this.props.masterConfig.gdsconfigformslave)) {
      const iIndex = this.props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bProductQtySelf');
      if (iIndex > -1) {
        bProductQtySelf = true;
      }
    }
    if (commonUtils.isNotEmptyObject(copyTo)) {
      const {
        app, sModelsId, token, sModelsType,
      } = this.props;
      const bCkxCopyFromTechnology = app.systemData.filter(item => item.sName === 'CkxCopyFromTechnology')[0].sValue;
      if (bCkxCopyFromTechnology === '1' && (sModelsType !== 'manufacture/workOrder2' && sModelsType !== 'manufacture/workOrderSupple2')) {
        if (slaveData.length > 1) {
          const dataUrl = `${commonConfig.server_host}business/getCopyToWorkOrderData?sModelsId=${sModelsId}`;
          const data = [];
          data.push(commonBusiness.mergeData('master', `${config.masterConfig.sTbName.toLowerCase()}_Tmp`, [masterData], [], true));
          data.push(commonBusiness.mergeData('slave', `${config.slaveConfig.sTbName.toLowerCase()}_tmp`, slaveData, [], true));
          const value = {
            data, sClientType: '1', sGuid: masterData.sId, sConfigId: copyTo.config[0].sId, sControlName: copyTo.name,
          };
          const dataReturn = (await commonServices.postValueService(token, value, dataUrl)).data;
          if (dataReturn.code === 1) {
            const valueReturn = dataReturn.dataset.rows[0];
            const masterDataArr = valueReturn[`${config.masterConfig.sTbName.toLowerCase()}_tmp`];
            if (commonUtils.isNotEmptyArr(masterDataArr)) {
              masterData = masterDataArr[0];
            }
            slaveData = valueReturn[`${config.slaveConfig.sTbName.toLowerCase()}_tmp`];
            controlData = valueReturn[`${config.controlConfig.sTbName.toLowerCase()}_tmp`];
            packData = valueReturn[`${config.packConfig.sTbName.toLowerCase()}_tmp`];
            materialsData = valueReturn[`${config.materialsConfig.sTbName.toLowerCase()}_tmp`];
            processData = valueReturn[`${config.processConfig.sTbName.toLowerCase()}_tmp`];
            processData = this.sortData(controlData, processData);
          } else {
            this.props.getServiceError(dataReturn.msg);
          }
        } else {
          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 copyToMasterDetailConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.masterdetail`.toLowerCase());
            const copyToSlaveDetailConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slavedetail`.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 copyToPackConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.pack`.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 packAssignField = commonUtils.isNotEmptyArr(copyToPackConfig) ? copyToPackConfig[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;
              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;
                if (dProductQty) {
                  dProductQty += commonUtils.isNull(item.dProductQty, 0);
                } else {
                  dProductQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0);
                }
              });
              const treeCopyNodes = new Map();
              await returnData.controlData.forEach(async (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;
                /* CopyTo时sAllId,sControlParentId 设置 */
                const sAllOldId = controlItem.sAllId;
                let arr = [];
                if (commonUtils.isNotEmptyObject(sAllOldId)) {
                  arr = sAllOldId.split(',');
                }
                const newId = controlRow.sId;
                let sOldParentId = '';
                let sNewParentAllId = '';
                if (arr.length < 2) { /* 根节点复制 */
                  controlRow.sAllId = newId;
                  sOldParentId = newId;
                  sNewParentAllId = newId;
                } else {
                  sOldParentId = arr[arr.length - 2];
                  if (treeCopyNodes.has(sOldParentId)) {
                    sNewParentAllId = treeCopyNodes.get(sOldParentId);
                  } else {
                    const obj = arr[arr.length - 1];
                    sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
                  }
                  const sNewArr = sNewParentAllId.split(',');
                  controlRow.sControlParentId = sNewArr[sNewArr.length - 1];
                  sNewParentAllId = `${sNewParentAllId},${newId}`;
                  controlRow.sAllId = sNewParentAllId;
                }
                treeCopyNodes.set(controlItem.sId, sNewParentAllId);
                controlRow.dPartsQty = dProductQty;
                controlData.push(controlRow);

                /* 复制到时增加合版表 */
                if (commonUtils.isNotEmptyArr(returnData.packData)) {
                  await copyTo.packData.filter(item => item.sControlId === controlItem.sId).forEach(async (packItem) => {
                    newCopyTo.pack = packItem;
                    let packRow = commonFunc.getDefaultData(config.packConfig, newCopyTo); // 取默认值
                    packRow = { ...packRow, ...commonFunc.getAssignFieldValue(packAssignField, packItem, newCopyTo) }; // 取赋值字段
                    packRow.sOriginalId = packItem.sId;/* 翻单前的sId */
                    /* sSlaveId赋值 */
                    const iSlaveIndex = slaveData.findIndex(item => item.sOriginalId === packItem.sSlaveId);
                    if (iSlaveIndex > -1) {
                      const slaveDataRow = slaveData[iSlaveIndex];
                      const packRowAdd = this.handlePackDataAdd(slaveDataRow, 0, controlRow.sId, 'add');
                      if (commonUtils.isNotEmptyObject(packRowAdd)) {
                        packRow = { ...packRow, ...packRowAdd };
                        packData.push(packRow);
                      }
                    }
                  });
                }

                if (commonUtils.isNotEmptyArr(returnData.processData)) {
                  returnData.processData.filter(item => item.sControlId === controlItem.sId && item.sType !== '3').forEach((processItem) => {
                    // eslint-disable-next-line radix
                    if ((slaveData.length <= 1) || (slaveData.length > 1 && parseInt(processItem.sType) <= 1)) {
                      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;
                      /* 根据合版表的源sOriginalId找到新sId */
                      let sNewIds = '';
                      let sNewNames = '';
                      const sOldIds = processItem.sCombinePartsName;
                      if (commonUtils.isNotEmptyObject(sOldIds)) {
                        const sOldArr = sOldIds.split(',');
                        for (const sId of sOldArr) {
                          const index = packData.findIndex(item => item.sOriginalId === sId);
                          if (index > -1) {
                            const tableDataRow = packData[index];
                            sNewIds += `${tableDataRow.sId},`;
                            sNewNames += `${tableDataRow.sCustomerName}-${tableDataRow.sProductName}-${tableDataRow.sCombinePartsName},`;
                          }
                        }
                        sNewIds = commonUtils.isNotEmptyObject(sNewIds) ? sNewIds.substr(0, sNewIds.length - 1) : '';
                        sNewNames = commonUtils.isNotEmptyObject(sNewNames) ? sNewNames.substr(0, sNewNames.length - 1) : '';
                      }
                      processRow.sCombinePartsName = sNewIds;
                      processRow.sCombinePartsNameNew = sNewNames;
                      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)) {
                  await returnData.materialsData.filter(item => item.sControlId === controlItem.sId && item.sType !== '2').forEach(async (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;
                    if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
                      const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                      const valueMaterialsStock = {
                        sProName: 'Sp_Inventory_MaterialsInventoryV56',
                        paramsMap: {
                          sMaterialsGuid: materialsRow.sMaterialsId,
                          sMaterialsStyle: materialsRow.sMaterialsStyle,
                          sWarehouseGuid: materialsRow.sWarehouseId,
                          sLocationalGuid: materialsRow.sLocationId,
                          sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                          sDefine_no: materialsRow.sDefineNo,
                          sDefine_no2: materialsRow.sDefineNo2,
                          iGetQty: 1,
                          iHasZero: 1,
                        },
                      };
                      const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
                      if (returnDataMaterialsStock.code === 1) {
                        materialsRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                      }
                    }
                    if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
                      const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                      const valueMaterialsAvailableQty = {
                        sProName: 'Sp_Inventory_MaterialsInventoryV56',
                        paramsMap: {
                          sMaterialsGuid: materialsRow.sMaterialsId,
                          sMaterialsStyle: materialsRow.sMaterialsStyle,
                          sWarehouseGuid: materialsRow.sWarehouseId,
                          sLocationalGuid: materialsRow.sLocationId,
                          sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                          sDefine_no: materialsRow.sDefineNo,
                          sDefine_no2: materialsRow.sDefineNo2,
                          iGetQty: 2,
                          iHasZero: 1,
                        },
                      };
                      const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
                      if (returnDataMaterialsAvailableQty.code === 1) {
                        materialsRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                      }
                    }
                    // 材料对应工序的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)) {
              await returnData.materialsData.filter(item => item.sType === '2').forEach(async (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;

                /* 根据从表源sOriginalId找到新sId */
                let sNewIds = '';
                let sNewNames = '';
                const sOldIds = materialsItem.sCombinePartsName;
                if (commonUtils.isNotEmptyObject(sOldIds)) {
                  const sOldArr = sOldIds.split(',');
                  for (const sId of sOldArr) {
                    const index = slaveData.findIndex(item => item.sOriginalId === sId);
                    if (index > -1) {
                      const tableDataRow = slaveData[index];
                      sNewIds += `${tableDataRow.sId},`;
                      sNewNames += `${tableDataRow.sProductName},`;
                    }
                  }
                  sNewIds = commonUtils.isNotEmptyObject(sNewIds) ? sNewIds.substr(0, sNewIds.length - 1) : '';
                  sNewNames = commonUtils.isNotEmptyObject(sNewNames) ? sNewNames.substr(0, sNewNames.length - 1) : '';
                }
                materialsRow.sCombinePartsName = sNewIds;
                materialsRow.sCombinePartsNameNew = sNewNames;

                if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
                  const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                  const valueMaterialsStock = {
                    sProName: 'Sp_Inventory_MaterialsInventoryV56',
                    paramsMap: {
                      sMaterialsGuid: materialsRow.sMaterialsId,
                      sMaterialsStyle: materialsRow.sMaterialsStyle,
                      sWarehouseGuid: materialsRow.sWarehouseId,
                      sLocationalGuid: materialsRow.sLocationId,
                      sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                      sDefine_no: materialsRow.sDefineNo,
                      sDefine_no2: materialsRow.sDefineNo2,
                      iGetQty: 1,
                      iHasZero: 1,
                    },
                  };
                  const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
                  if (returnDataMaterialsStock.code === 1) {
                    materialsRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                  }
                }
                if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
                  const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                  const valueMaterialsAvailableQty = {
                    sProName: 'Sp_Inventory_MaterialsInventoryV56',
                    paramsMap: {
                      sMaterialsGuid: materialsRow.sMaterialsId,
                      sMaterialsStyle: materialsRow.sMaterialsStyle,
                      sWarehouseGuid: materialsRow.sWarehouseId,
                      sLocationalGuid: materialsRow.sLocationId,
                      sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                      sDefine_no: materialsRow.sDefineNo,
                      sDefine_no2: materialsRow.sDefineNo2,
                      iGetQty: 2,
                      iHasZero: 1,
                    },
                  };
                  const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
                  if (returnDataMaterialsAvailableQty.code === 1) {
                    materialsRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                  }
                }
                materialsData.push(materialsRow);
              });
            }

            if (commonUtils.isNotEmptyArr(returnData.processData) && (slaveData.length <= 1)) {
              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;
                /* 根据从表的源sOriginalId找到新sId */
                let sNewIds = '';
                let sNewNames = '';
                const sOldIds = processItem.sCombinePartsName;
                if (commonUtils.isNotEmptyObject(sOldIds)) {
                  const sOldArr = sOldIds.split(',');
                  for (const sId of sOldArr) {
                    const index = slaveData.findIndex(item => item.sOriginalId === sId);
                    if (index > -1) {
                      const tableDataRow = slaveData[index];
                      sNewIds += `${tableDataRow.sId},`;
                      sNewNames += `${tableDataRow.sCustomerName}-${tableDataRow.sProductName},`;
                    }
                  }
                  sNewIds = commonUtils.isNotEmptyObject(sNewIds) ? sNewIds.substr(0, sNewIds.length - 1) : '';
                  sNewNames = commonUtils.isNotEmptyObject(sNewNames) ? sNewNames.substr(0, sNewNames.length - 1) : '';
                }
                processRow.sCombinePartsName = sNewIds;
                processRow.sCombinePartsNameNew = sNewNames;
                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);
                        });
                      }
                    }
                  }));
                }
              });
            } else if (slaveData.length > 1) {
              let sInfo;
              slaveData.forEach((item) => {
                sInfo = commonUtils.isEmpty(sInfo) ? `${item.sCustomerId}|${item.sProductId}` : `${sInfo},${item.sCustomerId}|${item.sProductId}`;
              });
              const dataUrl = `${commonConfig.server_host}salesorder/getgdsemigoodsMatchInfo?sModelsId=${sModelsId}`;
              const params = {
                customerProductInfo: sInfo,
              };
              const dataCombineProcess = (await commonServices.postValueService(token, params, dataUrl)).data;
              if (dataCombineProcess.code === 1) {
                const returnData = dataCombineProcess.dataset.rows;
                returnData.forEach((processItem, processIndex) => {
                  newCopyTo.process = processItem;
                  let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo); // 取默认值
                  processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                  processRow.sSlaveCustomerId = processItem.sCustomerId;
                  processRow.sCustomerName = processItem.sCustomerName;
                  processRow.sSlaveProductId = processItem.sProductId;

                  processRow.sProductName = processItem.sProductName;
                  processRow.iOrder = processIndex + 1;
                  processRow.sType = '3';

                  processRow.handleType = 'add';
                  processRow.sId = commonUtils.createSid();
                  processRow.sParentId = masterData.sId;
                  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);
              });
            }
          } 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 copyToPackConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.pack`.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 packAssignField = commonUtils.isNotEmptyArr(copyToPackConfig) ? copyToPackConfig[0].sAssignField : '';

        const newCopyTo = {};
        newCopyTo.master = copyTo.masterData;
        newCopyTo.slave = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
        let bProcessAssort = true;
        /* 生产翻单不生成配套工序 */
        const srcFormRoute = copyTo.srcFormRoute; /* 未清来源路径 */
        if (sModelsType === 'manufacture/workOrder' && (commonUtils.isEmpty(srcFormRoute) || srcFormRoute.includes('workOrder'))) {
          bProcessAssort = false;
        }
        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 };
          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.packData = returnData.packData;
            copyTo.colorData = returnData.colorData;
          } else {
            await 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);
          // });
          const treeCopyNodes = new Map();
          await copyTo.controlData.forEach(async (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.sOriginalId = controlItem.sId; /* 复制前的部件表sId */
            controlRow.sParentId = masterData.sId;
            /* CopyTo时sAllId,sControlParentId 设置 */
            const sAllOldId = controlItem.sAllId;
            let arr = [];
            if (commonUtils.isNotEmptyObject(sAllOldId)) {
              arr = sAllOldId.split(',');
            }
            const newId = controlRow.sId;
            let sOldParentId = '';
            let sNewParentAllId = '';
            if (arr.length < 2) { /* 根节点复制 */
              controlRow.sAllId = newId;
              sOldParentId = newId;
              sNewParentAllId = newId;
            } else {
              sOldParentId = arr[arr.length - 2];
              if (treeCopyNodes.has(sOldParentId)) {
                sNewParentAllId = treeCopyNodes.get(sOldParentId);
              } else {
                const obj = arr[arr.length - 1];
                sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
              }
              const sNewArr = sNewParentAllId.split(',');
              controlRow.sControlParentId = sNewArr[sNewArr.length - 1];
              sNewParentAllId = `${sNewParentAllId},${newId}`;
              controlRow.sAllId = sNewParentAllId;
            }
            treeCopyNodes.set(controlItem.sId, sNewParentAllId);
            // controlRow.dPartsQty = dProductQty;
            controlData.push(controlRow);

            /* 复制到时增加合版表 */
            if (commonUtils.isNotEmptyArr(copyTo.packData)) {
              await copyTo.packData.filter(item => item.sControlId === controlItem.sId).forEach(async (packItem) => {
                newCopyTo.pack = packItem;
                let packRow = commonFunc.getDefaultData(config.packConfig, newCopyTo); // 取默认值
                packRow = { ...packRow, ...commonFunc.getAssignFieldValue(packAssignField, packItem, newCopyTo) }; // 取赋值字段
                packRow.sOriginalId = packItem.sId;/* 翻单前的sId */
                /* sSlaveId赋值 */
                const iSlaveIndex = slaveData.findIndex(item => item.sOriginalId === packItem.sSlaveId || item.sOrderSlaveId === packItem.sSlaveId);
                if (iSlaveIndex > -1) {
                  const slaveDataRow = slaveData[iSlaveIndex];
                  const packRowAdd = this.handlePackDataAdd(slaveDataRow, 0, controlRow.sId, 'add');
                  if (commonUtils.isNotEmptyObject(packRowAdd)) {
                    packRow = { ...packRow, ...packRowAdd };

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

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

            if (commonUtils.isNotEmptyArr(copyTo.processData) && commonUtils.isNotEmptyObject(processAssignField)) {
              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;
                /* 根据合版表的源sOriginalId找到新sId */
                let sNewIds = '';
                let sNewNames = '';
                const sOldIds = processItem.sCombinePartsName;
                if (commonUtils.isNotEmptyObject(sOldIds)) {
                  const sOldArr = sOldIds.split(',');
                  for (const sId of sOldArr) {
                    const index = packData.findIndex(item => item.sOriginalId === sId);
                    if (index > -1) {
                      const tableDataRow = packData[index];
                      sNewIds += `${tableDataRow.sId},`;
                      sNewNames += `${tableDataRow.sCustomerName}-${tableDataRow.sProductName}-${tableDataRow.sCombinePartsName},`;
                    }
                  }
                  sNewIds = commonUtils.isNotEmptyObject(sNewIds) ? sNewIds.substr(0, sNewIds.length - 1) : '';
                  sNewNames = commonUtils.isNotEmptyObject(sNewNames) ? sNewNames.substr(0, sNewNames.length - 1) : '';
                }
                processRow.sCombinePartsName = sNewIds;
                processRow.sCombinePartsNameNew = sNewNames;
                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) && commonUtils.isNotEmptyObject(materialsAssignField)) {
              await copyTo.materialsData.filter(item => item.sControlId === controlItem.sId && item.sType !== '2').forEach(async (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;
                if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
                  const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                  const valueMaterialsStock = {
                    sProName: 'Sp_Inventory_MaterialsInventoryV56',
                    paramsMap: {
                      sMaterialsGuid: materialsRow.sMaterialsId,
                      sMaterialsStyle: materialsRow.sMaterialsStyle,
                      sWarehouseGuid: materialsRow.sWarehouseId,
                      sLocationalGuid: materialsRow.sLocationId,
                      sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                      sDefine_no: materialsRow.sDefineNo,
                      sDefine_no2: materialsRow.sDefineNo2,
                      iGetQty: 1,
                      iHasZero: 1,
                    },
                  };
                  const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
                  if (returnDataMaterialsStock.code === 1) {
                    materialsRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                  }
                }
                if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
                  const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
                  const valueMaterialsAvailableQty = {
                    sProName: 'Sp_Inventory_MaterialsInventoryV56',
                    paramsMap: {
                      sMaterialsGuid: materialsRow.sMaterialsId,
                      sMaterialsStyle: materialsRow.sMaterialsStyle,
                      sWarehouseGuid: materialsRow.sWarehouseId,
                      sLocationalGuid: materialsRow.sLocationId,
                      sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                      sDefine_no: materialsRow.sDefineNo,
                      sDefine_no2: materialsRow.sDefineNo2,
                      iGetQty: 2,
                      iHasZero: 1,
                    },
                  };
                  const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
                  if (returnDataMaterialsAvailableQty.code === 1) {
                    materialsRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
                  }
                }
                // 材料对应工序的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) && commonUtils.isNotEmptyObject(materialsAssignField)) {
          await copyTo.materialsData.filter(item => item.sType === '2').forEach(async (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;

            /* 根据从表源sOriginalId找到新sId */
            let sNewIds = '';
            let sNewNames = '';
            const sOldIds = materialsItem.sCombinePartsName;
            if (commonUtils.isNotEmptyObject(sOldIds)) {
              const sOldArr = sOldIds.split(',');
              for (const sId of sOldArr) {
                const index = slaveData.findIndex(item => item.sOriginalId === sId);
                if (index > -1) {
                  const tableDataRow = slaveData[index];
                  sNewIds += `${tableDataRow.sId},`;
                  sNewNames += `${tableDataRow.sProductName},`;
                }
              }
              sNewIds = commonUtils.isNotEmptyObject(sNewIds) ? sNewIds.substr(0, sNewIds.length - 1) : '';
              sNewNames = commonUtils.isNotEmptyObject(sNewNames) ? sNewNames.substr(0, sNewNames.length - 1) : '';
            }
            materialsRow.sCombinePartsName = sNewIds;
            materialsRow.sCombinePartsNameNew = sNewNames;

            if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
              const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
              const valueMaterialsStock = {
                sProName: 'Sp_Inventory_MaterialsInventoryV56',
                paramsMap: {
                  sMaterialsGuid: materialsRow.sMaterialsId,
                  sMaterialsStyle: materialsRow.sMaterialsStyle,
                  sWarehouseGuid: materialsRow.sWarehouseId,
                  sLocationalGuid: materialsRow.sLocationId,
                  sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                  sDefine_no: materialsRow.sDefineNo,
                  sDefine_no2: materialsRow.sDefineNo2,
                  iGetQty: 1,
                  iHasZero: 1,
                },
              };
              const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
              if (returnDataMaterialsStock.code === 1) {
                materialsRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
              }
            }
            if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
              const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
              const valueMaterialsAvailableQty = {
                sProName: 'Sp_Inventory_MaterialsInventoryV56',
                paramsMap: {
                  sMaterialsGuid: materialsRow.sMaterialsId,
                  sMaterialsStyle: materialsRow.sMaterialsStyle,
                  sWarehouseGuid: materialsRow.sWarehouseId,
                  sLocationalGuid: materialsRow.sLocationId,
                  sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
                  sDefine_no: materialsRow.sDefineNo,
                  sDefine_no2: materialsRow.sDefineNo2,
                  iGetQty: 2,
                  iHasZero: 1,
                },
              };
              const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
              if (returnDataMaterialsAvailableQty.code === 1) {
                materialsRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
              }
            }
            materialsData.push(materialsRow);
          });
        }

        if (commonUtils.isNotEmptyArr(copyTo.processData)&& commonUtils.isNotEmptyObject(processAssignField)) {
          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;
            /* 根据从表的源sOriginalId找到新sId */
            let sNewIds = '';
            let sNewNames = '';
            const sOldIds = processItem.sCombinePartsName;
            if (commonUtils.isNotEmptyObject(sOldIds)) {
              const sOldArr = sOldIds.split(',');
              if (sModelsType.includes('workOrderSet')) { /* 通用工单的合版部件名称来自于控制表，复制到时需换成新生成的控制表sId */
                const controlFilterData = controlData.filter(item => sOldArr.includes(item.sOriginalId));
                if (commonUtils.isNotEmptyArr(controlFilterData)) {
                  controlFilterData.forEach((item) => {
                    sNewIds += `${item.sId},`;
                    sNewNames += `${item.sPartsName},`;
                  });
                }
              } else {
                for (const sId of sOldArr) {
                  const index = slaveData.findIndex(item => item.sOriginalId === sId);
                  if (index > -1) {
                    const tableDataRow = slaveData[index];
                    sNewIds += `${tableDataRow.sId},`;
                    sNewNames += `${tableDataRow.sCustomerName}-${tableDataRow.sProductName},`;
                  }
                }
              }
              sNewIds = commonUtils.isNotEmptyObject(sNewIds) ? sNewIds.substr(0, sNewIds.length - 1) : '';
              sNewNames = commonUtils.isNotEmptyObject(sNewNames) ? sNewNames.substr(0, sNewNames.length - 1) : '';
            }
            processRow.sCombinePartsName = sNewIds;
            processRow.sCombinePartsNameNew = sNewNames;
            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) => {
                  if (dProductQty) {
                    dProductQty += commonUtils.isNull(item.dProductQty, 0);
                  } else {
                    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;
                    tableDataRow.sAllId = tableDataRow.sId;/* 第一级sAllId等于sId */
                    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开始 */
      tableDataRow.sCombinedMemo = '合版信息';
      tableDataRow.sAllId = tableDataRow.sId;
      let dProductQty = 0;
      slaveData.forEach((item) => {
        if (bProductQtySelf) {
          dProductQty += commonUtils.isNull(item.dProductQty, 0);
        } else {
          dProductQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
        }
      });
      tableDataRow.dPartsQty = dProductQty;
      controlData.push(tableDataRow);
    }
    /* 新增时,增加一条合版信息 */
    if (packData.length === 0) {
      slaveData.forEach((item, index) => {
        const tableDataRow = this.handlePackDataAdd(item, index, controlData[0].sId, 'add');
        if (commonUtils.isNotEmptyObject(tableDataRow)) {
          // tableDataRow.dCombineQty = 1;
          packData.push(tableDataRow);
        }
      });
    }
    const treeState = this.handleGetControlTreeData(controlData, true); /* 加载树形结构数据 */
    const stateNew = {
      ...state,
      ...treeState,
      controlData,
      controlSelectedRowKeys: [],
      packData,
      packSelectedRowKeys: [],
      materialsData,
      materialsSelectedRowKeys: [],
      processData,
      processSelectedRowKeys: [],
      colorData,
      colorSelectedRowKeys: [],
      checkProcessClassifyData: [],
    };
    if (isWait) {
      return stateNew;
    } else {
      this.props.onSaveState(stateNew);
    }
  };

  handleSelect = async (name, selectConfig, selectData) => {
    const {
      [`${name}Data`]: tableData, [`${name}Config`]: tableConfig, masterConfig, controlSelectedRowKeys, sModelsId, token,
      slaveConfig, controlConfig, materialsConfig, processConfig, colorConfig, packConfig, slaveData, controlData: controlDataOld, materialsData: materialsDataOld, processData: processDataOld, colorData: colorDataOld,
      controlDelData: controlDelDataOld, materialsDelData: materialsDelDataOld, processDelData: processDelDataOld, colorDelData: colorDelDataOld,
    } = this.props;
    let { masterData, slaveSelectedRowKeys } = this.props;
    if (name === 'productProcessInfo') {
      if (commonUtils.isNotEmptyArr(selectData)) {
        let controlData = [];
        let materialsData = [];
        let processData = [];
        let colorData = [];
        let packData = [];
        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;
        config.packConfig = packConfig;
        let iSlaveIndex = -1;
        if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
          slaveSelectedRowKeys = commonUtils.isNotEmptyArr(slaveData) ? slaveData[0].sId : [];
        }
        if (!commonUtils.isEmpty(slaveSelectedRowKeys)) {
          iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys.toString());
        }
        let condition = { sCardId: selectData[0].sId };
        let dataUrl = `${commonConfig.server_host}salesorder/getProcessCardDataByCustomIdProductId/?sModelsId=${sModelsId}`;

        /* 复制从工单功能 */
        const { productProcessInfoCopyFromKey } = this.props;
        let bCopyFromWorkOrder = false;
        if (commonUtils.isNotEmptyObject(productProcessInfoCopyFromKey) && productProcessInfoCopyFromKey.includes('BtnCopyFrom.sworkorder')) {
          // bCopyFromWorkOrder = true;
          condition = { sWorkOrderId: selectData[0].sId, slaveData };
          // dataUrl = `${commonConfig.server_host}salesorder/getCopyFromWorkOrder/?sModelsId=${sModelsId}`;
          dataUrl = `${commonConfig.server_host}salesorder/getWorkOrderToWorkOrder/?sModelsId=${sModelsId}`;
        }

        const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;

        /* 复制从工单逻辑 源数据集整体赋值 */
        if (bCopyFromWorkOrder && dataReturn.code === 1) {
          const returnData = dataReturn.dataset.rows[0];
          let treeState = [];
          if (commonUtils.isNotEmptyArr(returnData)) {
            if (commonUtils.isNotEmptyArr(returnData.controlData)) {
              controlData = returnData.controlData;
              treeState = this.handleGetControlTreeData(controlData, true);
            }
            if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
              materialsData = returnData.materialsData;
            }
            if (commonUtils.isNotEmptyArr(returnData.processData)) {
              processData = returnData.processData;
            }
            if (commonUtils.isNotEmptyArr(returnData.packData)) {
              packData = returnData.packData;
            }
            if (commonUtils.isNotEmptyArr(returnData.colorData)) {
              colorData = returnData.controlData;
            }
            this.props.onSaveState({
              [`${name}ChooseVisible`]: false,
              slaveData,
              processData,
              materialsData,
              controlData,
              colorData,
              packData,
              masterData,
              ...treeState,
              tableSelectedNewRowKeys: commonUtils.isEmptyArr(controlData) ? [] : [controlData[0].sId],
              controlSelectedRowKeys: commonUtils.isEmptyArr(controlData) ? [] : [controlData[0].sId],
              materialsSelectedRowKeys: [],
              processSelectedRowKeys: [],
              ...addState,
            });
          }
        } else if (!bCopyFromWorkOrder && 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 copyToPackConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.pack`.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 packAssignField = commonUtils.isNotEmptyArr(copyToPackConfig) ? copyToPackConfig[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;
            /* 主表配置bProductQtyAdd 则代表产品数量不叠加备货数 赠送数 */
            let bProductQtySelf = false;
            if (commonUtils.isNotEmptyObject(this.props.masterConfig) && commonUtils.isNotEmptyArr(this.props.masterConfig.gdsconfigformslave)) {
              const iIndex = this.props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bProductQtySelf');
              if (iIndex > -1) {
                bProductQtySelf = true;
              }
            }
            if (commonUtils.isNotEmptyArr(returnData.slaveData)) {
              returnData.slaveData.forEach((slaveItem, iIndex) => {
                /* 从工艺卡数据集 找到从表选中行的产品ID,客户ID */
                if(slaveItem.sProductId  === slaveData[iSlaveIndex].sProductId && slaveItem.sCustomerId  === slaveData[iSlaveIndex].sCustomerId ){
                  masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, slaveItem, newCopyTo) }; // 取赋值字段
                  slaveData[iSlaveIndex].sOriginalId = slaveItem.sSlaveId; /* 原始sId */
                  if (bProductQtySelf) {
                    dProductQty += commonUtils.isNull(slaveItem.dProductQty, 0);
                  } else {
                    dProductQty += commonUtils.isNull(slaveItem.dProductQty, 0) + commonUtils.isNull(slaveItem.dGiveQty, 0) + commonUtils.isNull(slaveItem.dStockupQty, 0);
                  }
                }else{ /* 其他数据 新增 */
                  newCopyTo.slave = slaveItem;
                  let slaveRow ={};
                  slaveRow = { ...slaveRow, ...commonFunc.getAssignFieldValue(slaveDetailAssignField,slaveItem, newCopyTo) }; // 取赋值字段
                  slaveRow.handleType = 'add';
                  slaveRow.sId = commonUtils.createSid();
                  slaveRow.sParentId = masterData.sId;
                  slaveRow.sOriginalId = slaveItem.sSlaveId;
                  slaveData.push(slaveRow);
                }
              });
            }
            const treeCopyNodes = new Map();
            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;
              const sAllOldId = controlItem.sAllId;
              let arr = [];
              if (commonUtils.isNotEmptyObject(sAllOldId)) {
                arr = sAllOldId.split(',');
              }
              const newId = controlRow.sId;
              let sOldParentId = '';
              let sNewParentAllId = '';
              if (arr.length < 2) { /* 根节点复制 */
                controlRow.sAllId = newId;
                sOldParentId = newId;
                sNewParentAllId = newId;
              } else {
                sOldParentId = arr[arr.length - 2];
                if (treeCopyNodes.has(sOldParentId)) {
                  sNewParentAllId = treeCopyNodes.get(sOldParentId);
                } else {
                  const obj = arr[arr.length - 1];
                  sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
                }
                const sNewArr = sNewParentAllId.split(',');
                controlRow.sControlParentId = sNewArr[sNewArr.length - 1];
                sNewParentAllId = `${sNewParentAllId},${newId}`;
                controlRow.sAllId = sNewParentAllId;
              }
              treeCopyNodes.set(controlItem.sId, sNewParentAllId);
              controlData.push(controlRow);

              /* 增加合版表 */
              if (commonUtils.isNotEmptyArr(returnData.packData)) {
                returnData.packData.filter(item => item.sControlId === controlItem.sId).forEach(async (packItem) => {
                  newCopyTo.pack = packItem;
                  let packRow = commonFunc.getDefaultData(config.packConfig, newCopyTo); // 取默认值
                  packRow = { ...packRow, ...commonFunc.getAssignFieldValue(packAssignField, packItem, newCopyTo) }; // 取赋值字段
                  packRow.sOriginalId = packItem.sId;/* 翻单前的sId */
                  /* sSlaveId赋值 */
                  const iSlaveIndex = slaveData.findIndex(item => item.sOriginalId === packItem.sSlaveId);
                  if (iSlaveIndex > -1) {
                    const slaveDataRow = slaveData[iSlaveIndex];
                    const packRowAdd = this.handlePackDataAdd(slaveDataRow, 0, controlRow.sId, 'add');
                    if (commonUtils.isNotEmptyObject(packRowAdd)) {
                      packRow = { ...packRow, ...packRowAdd };
                      /* 将控制表中的合版备注sId为新的sId */
                      let JsonData = [];
                      const jsonStr = controlRow.sCombinedMemo;
                      if (commonUtils.isNotEmptyObject(jsonStr) && commonUtils.isJSON(jsonStr)) {
                        JsonData = JSON.parse(jsonStr);
                        if (commonUtils.isNotEmptyArr(JsonData)) {
                          let sCombinedMemoNew = '';
                          JsonData.forEach((item, index) => {
                            if (item.sId === packItem.sId) {
                              JsonData[index].sId = packRow.sId;
                            }
                          });
                          sCombinedMemoNew = JSON.stringify(JsonData);
                          controlRow.sCombinedMemo = sCombinedMemoNew;
                          const icontrolIndex = controlData.findIndex(item => item.sId === controlRow.sId);
                          if (icontrolIndex) {
                            controlData[icontrolIndex] = { ...controlData[icontrolIndex], sCombinedMemo: sCombinedMemoNew };
                          }
                        }
                      }
                      packData.push(packRow);
                    }
                  }
                });
              }

              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);
              });
            }
          }
          const treeState = this.handleGetControlTreeData(controlData, true);
          this.props.onSaveState({
            [`${name}ChooseVisible`]: false,
            slaveData,
            processData,
            materialsData,
            controlData,
            colorData,
            packData,
            masterData,
            ...treeState,
            tableSelectedNewRowKeys: commonUtils.isEmptyArr(controlData) ? [] : [controlData[0].sId],
            controlSelectedRowKeys: commonUtils.isEmptyArr(controlData) ? [] : [controlData[0].sId],
            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 = tableDataRow.sType === '3' ?
                    tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId) :
                    tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlData[iControlIndex].sId);
                  if (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;

            const processLen = tableData.filter(item => item.sType !== '3').length + 1; /* 工序序号 */
            tableDataRow.iOrder = processLen;
            tableData.push(tableDataRow);
          } else if (tableDataRow.sType === '3') {
            const processLen = tableData.filter(item => item.sType === '3').length + 1; /* 工序序号 */
            tableDataRow.iOrder = processLen;
            tableData.push(tableDataRow);
          }
          // const processLen = commonBusiness.getTableTypes('process', this.props).data.filter(item => this.state.currentTab.process.split('-').indexOf(item.sType) !== -1).length;
          // tableDataRow.iOrder = processLen;
        }
      }
      const tableDataNew = this.sortData(controlData, tableData);
      this.props.onSaveState({
        [`${name}Data`]: tableDataNew, [`${name}ChooseVisible`]: false, materialsConfig, materialsSelectedRowKeys: [],
      });
    }
  };

  handleSelectProductMaterial = async (name, selectConfig, selectData, slaveFinalSelectedData) => {
    // 选择成品材料，将sType改为2
    if (name === 'productMaterials') {
      selectData = selectData.map(val => ({ ...val, sType: '2' }));
      name = 'materials';
    }
    const {
      [`${name}Data`]: tableData, [`${name}Config`]: tableConfig, controlSelectedRowKeys, materialsConfig,masterConfig,
    } = this.props;
    const { masterData } = this.props;
    const { controlData } = this.props;
    const iControlIndex = commonUtils.isNotEmptyArr(controlSelectedRowKeys) ? controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]) : -1;
    /* 取选择工序从表配置 */
    const slavesControlName = commonUtils.isNotEmptyObject(selectConfig.sControlName) ? `${selectConfig.sControlName}.slave` : '';
    let slaveSelectConfig = {};
    let slaveIndex = -1;
    if (commonUtils.isNotEmptyObject(masterConfig)) {
      slaveIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === slavesControlName);
      if (slaveIndex > -1) {
        slaveSelectConfig = masterConfig.gdsconfigformslave[slaveIndex];
      }
    }
    if (commonUtils.isNotEmptyArr(slaveFinalSelectedData)) {
      for (const slaveObj of slaveFinalSelectedData) {
        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) }; // 取赋值字段
            if (commonUtils.isNotEmptyObject(slaveSelectConfig)) {
              tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(slaveSelectConfig.sAssignField, slaveObj, newCopyTo) }; // 取从表赋值字段
            }
            tableDataRow.handleType = 'add';
            tableDataRow.sId = commonUtils.createSid();

            tableDataRow.sParentId = masterData.sId;
            tableDataRow.sCombinePartsName = slaveObj.sId; /* 成品材料sCombinePartsName 为从表id */
            tableDataRow.sCombinePartsNameNew = slaveObj.sProductName;
            // tableDataRow.sSlaveProductId = slaveObj.sId;

            if (iControlIndex > -1 && tableDataRow.sType !== '2') {
              tableDataRow.sControlId = controlData[iControlIndex].sId;
              tableDataRow.sPartsName = controlData[iControlIndex].sPartsName;
              tableData.push(tableDataRow);
            } else if (tableDataRow.sType === '2') {
              tableData.push(tableDataRow);
            }
          }
        }
      }
    } else {
      message.error('请选择产品！');
      return;
    }
    const tableDataNew = this.sortData(controlData, tableData);
    this.props.onSaveState({
      [`${name}Data`]: tableDataNew, [`${name}ChooseVisible`]: false, materialsConfig, materialsSelectedRowKeys: [],
    });
  }

  /* 选择成品工序点确定 */
  /* 工单从表选中selectedRowKeys */
  handleSelectFinalProcess = async (name, selectConfig, selectData, slaveFinalSelectedData) => {
    const targetname = 'process';
    const {
      [`${targetname}Data`]: tableData, [`${targetname}Config`]: tableConfig, controlSelectedRowKeys, sModelsId, token,
      materialsConfig, processConfig,masterConfig,
    } = this.props;
    const { masterData } = this.props;
    if (name === 'chooseProductProcess') {
      const { controlData } = this.props;
      const iControlIndex = commonUtils.isNotEmptyArr(controlSelectedRowKeys) ? controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]) : -1;
      /* 取选择工序从表配置 */
      const slavesControlName = commonUtils.isNotEmptyObject(selectConfig.sControlName) ? `${selectConfig.sControlName}.slave` : '';
      let slaveSelectConfig = {};
      let slaveIndex = -1;
      if (commonUtils.isNotEmptyObject(masterConfig)) {
        slaveIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === slavesControlName);
        if (slaveIndex > -1) {
          slaveSelectConfig = masterConfig.gdsconfigformslave[slaveIndex];
        }
      }
      /* 通过slaveFinalSelectedRowKeys找到slaveData数据 */
      if (commonUtils.isNotEmptyArr(slaveFinalSelectedData)) {
        for (const slaveObj of slaveFinalSelectedData) {
          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) }; // 取赋值字段
              if (commonUtils.isNotEmptyObject(slaveSelectConfig)) {
                tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(slaveSelectConfig.sAssignField, slaveObj, newCopyTo) }; // 取从表赋值字段
              }
              tableDataRow.handleType = 'add';
              tableDataRow.sId = commonUtils.createSid();
              tableDataRow.sParentId = masterData.sId;

              tableDataRow.sCombinePartsName = slaveObj.sId; /* 成品工序sCombinePartsName 为从表id */
              tableDataRow.sCombinePartsNameNew = slaveObj.sProductName; /* 成品工序sCombinePartsName 为从表产品名称 */
              // tableDataRow.sSlaveProductId = slaveObj.sId;

              tableDataRow.sType = '3';
              if (targetname === 'process') {
                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 = tableDataRow.sType === '3' ?
                        tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId) :
                        tableData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === controlData[iControlIndex].sId);
                      if (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);
                            }
                          });
                        }
                      }
                    }
                  }));
                }
              }
              // const processLen = commonBusiness.getTableTypes('process', this.props).data.filter(item => this.state.currentTab.process.split('-').indexOf(item.sType) !== -1).length;
              // tableDataRow.iOrder = processLen;
              if (iControlIndex > -1 && tableDataRow.sType !== '3') {
                tableDataRow.sControlId = controlData[iControlIndex].sId;
                tableDataRow.sPartsName = controlData[iControlIndex].sPartsName;
                const processLen = tableData.filter(item => item.sType !== '3').length + 1; /* 工序序号自增 */
                tableDataRow.iOrder = processLen;
                tableData.push(tableDataRow);
              } else if (tableDataRow.sType === '3') {
                const processLen = tableData.filter(item => item.sType === '3').length + 1; /* 工序序号自增 */
                tableDataRow.iOrder = processLen;
                tableData.push(tableDataRow);
              }
            }
          }
        }
      } else {
        message.error('请选择产品！');
        return;
      }
      const tableDataNew = this.sortData(controlData, tableData);
      this.props.onSaveState({
        [`${targetname}Data`]: tableDataNew, [`${name}ChooseVisible`]: false, materialsConfig, materialsSelectedRowKeys: [],
      });
    }
  }
  handleViewChoose= (name, sName, record) => {
    const { sId } = record; /* 控制表主键 */
    const { enabled, slaveData } = this.props;
    let { packData } = this.props;
    if (name === 'control') {
      const packSelectedRowKeys = [];

      /* 合并从表相同客户、产品数据 */
      const slaveDataMerge = [];
      slaveData.forEach((item) => {
        const iIndex = slaveDataMerge.findIndex(child => child.sCustomerId === item.sCustomerId && child.sProductId === item.sProductId);
        if (iIndex === -1) {
          const itemNew = JSON.parse(JSON.stringify(item));
          slaveDataMerge.push(itemNew);
        } else if (iIndex > -1) {
          const dProductQtyNew = commonUtils.isNull(slaveDataMerge[iIndex].dProductQty, 0) + commonUtils.isNull(item.dProductQty, 0); /* 生产数量叠加 */
          const dGiveQtyNew = commonUtils.isNull(slaveDataMerge[iIndex].dGiveQty, 0) + commonUtils.isNull(item.dGiveQty, 0); /* 赠送数量叠加 */
          const dStockupQtyNew = commonUtils.isNull(slaveDataMerge[iIndex].dStockupQty, 0) + commonUtils.isNull(item.dStockupQty, 0); /* 备货数量叠加 */
          slaveDataMerge[iIndex].dProductQty = dProductQtyNew;
          slaveDataMerge[iIndex].dGiveQty = dGiveQtyNew;
          slaveDataMerge[iIndex].dStockupQty = dStockupQtyNew;
        }
      });

      /* 合并合版表相同客户、产品数据 */
      const packDataMerge = [];
      packData.forEach((item) => {
        const iIndex = packDataMerge.findIndex(child => commonUtils.isNotEmptyObject(item.sCombinePartsName) && child.sCombinePartsName === item.sCombinePartsName && commonUtils.isNotEmptyObject(item.sProductId) && child.sProductId === item.sProductId);
        if (iIndex === -1) {
          const itemNew = JSON.parse(JSON.stringify(item));
          packDataMerge.push(itemNew);
        } else if (iIndex > -1) {
          const dProductQtyNew = commonUtils.isNull(packDataMerge[iIndex].dProductQty, 0) + commonUtils.isNull(item.dProductQty, 0); /* 生产数量叠加 */
          const dGiveQtyNew = commonUtils.isNull(packDataMerge[iIndex].dGiveQty, 0) + commonUtils.isNull(item.dGiveQty, 0); /* 赠送数量叠加 */
          const dStockupQtyNew = commonUtils.isNull(packDataMerge[iIndex].dStockupQty, 0) + commonUtils.isNull(item.dStockupQty, 0); /* 备货数量叠加 */
          packDataMerge[iIndex].dProductQty = dProductQtyNew;
          packDataMerge[iIndex].dGiveQty = dGiveQtyNew;
          packDataMerge[iIndex].dStockupQty = dStockupQtyNew;
        }
      });
      if (commonUtils.isNotEmptyArr(packDataMerge)) {
        packData = packDataMerge;
      }

      /* 填充合版信息数值 如果packData为空，则填充从表所有数据 */
      if (commonUtils.isNotEmptyArr(slaveDataMerge)) {
        slaveDataMerge.forEach((item, index) => {
          const packDataFilter = packData.filter(itemNew => itemNew.sSlaveId === item.sId && itemNew.sControlId === sId);
          if (commonUtils.isNotEmptyArr(packDataFilter)) {
            packDataFilter.forEach((itemPack) => {
              const iIndex = packData.findIndex(child => child.sId === itemPack.sId);
              if (iIndex > -1) {
                const packRowAdd = this.handlePackDataAdd(item);
                if (commonUtils.isNotEmptyObject(packRowAdd)) {
                  packData[iIndex] = { ...packData[iIndex], ...packRowAdd };
                  if (itemPack.dCombineQty !== undefined && itemPack.dCombineQty !== null && itemPack.dCombineQty !== 0) {
                    packSelectedRowKeys.push(itemPack.sId);
                  }
                }
              }
            });
          } else {
            const tableDataRow = this.handlePackDataAdd(item, index, sId, 'add');
            if (commonUtils.isNotEmptyObject(tableDataRow)) {
              packData.push(tableDataRow);
            }
          }
        });
      }
      this.props.onSaveState({
        productCombinationVisible: true,
        sCombinationsControlId: sId, /* 合版产品控制表sId */
        enabled,
        packSelectedRowKeys,
        packData,
      });
    } else if (name === 'process' && (sName === 'sCombinePartsNameNew'|| sName === 'sCombineProductNameNew')) {
      const { [`${name}Data`]: tableData } = this.props;
      const iIndex = tableData.findIndex(item => item.sId === sId);
      let packDataFilter = [];
      const combinePartsSelectedRowKeys = [];
      if (iIndex > -1) {
        if (commonUtils.isNotEmptyArr(slaveData)) {
          if (tableData[iIndex].sType === '3') { /* 成品工序跟着从表走 */
            packDataFilter = JSON.parse(JSON.stringify(slaveData));
            packDataFilter.forEach((itemPack, index) => {
              const packRowAdd = {};
              packRowAdd.sSlaveOldId = packRowAdd.sSlaveId;
              packRowAdd.sSlaveId = commonUtils.createSid();
              packDataFilter[index] = { ...packDataFilter[index], ...packRowAdd };
            });
          } else { /* 成品工序跟着合版表走 */
            packDataFilter = packData.filter(itemNew => itemNew.sControlId === tableData[iIndex].sControlId && itemNew.dCombineQty > 0);
            if (commonUtils.isNotEmptyArr(packDataFilter)) {
              packDataFilter.forEach((itemPack, index) => {
                let slaveDataRow = {};
                let packRowAdd = {};
                const iIndex = slaveData.findIndex(itemSlave => itemSlave.sId === itemPack.sSlaveId);
                if (iIndex > -1) {
                  slaveDataRow = slaveData[iIndex];
                }
                if (commonUtils.isNotEmptyObject(slaveDataRow)) {
                  packRowAdd = this.handlePackDataAdd(slaveDataRow);
                }
                packRowAdd.sSlaveOldId = packRowAdd.sSlaveId;
                packRowAdd.sSlaveId = commonUtils.createSid();
                packDataFilter[index] = { ...packDataFilter[index], ...packRowAdd };
              });
            }
          }
        }
        const sCombinePartsIds = tableData[iIndex].sCombinePartsName;
        if (commonUtils.isNotEmptyObject(sCombinePartsIds) && commonUtils.isNotEmptyArr(packDataFilter)) {
          const DataIds = sCombinePartsIds.split(',');
          for (const sId of DataIds) {
            const index = packDataFilter.findIndex(item => item.sId === sId);
            if (index > -1) {
              const rowKey = packDataFilter[index].sSlaveId;
              combinePartsSelectedRowKeys.push(rowKey);
            }
          }
        }
      }
      this.props.onSaveState({
        combinePartsChooseVisible: true,
        combinePartsData: packDataFilter,
        processSelectedRowId: sId, /* 工序表选中行sId */
        combinePartsSelectedRowKeys,
      });
    } else if (name === 'materials' && (sName === 'sCombinePartsNameNew'|| sName === 'sCombineProductNameNew')) {
      const { [`${name}Data`]: tableData } = this.props;
      const iIndex = tableData.findIndex(item => item.sId === sId);
      let packDataFilter = [];
      const combinePartsSelectedRowKeys = [];
      if (iIndex > -1) {
        if (commonUtils.isNotEmptyArr(slaveData)) {
          if (tableData[iIndex].sType === '2') { /* 成品材料跟着从表走 */
            packDataFilter = JSON.parse(JSON.stringify(slaveData));
            packDataFilter.forEach((itemPack, index) => {
              const packRowAdd = {};
              packRowAdd.sSlaveOldId = packRowAdd.sSlaveId;
              packRowAdd.sSlaveId = commonUtils.createSid();
              packDataFilter[index] = { ...packDataFilter[index], ...packRowAdd };
            });
          }
        }
        const sCombinePartsIds = tableData[iIndex].sCombinePartsName;
        if (commonUtils.isNotEmptyObject(sCombinePartsIds) && commonUtils.isNotEmptyArr(packDataFilter)) {
          const DataIds = sCombinePartsIds.split(',');
          for (const sId of DataIds) {
            const index = packDataFilter.findIndex(item => item.sId === sId);
            if (index > -1) {
              const rowKey = packDataFilter[index].sSlaveId;
              combinePartsSelectedRowKeys.push(rowKey);
            }
          }
        }
      }
      this.props.onSaveState({
        combinePartsChooseVisible: true,
        combinePartsData: packDataFilter,
        materialsSelectedRowId: sId, /* 工序表选中行sId */
        openTable: 'materials',
        combinePartsSelectedRowKeys,
      });
    } else if (name === 'process' && sName === 'sColorSerialMemo') {
      this.props.onViewChoose(name, sName, record);
    }
  }
  handlePackDataAdd= (item, index, sControlId, handleType) => {
    const tableDataRow = {};
    if (handleType === 'add') {
      tableDataRow.sId = commonUtils.createSid();
      tableDataRow.handleType = 'add';
      tableDataRow.sSlaveId = item.sId;
      tableDataRow.iOrder = item.iOrder;
    }
    tableDataRow.sParentId = item.sParentId;
    if (commonUtils.isNotEmptyObject(sControlId)) {
      tableDataRow.sControlId = sControlId;
    }
    // if (commonUtils.isNotEmptyObject(index)) {
    //   tableDataRow.iOrder = index + 1;
    // }
    tableDataRow.sProductId = item.sProductId; /* 产品id */
    tableDataRow.sCustomerId = item.sCustomerId; /* 客户id */
    tableDataRow.sCustomerName = item.sCustomerName; /* 客户名称 */
    tableDataRow.sProductName = item.sProductName; /* 产品名称 */
    tableDataRow.sProductNo = item.sProductNo; /* 产品编号 */
    /* 主表配置bProductQtyAdd 则代表产品数量不叠加备货数 赠送数 */
    let bProductQtySelf = false;
    if (commonUtils.isNotEmptyObject(this.props.masterConfig) && commonUtils.isNotEmptyArr(this.props.masterConfig.gdsconfigformslave)) {
      const iIndex = this.props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bProductQtySelf');
      if (iIndex > -1) {
        bProductQtySelf = true;
      }
    }
    if (bProductQtySelf) {
      tableDataRow.dProductQty = commonUtils.isNull(item.dProductQty, 0);
    } else {
      tableDataRow.dProductQty = commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0); /* 生产数量 */
    }
    tableDataRow.sProductUnit = item.sProductUnit; /* 单位 */
    tableDataRow.sProductStyle = item.sProductStyle; /* 产品规格 */
    return tableDataRow;
  }
  sortData = (tableData, processData) => {
    processData.sort((g1, g2) => {
      const iIndex1 = tableData.findIndex(item => item.sId === g1.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g1.sControlId);
      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 + sOrder1) - parseFloat(sPartOrder2 + sOrder2);
      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;
    // const processDataFiltered = processData.filter(item => this.state.currentTab.process.split('-').indexOf(item.sType) !== -1);
    const processDataFiltered = processData;
    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 = processDataFiltered.length;
      const newLen = processNew.length;
      let num = 0.01;/* 循环增加体 */
      let targetiOrder = -1;
      // 上下排序修改为两个item的order对调
      if (type === 1) { /*  上移 */
        const iIndex = processDataFiltered.findIndex(item => item.sId === processNew[0].sId);/* 选中第一个节点的下标 */
        if (iIndex === 0) {
          message.warn(commonFunc.showMessage(app.commonConst, 'NoUp'));/* 无需上移 */
          return;
        } else {
          targetiOrder = processDataFiltered[iIndex - 1].iOrder - 1; /* 目标排序号 */
        }
      } else if (type === 2) { /*  下移 */
        const iIndex = processDataFiltered.findIndex(item => item.sId === processNew[newLen - 1].sId);/* 选中最后一个节点的下标 */
        if (iIndex === len - 1) {
          message.warn(commonFunc.showMessage(app.commonConst, 'NoDown')); /* 无需下移 */
          return;
        } else {
          targetiOrder = processDataFiltered[iIndex + 1].iOrder;
        }
      } else if (type === 0) { /*  置顶 */
        const iIndex = processDataFiltered.findIndex(item => item.sId === processNew[0].sId);/* 选中第一个节点的下标 */
        if (iIndex === 0) {
          message.warn(commonFunc.showMessage(app.commonConst, 'NoTop')); /* 无需置顶 */
          return;
        } else {
          targetiOrder = processDataFiltered[0].iOrder - 1;
        }
      } else if (type === 3) { /*  置底 */
        const iIndex = processDataFiltered.findIndex(item => item.sId === processNew[newLen - 1].sId);/* 选中最后一个节点的下标 */
        if (iIndex === len - 1) {
          message.warn(commonFunc.showMessage(app.commonConst, 'NoBottom')); /* 无需置底 */
          return;
        } else {
          targetiOrder = 999;
        }
      }
      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, masterConfig, controlConfig, masterData, [`${name}Data`]: tableData, controlData: controlDataOld, packData,
      } = 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 = {};
      let bProductQtySelf = false;
      if (commonUtils.isNotEmptyObject(this.props.masterConfig) && commonUtils.isNotEmptyArr(this.props.masterConfig.gdsconfigformslave)) {
        const iProductQtyIndex = this.props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bProductQtySelf');
        if (iProductQtyIndex > -1) {
          bProductQtySelf = true; /* 生产数量无需叠加 */
        }
      }
      if (sFieldName === 'dProductQty' || sFieldName === 'dGiveQty' || sFieldName === 'dStockupQty') {
        let dPartsQty = 0;
        tableData.forEach((item) => {
          if (bProductQtySelf) {
            dPartsQty += commonUtils.isNull(item.dProductQty, 0);
          } else {
            dPartsQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
          }
        });
        /* 找到所有一级部件 */
        const controlRootData = commonUtils.isNotEmptyArr(controlDataOld) ? controlDataOld.filter(item => commonUtils.isEmpty(item.sControlParentId)) : [];
        if (commonUtils.isNotEmptyArr(controlRootData)) {
          controlRootData.forEach((item) => {
            let itemNew = { ...item };
            /*  父级的dPartsQty为dPartsQty */
            itemNew.dPartsQty = dPartsQty;
            itemNew = this.singlePQtyChange(itemNew);
            /* 找到子部件 */
            const controlChildData = controlDataOld.filter(itemOld => commonUtils.isNotEmptyObject(itemOld.sAllId) && itemOld.sAllId.indexOf(item.sId) > -1 && itemOld.sId !== item.sId);
            if (commonUtils.isNotEmptyArr(controlChildData)) {
              const { dMachineQty } = itemNew;
              controlChildData.forEach((child) => {
                let tableDataRow = { ...child };
                const iIndex = controlDataOld.findIndex(item => item.sId === child.sId);
                if (iIndex > -1) {
                  /* 子部件部件数量为父部件上机数量  */
                  tableDataRow.dPartsQty = dMachineQty;
                  tableDataRow = this.singlePQtyChange(tableDataRow);
                  controlDataOld[iIndex] = tableDataRow;
                }
              });
            }
            const addStata = {};
            addStata.dPartsQty = dPartsQty;
            const iRootIndex = controlDataOld.findIndex(itemControl => itemControl.sId === item.sId);
            controlDataOld[iRootIndex] = { ...controlDataOld[iRootIndex], ...itemNew };
          });
        }
        addState.controlData = controlDataOld;
      } else 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) => {
                if (bProductQtySelf) {
                  dProductQty += commonUtils.isNull(item.dProductQty, 0);
                } else {
                  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;
              }
            }
          }
        }
      }
      /* 从表改变时合版表数据对应改变,从新改变packData数据 */
      packData.forEach((item, index) => {
        if (item.sSlaveId === tableDataRow.sId) {
          const addState = {};
          addState.sProductId = tableDataRow.sProductId; /* 产品id */
          addState.sCustomerId = tableDataRow.sCustomerId; /* 客户id */
          addState.sCustomerName = tableDataRow.sCustomerName; /* 客户名称 */
          addState.sProductName = tableDataRow.sProductName; /* 产品名称 */
          addState.sProductNo = tableDataRow.sProductNo; /* 产品编号 */
          addState.dProductQty = tableDataRow.dProductQty; /* 生产数量 */
          addState.sProductUnit = tableDataRow.sProductUnit; /* 单位 */
          addState.sProductStyle = tableDataRow.sProductStyle; /* 产品规格 */
          packData[index] = { ...packData[index], ...addState };
        }
      });
      addState.packData = packData;
      this.props.onSaveState({ [`${name}Data`]: tableData, ...addState, calculated: false });
    } else if (name === 'control') {
      const {
        [`${name}Data`]: tableData, materialsData: materialsDataOld, processData: processDataOld, sModelsType,
      } = this.props;
      let tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
      if (tableDataRow === undefined) return;
      if (sFieldName === 'dSinglePQty' || sFieldName === 'dPartsQty' || sFieldName === 'dSumPQty' || sFieldName === 'iPrintModePo' || sFieldName === 'iPrintMode' || sFieldName === 'iPrintModePo' || sFieldName === 'iPositiveColor' ||
        sFieldName === 'iPositiveSpecialColor' || sFieldName === 'iOppositeColor' || sFieldName === 'iOppositeSpecialColor') {
        if (sFieldName === 'iPrintModePo') {
          if (tableDataRow.iPrintModePo === 0) {
            tableDataRow.iPrintMode = 3;
            if (tableDataRow.iPositiveColor === 0) {
              tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
              tableDataRow.iOppositeColor = 0;
              tableDataRow.iOppositeSpecialColor = 0;
            } else {
              tableDataRow.iOppositeColor = 0;
              tableDataRow.iOppositeSpecialColor = 0;
            }
          } else if (tableDataRow.iPrintModePo === 1) {
            tableDataRow.iPrintMode = 3;
            if (tableDataRow.iPositiveColor === 0) {
              tableDataRow.iPositiveColor = 0;
              tableDataRow.iPositiveSpecialColor = 0;
              tableDataRow.iOppositeColor = tableDataRow.iOppositeColor === 0 ? 4 : tableDataRow.iOppositeColor;
            } else {
              tableDataRow.iPositiveColor = 0;
              tableDataRow.iPositiveSpecialColor = 0;
            }
          } else {
            tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
            tableDataRow.iOppositeColor = tableDataRow.iOppositeColor === 0 ? tableDataRow.iPositiveColor : tableDataRow.iOppositeColor;
          }
        } else if (sFieldName === 'iPrintMode') {
          if (tableDataRow.iPrintMode === 0 || tableDataRow.iPrintMode === 1) {
            tableDataRow.iPositiveColor = commonUtils.isEmpty(tableDataRow.iPositiveColor) || tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
            tableDataRow.iOppositeColor = tableDataRow.iPositiveColor;
            tableDataRow.iOppositeSpecialColor = tableDataRow.iPositiveSpecialColor;
          } else if (tableDataRow.iPrintMode === 2) {
            tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
            tableDataRow.iOppositeColor = tableDataRow.iOppositeColor === 0 ? tableDataRow.iPositiveColor : tableDataRow.iOppositeColor;
          } else if (tableDataRow.iPrintMode === 3) {
            tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
            tableDataRow.iOppositeColor = 0;
            tableDataRow.iOppositeSpecialColor = 0;
          } else if (tableDataRow.iPrintMode === 4) {
            tableDataRow.iPositiveColor = 0;
            tableDataRow.iPositiveSpecialColor = 0;
            tableDataRow.iOppositeColor = 0;
            tableDataRow.iOppositeSpecialColor = 0;
          }
        } else if (sFieldName === 'iPositiveColor' || sFieldName === 'iPositiveSpecialColor') {
          if (tableDataRow.iPrintMode === 0 || tableDataRow.iPrintMode === 1) {
            tableDataRow.iOppositeColor = tableDataRow.iPositiveColor;
            tableDataRow.iOppositeSpecialColor = tableDataRow.iPositiveSpecialColor;
          }
        }
        tableDataRow = this.singlePQtyChange(tableDataRow);
        /* 上机数量改变时,子级部件数量同步改变 */
        const { dMachineQty } = tableDataRow;
        /* 查找该节的所有子节点，将上机数量改为部件数量 */
        tableData.forEach((item, index) => {
          if (commonUtils.isNotEmptyObject(item.sAllId) && item.sAllId.indexOf(tableDataRow.sId) > -1 && item.sId !== tableDataRow.sId) {
            const addstate = {};
            addstate.dPartsQty = dMachineQty;
            tableData[index] = { ...tableData[index], ...addstate };
          }
        });
      } else if (sFieldName === 'dMachineLength' || sFieldName === 'dMachineWidth') { /* 控制表长宽改变 关联材料表type为0的上机长宽对应改变 */
        if (commonUtils.isNotEmptyArr(materialsDataOld)) {
          materialsDataOld.forEach((item, index) => {
            const itemNew = { ...item };
            if (itemNew.sControlId === tableDataRow.sId && itemNew.sType === '0') {
              itemNew.sMachineStyle = `${tableDataRow.dMachineLength.toString()}*${tableDataRow.dMachineWidth.toString()}`;
              itemNew.handleType = commonUtils.isEmpty(itemNew.handleType) ? 'update' : itemNew.handleType;
            }
            materialsDataOld[index] = { ...materialsDataOld[index], ...itemNew };
          });
        }
      } else if (sModelsType.includes('manufacture/workOrder')) {
        /* 计算材料开数 */
        // if (sFieldName === 'dMachineLength' || sFieldName === 'dMachineWidth' || sFieldName === 'dMaterialsLength' || sFieldName === 'dMaterialsWidth') {
        //   let dProductLength = 0; /* 产品长 */
        //   let dProductWidth = 0; /* 产品宽 */
        //   if (commonUtils.isNotEmptyArr(slaveData)) {
        //     dProductLength = !commonUtils.isEmpty(slaveData[0].sProductStyle) && slaveData[0].sProductStyle.split('*').length === 2 ? slaveData[0].sProductStyle.split('*')[0] : 0;
        //     dProductLength = commonUtils.convertStrToNumber(commonUtils.isNull(dProductLength, 0)); /* 产品长 */
        //     dProductLength = (typeof dProductLength === 'number' && !isNaN(dProductLength)) ? dProductLength : 0; /* 产品长 */
        //     dProductWidth = !commonUtils.isEmpty(slaveData[0].sProductStyle) && slaveData[0].sProductStyle.split('*').length === 2 ? slaveData[0].sProductStyle.split('*')[1] : 0;
        //     dProductWidth = commonUtils.convertStrToNumber(commonUtils.isNull(dProductWidth, 0)); /* 产品宽 */
        //     dProductWidth = (typeof dProductLength === 'number' && !isNaN(dProductLength)) ? dProductWidth : 0; /* 产品宽 */
        //   }
        //   const dMachineLength = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMachineLength, 0)); /* 上机长 */
        //   const dMachineWidth = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMachineWidth, 0)); /* 上机宽 */
        //   const dMaterialsLength = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMaterialsLength, 0)); /* 材料长 */
        //   const dMaterialsWidth = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMaterialsWidth, 0)); /* 材料宽 */
        //
        //   /* 算材料开数 */
        //   const mapMaterialsKQty = this.props.onResolveMachineComposing(dMachineLength, dMachineWidth, dMaterialsLength, dMaterialsWidth);
        //   if (commonUtils.isNotEmptyObject(mapMaterialsKQty)) {
        //     const dMaterialsKQty = mapMaterialsKQty.totalNum;
        //     tableDataRow.dMaterialsKQty = dMaterialsKQty;
        //   }
        //
        //   /* 算拼版数 */
        //   if (dProductLength !== 0 && dProductWidth !== 0) {
        //     const mapSinglePQty = this.props.onResolveMachineComposing(dProductLength, dProductWidth, dMachineLength, dMachineWidth);
        //     if (commonUtils.isNotEmptyObject(mapSinglePQty)) {
        //       const dSinglePQty = mapSinglePQty.totalNum;
        //       tableDataRow.dSinglePQty = dSinglePQty;
        //     }
        //   }
        // }
      }
      const materialsData = [];
      const processData = [];
      materialsDataOld.forEach((item) => {
        const itemNew = { ...item };
        if (itemNew.sControlId === sId) {
          itemNew.sPartsName = tableDataRow.sPartsName;
        }
        materialsData.push(itemNew);
      });
      processDataOld.forEach((item) => {
        const itemNew = { ...item };
        if (itemNew.sControlId === sId) {
          itemNew.sPartsName = tableDataRow.sPartsName;
        }
        processData.push(itemNew);
      });
      const materialsDataNew = this.sortData(tableData, materialsData);
      const processDataNew = this.sortData(tableData, processData);
      if (sFieldName === 'sPartsName') { /* 部件名称与子部件同步 */
        const { sPartsName } = tableDataRow;
        const { treeSelectedKeys, treeData } = this.props;
        if (commonUtils.isNotEmptyArr(treeSelectedKeys)) {
          this.handleSearchNodes(treeSelectedKeys[0], treeData, sPartsName);
        }
      }
      const iIndex = tableData.findIndex(item => item.sId === sId);
      tableData[iIndex] = tableDataRow;
      this.props.onSaveState({
        [`${name}Data`]: tableData, materialsData: materialsDataNew, processData: processDataNew, calculated: false,
      });
    } else if (name === 'materials') {
      const {
        [`${name}Data`]: tableData, controlData, controlSelectedRowKeys, app, sModelsId,
      } = this.props;
      const tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
      if (tableDataRow === undefined) return;
      if (Object.keys(changeValue).length > 0 && Object.keys(changeValue).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
        const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
        const valueMaterialsStock = {
          sProName: 'Sp_Inventory_MaterialsInventoryV56',
          paramsMap: {
            sMaterialsGuid: tableDataRow.sMaterialsId,
            sMaterialsStyle: tableDataRow.sMaterialsStyle,
            sWarehouseGuid: tableDataRow.sWarehouseId,
            sLocationalGuid: tableDataRow.sLocationId,
            sWarehouseLocationGuid: tableDataRow.sWarehouseLocationId,
            sDefine_no: tableDataRow.sDefineNo,
            sDefine_no2: tableDataRow.sDefineNo2,
            iGetQty: 1,
            iHasZero: 1,
          },
        };
        const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
        if (returnDataMaterialsStock.code === 1) {
          tableDataRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
        }
      }
      if (Object.keys(changeValue).length > 0 && Object.keys(changeValue).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
        const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
        const valueMaterialsAvailableQty = {
          sProName: 'Sp_Inventory_MaterialsInventoryV56',
          paramsMap: {
            sMaterialsGuid: tableDataRow.sMaterialsId,
            sMaterialsStyle: tableDataRow.sMaterialsStyle,
            sWarehouseGuid: tableDataRow.sWarehouseId,
            sLocationalGuid: tableDataRow.sLocationId,
            sWarehouseLocationGuid: tableDataRow.sWarehouseLocationId,
            sDefine_no: tableDataRow.sDefineNo,
            sDefine_no2: tableDataRow.sDefineNo2,
            iGetQty: 2,
            iHasZero: 1,
          },
        };
        const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
        if (returnDataMaterialsAvailableQty.code === 1) {
          tableDataRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
        }
      }
      const 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, calculated: false });
    } 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, calculated: false,
      });
    } else if (name === 'pack') {
      const { packData, packSelectedRowKeys } = this.props;
      const tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
      if (tableDataRow === undefined) return;
      const iIndex = packData.findIndex(item => item.sId === sId);
      packData[iIndex] = tableDataRow;
      if (sFieldName === 'dCombineQty' || sFieldName === 'dProductQty') {
        this.handleGetdFactProductQty(packSelectedRowKeys, packData);
      }
      this.props.onSaveState({ packData, calculated: false });
    } else {
      this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData);
    }
  };
  /* 重新计算实际生产数 */
  handleGetdFactProductQty = (selectedRowKeys, tableData) => {
    const maxArr = [];
    if (commonUtils.isNotEmptyArr(selectedRowKeys)) {
      const tableFilter = tableData.filter(item => selectedRowKeys.includes(item.sId) && item.dCombineQty > 0);
      if (selectedRowKeys.length === 1 || tableFilter.length === 1) { /*  当选中行只有一行时,实际生产数等于生产数 */
        const iSlaveIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
        if (iSlaveIndex > -1) {
          const dProductQty = tableData[iSlaveIndex].dProductQty;
          tableData[iSlaveIndex] = { ...tableData[iSlaveIndex], dFactProductQty: dProductQty };
        }
      } else {
        for (const sId of selectedRowKeys) {
          const iSlaveIndex = tableData.findIndex(item => item.sId === sId);
          if (iSlaveIndex > -1) {
            const slaveDataRow = tableData[iSlaveIndex];
            const { dCombineQty, dProductQty } = slaveDataRow;
            if (dCombineQty > 0) {
              let dNum = commonUtils.convertFixNum(dCombineQty !== 0 ? dProductQty / dCombineQty : 0, 2); /* 生产数/排版数 取最大值 */
              dNum = Math.ceil(dNum);
              maxArr.push(dNum);
            }
          }
        }
        let dMax = 0;
        if (commonUtils.isNotEmptyArr(maxArr)) {
          dMax = Math.max(...maxArr);
        }
        dMax = commonUtils.isNotNum(dMax) ? 0 : dMax;
        for (const sId of selectedRowKeys) {
          const iSlaveIndex = tableData.findIndex(item => item.sId === sId);
          if (iSlaveIndex > -1) {
            const slaveDataRow = tableData[iSlaveIndex];
            let { dCombineQty } = slaveDataRow;
            if (dCombineQty > 0) {
              dCombineQty = commonUtils.isNotNum(dCombineQty) ? 0 : dCombineQty;
              const dFactProductQty = commonUtils.convertFixNum(dCombineQty * dMax, 2); /* 实际生产数 =最大值 * 排版数 */
              tableData[iSlaveIndex] = { ...tableData[iSlaveIndex], dFactProductQty };
            }
          }
        }
      }
      this.props.onSaveState({ packData: tableData });
    }
  }
  handleCancelFastOrderModal = () => {
    this.props.onSaveState({ fastOrderModalVisible: false, workOrderAllprogress: 0, Loading: false });
  };
  handleCancelProcessChooseModal = () => {
    this.props.onSaveState({ processChooseVisible: false });
  };
  handleCancelMaterialsChooseModal = () => {
    this.props.onSaveState({ materialsChooseVisible: false });
  };
  handleCancelProductMaterialsChooseModal = () => {
    this.props.onSaveState({ productMaterialsChooseVisible: false });
  };
  handleCancelProductProcessInfoChooseModal = () => {
    this.props.onSaveState({ productProcessInfoChooseVisible: false });
  };
  handleCancelProductCombinationChooseModal = () => {
    this.props.onSaveState({ productCombinationVisible: false });
  };

  handleSelectProductCombination= () => {
    const {
      controlData, sCombinationsControlId, packData, enabled, app,
    } = this.props;
    let { packSelectedRowKeys: selectedRowKeys } = this.props;
    let sCombinedMemo = '';
    const tableCombineSelectedData = [];
    selectedRowKeys = commonUtils.isNotEmptyArr(selectedRowKeys) ? selectedRowKeys : [];
    const maxArr = [];
    const maxMap = new Map();
    for (const sId of selectedRowKeys) {
      const iIndex = packData.findIndex(item => item.sId === sId);
      if (iIndex > -1) {
        const tableDataRow = packData[iIndex];
        const {
          sId, sProductNo, dCombineQty, dProductQty, dFactProductQty, sCombinePartsName,
        } = tableDataRow;
        if (dCombineQty > 0) { /* 排版数大于0时,把数据带回到控制表 */
          const jsonObj = {};
          jsonObj.sId = sId;
          jsonObj.sProductNo = sProductNo; /* 产品编号 */
          jsonObj.dCombineQty = commonUtils.isNotEmptyNumber(dCombineQty) ? dCombineQty : 0; /* 排版数 */
          jsonObj.dProductQty = commonUtils.isNotEmptyNumber(dProductQty) ? dProductQty : 0; /* 生产数 */
          jsonObj.dFactProductQty = commonUtils.isNotEmptyNumber(dFactProductQty) ? dFactProductQty : 0; /* 实际生产数 */
          jsonObj.sCombinePartsName = sCombinePartsName; /* 合版部件名称 */
          tableCombineSelectedData.push(jsonObj);
          maxMap.set(dFactProductQty, jsonObj);
          maxArr.push(dFactProductQty);
        } else {
          message.warn(commonFunc.showMessage(app.commonConst, 'pleaseInputQty'));/* 请填写合拼排版数 */
          return;
        }
      }
    }

    /* 没勾选的合版数据 合拼排版数置为0 */
    const packNoChooseData = packData.filter(item => item.sControlId === sCombinationsControlId && !selectedRowKeys.includes(item.sId));
    if (commonUtils.isNotEmptyArr(packNoChooseData) && packNoChooseData.length > 0) {
      packNoChooseData.forEach((item) => {
        const iIndex = packData.findIndex(child => child.sId === item.sId);
        if (iIndex > -1) {
          packData[iIndex].dCombineQty = 0;
        }
      });
    }

    let iMax = 0;
    if (commonUtils.isNotEmptyArr(maxArr)) {
      iMax = Math.max(...maxArr);
    }
    sCombinedMemo = commonUtils.isNotEmptyArr(tableCombineSelectedData) ? JSON.stringify(tableCombineSelectedData) : ''; /* JSON对象转换为字符串存放到合版信息中 */
    const iControlIndex = controlData.findIndex(item => item.sId === sCombinationsControlId);
    if (iControlIndex > -1 && enabled) {
      const addState = {};
      const maxObj = maxMap.get(iMax);
      let { handleType } = controlData[iControlIndex];
      handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
      addState.handleType = handleType;
      addState.sCombinedMemo = sCombinedMemo;
      addState.dPartsQty = iMax;
      addState.dSinglePQty = commonUtils.isNotEmptyObject(maxObj) ? maxObj.dCombineQty : 0;
      controlData[iControlIndex] = { ...controlData[iControlIndex], ...addState };
    }
    this.props.onSaveState({
      productCombinationVisible: false,
      packData,
      controlData,
    });
  };
  handleCancelCombinePartsChooseModal = () => {
    this.props.onSaveState({ combinePartsChooseVisible: false });
  };
  /* 选择合版部件名称 */
  handleSelectCombineParts = (name, selectConfig, selectData) => {
    const {
      processData, processSelectedRowId, materialsData, materialsSelectedRowId, openTable,
    } = this.props;
    let sCombinedStr = '';
    let sCombinedId = '';
    if (selectData !== undefined) {
      if (commonUtils.isNotEmptyArr(selectData)) {
        selectData.forEach((item) => {
          const { sId } = item;
          let { sProductName } = item;
          let { sCombinePartsName } = item;
          sProductName = commonUtils.isNotEmptyObject(sProductName) ? sProductName : '';
          sCombinePartsName = commonUtils.isNotEmptyObject(sCombinePartsName) ? sCombinePartsName : '';
          // sCombinedStr += `${sCustomerName}-${sProductName}-${sCombinePartsName},`;
          if (commonUtils.isNotEmptyObject(sCombinePartsName)) {
            sCombinedStr += `${sProductName}-${sCombinePartsName},`;
            sCombinedId += `${sId},`;
          } else {
            sCombinedStr += `${sProductName},`;
            sCombinedId += `${sId},`;
          }
        });
        // sCombinedStr = `${selectData.length.toString()}   `;
        if (commonUtils.isNotEmptyObject(sCombinedStr)) {
          sCombinedStr = commonUtils.isNotEmptyObject(sCombinedStr) ? sCombinedStr.substr(0, sCombinedStr.length - 1) : '';
        }
        if (commonUtils.isNotEmptyObject(sCombinedId)) {
          sCombinedId = commonUtils.isNotEmptyObject(sCombinedId) ? sCombinedId.substr(0, sCombinedId.length - 1) : '';
        }
      }
      if (commonUtils.isNotEmptyObject(openTable) && openTable === 'materials') {
        const iIndex = materialsData.findIndex(item => item.sId === materialsSelectedRowId);
        if (iIndex > -1) {
          if(!materialsData[iIndex]) {
            return;
          }
          const addState = {};
          let { handleType } = materialsData[iIndex];
          handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
          addState.handleType = handleType;
          addState.sCombinePartsNameNew = sCombinedStr;
          addState.sCombineProductNameNew = sCombinedStr;
          addState.sCombinePartsName = sCombinedId;
          materialsData[iIndex] = { ...materialsData[iIndex], ...addState };
        }
        this.props.onSaveState({ materialsData, combinePartsChooseVisible: false });
      } else {
        const iIndex = processData.findIndex(item => item.sId === processSelectedRowId);
        if (iIndex > -1) {
          if(!processData[iIndex]) {
            return;
          }
          const addState = {};
          let { handleType } = processData[iIndex];
          handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
          addState.handleType = handleType;
          addState.sCombinePartsNameNew = sCombinedStr;
          addState.sCombineProductNameNew = sCombinedStr;
          addState.sCombinePartsName = sCombinedId;
          processData[iIndex] = { ...processData[iIndex], ...addState };
        }
        this.props.onSaveState({ processData, combinePartsChooseVisible: false });
      }
    }
  };
  handleCancelModal = (modelVisible) => {
    this.props.onSaveState({
      [modelVisible]: false,
    });
  }
  /**   复制   */
  handleTableCopy = (name, isWait) => {
    /* 部件树节点复制功能 */
    const {
      [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys, [`${name}Pagination`]: tablePagination, packData, slaveData,
    } = this.props;
    if (name === 'control') {
      const {
        [`${name}SelectedRowKeys`]: treeSelectedKeys,
      } = this.props;
      if (commonUtils.isEmptyArr(treeSelectedKeys)) {
        message.warn('请选择部件！'); // 请选择部件
        return;
      }
      /* 获取复制节点下的所有子节点 */
      const controlChildData = tableData.filter(item => item.sAllId.indexOf(treeSelectedKeys[0]) > -1 && item.sId !== treeSelectedKeys[0]);
      if (commonUtils.isNotEmptyArr(tableData)) {
        controlChildData.forEach((itemNew) => {
          tableSelectedRowKeys.push(itemNew.sId);
        });
      }
      const treeCopyNodes = new Map();
      for (const sId of tableSelectedRowKeys) {
        const tableDataIndex = tableData.findIndex(item => item.sId === sId);
        if (tableDataIndex > -1) {
          const tableDataRow = JSON.parse(JSON.stringify(tableData[tableDataIndex]));
          const sAllOldId = tableData[tableDataIndex].sAllId;
          const arr = sAllOldId.split(',');
          const newId = commonUtils.createSid();
          tableDataRow.sId = newId;
          let sOldParentId = '';
          let sNewParentAllId = '';
          if (arr.length < 2) { /* 根节点复制 */
            tableDataRow.sAllId = newId;
            sOldParentId = newId;
            sNewParentAllId = newId;
          } else {
            sOldParentId = arr[arr.length - 2];
            if (treeCopyNodes.has(sOldParentId)) {
              sNewParentAllId = treeCopyNodes.get(sOldParentId);
            } else {
              const obj = arr[arr.length - 1];
              sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
            }
            const sNewArr = sNewParentAllId.split(',');
            tableDataRow.sControlParentId = sNewArr[sNewArr.length - 1];
            sNewParentAllId = `${sNewParentAllId},${newId}`;
            tableDataRow.sAllId = sNewParentAllId;
          }
          treeCopyNodes.set(sId, sNewParentAllId);
          tableDataRow.handleType = 'add';
          tableDataRow.key = tableDataRow.sId;
          tableDataRow.sSrcSlaveId = '';
          tableDataRow.sSrcId = '';
          tableDataRow.dSrcQty = null;
          const iOrderArr = [];
          tableData.forEach((item) => {
            const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
            iOrderArr.push(iOrder);
          });
          const iOrderMax = Math.max(...iOrderArr);
          tableDataRow.iOrder = commonUtils.isNotEmptyArr(tableData) ? iOrderMax + 1 : 0;
          if (commonUtils.isNotEmptyObject(tableDataRow.sMaterialsMemo)) {
            tableDataRow.sMaterialsMemo = '';
          }
          if (commonUtils.isNotEmptyObject(tableDataRow.sProcessMemo)) {
            tableDataRow.sProcessMemo = '';
          }
          tableData.push(tableDataRow);
          const tableSelectedNewRowKeys = [];
          if (commonUtils.isNotEmptyObject(newId)) {
            tableSelectedNewRowKeys.push(newId);
          }
          if (commonUtils.isNotEmptyArr(slaveData)) {
            slaveData.forEach((item, index) => {
              /* 合版信息表增加一条从表数据  */
              const packDataRow = this.handlePackDataAdd(item, index, tableDataRow.sId, 'add');
              if (commonUtils.isNotEmptyObject(packDataRow)) {
                // packDataRow.dCombineQty = 1;
                packData.push(packDataRow);
              }
            });
          }
          this.props.onSaveState({
            [`${name}Data`]: tableData, [`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 }, [`${name}SelectedRowKeys`]: tableSelectedNewRowKeys, treeSelectedKeys: tableSelectedNewRowKeys, packData,
          });
        }
      }
      this.handleGetControlTreeData(tableData);
    } else if (name === 'slave') {
      const { packData, controlData } = this.props;
      if (commonUtils.isEmptyArr(tableSelectedRowKeys)) {
        message.warn('请选择数据！'); // 请选择从表数据
        return;
      }
      for (const sId of tableSelectedRowKeys) {
        const tableDataIndex = tableData.findIndex(item => item.sId === sId);
        if (tableDataIndex > -1) {
          const tableDataRow = this.props.onDataRowCopy(name, true);
          if (commonUtils.isNotEmptyArr(controlData)) {
            controlData.forEach((item) => {
              /* 合版信息表增加一条从表数据  */
              const packDataRow = this.handlePackDataAdd(tableDataRow, tableData.length, item.sId, 'add');
              // packDataRow.dCombineQty = 1;
              if (commonUtils.isNotEmptyObject(packDataRow)) {
                packData.push(packDataRow);
              }
            });
          }
          tableData.push(tableDataRow);
          this.props.onSaveState({
            [`${name}Data`]: tableData, packData, [`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 },
          });
        }
      }
    } else {
      this.props.onDataRowCopy(name, isWait);
    }
  }
  /**   复制全部   */
  handleTableCopyAll = (name, isWait) => {
    const {
      [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys, materialsData, app, packData, slaveData,
    } = this.props;
    let { processData } = this.props;
    if (name === 'control') {
      const {
        [`${name}SelectedRowKeys`]: treeSelectedKeys,
      } = this.props;
      if (commonUtils.isEmptyArr(treeSelectedKeys)) {
        message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseCopyData'));/* 请选择复制数据 */
      } else {
        /* 获取复制节点下的所有子节点 */
        const controlChildData = tableData.filter(item => item.sAllId.indexOf(treeSelectedKeys[0]) > -1 && item.sId !== treeSelectedKeys[0]);
        if (commonUtils.isNotEmptyArr(tableData)) {
          controlChildData.forEach((itemNew) => {
            tableSelectedRowKeys.push(itemNew.sId);
          });
        }
        const treeCopyNodes = new Map();
        for (const sId of tableSelectedRowKeys) {
          const tableDataIndex = tableData.findIndex(item => item.sId === sId);
          if (tableDataIndex > -1) {
            const tableDataRow = JSON.parse(JSON.stringify(tableData[tableDataIndex]));
            tableDataRow.sId = commonUtils.createSid();
            tableDataRow.handleType = 'add';
            tableDataRow.key = tableDataRow.sId;
            tableDataRow.sPartsName = `${tableData[tableDataIndex].sPartsName}new`;
            const sAllOldId = tableData[tableDataIndex].sAllId;
            const arr = sAllOldId.split(',');
            const newId = tableDataRow.sId;
            let sOldParentId = '';
            let sNewParentAllId = '';
            if (arr.length < 2) { /* 根节点复制 */
              tableDataRow.sAllId = newId;
              sOldParentId = newId;
              sNewParentAllId = newId;
            } else {
              sOldParentId = arr[arr.length - 2];
              if (treeCopyNodes.has(sOldParentId)) {
                sNewParentAllId = treeCopyNodes.get(sOldParentId);
              } else {
                const obj = arr[arr.length - 1];
                sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
              }
              const sNewArr = sNewParentAllId.split(',');
              tableDataRow.sControlParentId = sNewArr[sNewArr.length - 1];
              sNewParentAllId = `${sNewParentAllId},${newId}`;
              tableDataRow.sAllId = sNewParentAllId;
            }
            treeCopyNodes.set(sId, sNewParentAllId);
            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;
                materialsRow.bPurchaseApplyComplete = 0;
                materialsRow.dPurchaseApplyAuxiliaryQty = 0;
                materialsRow.dPurchaseApplyQty = 0;
                materialsRow.bPurchaseComplete = 0;
                materialsRow.dPurchaseAuxiliaryQty = 0;
                materialsRow.dPurchaseQty = 0;
                materialsRow.dProductionAuxiliaryQty = 0;
                materialsRow.dProductionQty = 0;
                materialsRow.bProductionComplete = 0;

                materialsRow.dProductionApplyAuxiliaryQty = 0;
                materialsRow.dProductionApplyQty = 0;
                materialsRow.bProductionApplyComplete = 0;

                materialsRow.bComComplete = 0;
                materialsRow.dComAuxiliaryQty = 0;
                materialsRow.dComQty = 0;
                // 材料对应工序的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);
              });
              const treeState = this.handleGetControlTreeData(tableData, true);
              const tableSelectedNewRowKeys = [];
              if (commonUtils.isNotEmptyObject(newId)) {
                tableSelectedNewRowKeys.push(newId);
              }
              if (commonUtils.isNotEmptyArr(slaveData)) {
                slaveData.forEach((item, index) => {
                  /* 合版信息表增加一条从表数据  */
                  const packDataRow = this.handlePackDataAdd(item, index, tableDataRow.sId, 'add');
                  if (commonUtils.isNotEmptyObject(packDataRow)) {
                    // packDataRow.dCombineQty = 1;
                    packData.push(packDataRow);
                  }
                });
              }
              this.props.onSaveState({
                ...treeState,
                [`${name}Data`]: tableData,
                [`${name}Pagination`]: { total: tableData.length, current: 9999 },
                [`${name}SelectedRowKeys`]: tableSelectedNewRowKeys,
                treeSelectedKeys: tableSelectedNewRowKeys,
                materialsSelectedRowKeys: [],
                materialsData,
                processData,
                packData,
              });
            }
          }
        }
      }
    }
  };

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

    /* 计算材料开数 */
    // const dMachineLength = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMachineLength, 0)); /* 上机长 */
    // const dMachineWidth = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMachineWidth, 0)); /* 上机宽 */
    // const dMaterialsLength = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMaterialsLength, 0)); /* 材料长 */
    // const dMaterialsWidth = commonUtils.convertStrToNumber(commonUtils.isNull(tableDataRow.dMaterialsWidth, 0)); /* 材料宽 */
    // const sResult = this.props.onResolveMachineComposing(dMachineLength, dMachineWidth, dMaterialsLength, dMaterialsWidth);
    // if (commonUtils.isNotEmptyObject(sResult)) {
    //   const dMaterialsKQty = sResult.totalNum;
    //   tableDataRow.dMaterialsKQty = dMaterialsKQty;
    // }

    return tableDataRow;
  };

  handleCancel1 = () => {
    this.props.onSaveState({
      visible: false,
    });
  };

  handleOk = async (flag, tmpCheck, isWait) => {
    const {
      sModelsId, masterData, app, checkConditions, sCheckModelId, checkPersonData, currentId, masterConfig, slaveConfig, checkConfig,
    } = this.props;
    const { currentPane } = app;
    const bCkxTmpCheck = app.systemData.filter(item => item.sName === 'CkxTmpCheck')[0].sValue;
    if (bCkxTmpCheck === '1') {
      const returnData = await this.props.onDataAudit(flag, tmpCheck, isWait);
      if (returnData.code === 1) {
        if (returnData.dataset.rows[0].dataSet.outData[0].sCode === 1) {
          this.props.onGetData(masterConfig, slaveConfig, checkConfig);
          message.success(returnData.msg);
        } else {
          message.error(returnData.dataset.rows[0].dataSet.outData[0].sReturn);
        }
      } else { /*   失败   */
        this.props.getServiceError(returnData);
      }
    } else {
      const dataPersonArray = commonUtils.isEmptyObject(this.props.dataPersonArray) ? [] : this.props.dataPersonArray;
      if (commonUtils.isEmptyObject(dataPersonArray)) {
        checkPersonData.forEach((item) => {
          dataPersonArray.push(item.sUserId);
        });
      }
      const dataPersonString = dataPersonArray.join(',');
      const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
      const value = {
        sProName: 'Sp_System_AutoSendCheckMsg',
        paramsMap: {
          sFormGuid: sModelsId,
          sBillKey: currentPane.sProcName,
          sTbName: masterConfig.sTbName,
          sGuid: masterData.sId,
          sBillNo: masterData.sBillNo,
          sCheckCondition: checkConditions,
          sMemo: '',
          sCheckModelGuid: sCheckModelId,
          sCheckPerson: dataPersonString,
        },
      };

      const returnData = (await commonServices.postValueService(app.token, value, url)).data;
      if (returnData.code === 1) {
        const noCheckMsg = commonFunc.showMessage(app.commonConst, 'NoCheckMsg'); /* 您有消息待审核 */
        if (returnData.dataset.rows[0].dataSet.outData[0].sCode === 1) {
          this.props.handleSendSocketMessage('examine', 'showImg', currentId, dataPersonString, noCheckMsg, null);
          const urlCanCheckBill = `${commonConfig.server_host}checkModel/getCanCheckBill?sModelsId=${sModelsId}`;
          const valueCanCheckBill = { sCheckModelId, checkPersonData, sBillId: masterData.sId };
          const returnCanCheckBill = (await commonServices.postValueService(app.token, valueCanCheckBill, urlCanCheckBill)).data;
          if (returnCanCheckBill.code === 1) {
            if (returnCanCheckBill.dataset.rows[0].iCount === 1) {
              this.props.onDataAudit(1, 1);
              this.props.onSaveState({
                visible: false,
              });
              return;
            }
          } else { /*   失败   */
            this.props.getServiceError(returnCanCheckBill);
          }
          this.props.handleSendSocketMessage('reflush', 'showImg', currentId, dataPersonString, noCheckMsg, null);
          message.success(returnData.msg);
        } else {
          message.error(returnData.dataset.rows[0].dataSet.outData[0].sReturn);
        }
      } else { /*   失败   */
        this.props.getServiceError(returnData);
      }
    }
    this.props.onSaveState({
      visible: false,
    });
  };

  /**   树节点选中   */
  handleTreeSelect = (name, checkedKeys, e) => {
    let { controlSelectedRowKeys } = this.props;
    controlSelectedRowKeys = checkedKeys; /* 把树形选中节点赋值给表格部件选中节点 */
    this.props.onTreeSelect(name, checkedKeys, e);
    this.props.onSaveState({
      controlSelectedRowKeys,
    });
  };

  handleTabChange = (value) => {
    this.setState({
      currentTab: +value
    });
  }

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

  handleDrag = (data) => {
    let { controlSelectedRowKeys } = this.props;
    if(this.props.enabled && controlSelectedRowKeys.length) {
      if(isQianCai) {
        // process : 0-1-2 部品工序 : 3成品工序;
        let processData = this.props.processData.slice(0);

        let preDataIndex = 0;
        let preData = data.filter(item => item.sType === '0' && item.sControlId === this.props.controlSelectedRowKeys[0]).map((item) => {
          preDataIndex = preDataIndex + 1;
          return  {...item, iOrder: preDataIndex}
        });

        let afterDataIndex = 0;
        let afterData = data.filter(item => item.sType !== '3' && item.sType !== '0' && item.sControlId === this.props.controlSelectedRowKeys[0]).map((item) => {
          afterDataIndex = afterDataIndex + 1;
          return  {...item, iOrder: afterDataIndex}
        });
        let allData = preData.concat(afterData);
        allData.forEach((item, index) => {
          if(item.sControlId === this.props.controlSelectedRowKeys[0]) {
            if(!allData[index].handleType) {
              allData[index].handleType = 'update';
            }
          }
        });
        processData = processData.filter(item => item.sControlId !== this.props.controlSelectedRowKeys[0]);
        processData = processData.concat(allData);
        this.props.onSaveState({ processData});
      } else {
        // process : 0-1-2 部品工序 : 3成品工序;
        let processData = this.props.processData.slice(0);
        let preDataIndex = 0;
        let preData = data.filter(item => item.sType === '0' && item.sControlId === this.props.controlSelectedRowKeys[0]).map((item) => {
          preDataIndex = preDataIndex + 1;
          return  {...item, iOrder: preDataIndex}
        });
        let inDataIndex = 0;
        let inData = data.filter(item => item.sType === '1' && item.sControlId === this.props.controlSelectedRowKeys[0]).map((item) => {
          inDataIndex = inDataIndex + 1;
          return  {...item, iOrder: inDataIndex}
        });
        let afterDataIndex = 0;
        let afterData = data.filter(item => item.sType === '2' && item.sControlId === this.props.controlSelectedRowKeys[0]).map((item) => {
          afterDataIndex = afterDataIndex + 1;
          return  {...item, iOrder: afterDataIndex}
        });
        let allData = preData.concat(inData, afterData);
        allData.forEach((item, index) => {
          if(item.sControlId === this.props.controlSelectedRowKeys[0]) {
            if(!allData[index].handleType) {
              allData[index].handleType = 'update';
            }
          }
        });
        processData = processData.filter(item => item.sControlId !== this.props.controlSelectedRowKeys[0]);
        processData = processData.concat(allData);
        this.props.onSaveState({ processData});
      }
    }
  }

  handleProductDrag = (data) => {
    if(this.props.enabled) {
      // process : 0-1-2 部品工序 : 3成品工序;
      let processData = this.props.processData.slice(0);
      let dataIndex = 0;
      const allData = data.filter(item => item.sType === '3' && item.sCombinePartsName === this.props.slaveSelectedRowKeys[0]).map((item) => {
        dataIndex = dataIndex + 1;
        return {...item, iOrder: dataIndex, handleType: item.handleType ? item.handleType : 'update'};
      });
      processData = processData.filter(item => item.sCombinePartsName !== this.props.slaveSelectedRowKeys[0]);
      processData = processData.concat(allData);
      this.props.onSaveState({ processData });
    }
  }

  render() {
    const { pageLoading, masterData, fastOrderModalVisible, sModelsType, app  } = this.props;
    const imgSrc = commonBusiness.handleAddIcon(masterData, sModelsType, app );
    return (
      <Spin spinning={pageLoading}>
        <WorkOrderComponent
          {...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}
          handleCancel1={this.handleCancel1}
          handleOk={this.handleOk}
          onChange1={this.onChange1}
          onFilterData={this.handleFilterData}
          onFilterProductData={this.handleFilterProductData}
          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}
          onCombinationSelect={this.handelCombinationSelect}
          onSelectCombinePartsChoose={this.handleSelectCombineParts}
          onSelectFinalProcess={this.handleSelectFinalProcess}
          onSelectProductMaterial={this.handleSelectProductMaterial}
          onCancelModal={this.handleCancelModal}
          onDataChange={this.handleTableChange}
          imgSrc={imgSrc}
          fastOrderModalVisible={fastOrderModalVisible}
          onCancelFastOrderModal={this.handleCancelFastOrderModal}
          onCancelProcessChooseModal={this.handleCancelProcessChooseModal}
          onCancelMaterialsChooseModal={this.handleCancelMaterialsChooseModal}
          onCancelProductMaterialsChooseModal={this.handleCancelProductMaterialsChooseModal}
          onCancelProductProcessInfoChooseModal={this.handleCancelProductProcessInfoChooseModal}
          onCancelProductCombinationChooseModal={this.handleCancelProductCombinationChooseModal}
          onSelectProductCombination={this.handleSelectProductCombination}
          onDataRowCopyAll={this.handleTableCopyAll}
          onDataRowCopy={this.handleTableCopy}
          // onRowClick={this.onRowClick}
          // onDoubleClick={this.onDoubleClick}
          // onRowMouseEnter={this.onRowMouseEnter}
          onDataRowModal={this.handleTableModal}
          OnGetFilterData={this.handleGetFilterData}
          onTableSelectRowChange={this.handleTableSelectRowChange}
          onKeyDown={this.handleKeyDown}
          orderData={this.orderData}
          onSelectTree={this.handleTreeSelect}
          onEject={this.handleEject}
          onViewChoose={this.handleViewChoose}
          onTabChange={this.handleTabChange}
          onDrag={this.handleDrag}
          onProductDrag={this.handleProductDrag}
          /* --- */
          onProcessParamsOk={this.handleProcessParamsOk}
          onCancelProcessParamsModalVisible={this.handleCancelProcessParamsModalVisible}
        />
      </Spin>
    );
  }
}

const WorkOrderComponent = 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,
    // AutoTableHeight,
    colorConfigGrdVisible,
    visible,
    checkConditions,
    checkPersonData,
    Loading,
    sModelsType,
    productCombinationVisible,
    combinePartsChooseVisible,
    sisColorChooseVisible,
    // currentTab,
    finishedMaterialsColumn,
    finishedMaterialsConfig,
    finishedProcessColumn,
    finishedProcessConfig,
  } = props;

  // 计算控制表记录数量，计算sticky高度
  const controlLen = props.controlData ? props.controlData.length : 0;
  let stickyHeight = 0;
  let stickyTabHeight = 0;
  if(props.currentTab === 1) {
    if (controlLen && controlLen < 5) {
      stickyHeight = (controlLen * 29) + 40 + 30 - 4; // 153
    } else {
      stickyHeight = 162 + 30;
    }
  } else {
    const slaveLen = props.slaveData ? props.slaveData.length : 0;
    if (slaveLen && slaveLen < 5) {
      stickyHeight = (slaveLen * 29) + 40 + 30 - 4;
      stickyTabHeight = (slaveLen * 29) + 40;
    } else {
      stickyHeight = 162 + 30;
      stickyTabHeight = 162;
    }
  }

  /*   回带表单   */
  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 checkCondition = commonFunc.showMessage(app.commonConst, 'checkCondition');/* 审核条件 */
  const checkSmemo = commonFunc.showMessage(app.commonConst, 'checkSmemo');/* 备注 */
  const columns = [{
    title: checkCondition,
    dataIndex: 'condition',
    key: 'condition',
  }, {
    title: checkSmemo,
    dataIndex: 'sMemo',
    key: 'sMemo',
  }];
  const btnSure = commonFunc.showMessage(app.commonConst, 'btnSure');/* 确认 */
  const check = commonFunc.showMessage(app.commonConst, 'check');/* 审核 */
  const BtnClose = commonFunc.showMessage(app.commonConst, 'BtnClose');/* 关闭 */
  const checkPerson = commonFunc.showMessage(app.commonConst, 'checkPerson');/* 审核人 */
  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 = '16px';
  const height = '16px';
  const setAdd = {
    title: '增加',
    img: <SvgIcon iconClass="plus" fill="#8c949e" size="14" offsetY="3" alt="添加"></SvgIcon>,
    disableimg: <SvgIcon iconClass="plus" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="添加"></SvgIcon>,
  };
  const setAddChild = {
    title: '增加',
    img: <SvgIcon iconClass="tree" fill="#8c949e" size="14" offsetY="3" alt="增加"></SvgIcon>,
    disableimg: <SvgIcon iconClass="tree" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="增加"></SvgIcon>,
  };

  const setCopy = {
    title: '复制',
    img: <SvgIcon iconClass="copy" fill="#8c949e" size="14" offsetY="3" alt="复制"></SvgIcon>,
    disableimg: <SvgIcon iconClass="copy" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="复制"></SvgIcon>,
  };
  const setCopyAll = {
    title: '复制部件',
    img: <SvgIcon iconClass="copyall" fill="#8c949e" size="14" offsetY="3" alt="复制部件"></SvgIcon>,
    disableimg: <SvgIcon iconClass="copyall" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="复制部件"></SvgIcon>,
  };
  const setDelete = {
    title: '删除',
    img: <SvgIcon iconClass="close" fill="#8c949e" size="14" offsetY="3" alt="删除"></SvgIcon>,
    disableimg: <SvgIcon iconClass="close" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="删除"></SvgIcon>,
  };
  const setProcess = {
    title: '工序',
    img: <SvgIcon iconClass="process" fill="#8c949e" size="14" offsetY="3" alt="选择工序"></SvgIcon>,
    disableimg: <SvgIcon iconClass="process" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="选择工序"></SvgIcon>,
  };
  const setMaterial = {
    title: '材料',
    img: <SvgIcon iconClass="material" fill="#8c949e" size="14" offsetY="3" alt="选择材料"></SvgIcon>,
    disableimg: <SvgIcon iconClass="material" fill="rgb(189, 189, 189)" size="14" offsetY="3" alt="选择材料"></SvgIcon>,
  };
  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 bShowProductProcess = false;
  let chooseProductProcessConfigRow = {};
  let onChooseProductProcessIndex;
  if (commonUtils.isNotEmptyObject(masterConfigOld)) {
    onChooseProductProcessIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProductProcess');
    if (onChooseProductProcessIndex > -1) {
      chooseProductProcessConfigRow = props.masterConfig.gdsconfigformslave[onChooseProductProcessIndex];/* 配置了成品工序按钮 */
      bShowProductProcess = true;/* 配置了成品工序按钮 */
    }
  }

  /* 获取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];
    }
  }

  /* 获取toolbar 选择成品材料 */
  let bShowProductMaterials = false;
  let chooseProductMaterialsConfigRow = {};
  let onChooseProductMaterialsIndex;
  if (commonUtils.isNotEmptyObject(masterConfigOld)) {
    onChooseProductMaterialsIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProductMaterials');
    if (onChooseProductMaterialsIndex > -1) {
      chooseProductMaterialsConfigRow = props.masterConfig.gdsconfigformslave[onChooseProductMaterialsIndex];/* 配置了成品工序按钮 */
      bShowProductMaterials = true;/* 配置了成品材料按钮 */
    }
  }

  const slaveTableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    tableProps: {
      rowSelection: null, pagination, onChange: props.onTitleChange, setAdd, setCopy, setDelete, AutoTableHeight: 132,
    },
    onKeyDown: props.onKeyDown,
  };
  // const mProps = { ...commonBusiness.createMemoProps('slave', props) };
  const controlPropsType = {
    ...commonBusiness.getTableTypes('control', props),
    onKeyDown: props.onKeyDown,
    bMutiSelect1: true, // 设置点击整行勾选框不勾选，只有点击勾选框才勾选
    tableProps: {
      // rowSelection: enabled ? null : '',
      // setAdd,
      sModelsType,
      // setCopyAll,
      // setDelete,
      setProcess,
      setMaterial,
      // bShowProductProcess, /* 是否显示成品工序 */
      // bShowProductMaterials, /* 是否显示成品工序 */
      chooseProcessConfigRow,
      chooseMaterialsConfigRow,
      // chooseProductProcessConfigRow, /* 成品工序按钮配置 */
      // chooseProductMaterialsConfigRow, /* 成品材料按钮配置 */
      setNoCommonOperate: true, /* 没有新增、修改、删除通用操作按钮 */
      AutoTableHeight: 132,
      // onRow: (record) => {
      //   return {
      //     onClick: () => { props.onRowClick('control', record); },
      //     onDoubleClick: () => { props.onDoubleClick('control', record); },
      //     onMouseEnter: () => { props.onRowMouseEnter('control', record); },
      //   };
      // },
    },
  };
  const name = 'controlTree';
  const treeProps = {
    ...commonBusiness.getTreeTypes('tree', props),
    isSearch: false,
    checkable: false,
    disabled: false,
    checkedAll: false,
    unChecked: false,
    [`${name}Column`]: props[`${name}Column`],
    [`${name}Config`]: props[`${name}Config`],
    [`${name}Data`]: props[`${name}Data`],
    getFloatNum: props.getFloatNum,
    getSqlDropDownData: props.getSqlDropDownData,
    getSqlCondition: props.getSqlCondition,
    handleSqlDropDownNewRecord: props.handleSqlDropDownNewRecord,
    getDateFormat: props.getDateFormat,
    onDoubleClick: props.onDoubleClick,
    onSelect: props.onSelectTree,
    expandedKeys: props.expandedKeys,
    showLine: true,
  };
  const genCustomDropData = () => {
    const data = commonBusiness.getTableTypes('process', props).data;
    const selectData = commonBusiness.getTableTypes('materials', props).data;
    const materialKey = props.materialsSelectedRowKeys ? props.materialsSelectedRowKeys[0] : 0;
    let selectRow = {};
    if (selectData && materialKey) {
      selectRow = selectData.filter(val => val.sId === materialKey)[0];
    }

    // materials : 0-1部件材料 : 2成品材料;
    // process : 0-1-2 部品工序 : 3成品工序;;
    const ruleMap = {
      0: '0-1-2',
      1: '0-1-2',
      2: '3',
    };
    const arr = [];
    if (data && selectRow) {
      const rule = ruleMap[selectRow.sType];
      const sParentId = selectRow.sSlaveProductId ? selectRow.sSlaveProductId : selectRow.sParentId;
      data.forEach((val) => {
        const obj = {};
        obj.value = val.sProcessName;
        obj.sId = val.sId;
        const valSparentId = val.sCombinePartsName ? val.sCombinePartsName : val.sParentId;
        if (rule && rule.split('-').indexOf(val.sType) !== -1 && valSparentId === sParentId) {
          arr.push(obj);
        }
      });
    }
    return arr;
  };

  /* 通过bFinal判断是否成品 */
  const dataFilter = (data, type, bFinal) => {
    // materials : 0-1部件材料 : 2成品材料;
    // process : 0-1-2 部品工序 : 3成品工序;
    // bfinal: 是否成品
    const { slaveSelectedRowKeys, controlSelectedRowKeys } = props;
    const oriData = data.data || [];
    if (data.data) {
      let res = [];
      switch (type) {
        case 'materials':
          if (finishedMaterialsColumn) {
            if (bFinal) { /* 成品材料 */
              if (slaveSelectedRowKeys && slaveSelectedRowKeys.length) {
                res = oriData.filter((val) => {
                  return val.sType === '2' && (val.sCombinePartsName === slaveSelectedRowKeys[0] || !val.sCombinePartsName);
                });
              } else {
                res = oriData.filter((val) => {
                  return val.sType === '2';
                });
              }
            } else { /* 部件材料 */
              res = oriData.filter((val) => {
                return val.sType !== '2';
              });
            }
          } else {
            res = oriData;
          }
          break;
        case 'process':
          if (finishedProcessColumn) {
            if (bFinal) { /* 成品工序 */
              if (slaveSelectedRowKeys && slaveSelectedRowKeys.length) {
                res = oriData.filter((val) => {
                  return val.sType === '3' && (val.sCombinePartsName === slaveSelectedRowKeys[0] || !val.sCombinePartsName);
                });
              } else {
                res = oriData.filter((val) => {
                  return val.sType === '3';
                });
              }
            } else { /* 部件工序 */
              if (controlSelectedRowKeys && controlSelectedRowKeys.length) {
                res = oriData.filter((val) => {
                  return val.sType !== '3' && (val.sControlId === controlSelectedRowKeys[0] || !val.sControlId);
                });
              } else {
                res = oriData.filter((val) => {
                  return val.sType !== '3';
                });
              }
              if(isQianCai) {
                const pre = res.filter(item => item.sType == '0').sort((a, b) => a.iOrder - b.iOrder);
                const after = res.filter(item => (item.sType == '1' || item.sType == '2')).sort((a, b) => a.iOrder - b.iOrder);
                res = pre.concat(after);
              }
            }
          } else {
            res = oriData;
          }
          break;
        default:
          res = oriData;
      }
      return res;
    } else {
      return oriData || [];
    }
  };
  const materialsPropsType = {
    ...commonBusiness.getTableTypes('materials', props),
    data: dataFilter(commonBusiness.getTableTypes('materials', props), 'materials'),
    filteredValue: props.controlSelectedRowKeys,
    onFilterData: props.onFilterData,
    OnGetFilterData: props.OnGetFilterData,
    customDropData: genCustomDropData(),
    onKeyDown: props.onKeyDown,
    tableProps: {
      rowSelection: null,
      setAdd,
      setCopy,
      setDelete,
      AutoTableHeight: '100%',
      sticky: {
        offsetHeader: stickyHeight,
      },
    },
  };
  const finishedMaterialsPropsType = {
    ...commonBusiness.getTableTypes('materials', props),
    configName: 'finishedMaterials',
    data: dataFilter(commonBusiness.getTableTypes('materials', props), 'materials', true),
    headerColumn: finishedMaterialsColumn,
    config: finishedMaterialsConfig,
    filteredValue: props.controlSelectedRowKeys,
    // onFilterData: props.onFilterProductData,
    OnGetFilterData: props.OnGetFilterData,
    customDropData: genCustomDropData(),
    onKeyDown: props.onKeyDown,
    tableProps: {
      rowSelection: null,
      setAdd,
      setCopy,
      setDelete,
      bShowProductMaterials,
      chooseProductMaterialsConfigRow, /* 成品材料按钮配置 */
      // setNoCommonOperate: true, /* 没有新增、修改、删除通用操作按钮 */
      AutoTableHeight: '100%',
      sticky: {
        offsetHeader: stickyHeight,
      },
    },
  };
  const processPropsType = {
    ...commonBusiness.getTableTypes('process', props),
    data: dataFilter(commonBusiness.getTableTypes('process', props), 'process'),
    filteredValue: props.controlSelectedRowKeys,
    onFilterData: props.onFilterData,
    OnGetFilterData: props.OnGetFilterData,
    onKeyDown: props.onKeyDown,
    tableProps: {
      rowSelection: null,
      setAdd,
      setCopy,
      setDelete,
      AutoTableHeight: '100%',
      sticky: {
        offsetHeader: stickyHeight,
      },
    },
    onDrag: props.onDrag,
    isDragAndDrop: true,
  };

  const finishedProcessPropsType = {
    ...commonBusiness.getTableTypes('process', props),
    configName: 'finishedProcess',
    data: dataFilter(commonBusiness.getTableTypes('process', props), 'process', true),
    headerColumn: finishedProcessColumn,
    config: finishedProcessConfig,
    filteredValue: props.controlSelectedRowKeys,
    // onFilterData: props.onFilterProductData,
    OnGetFilterData: props.OnGetFilterData,
    onKeyDown: props.onKeyDown,
    tableProps: {
      rowSelection: null,
      setAdd,
      setCopy,
      setDelete,
      bShowProductProcess,
      chooseProductProcessConfigRow, /* 成品工序按钮配置 */
      // setNoCommonOperate: true, /* 没有新增、修改、删除通用操作按钮 */
      AutoTableHeight: '100%',
      sticky: {
        offsetHeader: stickyHeight,
      },
    },
    onDrag: props.onProductDrag,
  };

  let colorTableProps = {};
  if (colorConfigGrdVisible) {
    colorTableProps = {
      ...commonBusiness.getTableTypes('color', props),
      onKeyDown: props.onKeyDown,
      tableProps: {
        rowSelection: null, setAdd, setCopy, setDelete, AutoTableHeight: '100%',
      },
    };
    // cProps = { ...commonBusiness.createMemoProps('color', props) };
  }
  const packTableProps = {
    ...commonBusiness.getTableTypes('pack', props),
    filteredValue: props.controlSelectedRowKeys,
    onFilterData: props.onFilterData,
    onKeyDown: props.onKeyDown,
    tableProps: {
      setCopy, setDelete, CalLastWidth: '1150', AutoTableHeight: '300px',
    },
    bRowClick: true,
  };

  let combinePartsConfig = {};
  if (commonUtils.isNotEmptyObject(props.packConfig)) {
    combinePartsConfig = JSON.parse(JSON.stringify(props.packConfig));
    const gdsconfigformslaveFilter = combinePartsConfig.gdsconfigformslave.filter(item => (item.sName === 'sId'
      || item.sName === 'sCustomerName'
      || item.sName === 'sProductName'
      || item.sName === 'sCombinePartsName'));
    combinePartsConfig.gdsconfigformslave = gdsconfigformslaveFilter;
    combinePartsConfig.bMutiSelect = false;
  }
  let combinePartsColumn = [];
  if (commonUtils.isNotEmptyObject(props.packColumn)) {
    combinePartsColumn = JSON.parse(JSON.stringify(props.packColumn));
    const packColumnFilter = props.packColumn.filter(item => (item.dataIndex === 'sId'
      || item.dataIndex === 'sCustomerName'
      || item.dataIndex === 'sProductName'
      || item.dataIndex === 'sCombinePartsName'));
    combinePartsColumn = packColumnFilter;
  }
  const combinePartsTableProps = {
    app: {
      ...props.app,
      currentPane: {
        ...props.app.currentPane,
        formRoute: '/indexPage/commonList',
        route: '/indexPage/commonList',
        name: 'combineParts',
        config: combinePartsConfig,
        select: props.onSelectCombinePartsChoose,
        selectCancel: props.onCancelModal.bind(this, 'combinePartsChooseVisible'),
      },
    },
    formRoute: '/indexPage/commonList',
    slaveConfig: combinePartsConfig,
    slaveColumn: combinePartsColumn,
    slaveData: props.combinePartsData,
    slaveSelectedRowKeys: props.combinePartsSelectedRowKeys,
    selectedRowKeys: props.combinePartsSelectedRowKeys,
    pageLoading: false,
    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,
          bEdit: props.enabled,
        },
      },
      enabled: props.enabled,
      sisColorSelectedData: props.sisColorSelectedData,
      // sisColorSelectedData: props.slaveFilterData,
      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) || {},
    };
  }

  let searchProcessType = {};
  let chooseProcessConfig = {};
  let setProcessTitle = commonFunc.showMessage(app.commonConst, 'setProcess');/* 选择工序标题 */
  if (commonUtils.isNotEmptyObject(props.processChooseData)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProcess');
    if (iIndex > -1) {
      chooseProcessConfig = props.masterConfig.gdsconfigformslave[iIndex];
    }
    setProcessTitle = props.processChooseData.sMenuName;
    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 chooseProdutProcessType = {};
  let chooseProdutProcessConfig = {};
  if (commonUtils.isNotEmptyObject(props.productProcessChooseData)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProductProcess');
    if (iIndex > -1) {
      chooseProdutProcessConfig = props.masterConfig.gdsconfigformslave[iIndex];
    }
    let slaveFinalData = [];
    let slaveFinalSelectedRowKeys =[];
    if (commonUtils.isNotEmptyArr(props.slaveData)) {
      slaveFinalData = JSON.parse(JSON.stringify(props.slaveData));
      if (commonUtils.isNotEmptyArr(slaveFinalData) && slaveFinalData.length > 0) {
        slaveFinalData.forEach((item) => {
          item.sSlaveId = commonUtils.createSid(); /* 添加成品工序从表 */
        });
      }
      /* 选择成品工序 只有一条从表 则默认选中 */
      if(slaveFinalData.length ===1){
        slaveFinalSelectedRowKeys.push(slaveFinalData[0].sSlaveId);
      }

    }

    let slaveFinalConfig = {};
    if (commonUtils.isNotEmptyObject(props.slaveConfig)) {
      slaveFinalConfig = JSON.parse(JSON.stringify(props.slaveConfig));
      slaveFinalConfig.bMutiSelect = true;
    }

    chooseProdutProcessType = {
      app: {
        ...props.app,
        currentPane: {
          name: 'chooseProductProcess',
          config: chooseProdutProcessConfig,
          conditonValues: props.getSqlCondition(chooseProdutProcessConfig),
          title: props.productProcessChooseData.sMenuName,
          route: props.productProcessChooseData.sName,
          formId: props.productProcessChooseData.sId,
          key: sModelsId + props.productProcessChooseData.sId,
          sModelsType: 'search/finalProcess',
          select: props.onSelectFinalProcess, /* 选择成品工序 */
          selectCancel: props.onCancelModal.bind(this, 'productProcessChooseVisible'),
        },
      },
      slaveFinalConfig,
      slaveFinalColumn: props.slaveColumn,
      slaveFinalData,
      slaveFinalSelectedRowKeys,
      dispatch: props.dispatch,
      fatherModelsType: props.sModelsType,
      content: props.content,
      id: new Date().getTime().toString(),
    };
  }

  /* 选择成品材料 */
  let chooseProductMaterialsType = {};
  let chooseProductMaterialsConfig = {};
  if (commonUtils.isNotEmptyObject(props.productMaterialsChooseData)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProductMaterials');
    if (iIndex > -1) {
      chooseProductMaterialsConfig = props.masterConfig.gdsconfigformslave[iIndex];
    }
    let slaveFinalData = [];
    let slaveFinalSelectedRowKeys =[];
    if (commonUtils.isNotEmptyArr(props.slaveData)) {
      slaveFinalData = JSON.parse(JSON.stringify(props.slaveData));
      if (commonUtils.isNotEmptyArr(slaveFinalData) && slaveFinalData.length > 0) {
        slaveFinalData.forEach((item) => {
          item.sSlaveId = commonUtils.createSid(); /* 添加成品工序从表s */
        });
      }
      /* 选择成品材料 只有一条从表 则默认选中 */
      if(slaveFinalData.length ===1){
        slaveFinalSelectedRowKeys.push(slaveFinalData[0].sSlaveId);
      }
    }

    let slaveFinalConfig = {};
    if (commonUtils.isNotEmptyObject(props.slaveConfig)) {
      slaveFinalConfig = JSON.parse(JSON.stringify(props.slaveConfig));
      slaveFinalConfig.bMutiSelect = true;
    }
    chooseProductMaterialsType = {
      app: {
        ...props.app,
        currentPane: {
          name: 'productMaterials',
          config: chooseProductMaterialsConfig,
          conditonValues: props.getSqlCondition(chooseProductMaterialsConfig),
          title: props.productMaterialsChooseData.sMenuName,
          route: props.productMaterialsChooseData.sName,
          formId: props.productMaterialsChooseData.sId,
          key: sModelsId + props.productMaterialsChooseData.sId,
          sModelsType: 'search/finalMaterials',
          select: props.onSelectProductMaterial,
          selectCancel: props.onCancelModal.bind(this, 'productMaterialsChooseVisible'),
        },
      },
      slaveFinalConfig,
      slaveFinalColumn: props.slaveColumn,
      slaveFinalData,
      slaveFinalSelectedRowKeys,
      dispatch: props.dispatch,
      fatherModelsType: props.sModelsType,
      content: props.content,
      id: new Date().getTime().toString(),
    };
  }

  let searchMaterialsType = {};
  let chooseMaterialsConfig = {};
  let setMaterialTitle = commonFunc.showMessage(app.commonConst, 'setMaterial');/* 选择材料标题 */
  if (commonUtils.isNotEmptyObject(props.materialsChooseData)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseMaterials');
    if (iIndex > -1) {
      chooseMaterialsConfig = props.masterConfig.gdsconfigformslave[iIndex];
    }
    setMaterialTitle = props.materialsChooseData.sMenuName;

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

  const tabChange = (e) => {
    props.onTabChange(e);
  };

  const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
  const materialsInfo = commonFunc.showMessage(app.commonConst, 'materialsInfo');/* 材料信息 */
  const processInfo = commonFunc.showMessage(app.commonConst, 'processInfo');/* 工序信息 */
  const productMaterialsInfo = commonFunc.showMessage(app.commonConst, 'productMaterialsInfo');/* 成品材料 */
  const productProcessInfo = commonFunc.showMessage(app.commonConst, 'productProcessInfo');/* 成品工序 */
  const colorInfo = commonFunc.showMessage(app.commonConst, 'colorInfo');/* 颜色信息 */

  const setProductProcessTitle = commonFunc.showMessage(app.commonConst, 'setProductProcess');/* 选择成品工序标题 */
  const setProductMaterialsTitle = commonFunc.showMessage(app.commonConst, 'setProductMaterials');/* 选择成品工序标题 */
  const setSisColorTitle = commonFunc.showMessage(app.commonConst, 'setSisColor');/* 选择颜色标题 */
  const setProductCombinationTitle = commonFunc.showMessage(app.commonConst, 'setProductCombination');/* 选择合拼产品标题 */

  // tree组件新增滚动至底部方法
  // let treeNode = null;
  // const treeRef = (n) => {
  //   treeNode = n;
  // };
  // const treeScrollToBottom = (node) => {
  //   console.log(node, 112233);
  //   if (node) {
  //     node.scrollTop = node.scrollHeight;
  //   }
  // };
  // tree组件新增滚动至底部方法ends

  const fastOrder = commonFunc.showMessage(app.commonConst, 'fastOrder');/* 快速下单 s */
  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');/* 置底s */
  const sProcessParams = commonFunc.showMessage(app.commonConst, 'sProcessParams');/* 选择工艺参数标题 */
  // eslint-disable-next-line jsx-a11y/anchor-is-valid
  const operateAdd = <a title="添加同级" alt="" onClick={props.enabled ? props.onDataRowAdd.bind(this, 'control', true, 'sameNode', false) : null}>{props.enabled ? setAdd.img : setAdd.disableimg} </a>;
  // eslint-disable-next-line jsx-a11y/anchor-is-valid
  const operateAddChild = <a title="添加子级" onClick={props.enabled ? props.onDataRowAdd.bind(this, 'control', true, 'childNode') : null}>{props.enabled ? setAddChild.img : setAddChild.disableimg }</a>;
  // eslint-disable-next-line jsx-a11y/anchor-is-valid
  const operateCopy = <a title="复制" onClick={props.enabled ? props.onDataRowCopy.bind(this, 'control', false, 'isChild') : null}>{props.enabled ? setCopy.img : setCopy.disableimg}</a>;
  // eslint-disable-next-line jsx-a11y/anchor-is-valid
  const operateUpdate = <a title="复制全部" onClick={props.enabled ? props.onDataRowCopyAll.bind(this, 'control', false, 'isChild') : null}>{props.enabled ? setCopyAll.img : setCopyAll.disableimg }</a>;
  // eslint-disable-next-line jsx-a11y/anchor-is-valid
  const operateDel = <a title="删除" onClick={props.enabled ? props.onDataRowDel.bind(this, 'control', true, '') : null}>{props.enabled ? setDelete.img : setDelete.disableimg}</a>;

  let bControlShow = true; /* 控制表 */
  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndexControl = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tbControl');
    if (iIndexControl > -1) {
      bControlShow = props.masterConfig.gdsconfigformslave[iIndexControl].bVisible;
    }
  }
  let bMaterialShow = true; /* 材料表 */
  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndexMaterial = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tbMaterial');
    if (iIndexMaterial > -1) {
      bMaterialShow = props.masterConfig.gdsconfigformslave[iIndexMaterial].bVisible;
    }
  }
  let bProcessShow = true; /* 工序表 */
  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndexProcess = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'tbProcess');
    if (iIndexProcess > -1) {
      bProcessShow = props.masterConfig.gdsconfigformslave[iIndexProcess].bVisible;
    }
  }


  const bFinalMaterialsTabShow = commonUtils.isEmptyObject(finishedMaterialsConfig) ? false :true; /* 没有成品材料配置 则材料Tab不展示 */
  const bFinalProcessTabShow = commonUtils.isEmptyObject(finishedProcessConfig) ? false :true; /* 没有成品工序配置 则工序Tab不展示 */

  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, 'slave-tabs-container', props.currentTab === 1 ? '' : 'workerOrderSlaveTable'].join(' ')} style={{ marginLeft: '10px' }}>
                <Layout>
                  <Content>
                    <StaticEditTable {...slaveTableProps} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                  </Content>
                </Layout>
              </div>
              <div
                className="workerOrderControlTable"
                style={{
                marginLeft: '10px', display: bControlShow ? 'block' : 'none', top: props.currentTab === 1 ? 0 : stickyTabHeight + 'px',
              }}
              >
                <Tabs className={styles.slaveTabs} style={{ marginRight: '10px'}} onChange={tabChange}>
                  <TabPane tab="部件信息" key={1} ></TabPane>
                  {bFinalMaterialsTabShow ?  <TabPane tab="成品材料" key={2} ></TabPane> :''}
                  {bFinalProcessTabShow?  <TabPane tab="成品工序" key={3} ></TabPane> :''}
                </Tabs>
                {props.currentTab === 1 ?
                  <Layout className="processList" style={{ marginBottom: '10px'}}>
                    <Sider className="controlhandcover">
                      {/* {controlInfo} */}
                      <div className="xly-control">
                        <div className="xly-control-header">部件信息</div>
                        <div className="xly-control-tree"><StaticEditTree {...treeProps} noVlist /></div>
                        <div className="xly-control-operate" >
                          <span>{operateAdd}</span>
                          <span>{operateAddChild}</span>
                          <span>{operateCopy}</span>
                          <span>{operateUpdate}</span>
                          <span>{operateDel}</span>
                        </div>
                      </div>
                    </Sider>
                    <Content>
                      <StaticEditTable {...controlPropsType} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                    </Content>
                  </Layout> : ''
                }
              </div>

              {props.currentTab === 1 ?
                <div style={{ marginLeft: '10px', display: bMaterialShow ? 'block' : 'none' }}>
                  <Layout>
                    {/*<Sider className="materials">*/}
                    {/*  {materialsInfo}*/}
                    {/*</Sider>*/}
                    <Content>
                      <StaticEditTable {...materialsPropsType} setOpterationColumn="Y" noVlist selfTableHeight={82}/>
                    </Content>
                  </Layout>
                </div> : ''
              }

              {finishedMaterialsColumn && props.currentTab === 2 ?
                <div style={{ marginLeft: '10px' }}>
                  <Layout>
                    {/*<Sider className="materials">*/}
                    {/*  {productMaterialsInfo}*/}
                    {/*</Sider>*/}
                    <Content>
                      <StaticEditTable {...finishedMaterialsPropsType} bFinished bModalAdd 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> : ''
              }

              {props.currentTab === 1 ?
                <div style={{ marginLeft: '10px', display: bProcessShow ? 'block' : 'none' }}>
                  <Layout className="processList">
                    <Content className="processTable">
                      <StaticEditTable {...processPropsType} setOpterationColumn="Y" dragHandle selfTableHeight={330} noVlist />
                    </Content>
                  </Layout>
                </div> : ''
              }

              {finishedProcessColumn && props.currentTab === 3?
                <div style={{ marginLeft: '10px' }}>
                  <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>*/}
                    {/*  {productProcessInfo}*/}
                    {/*</Sider>*/}
                    <Content className="processTable" >
                      <StaticEditTable {...finishedProcessPropsType} bFinished bModalAdd setOpterationColumn="Y" dragHandle selfTableHeight={330} noVlist />
                    </Content>
                  </Layout>
                </div> : ''}
            </div>
          </div>
        </Layout>
        {
          visible ?
            <AntdDraggableModal
              title={check}
              visible={visible}
              onCancel={props.handleCancel1}
              footer={[
                <Button key="back" onClick={props.handleCancel1}>{BtnClose}</Button>,
                <Button key="submit" type="primary" onClick={props.handleOk.bind(this, 1, 1, true)}>
                  {btnSure}
                </Button>,
              ]}
            >
              <Table columns={columns} dataSource={checkConditions} bordered pagination={false} className={styles.checkTable} />
              <div style={{ float: 'left', width: '15%' }}>{checkPerson}</div>
              <div style={{ float: 'left', width: '60%' }}>
                <Checkbox.Group style={{ width: '100%' }} onChange={props.onChange1}>
                  <Row>
                    { commonUtils.isNotEmptyObject(checkPersonData) ?
                      checkPersonData.map((item) => {
                        return (
                          <Col span={8}>
                            <Checkbox value={item.sUserId}>{item.sUserName}</Checkbox>
                          </Col>
                        );
                      })
                      : ''
                    }
                  </Row>
                </Checkbox.Group>
              </div>
            </AntdDraggableModal>
            : ''
        }
        {
          (pane.notCurrentPane ? false : props.processChooseVisible) ?
            <AntdDraggableModal
              width={1300}
              title={commonUtils.isEmptyObject(searchProcessType) ? setProcessTitle : searchProcessType.app.currentPane.title}
              visible={pane.notCurrentPane ? false : props.processChooseVisible}
              onCancel={props.onCancelProcessChooseModal}
              footer={null}
              wrapClassName="worker-order-pack-modal"
            >
              <CommonListSelectTree dragHandle {...searchProcessType} />
            </AntdDraggableModal>
            : ''
        }

        {
          /* 选择成品工序Modal */
          (pane.notCurrentPane ? false : props.productProcessChooseVisible) ?
            <AntdDraggableModal
              width={1300}
              title={commonUtils.isEmptyObject(chooseProdutProcessType) ? setProductProcessTitle : chooseProdutProcessType.app.currentPane.title}
              visible={pane.notCurrentPane ? false : props.productProcessChooseVisible}
              onCancel={props.onCancelModal.bind(this, 'productProcessChooseVisible')}
              footer={null}
              wrapClassName="worker-order-pack-modal"
            >
              <CommonListSelectProductProcess {...chooseProdutProcessType} productProcess />
            </AntdDraggableModal>
            : ''
        }

        {
          (pane.notCurrentPane ? false : props.productMaterialsChooseVisible) ?
            <AntdDraggableModal
              width={1300}
              title={commonUtils.isEmptyObject(chooseProductMaterialsType) ? setProductMaterialsTitle : chooseProductMaterialsType.app.currentPane.title}
              visible={pane.notCurrentPane ? false : props.productMaterialsChooseVisible}
              onCancel={props.onCancelProductMaterialsChooseModal}
              footer={null}
              wrapClassName="worker-order-pack-modal"
            >
              <CommonListSelectProductMaterial {...chooseProductMaterialsType} />
            </AntdDraggableModal>
            : ''
        }

        {
          (pane.notCurrentPane ? false : props.materialsChooseVisible) ?
            <AntdDraggableModal
              width={1300}
              title={commonUtils.isEmptyObject(searchMaterialsType) ? setMaterialTitle : searchMaterialsType.app.currentPane.title}
              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}
              wrapClassName="worker-order-pack-modal"
            >
              <CommonListSelect {...productProcessInfoType} />
            </AntdDraggableModal> : ''
        }

        {
          productCombinationVisible ?
            <AntdDraggableModal
              width={1150}
              title={setProductCombinationTitle}
              visible={productCombinationVisible === undefined ? false : productCombinationVisible}
              onCancel={props.onCancelProductCombinationChooseModal}
              onOk={props.onSelectProductCombination}
            >
              <div id="ModalMaterialRemark">
                <div id="packModal" style={{ marginTop: 0, height: '350px', overflowY: 'hidden' }} >
                  <StaticEditTable {...packTableProps} footer="hidden" setOpterationColumn="Y" />
                </div>
              </div>
            </AntdDraggableModal> : ''
        }

        {
          combinePartsChooseVisible ?
            <AntdDraggableModal
              width={1150}
              title="选择合版部件名称"
              visible={combinePartsChooseVisible === undefined ? false : combinePartsChooseVisible}
              onCancel={props.onCancelModal.bind(this, 'combinePartsChooseVisible')}
              // onOk={props.onSelectCombinePartsChoose}
              footer={null}
            >
              <CommonListSelect {...combinePartsTableProps} />
            </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.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={
              <Spin spinning={Loading === undefined ? false : Loading}><Button type="primary" onClick={props.handleDataCreate}>{Loading ? '下单中' : '确认下单'}</Button>
                {Loading ? <Slider tooltipVisible value={props.workOrderAllprogress} /> : ''}
              </Spin>}
            onCancel={props.onCancelFastOrderModal}
          >
            <SplitPaste {...props} />
          </AntdDraggableModal>
          : ''
        }
        <SlavesInfo {...props} />
        {
          props.contextMenuModalVisible ?
            <ContextMenuModal {...props} />
            : ''
        }
        {commonUtils.isEmptyArr(treeProps.treeData) || !commonUtils.isEmpty(props.routing) || true ? '' :
        <AntdDraggableDiv draggableDivClassName="xly-eject" >
          {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
          <a onClick={props.onEject}><img src={Eject} alt="eject" /></a>
        </AntdDraggableDiv>
        }
        {commonUtils.isEmptyArr(treeProps.treeData) || !commonUtils.isEmpty(props.routing) ? '' :
        <div className="xly-filter-tree">
          <StaticEditTree {...treeProps} />
          <div className="xly-tree-close" >
            {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
            <a onClick={props.onEject}> <img src={Close} alt="close" /></a>
          </div>
        </div>
        }
        {
          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>
            : ''
        }
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonSales(WorkOrderPack));
