/* 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,
  Button,
  Table,
  Checkbox,
  Row,
  Col,
  Avatar,
  Slider,
  Tabs,
  Collapse,
  Radio,
  Divider
} from 'antd-v4';
import {
  RightOutlined,
} from '@ant-design/icons';

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 EjectRight from '@/assets/eject.svg';/* 弹出图标 */
import CommonListSelect from '@/components/Common/CommonListSelect';/* 选择界面 */
import CommonListSelectFlex from '@/components/Common/CommonListSelectFlex';
/* 可编辑的选择界面 */
import CommonListSelectTree from '@/components/Common/CommonListSelectTree';
import CommonListSelectMulti from '@/components/Common/CommonListSelectMulti';
import CommonExamInfo from '@/components/Common/CommonExamInfo';

// import CommonListSelectParam from '@/components/Common/CommonListSelectParam';
import CommonViewDragable from '@/components/Common/CommonViewDragable';
import CommonPartsInfo from '@/components/Common/CommonPartsInfo';
/* 树形选择界面 */
import CommonListSelectProductProcess from '@/components/Common/CommonListSelectAssignment';
import CommonListSelectProductMaterial from '@/components/Common/CommonListSelectProductMaterial';
import WorkFlow from '@/components/Common/Flows/CommonFlow'; /* 工作流 */
/* 选择成品工序 */
// 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 { message } from '@/utils/common/message';
import selfstyles from '../index.less';
import CloseRight from "../../../assets/close.svg";
import SvgIcon from "../../SvgIcon";
const { Header, Content, Sider } = Layout;
const { Option } = Select;
const { confirm } = Modal;
const { TabPane } = Tabs;
const { Panel } = Collapse;

const isQianCai = false;
const isYaChang = false;


class WorkOrderPack extends Component {
  constructor(props) {
    super(props);
    window.fetchCount = 0;
    this.baseTableHeight = document?.documentElement?.getBoundingClientRect()?.height >= 700 ? '40vh' : '250px';
    this.state = {
      currentTab: 12,
      currentTab2: 1,
      activeKey: ['1', '2', '3', '3-1'],
      processTableId: `processTableId_${commonUtils.createSid()}`,
      pageLoadingPage: false,
    };
    this.isLayout = false;
  }

  /**
   * 无法确认哪些接口billevent\base当前会调用, 修改地方太多
   * 简单解决loading问题
   * 忽略弹窗请求等类似问题，**当前弹窗控制以Visible结尾**
   */
  componentDidMount() {
    window.addEventListener('fetchCount', (e) => {
      const modalOption = Object.keys(this.props).map(i => i?.toString()?.endsWith('Visible') && i).filter(i => i && i !== 'colorConfigGrdVisible');
      if (modalOption.find(i => this.props[i]) || this.props.visible) return;
      if (e.detail.value > 0) {
        this.setState({
          pageLoadingPage: true
        })
      } else {
        this.setState({
          pageLoadingPage: false
        })
      }
    })
  }

  async componentWillReceiveProps(nextProps) {
    let {
      controlColumn, materialsColumn, processColumn, colorColumn, packColumn,
    } = nextProps;
    const { formData, currentId, sModelsId } = nextProps;
    if (commonUtils.isEmptyArr(controlColumn) && formData.length > 0) {
      const sId = currentId || nextProps.masterData?.sId || '';
      /* 数据Id */
      const masterConfig = formData.filter(item => !item.bGrd)[0];
      if(masterConfig && masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'bLayout')[0]) {
        this.isLayout = masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'bLayout')[0].bVisible;
      }
      /* bGrd代表是否是表格 */
      const slaveConfig = formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult')[0];
      const slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
      let checkConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.bGrd && item.sTbName === 'sysbillcheckresult')) ?
        formData.filter(item => item.bGrd && item.sTbName === 'sysbillcheckresult')[0] : {};
      let checkColumn = {};
      if(commonUtils.isNotEmptyObject(checkConfig)) {
        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);

      let finishedMaterialsConfig = commonUtils.isNotEmptyArr( formData.filter(item => item.sTbName.toUpperCase() === 'MftWorkOrderMaterials'.toUpperCase() && item.showName === '成品材料')) ?
        formData.filter(item => item.sTbName.toUpperCase() === 'MftWorkOrderMaterials'.toUpperCase() && item.showName === '成品材料')[0] : false;
      const finishedMaterialsColumn = finishedMaterialsConfig ? commonFunc.getHeaderConfig(finishedMaterialsConfig) : false;
     const addState2 ={};
      const addStateConfig ={};
      /* 取材料组配置放在数组 */
      let  materialsInfoList = [];
      let  materialsChildInfoList = [];
      let materialsFormData = formData.filter(item =>  item.sGrd && item.sGrd.includes('materials') && item.bGrdVisible );
      if(sModelsId === '12710101116950085152680') { /* 研发工单 不要成品材料 */
        materialsFormData = formData.filter(item =>  item.sGrd && item.sGrd.includes('materials') && item.bGrdVisible
          && item.showName !== '成品材料');
      }
      // const materialsFormData = formData.filter(item => item.sTbName !== 'mftworkordermaterials' && item.sGrd && item.sGrd.includes('materials') && item.bGrdVisible );
      /* 找到除了材料，成品材料外的其他所有父级材料 */

      if(commonUtils.isNotEmptyArr(materialsFormData)) {
        materialsFormData.forEach((item, index) => {
          addState2[`materials${index}Config`] = item;
          addStateConfig[`materials${index}Config`] = item;
          addState2[`materials${index}Column`] = commonFunc.getHeaderConfig(item);
          /* 找到该配置的子从表 */
          const childFormData =  formData.filter(child => child.sGrd === item.sChildTableName );
          if(commonUtils.isNotEmptyArr(childFormData)) {
            childFormData.forEach((child, num) => {
              addState2[`materials${index}ChildConfig`] = child;
              addStateConfig[`materials${index}ChildConfig`] = child;
              addState2[`materials${index}ChildColumn`] = commonFunc.getHeaderConfig(child);
              // materialsInfoList.push(child.showName);
              const sChildName = item.showName + num +1;
              materialsChildInfoList.push(`materials${index}Child`);
            });
          }
          materialsInfoList.push(`materials${index}`);
        });
      }
      const addStateMap = addStateConfig;

      const packingConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.sTbName.toUpperCase() === 'mftworkorderpacking'.toUpperCase())) ?
        formData.filter(item => item.sTbName.toUpperCase() === 'mftworkorderpacking'.toUpperCase())[0] : {};
      const packingColumn = commonUtils.isNotEmptyObject(packingConfig) ? commonFunc.getHeaderConfig(packingConfig) : 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 */
      let packConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.sTbName.toUpperCase() === 'mftworkordercontrolcombine'.toUpperCase())) ?
        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) && commonUtils.isNotEmptyObject(packConfig)) {
        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)) {
        if(commonUtils.isNotEmptyObject(packConfig)) {
          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 = commonUtils.isNotEmptyObject(packConfig) ?  commonFunc.getHeaderConfig(packConfig, packColumn) : [];
      let colorConfigGrdVisible;
      const colorConfigTrue = commonUtils.isNotEmptyArr(formData.filter(item => item.sTbName.toUpperCase() === 'mftproductchange'.toUpperCase())) ?
        formData.filter(item => item.sTbName.toUpperCase() === 'mftproductchange'.toUpperCase())[0] : {};

      if (commonUtils.isNotEmptyObject(colorConfigTrue)) {
        colorConfigGrdVisible = colorConfigTrue.bGrdVisible;
        if (colorConfigGrdVisible) {
          colorColumn = commonFunc.getHeaderConfig(colorConfigTrue, colorColumn);
        }
      }

      /* 改版信息表 */
      let visionConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.sTbName.toUpperCase() === 'sisrevision'.toUpperCase() &&  item.bGrdVisible )) ?
        formData.filter(item => item.sTbName.toUpperCase() === 'sisrevision'.toUpperCase() && item.bGrdVisible)[0] : {};
      let visionColumn = [];
      if (commonUtils.isNotEmptyObject(visionConfig)) {
        visionColumn = commonFunc.getHeaderConfig(colorConfigTrue, colorColumn);
        addStateConfig['visionConfig'] = visionConfig;
        addStateMap['visionConfig'] = visionConfig;
        addState2['visionColumn'] = visionColumn;
      }


      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;
        config.visionConfig = visionConfig;
        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.handleGetOtherData(materialsInfoList, materialsChildInfoList, addStateConfig);
      }
      this.setState({ activeKey: [...this.state.activeKey, ...materialsInfoList.map((_, index) => `1-${index}`)]});
      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,
        ...addState2,
        ...addStateConfig,
        addStateMap,
        materialsInfoList,
        materialsChildInfoList,
        colorConfigGrdVisible,
      });
    }
  }

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

  componentDidUpdate() {
    // 处理选择材料新增返回有时不更新问题
    const materialsId = this.getModalId('materials');
    if (materialsId) {
      const modalMaterials = document.querySelector(`.modalMaterials_${materialsId}`);
      if (!this.forbidForceUpdate && modalMaterials && modalMaterials.parentNode && modalMaterials.parentNode.parentNode && modalMaterials.parentNode.parentNode.style.display === 'none') {
        this.forbidForceUpdate = true;
        this.didUpdateTimer = setTimeout(() => {
          this.forbidForceUpdate = false;
        }, 1000);
        this.forceUpdate();
      }
    }
  }

  componentWillUnmount() {
    window.removeEventListener('fetchCount', () => { window.fetchCount = 0 });
  }

  /**   行选择   */
  // 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;
    }
  };


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

  handleEjectRight = () => { /* 右侧树形弹出展开 */
    const { currentPane, panes } = this.props.app;
    if (commonUtils.isNotEmptyArr(panes) && commonUtils.isNotEmptyObject(currentPane)) {
      // const index = panes.indexOf(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';

            const { masterData, slaveData, controlData, materialsData, processData }=this.props;
            if (commonUtils.isNotEmptyObject(masterData) && commonUtils.isNotEmptyArr(slaveData)) {
              const totalTreeState = this.handleGetTotalTreeData(masterData, slaveData, controlData, materialsData, processData, true);
              if (commonUtils.isNotEmptyObject(totalTreeState)) {
                const totalTreeData = totalTreeState.totalTreeData;
                const expandedKeys = totalTreeState.expandedKeys;
                if (commonUtils.isNotEmptyArr(totalTreeData)) {
                  this.props.onSaveState({
                    totalTreeData,
                    expandedKeys
                  });
                }
              }
            }

          }
        }
      }
    }

  };

  handleGetProcessData = (processConfig, addStateControl, addStateProcess) => {
    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.processSelectedRowKeys = [];
        addStateProcess.processSelectedRowKeys = [];
        if(commonUtils.isNotEmptyArr(addStateProcess.processData) && commonUtils.isNotEmptyArr(addStateControl?.controlSelectedRowKeys)) {
          const processFilterData = addStateProcess.processData.filter(item => item.sControlId === addStateControl?.controlSelectedRowKeys[0])
          if (commonUtils.isNotEmptyArr(processFilterData)) {
            addStateProcess.processSelectedData = [processFilterData[0]];
            addStateProcess.processSelectedRowKeys = [processFilterData[0].sId];
          }
        }
      }
    }
    return { ...addStateProcess || {} };
   }

  handleGetControlData = (addStateControl) => {
    const { sModelsType } = this.props; /* 当前页签数据 */
    const { controlData, controlSelectedRowKeys } = addStateControl; /* 同步树选中节点与部件选中节点 */
    const treeState = this.handleGetControlTreeData(controlData, true);
    const noSelected = sModelsType === 'manufacture/workOrderPackTableTree';
    return ({ ...addStateControl, ...treeState, treeSelectedKeys: noSelected ? [] : controlSelectedRowKeys });
  }

  handleGetAllData = (controlConfig, processConfig, sId, materialsConfig, colorConfig, packConfig, extraState) => {
    const { slaveData } = this.props; /* 当前页签数据 */

    const allRequest = [];

    if (commonUtils.isNotEmptyObject(controlConfig)) {
      allRequest.push(
        this.props.handleGetDataSet({
          name: 'control', configData: controlConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
        }),
      )
    } else {
      allRequest.push(Promise.reject());
    }

    if (commonUtils.isNotEmptyObject(processConfig)) {
      allRequest.push(
        this.props.handleGetDataSet({
          name: 'process', configData: processConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
        })
      )
    } else {
      allRequest.push(Promise.reject());
    }

    if (commonUtils.isNotEmptyObject(materialsConfig)) {
      allRequest.push(this.props.handleGetDataSet({
          name: "materials",
          configData: materialsConfig,
          condition: { sSqlCondition: { sParentId: sId } },
          isWait: true
        }));
    } else {
      allRequest.push(Promise.reject());
    }

    if (commonUtils.isNotEmptyObject(packConfig)) {
      allRequest.push(this.props.handleGetDataSet({
        name: 'pack', configData: packConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
      }));
    } else {
      allRequest.push(Promise.reject());
    }

    if (colorConfig) {
      allRequest.push(this.props.handleGetDataSet({
        name: 'color', configData: colorConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
      }))
    } else {
      allRequest.push(Promise.reject());
    }

    Promise.allSettled(allRequest).then(
      ([
        { status: controlStatus, value: addStateControl },
        { status: processStatus, value: addStateProcess },
        { status: materialsStatus, value: addStateMaterials },
        { status: packStatus, value: addStatePack },
        { status: colorStatus, value: addStateColor },
      ]) => {

      let result = {};

      if (controlStatus === 'fulfilled') {
        const controlValue = this.handleGetControlData(addStateControl);
        result = { ...result, ...controlValue };
      }

      if (processStatus === 'fulfilled') {
        const processValue = this.handleGetProcessData(processConfig, addStateControl, addStateProcess);
        result = { ...result, ...processValue };
      }

      if (materialsStatus === 'fulfilled') {
        addStateMaterials.materials0Data = addStateMaterials.materialsData;
        result = { ...result, ...addStateMaterials };
      }

      if (packStatus === 'fulfilled') {
        const { packData } = addStatePack;
        if (commonUtils.isNotEmptyArr(slaveData)) {
          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;
        result = { ...result, ...addStatePack };
      }

      if (colorStatus === 'fulfilled') {
        result = { ...result, ...addStateColor };
      }

      this.props.onSaveState({ ...result, pageLoading: false, ...extraState, })

    })
  }

  /* 获取表数据 */
  handleGetData = async (controlConfig, materialsConfig, processConfig, colorConfig, packConfig, extraState = {}) => {
    const { currentId, slaveData } = this.props; /* 当前页签数据 */
    const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */

    this.handleGetAllData(controlConfig, processConfig, sId, materialsConfig, colorConfig, packConfig, extraState);
  };


  handleGetOtherData = async (tableList, childTableList, configMap) => {
    const { currentId, slaveData, sModelsType, masterData } = this.props; /* 当前页签数据 */
    const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */
    if(commonUtils.isNotEmptyObject(configMap)){
      for (const configName of Object.keys(configMap)) {
        const tableName = configName.replace('Config', '').trim();
        const childConfig = configMap[configName];
        this.props.handleGetDataSet({
          name: tableName, configData: childConfig, condition: { sSqlCondition: { sParentId: sId } },
        });
      }

    }

  };

  /* 获取套件树形全部结构 */
  handleGetTotalTreeData= (masterData,slaveData,controlData,materialsData,processData, isWait) => {
    /* 生成部件树结构 */
    let totalTreeData = [];
    const expandedKeys = [];
    const addState ={};
    // let { totalTreeSelectedKeys } = this.props;
    if (commonUtils.isNotEmptyObject(masterData) && commonUtils.isNotEmptyObject(masterData.sProductName1)) {
      const rootData = [masterData]; /* 找到所有一级树结构 */
      rootData.forEach((item) => {
        const treeDataRoot = {};
        const { sId, sProductName1 } = item;
        treeDataRoot.key = sId;
        treeDataRoot.showName = sProductName1;
        treeDataRoot.sAllId = item.sId;
        expandedKeys.push(sId);
        /* 添加从表作为二级节点 */
        const childrenSlave = [];
        let bRelation = false; /* 从表与控制表没有关联性 */
        if(commonUtils.isNotEmptyArr(slaveData)){
          slaveData.forEach((itemSlave,index) => {
            const { sId, sProductName } = itemSlave;
            const treeSlaveRow = {};
            treeSlaveRow.key = sId;
            treeSlaveRow.showName ='产品-'+ sProductName;
            treeSlaveRow.sAllId = itemSlave.sId;
            /* 获取从表关联的控制表 */
            const childrenControl = [];
            if(commonUtils.isNotEmptyArr(controlData)){
              const controlCollection =[];
              controlData.forEach((itemControl) => {
                if(itemControl.sCombinedMemo && itemControl.sCombinedMemo !== '') {
                  const sCombinedMemoArr = commonUtils.isJSON(itemControl.sCombinedMemo) ? JSON.parse(itemControl.sCombinedMemo) : [];
                  const len = sCombinedMemoArr.filter(item => item.sProductNo.indexOf(itemSlave.sProductNo) !== -1).length;
                  if(len > 0) {
                    const sAllId =itemControl.sAllId;
                    /* 找到这个sAllId的第一级 把整个部件挂到产品下面 */
                    if (commonUtils.isNotEmptyObject(sAllId)) {
                      const arr = sAllId.split(',');
                      if (arr.length > 0){
                        const firstsId =arr[0]; /* 从sAllId找第一级*/
                        if(!controlCollection.includes(firstsId)){
                          controlCollection.push(firstsId)
                        }
                      }
                    }
                  }
                }
              });
              if(commonUtils.isNotEmptyArr(controlCollection)){ /* 作为子表子级 */
                bRelation =true;
                for (const key of controlCollection) {
                  const iIndex =controlData.findIndex(item => item.sId === key);
                  if(iIndex > -1) {
                    const tableRow = controlData[iIndex];
                    const { sId,sAllId } = tableRow;
                    const treeControlRow = {}
                    treeControlRow.key = sId + '-' +commonUtils.createSid();
                    treeControlRow.showName = '部件-' + tableRow.sPartsName;
                    treeControlRow.sAllId = sAllId;
                    /* 控制表根据一级菜单获取子集 */
                    let childrenChild = [];
                    childrenChild = this.handleGetControlTreeChildData(sId, controlData,materialsData,processData);
                    let sChildren = '1'; /* 树形结构最后一个节点设置为1 */
                    if (commonUtils.isNotEmptyArr(childrenChild)) {
                      sChildren = '0'; /* 树形结构其他节点设置为0 */
                    }
                    treeControlRow.sChildren = sChildren;
                    treeControlRow.children = commonUtils.isNotEmptyArr(childrenChild) ? childrenChild : [];

                    childrenControl.push(treeControlRow);


                  }
                };
              }
            }

            treeSlaveRow.children = commonUtils.isNotEmptyArr(childrenControl) ? childrenControl : [];
            childrenSlave.push(treeSlaveRow);

            /* 如果从表与控制表没有关联 */
            if(!bRelation){
              controlData.forEach((itemControl) => {
                const { sId,sAllId,sPartsName } = itemControl;
                const treeControlRow = {}
                treeControlRow.key = sId + '-' +commonUtils.createSid();
                treeControlRow.showName = '部件-' + sPartsName;
                treeControlRow.sAllId = sAllId;
                treeControlRow.sId =sId;
                /* 控制表根据一级菜单获取子集 */
                let childrenChild = [];
                childrenChild = this.handleGetControlTreeChildData(sId, controlData,materialsData,processData);
                let sChildren = '1'; /* 树形结构最后一个节点设置为1 */
                if (commonUtils.isNotEmptyArr(childrenChild)) {
                  sChildren = '0'; /* 树形结构其他节点设置为0 */
                }
                treeControlRow.sChildren = sChildren;
                treeControlRow.children = commonUtils.isNotEmptyArr(childrenChild) ? childrenChild : [];
                const filterData =childrenSlave.filter(item => item.sId ===treeControlRow.sId);
                if(commonUtils.isEmptyArr(filterData)){
                  childrenSlave.push(treeControlRow);
                }
              });
            }

            /* 加载成品材料、成品工序作为从表的同级 */
            if(commonUtils.isNotEmptyArr(materialsData)){
              const childTree = commonUtils.isNotEmptyArr(materialsData) ? materialsData.filter(item => item.sType === 2) : [];
              if (commonUtils.isNotEmptyArr(childTree)) {
                childTree.forEach((child) => {
                  const { sId, sMaterialsName,sPartsName } = child;
                  const treeDataRow = {};
                  treeDataRow.key = sId;
                  treeDataRow.showName = '成品材料' +'-'+  sMaterialsName;
                  treeDataRow.sAllId = child.sAllId;
                  childrenSlave.push(treeDataRow);
                });
              }
            }
            /* 获取工序表 */
            if(commonUtils.isNotEmptyArr(processData)){
              const childTree = commonUtils.isNotEmptyArr(processData) ? processData.filter(item => item.sType === 3) : [];
              if (commonUtils.isNotEmptyArr(childTree)) {
                childTree.forEach((child) => {
                  const { sId, sProcessName,sPartsName  } = child;
                  const treeDataRow = {};
                  treeDataRow.key = sId;
                  treeDataRow.showName = '成品工序' +'-'+  sProcessName;
                  treeDataRow.sAllId = child.sAllId;
                  childrenSlave.push(treeDataRow);
                });
              }
            }




            if(!expandedKeys.includes(sId)){
              expandedKeys.push(sId);
            }
          });
          treeDataRoot.children = commonUtils.isNotEmptyArr(childrenSlave) ? childrenSlave : [];
        }
        totalTreeData.push(treeDataRoot);
      });
    } else {
      totalTreeData = [];
    }
    addState.totalTreeData=totalTreeData;
    addState.expandedKeys=expandedKeys;
    if (isWait) {
      return { ...addState };
    } else {
      this.props.onSaveState({
        totalTreeData,
        expandedKeys,
      });
    }
  };

  /**   获取部件树   */
  handleGetControlTreeData= (controlData, isWait) => {
    /* 生成部件树结构 */
    let treeData = [];
    if (isWait) {
      return { treeData };
    } else {
      this.props.onSaveState({
        treeData,
        // expandedKeys,
      });
    }
  };

  handleGetControlTreeDataBak= (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 (flag) => {
    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,
    });

    let dataReturn = paramMap;
    if (!flag) {
      const url = `${commonConfig.server_host}calculationStd/countMoney?sModelsId=${sModelsId}`;
      dataReturn = (await commonServices.postValueService(token, paramMap, url)).data;
    }
    if (dataReturn.code === 1 || flag) {
      const {
        productClassify, productProcessInfo, partsInfo: partsOldInfo,
      } = flag ? dataReturn : dataReturn.dataset.rows[0];
      let partsNewInfo = [];
      if (!flag) {
        partsNewInfo = dataReturn.dataset.rows[0].partsNewInfo;
      } else {
        partsNewInfo = partsOldInfo;
      }
      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 = false;
      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 && 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 || partInfo.sPrintProcessId;
        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;
        if (partInfo.sProcessName) {
          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,
      });
    }
    if (dataReturn.code !== 1 && !flag) {
      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 () => {
    // 判断控制表不能为空--开始
    // let len = this.handleCheckControlLen();
    // if (!len) {
    //   message.error('请选择部件');/* 请填写从表数据 */
    //   this.props.onSaveState({
    //     loading: false,
    //     calculated: false,
    //   });
    //   return;
    // }
    // 判断控制表不能为空--结束
    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,
          materials0Config: materialsConfig, materials0Data: materialsData, materials0DelData: materialsDelData, processConfig, processData, processDelData, colorConfig,
          colorData, colorDelData, packConfig, packData, packDelData, app, calculated, sModelsType, addStateMap
        } = 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)) {
          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 (sModelsType.includes('manufacture/workOrder') && !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));

          if(commonUtils.isNotEmptyObject(addStateMap)){
            for (const childConfig of Object.keys(addStateMap)) {
              const tableName = childConfig.replace('Config', '').trim();
              const { [`${tableName}Data`]: tableData,[`${tableName}Config`]: tableConfig, [`${tableName}DelData`]: tableDelData} = this.props;
              if(tableConfig.sTbName !== 'noTable') {
                data.push(commonBusiness.mergeData(tableName, tableConfig.sTbName, tableData, tableDelData));
              }
            }
          }

          this.props.onSaveData({
            data, sClientType: '1', loading: false, sSysLogSrcId: masterData.sId,
          });
        }
      }
    });
  };

  /**   处理选择行发生改变   */
  handleTableSelectRowChange = async (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 , masterData} = this.props;
      const addState = await this.props.onTableSelectRowChange(name, selectedRowKeys, null, 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];
        }
        if(name === 'process') {
          addState.processSelectedData = [tableData[iIndex]];
          addState.processSelectedRowKeys = selectedRowKeys;
          const sTypeName = 'sWorkOrderParam';
          /* 把工艺参数塞入masterData */
          const sParams = commonUtils.isNotEmptyArr(addState.processSelectedData) ?   addState.processSelectedData[0].sParams : '';
          const sParamData = commonUtils.isNotEmptyObject(sParams) && commonUtils.isJSON(sParams) ? JSON.parse(sParams) : [];
          tableData[iIndex] = { ... tableData[iIndex], ...commonUtils.convertStrToObj( tableData[iIndex].sWorkOrderParam) };
          const viewRow = tableData[iIndex];

          /* 把sParams的数据替换到viewRow */
          if(commonUtils.isNotEmptyArr(sParamData)) {
            for (const key of Object.keys(viewRow)) {
              if(key.includes('sParam')){
                const filterData = sParamData.filter(item => item.sParamKey === key);
                if(commonUtils.isNotEmptyArr(filterData)){
                  const num = key.replace('sParam', '').trim();
                  const newKey = `${key}_${sTypeName}_${addState.processSelectedData[0].sId}`;
                  const newDefalut = 'sParamDefault' + num;
                  masterData[newKey] = filterData[0].sParamValue;
                  // masterData[key] = filterData[0].sParamValue;
                }
              }
            }
          }
          addState.masterData = masterData;

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

  handleShowParam = (processSelectedData, masterData) => {
    const sTypeName = 'sWorkOrderParam';
    /* 把工艺参数塞入masterData */
    const sParams = commonUtils.isNotEmptyArr(processSelectedData) ?   processSelectedData[0].sParams : '';
    const sParamData = commonUtils.isNotEmptyObject(sParams) ? JSON.parse(sParams) : [];
    let viewRow ={ ...processSelectedData[0], ...commonUtils.convertStrToObj(processSelectedData[0].sWorkOrderParam)};
    /* 把sParams的数据替换到viewRow */
    if(commonUtils.isNotEmptyArr(sParamData)) {
      for (const key of Object.keys(viewRow)) {
        if(key.includes('sParam')){
          const filterData = sParamData.filter(item => item.sParamKey === key);
          if(commonUtils.isNotEmptyArr(filterData)){
            const num = key.replace('sParam', '').trim();
            const newKey = `${key}_${sTypeName}_${processSelectedData[0].sId}`;
            const newDefalut = 'sParamDefault' + num;
            masterData[newKey] = filterData[0].sParamValue;
            // masterData[key] = filterData[0].sParamValue;
          }
        }
      }
    }
    return masterData;
  }

  /** 控制选择控制表时，显示部件工序与成品工序 */
  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') {
        let iIndex = -1;
        if (bFinished) {
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "BtnChooseProductMaterials");
          if (iIndex > -1) {
            this.props.onBtnChoose('productMaterials', 'materials', masterConfig.gdsconfigformslave[iIndex]);
          }
        } else {
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "BtnChooseMaterials");
          if (iIndex > -1) {
            this.props.onBtnChoose('materials', 'materials', masterConfig.gdsconfigformslave[iIndex]);
          }
        }
      }
      if(name === 'process') {
        let iIndex = -1;
        if (bFinished) {
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "BtnChooseProductProcess");
          if (iIndex > -1) {
            this.props.onBtnChoose('productProcess', 'process', masterConfig.gdsconfigformslave[iIndex]);
          }
        } else {
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "BtnChooseProcess");
          if (iIndex > -1) {
            this.props.onBtnChoose('process', 'process', masterConfig.gdsconfigformslave[iIndex]);
          }
        }
      }
      return;
    }
    /*   外置处理业务   */
    const {
      gdsformconst, slaveData, controlData, controlSelectedRowKeys, slaveSelectedRowKeys, [`${name}Data`]: tableData,
    } = this.props;
    let { packData }=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}`;
        }
      }
      if(bchild !=='sameNode' && bchild !=='childNode') { /* 列头新增 */
        tableDataRow.sAllId = tableDataRow.sId;
      }
      let slaveSelectedRow = {};
      if(commonUtils.isNotEmptyArr(slaveSelectedRowKeys)){ /* 从表有选中行 */
        const iSlaveIndex = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId));
        if(iSlaveIndex > -1){
          slaveSelectedRow = slaveData[iSlaveIndex];
        }
      }else{ /* 没有选中行 */
        if(slaveData.length ===1){
          slaveSelectedRow =slaveData[0];
        }else{
          message.error('请选择从表！')
        }
      }

      /* 新增工艺卡，部件名称要默认选中从表行的产品名称 */
      tableDataRow.sPartsName = slaveSelectedRow.sProductName;

      /* 部件表新增时,若合版表没有该sControlId 则默认取从表选中行,合拼1 作为一条packData数据 */
      if(commonUtils.isEmptyArr(packData)){
        packData =[];
      }
      if(false){
        packData =[];
      } else{
        const iIndex =packData.findIndex(item=> item.sControlId === tableDataRow.sId);
        if(iIndex ===-1){

          if(commonUtils.isEmptyObject(slaveSelectedRow.sProductId)) {
            message.error('请先选择产品！');
            return;
          }
          if(slaveSelectedRow){
            const packDataRow = this.handlePackDataAdd(slaveSelectedRow, 0, tableDataRow.sId, 'add');
            packDataRow.dCombineQty = 1; /* 排版数 */
            if(commonUtils.isNotEmptyObject(packDataRow) && commonUtils.isNotEmptyObject(packDataRow.sProductId)){ /* 从表要选择产品 */
              const { sId, sProductNo, dProductQty, dCombineQty, dFactProductQty,sCombinePartsName  }= packDataRow;
              const tableCombineSelectedData =[];
              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);
              const sCombinedMemo = commonUtils.isNotEmptyArr(tableCombineSelectedData) ? JSON.stringify(tableCombineSelectedData) : ''; /* JSON对象转换为字符串存放到合版信息中 */
              tableDataRow.sCombinedMemo =commonUtils.isNotEmptyObject(sCombinedMemo)? sCombinedMemo: '合版信息';
            }
            packData.push(packDataRow);
          }

        }
      }

      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], packData,
      });
    } 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 } = this.props;
      let { expKeys }= this.props;
      if(commonUtils.isEmptyArr(expKeys)) {
        expKeys = [];
      }
      const tableDataRow = this.props.onDataRowAdd(name, true);
      if (commonUtils.isNotEmptyArr(slaveData) && commonUtils.isEmptyArr(tableSelectedRowKeys)) {
        message.warning(commonFunc.showMessage(app.commonConst, 'selectedRowKeysNo'));
        return;
      }
      if (bchild === 'childNode') { /* 添加子级 */
        tableDataRow.sFatherSlaveId = tableSelectedRowKeys[0];
        const iIndex = tableData.findIndex(item => item.sId === tableSelectedRowKeys[0]);
        if (iIndex > -1) {
          const sAllId = commonUtils.isNotEmptyObject(tableData[iIndex].sAllId)?  tableData[iIndex].sAllId : tableData[iIndex].sId;
          if (commonUtils.isEmptyObject(sAllId)) {
            message.warn('子部件数据生成错误！[sAllId为空]'); // 获取父节点的sAllId
            return;
          }
          tableDataRow.sAllId = `${tableData[iIndex].sAllId},${tableDataRow.sId}`;
          tableDataRow.sCustomerId = tableData[iIndex].sCustomerId;
          tableDataRow.sCustomerName= tableData[iIndex].sCustomerName;
        }
        /* 新增子级时 子级展开 */
        expKeys.push(tableSelectedRowKeys[0]); /* 展开只要展开父级即可 */
      }
      if(bchild !=='sameNode' && bchild !=='childNode') { /* 列头新增 */
        tableDataRow.sAllId = tableDataRow.sId;
      }
      console.log(333, tableDataRow);
      tableData.push(tableDataRow);
      this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId], expKeys });
    } 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, [`${name}SelectedRowKeys`]: tableSelectedRowKeys } = this.props;
      let { treeSelectedKeys } = this.props;
      if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) {
        const iIndex = controlData.findIndex(item => tableSelectedRowKeys.includes(item.sId) && item.rowTag === 1);
        if (iIndex > -1) {
          /* 如果行被锁定不可更改删除时 */
          return false;
        }
        /* 删除该节点及所有子节点 */
        treeSelectedKeys = treeSelectedKeys || [];
        const controlChildData = controlData.filter(item => commonUtils.isNotEmptyObject(item.sAllId) && item.sAllId.indexOf(tableSelectedRowKeys[0]) > -1 && item.sId !== tableSelectedRowKeys[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);
      /* 删除工序对应的材料 */
      const materialsFilterDelData = materialsData.filter(item  => tableSelectedRowKeys.includes(item.sProcessTbId) && item.sProcessId === sProcessId );
      let materialsSelectedDelRowKeys = [];
      if(commonUtils.isNotEmptyArr(materialsFilterDelData)) {
        materialsFilterDelData.forEach((item) =>{
          const materialsChildFilter = materialsData.filter(row => commonUtils.isNotEmptyObject(row.sParentMaterialsId ) && row.sParentMaterialsId === item.sId); /* 删除对应的替代料 */
          if(commonUtils.isNotEmptyArr(materialsChildFilter)) {
            materialsChildFilter.forEach((child) =>{
              materialsSelectedDelRowKeys.push(child.sId);
            })
          }
          materialsSelectedDelRowKeys.push(item.sId);
        })
      }
      let materialsReturnData = {};
      if (commonUtils.isNotEmptyArr(materialsSelectedDelRowKeys)) {
        materialsReturnData = this.props.onDataRowDel('materials0', true, materialsSelectedDelRowKeys);
        if(commonUtils.isNotEmptyObject(materialsReturnData) && commonUtils.isNotEmptyArr(materialsReturnData.materials0DelData)) {
          materialsReturnData.materials0DelData = materialsReturnData.materials0DelData.concat(materialsDelData);
        }
      }
      this.props.onSaveState({
        ...processReturnData,
          ...materialsReturnData,
        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;
          });
        }
      }
    }
  }

  handleCheckControlLen = () => {
    let controlTableData = [];
    if(commonBusiness.getTableTypes('control', this.props).data && commonUtils.isNotEmptyObject(this.props) && commonUtils.isNotEmptyObject(this.props.slaveData)) {
      const iSlaveIndex = this.props.slaveData.findIndex(item => item.sId === this.props.slaveSelectedRowKeys[0]);
      const slaveSelectedRow = this.props.slaveData[iSlaveIndex] || {sProductNo: 0};
      if(iSlaveIndex !== -1) {
        commonBusiness.getTableTypes('control', this.props).data.forEach(item => {
          if(item.sCombinedMemo && item.sCombinedMemo !== '' && item.sCombinedMemo !== '合版信息') {
            const sCombinedMemoArr = commonUtils.isJSON(item.sCombinedMemo) ? JSON.parse(item.sCombinedMemo) : [];
            const len = sCombinedMemoArr.filter(item => item.sProductNo && item.sProductNo.indexOf(slaveSelectedRow.sProductNo) !== -1).length;
            if(len) {
              controlTableData.push(item);
            }
          } else {
            controlTableData.push(item);
          }
        })
      } else {
        controlTableData = commonBusiness.getTableTypes('control', this.props).data;
      }
    }
    return controlTableData.length;
  }

  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,
      addStateMap, materials0Config, materials0DelData,
    } = this.props;
    // 判断控制表不能为空--开始
    // let len = this.handleCheckControlLen();
    // if (!len) {
    //   message.error('请选择部件');/* 请填写从表数据 */
    //   this.props.onSaveState({
    //     loading: false,
    //     calculated: false,
    //   });
    //   return;
    // }
    // 判断控制表不能为空--结束
    let {
      slaveData, packData, controlData, materialsData, processData, masterData, materials0Data,
    } = 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', `${materials0Config.sTbName.toLowerCase()}_tmp`, materials0Data, [], 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`];
      materials0Data = valueReturn[`${materials0Config.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', materials0Config.sTbName, materials0Data, materials0DelData));
        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));
        if(commonUtils.isNotEmptyObject(addStateMap)){
          for (const childConfig of Object.keys(addStateMap)) {
            const tableName = childConfig.replace('Config', '').trim();
            const { [`${tableName}Data`]: tableData,[`${tableName}Config`]: tableConfig, [`${tableName}DelData`]: tableDelData} = this.props;
            if(tableConfig.sTbName !== 'noTable' && tableConfig.sTbName!=='MftWorkOrderMaterials') {
              data.push(commonBusiness.mergeData(tableName, tableConfig.sTbName, tableData, tableDelData));
            }
          }
        }

        this.props.onSaveData({
          data, sClientType: '1', loading: false, sSysLogSrcId: masterData.sId,
        });
        this.props.onSaveState({
          slaveData, packData, controlData,  materials0Data, processData, masterData, loading: false, calculated: true,
        });
      } else {
        this.props.onSaveState({
          slaveData, packData, controlData,  materials0Data, 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, packConfig, packData, packDelData,
      } = 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(packConfig)) {
        packConfig.gdsconfigformslave.forEach((itemConfig) => {
          packData.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));
      }
      if (commonUtils.isNotEmptyObject(packConfig)) {
        data.push(commonBusiness.mergeData('pack', packConfig.sTbName, packData, packDelData));
      }
      this.props.onSaveData({
        data, sClientType: '1', loading: false, sSysLogSrcId: masterData.sId, bIsUnCcg: false,
      });
    }  else if(name === 'BtnWorkFlow') {
      const dataUrl = `${commonConfig.server_host}workOrderFlow/getWorkOrderFlow/`;
      let {token} = this.props.app
      let { slaveData, controlData, materialsData, processData, packData} = this.props
      const value = {
        slave:slaveData,
        control:controlData,
        materials:materialsData,
        process:processData,
        pack:packData
      }
      let dataReturn = (await commonServices.postValueService(token,value,dataUrl)).data;
      if (commonUtils.isNotEmptyObject(dataReturn)) {
        if (dataReturn.code === 1) {
          const flowData = dataReturn.dataset.rows[0];
          console.log(flowData);
          if (commonUtils.isNotEmptyObject(flowData)) {
            this.props.onSaveState({
              flowData: flowData,workFlowVisible:true
            });
            // localStorage.setItem('flow', JSON.stringify(flowData));
          }
        } else {
          this.props.getServiceError(dataReturn);
        }
      }
    } else {
      this.props.onButtonClick(name);
    }
  };

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

  /*   单据页复制到   */
  handleCopyTo = async (name, sActiveId) => {
    /*   待用数据声明   */
    const {
      masterConfig, masterData, slaveData, controlData, materialsData, processData, colorData, packData, app, token, sModelsId, formRoute, visionData,
    } = 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;
    copyTo.visionData = visionData;
    copyTo.srcFormRoute = formRoute; /* 来源路由 */
    copyTo.oldFormId = sModelsId; /* 生成前的模块ID */
    copyTo.newFormId = sActiveId;  /* 生成后的模块ID */
    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;
    const getDataNew = this.getDataNew;
    dispatch({
      type: 'content/onRouter',
      payload: {
        url: `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}`, /*   接口地址   */
        copyTo,
        refresh: getDataNew.bind(this),
        sSrcModelsId: this.props.sModelsId
      },
    });
  };

  getDataNew = () => {
    const { masterConfig, slaveConfig, checkConfig, controlConfig, materialsConfig, processConfig, colorConfig, packConfig, materialsInfoList, materialsChildInfoList, visionConfig } = this.props;
    this.props.onGetData(masterConfig, slaveConfig, checkConfig);
    this.handleGetData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig);
    const addStateConfig = {};
    addStateConfig['visionConfig'] = visionConfig;
    this.handleGetOtherData(materialsInfoList, materialsChildInfoList, addStateConfig);
  }


  /* 确定要删除 */
  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 materials0Data = []; /* 全部材料 */
    let processData = [];
    const colorData = [];
    const visionData = [];
    /* 主表配置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;
      const bCopyFromProcessCard =  (commonUtils.isNotEmptyObject(copyTo.oldFormId) && copyTo.oldFormId === copyTo.newFormId) || sModelsType === 'manufacture/workOrder2';
      if (bCkxCopyFromTechnology === '1' && !bCopyFromProcessCard) {
        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, sRowData:  copyTo.slaveData || [] };
          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 copyToSlaveConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slave`.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 slaveAssignField = commonUtils.isNotEmptyObject(copyToSlaveConfig) ? copyToSlaveConfig[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 = false;
            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) }; // 取赋值字段
                state.masterData = masterData;
              }
              if (commonUtils.isNotEmptyArr(returnData.slaveData)) {
                if (slaveData.length === 1 && returnData.slaveData.length ===1){ /* 从表与返回数据从表只有一条时 替换该从表数据  */
                  // masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, returnData.slaveData[0], newCopyTo) }; // 取赋值字段
                  slaveData.forEach((item, iSlaveIndex) => {
                    item = { ...item, ...commonFunc.getAssignFieldValue(slaveDetailAssignField, returnData.slaveData[0], newCopyTo) }; // 取赋值字段
                    slaveData[iSlaveIndex] = 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);
                    }
                  });
                } else {
                  // slaveData =[];
                  returnData.slaveData.forEach((slaveItem) => {
                    newCopyTo.slave = slaveItem;
                    const iSameIndex = commonUtils.isNotEmptyArr(slaveData) ?  slaveData.findIndex(itemCurrent => itemCurrent.sProductId === slaveItem.sProductId  && itemCurrent.sCustomerId  === slaveItem.sCustomerId) : -1;
                    if(iSameIndex > -1){
                      masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, slaveItem, newCopyTo) }; // 取赋值字段
                      slaveData[iSameIndex] = { ...slaveData[iSameIndex], ...commonFunc.getAssignFieldValue(slaveAssignField, slaveItem, newCopyTo) }; // 取赋值字段
                      slaveData[iSameIndex].sOriginalId = commonUtils.isNotEmptyObject(slaveItem.sSlaveId) ? slaveItem.sSlaveId : slaveItem.sId;  /* 原始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 {
                      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);
                    }
                  });
                }
              }
              // 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 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) => {
                    // eslint-disable-next-line radix
                    if (true) {
                      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;
                    materialsRow.sOriginalId = materialsItem.sId;
                    materialsRow.sZmldlt = materialsItem.sZmldlt;
                    materialsRow.sInkFatherMaterialsTbId = materialsItem.sInkFatherMaterialsTbId;
                    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);
                  });
                }
                /* 将 materialsData中sParentMaterialsId替换为最新的sid */
                if(commonUtils.isNotEmptyArr(materialsData)) {
                  const materialsFilterData = materialsData.filter(item => commonUtils.isNotEmptyObject(item.sParentMaterialsId));
                  if(commonUtils.isNotEmptyArr(materialsFilterData)) {
                    materialsFilterData.forEach((filterItem, index) => {
                      const iIndex = materialsData.findIndex(item => item.sOriginalId === filterItem.sParentMaterialsId);
                      if(iIndex > -1) {
                        const iNexIndex = materialsData.findIndex(item => item.sId === filterItem.sId);
                        if (iNexIndex > -1) {
                          materialsData[iNexIndex] = {...materialsData[iNexIndex], sParentMaterialsId: materialsData[iIndex].sId }
                        }
                      }

                    });
                  }

                  const materialsInkFilterData = materialsData.filter(item => commonUtils.isNotEmptyObject(item.sInkFatherMaterialsTbId));
                  if(commonUtils.isNotEmptyArr(materialsInkFilterData)) {
                    materialsInkFilterData.forEach((filterItem, index) => {
                      const iIndex = materialsData.findIndex(item => item.sOriginalId === filterItem.sInkFatherMaterialsTbId);
                      if(iIndex > -1) {
                        const iNexIndex = materialsData.findIndex(item => item.sId === filterItem.sId);
                        if(iNexIndex > -1) {
                          materialsData[iNexIndex] = { ...materialsData[iNexIndex], sInkFatherMaterialsTbId: materialsData[iIndex].sId}
                        }
                      }
                    });
                  }
                }

              });
            }
            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)) {
              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 (false && 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 copyToVisionConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.vision`.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 visionAssignField = commonUtils.isNotEmptyArr(copyToVisionConfig) ? copyToVisionConfig[0].sAssignField : '';

        const newCopyTo = {};
        newCopyTo.master = copyTo.masterData;
        newCopyTo.slave = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
        let bProcessAssort = false;
        /* 生产翻单不生成配套工序 */
        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 (commonUtils.isNotEmptyArr(copyTo.visionData)) {
          if (commonUtils.isNotEmptyObject(config.visionConfig)) {
            copyTo.visionData.forEach((visionItem) => {
              newCopyTo.vision = visionItem;
              let visionRow = commonFunc.getDefaultData(config.visionConfig, newCopyTo); // 取默认值
              visionRow = { ...visionRow, ...commonFunc.getAssignFieldValue(visionAssignField, visionItem, newCopyTo) }; // 取赋值字段
              visionRow.handleType = 'add';
              visionRow.sId = commonUtils.createSid();
              visionRow.sParentId = masterData.sId;
              visionData.push(visionRow);
            });
          }
        }
      }
      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;

      if(commonUtils.isEmptyObject(tableDataRow.sPartsName)) {
        tableDataRow.sPartsName = commonUtils.isNotEmptyArr(slaveData) ? slaveData[0].sProductName : '';
      }

      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;
      /* 点击新增按钮 控制表自动默认增一条 同时默认新增一条合版表 */
      if(commonUtils.isNotEmptyArr(slaveData) && slaveData.length === 1 && commonUtils.isEmptyArr(packData)){
        const packDataRow = this.handlePackDataAdd(slaveData[0], 0, tableDataRow.sId, 'add');
        packDataRow.dCombineQty = 1; /* 排版数 */
        if(commonUtils.isNotEmptyObject(packDataRow) && commonUtils.isNotEmptyObject(packDataRow.sProductId)){ /* 从表要选择产品 */
          const { sId, sProductNo, dProductQty, dCombineQty, dFactProductQty,sCombinePartsName  }= packDataRow;
          const tableCombineSelectedData =[];
          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);
          const sCombinedMemo = commonUtils.isNotEmptyArr(tableCombineSelectedData) ? JSON.stringify(tableCombineSelectedData) : ''; /* JSON对象转换为字符串存放到合版信息中 */
          tableDataRow.sCombinedMemo =commonUtils.isNotEmptyObject(sCombinedMemo)? sCombinedMemo: '合版信息';
        }
        packData.push(packDataRow);
      }
      controlData.push(tableDataRow);
    }
    const treeState = this.handleGetControlTreeData(controlData, true); /* 加载树形结构数据 */
    const stateNew = {
      ...state,
      ...treeState,
      slaveData,
      controlData,
      controlSelectedRowKeys: [],
      packData,
      packSelectedRowKeys: [],
      materialsData,
      materials0Data: materialsData,
      materialsSelectedRowKeys: [],
      processData,
      processSelectedRowKeys: [],
      colorData,
      colorSelectedRowKeys: [],
      visionData,
      visionSelectedRowKeys: [],
      checkProcessClassifyData: [],
    };
    if (isWait) {
      return stateNew;
    } else {
      this.props.onSaveState(stateNew);
    }
  };

  handleSelect = async (name, selectConfig, selectData) => {
    if(name ==='materials') {
      name = 'materials0';
    }
    const {
      [`${name}Data`]: tableData, [`${name}Config`]: tableConfig, masterConfig, controlSelectedRowKeys,processSelectedRowKeys, 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 (commonUtils.isNotEmptyObject(selectConfig) && selectConfig.sControlName.includes('TmpInfoBySql')) { /* 复制从部件 根据配置下拉sql获取数据源 通过按钮名称是否包含add来判断数据源新增还是删除 */
      const addState = {};
      let controlData = commonUtils.isEmptyArr(controlDataOld) ? [] : controlDataOld;
      let materialsData = commonUtils.isEmptyArr(materialsDataOld) ? [] : materialsDataOld;
      let processData = commonUtils.isEmptyArr(processDataOld) ? [] : processDataOld;
      let colorData = commonUtils.isEmptyArr(colorDataOld) ? [] : colorDataOld;


      const config = {};
      config.masterConfig = masterConfig;
      config.slaveConfig = slaveConfig;
      config.controlConfig = controlConfig;
      config.materialsConfig = materialsConfig;
      config.processConfig = processConfig;
      config.colorConfig = colorConfig;
      config.packConfig = packConfig;


      const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfoBySql/?sModelsId=${sModelsId}`;
      const sConfigformId = commonUtils.isEmpty(selectConfig) ? '' : selectConfig.sParentId;
      const sRowData = selectData;
      const sControlName =  selectConfig.sControlName; /* 按钮名称 */
      // const sSqlCondition = { sId: selectData[0].sSlaveId }; /* 后台根据rowData自己取 */
      const condition = { sConfigformId, sControlName, sRowData };
      const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
      console.log('aaaadataReturn', dataReturn);
      if (dataReturn.code === 1) {
        const copyTo = { config: masterConfig.gdsconfigformslave, name: selectConfig.sControlName };
        const returnDataSet = dataReturn.dataset.rows[0];
        const returnData = {};
        const copyToMasterDetailConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}`.toLowerCase());
        const copyToSlaveDetailConfig = copyTo.config.filter(item => item.sControlName.toLowerCase().replace('_add','').replace('_edit','').trim() === `${copyTo.name}.slave`.toLowerCase());
        const copyToControlConfig = copyTo.config.filter(item => item.sControlName.toLowerCase().replace('_add','').replace('_edit','').trim() === `${copyTo.name}.control`.toLowerCase());
        const copyToMaterialsConfig = copyTo.config.filter(item => item.sControlName.toLowerCase().replace('_add','').replace('_edit','').trim() === `${copyTo.name}.materials`.toLowerCase());
        const copyToProcessConfig = copyTo.config.filter(item => item.sControlName.toLowerCase().replace('_add','').replace('_edit','').trim() === `${copyTo.name}.process`.toLowerCase());
        const masterDetailAssignField = commonUtils.isNotEmptyArr(copyToMasterDetailConfig) ? copyToMasterDetailConfig[0].sAssignField : '';
        const slaveDetailAssignField = commonUtils.isNotEmptyArr(copyToSlaveDetailConfig) ? copyToSlaveDetailConfig[0].sAssignField : '';
        const copyToColorConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.param`.toLowerCase());
        const controlAssignField = commonUtils.isNotEmptyArr(copyToControlConfig) ? copyToControlConfig[0].sAssignField : '';
        const materialsAssignField = commonUtils.isNotEmptyArr(copyToMaterialsConfig) ? copyToMaterialsConfig[0].sAssignField : '';
        const processAssignField = commonUtils.isNotEmptyArr(copyToProcessConfig) ? copyToProcessConfig[0].sAssignField : '';
        const colorAssignField = commonUtils.isNotEmptyArr(copyToColorConfig) ? copyToColorConfig[0].sAssignField : '';

        /* 判断是插入 还是删除  */
        if(commonUtils.isNotEmptyArr(copyToControlConfig)) {
          if(commonUtils.isNotEmptyArr(controlSelectedRowKeys)) {
            if(!copyToControlConfig[0].sControlName.includes('_add') && !copyToControlConfig[0].sControlName.includes('_edit')) { /* 删除 */
              controlData = [];
              const controlDelData = commonUtils.isEmptyArr(controlDelDataOld) ? [] : controlDelDataOld;
              const controlDataFilterData = controlDataOld.filter(obj => controlSelectedRowKeys.includes(obj.sId));
              if(commonUtils.isNotEmptyArr(controlDataFilterData)) {
                controlDataFilterData.forEach((item) => {
                  item.handleType = 'del';
                  controlDelData.push(item);
                });
              }
              addState.controlDelData = controlDelData;
            }
          } else {
            message.error('请选择部件！');
          }
        }

        if(commonUtils.isNotEmptyArr(copyToMaterialsConfig)) {
          if(!copyToMaterialsConfig[0].sControlName.includes('_add') && !copyToMaterialsConfig[0].sControlName.includes('_edit')) { /* 删除 */
            materialsData = [];
            const materialsDelData = commonUtils.isEmptyArr(materialsDelDataOld) ? [] : materialsDelDataOld;
            const materialsDataFilterData = materialsDataOld.filter(obj => controlSelectedRowKeys.includes(obj.sControlId));
            if(commonUtils.isNotEmptyArr(materialsDataFilterData)) {
              materialsDataFilterData.forEach((item) => {
                item.handleType = 'del';
                materialsDelData.push(item);
              });
              addState.materialsDelData = materialsDelData;
            }
          }
        }

        if(commonUtils.isNotEmptyArr(copyToProcessConfig)) {
          if(!copyToProcessConfig[0].sControlName.includes('_add') && !copyToProcessConfig[0].sControlName.includes('_edit')) { /* 删除 */
            processData = [];
            const processDelData = commonUtils.isEmptyArr(processDelDataOld) ? [] : processDelDataOld;
            const processDataFilterData = processDataOld.filter(obj => controlSelectedRowKeys.includes(obj.sControlId));
            if(commonUtils.isNotEmptyArr(processDataFilterData)) {
              processDataFilterData.forEach((item) => {
                item.handleType = 'del';
                processDelData.push(item);
              });
              addState.processDelData = processDelData;
            }
          }
        }

        if(commonUtils.isNotEmptyArr(colorAssignField)) {
          if(!colorAssignField[0].sControlName.includes('_add') && !colorAssignField[0].sControlName.includes('_edit')) { /* 删除 */
            colorData = [];
            const colorDelData = commonUtils.isEmptyArr(colorDelDataOld) ? [] : colorDelDataOld;
            if (commonUtils.isNotEmptyArr(colorDataOld) && colorDataOld.length > 0) {
              colorDataOld.forEach((item) => {
                item.handleType = 'del';
                colorDelData.push(item);
              });
            }
            addState.colorDelData = colorDelData;
          }
        }
        const newCopyTo = {};
        newCopyTo.master = copyTo.masterData;
        newCopyTo.slave = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
        let iSlaveIndex = -1;
        if (!commonUtils.isEmpty(slaveSelectedRowKeys)) {
          iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys.toString());
        }
        if (iSlaveIndex > -1) {
          slaveData[iSlaveIndex] = { ...slaveData[iSlaveIndex], ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, selectData[0], newCopyTo) }; // 取赋值字段
        }
        let controlSelectedRow = {}; /* 控制表选中行  */
        let iControlIndex = -1;
        if (!commonUtils.isEmpty(controlSelectedRowKeys)) {
          iControlIndex = controlData.findIndex(item => controlSelectedRowKeys.includes(item.sId));
          if(iControlIndex > -1) {
            controlSelectedRow = controlData[iControlIndex];
          }
        }

        const bProcessAssort = false;
        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.isNotEmptyObject(returnDataSet)) {
          /* 数据塞到Data中 */
          for (const key of Object.keys(returnDataSet)) {
            const sName = `${key}Data`;
            returnData[sName] = returnDataSet[key];
          }
        }
        if (commonUtils.isNotEmptyArr(returnData.slaveData)) {
          masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, returnData.slaveData[0], newCopyTo) }; // 取赋值字段
        }
        let dProductQty = 0;
        if(commonUtils.isNotEmptyObject(copyToSlaveDetailConfig)) {
          /* 主表配置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;
            }
          }
          console.log(22, returnData.slaveData);
          if (commonUtils.isNotEmptyArr(returnData.slaveData)) {
            returnData.slaveData.forEach((slaveItem, iIndex) => {
              /* 从工艺卡数据集 找到从表相同产品ID,客户ID */
              const iSameIndex = slaveData.findIndex(itemCurrent => itemCurrent.sProductId === slaveItem.sProductId  && itemCurrent.sCustomerId  === slaveItem.sCustomerId);
              if(false){
                // masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, slaveItem, newCopyTo) }; // 取赋值字段
                slaveData[iSameIndex].sOriginalId = commonUtils.isNotEmptyObject(slaveItem.sSlaveId) ? slaveItem.sSlaveId : slaveItem.sId;  /* 原始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 if(commonUtils.isNotEmptyObject(slaveDetailAssignField)){ /* 其他数据 新增 */
                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 = commonUtils.isNotEmptyObject(slaveItem.sSlaveId) ? slaveItem.sSlaveId : slaveItem.sId; /* 原始sId */
                slaveData.push(slaveRow);
              }
            });
          }
        }
        if (commonUtils.isNotEmptyArr(returnData.controlData) && commonUtils.isNotEmptyObject(controlAssignField)) {
          const treeCopyNodes = new Map();
          returnData.controlData.forEach((controlItem) => {
            newCopyTo.control = controlItem;
            let controlRow = commonFunc.getDefaultData(config.controlConfig, newCopyTo); // 取默认值
            if(copyToControlConfig[0].sControlName.includes('_edit')) {
              controlRow = { ...controlSelectedRow, ...commonFunc.getAssignFieldValue(controlAssignField, controlItem, newCopyTo) }; // 取赋值字段
              if(iControlIndex > -1) {
                controlData[iControlIndex] = { ...controlSelectedRow, ...controlRow};
              }
            } else  {
              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.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;
                materialsRow.sOriginalId = materialsItem.sId;
                materialsRow.sZmldlt = materialsItem.sZmldlt;
                materialsRow.sInkFatherMaterialsTbId = materialsItem.sInkFatherMaterialsTbId;
                // 材料对应工序的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);
              });
            }
            /* 将 materialsData中sParentMaterialsId替换为最新的sid */
            if(commonUtils.isNotEmptyArr(materialsData)) {
              const materialsFilterData = materialsData.filter(item => commonUtils.isNotEmptyObject(item.sParentMaterialsId));
              if(commonUtils.isNotEmptyArr(materialsFilterData)) {
                materialsFilterData.forEach((filterItem, index) => {
                  const iIndex = materialsData.findIndex(item => item.sOriginalId === filterItem.sParentMaterialsId);
                  if(iIndex > -1) {
                    const iNexIndex = materialsData.findIndex(item => item.sId === filterItem.sId);
                    if (iNexIndex > -1) {
                      materialsData[iNexIndex] = {...materialsData[iNexIndex], sParentMaterialsId: materialsData[iIndex].sId }
                    }
                  }

                });
              }

              const materialsInkFilterData = materialsData.filter(item => commonUtils.isNotEmptyObject(item.sInkFatherMaterialsTbId));
              if(commonUtils.isNotEmptyArr(materialsInkFilterData)) {
                materialsInkFilterData.forEach((filterItem, index) => {
                  const iIndex = materialsData.findIndex(item => item.sOriginalId === filterItem.sInkFatherMaterialsTbId);
                  if(iIndex > -1) {
                    const iNexIndex = materialsData.findIndex(item => item.sId === filterItem.sId);
                    if(iNexIndex > -1) {
                      materialsData[iNexIndex] = { ...materialsData[iNexIndex], sInkFatherMaterialsTbId: materialsData[iIndex].sId}
                    }
                  }
                });
              }
            }

          });
        }
        if (commonUtils.isNotEmptyArr(returnData.materialsData) && materialsAssignField) {
          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) && processAssignField) {
          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;
            processRow.sOriginalId = processItem.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);
                    });
                  }
                }
              }));
            }
          });
        }

        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); /* 加载树形结构数据 */
        addState.materials0DelData = addState.materialsDelData;
        addState.materials0Data = materialsData;
        this.props.onSaveState({
          [`${name}ChooseVisible`]: false,
          processData,
          materialsData,
          controlData,
          ...treeState,
          colorData,
          masterData,
          controlSelectedRowKeys: [],
          materialsSelectedRowKeys: [],
          processSelectedRowKeys: [],
          ...addState,
        });

      } else {
        this.props.getServiceError(dataReturn.msg);
      }
    } else if (false && commonUtils.isNotEmptyObject(selectConfig) && selectConfig.sControlName.includes('BtnCopyFrom.sworkorder')) {
      if (commonUtils.isNotEmptyArr(selectData)) {
        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());
        }
        if (commonUtils.isNotEmptyArr(selectData)) {
          const copyTo = {config: masterConfig.gdsconfigformslave, name: selectConfig.sControlName};
          const returnData = {
            slaveData: selectData,
            controlData: controlDataOld
          };
          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 masterDetailAssignField = commonUtils.isNotEmptyArr(copyToMasterDetailConfig) ? copyToMasterDetailConfig[0].sAssignField : '';
          const slaveDetailAssignField = commonUtils.isNotEmptyArr(copyToSlaveDetailConfig) ? copyToSlaveDetailConfig[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)}; // 取赋值字段
          }
          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)) {
            masterData = {...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, returnData.slaveData[0], newCopyTo)}; // 取赋值字段
          }
          console.log('ss', slaveDetailAssignField);
          if (commonUtils.isNotEmptyArr(returnData.slaveData)) {
            returnData.slaveData.forEach((slaveItem, iIndex) => {
              /* 从工艺卡数据集 找到从表相同产品ID,客户ID */
              const iSameIndex = iSlaveIndex;
              if (iSameIndex > -1) {
                if (commonUtils.isNotEmptyObject(slaveDetailAssignField)) {
                  // masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, slaveItem, newCopyTo) }; // 取赋值字段
                  slaveData[iSameIndex] = {...slaveData[iSameIndex], ...commonFunc.getAssignFieldValue(slaveDetailAssignField, slaveItem, newCopyTo)}; // 取赋值字段
                }
                slaveData[iSameIndex].sOriginalId = commonUtils.isNotEmptyObject(slaveItem.sSlaveId) ? slaveItem.sSlaveId : slaveItem.sId;  /* 原始sId */
                if (bProductQtySelf) {
                  dProductQty += commonUtils.isNull(slaveData[iSameIndex].dProductQty, 0);
                } else {
                  dProductQty += commonUtils.isNull(slaveData[iSameIndex].dProductQty, 0) + commonUtils.isNull(slaveData[iSameIndex].dGiveQty, 0) +
                    commonUtils.isNull(slaveData[iSameIndex].dStockupQty, 0);
                }
              } else if (commonUtils.isNotEmptyObject(slaveDetailAssignField)) { /* 其他数据 新增 */
                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 = commonUtils.isNotEmptyObject(slaveItem.sSlaveId) ? slaveItem.sSlaveId : slaveItem.sId; /* 原始sId */
                slaveData.push(slaveRow);
              }
            });
          }
          if (commonUtils.isNotEmptyArr(controlDataOld)) {
            let packRow = {};
            const slaveSelectedRow = iSlaveIndex > -1 ? slaveData[iSlaveIndex] : {};
            const controlRow = controlDataOld[0];
            if(slaveSelectedRow){
              const packDataRow = this.handlePackDataAdd(slaveSelectedRow, 0, controlRow.sId, 'add');
              packDataRow.dCombineQty = 1; /* 排版数 */
              if(commonUtils.isNotEmptyObject(packDataRow) && commonUtils.isNotEmptyObject(packDataRow.sProductId)){ /* 从表要选择产品 */
                const { sId, sProductNo, dProductQty, dCombineQty, dFactProductQty,sCombinePartsName  }= packDataRow;
                const tableCombineSelectedData =[];
                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);
                const sCombinedMemo = commonUtils.isNotEmptyArr(tableCombineSelectedData) ? JSON.stringify(tableCombineSelectedData) : ''; /* JSON对象转换为字符串存放到合版信息中 */
                controlRow.sCombinedMemo =commonUtils.isNotEmptyObject(sCombinedMemo)? sCombinedMemo: '合版信息';
                controlDataOld[0].sCombinedMemo = controlRow.sCombinedMemo;
              }
              packData.push(packDataRow);
            }
          }
          this.props.onSaveState({
            [`${name}ChooseVisible`]: false,
            slaveData,
            controlData: controlDataOld,
            packData,
            masterData,
            ...addState,
          });
        }
      }
    } else 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;
              materialsData.forEach((item, idx) => {
                materialsData[idx].sPartsName = controlData.filter(o => o.sId === item.sControlId).length ?
                  controlData.filter(o => o.sId === item.sControlId)[0].sPartsName : '';
              })
            }
            if (commonUtils.isNotEmptyArr(returnData.processData)) {
              processData = returnData.processData;
              processData.forEach((item, idx) => {
                processData[idx].sPartsName = controlData.filter(o => o.sId === item.sControlId).length ?
                  controlData.filter(o => o.sId === item.sControlId)[0].sPartsName : '';
              })
            }
            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 = false;
          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)) {
              masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, returnData.slaveData[0], newCopyTo) }; // 取赋值字段
            }
            if (commonUtils.isNotEmptyArr(returnData.slaveData)) {
              returnData.slaveData.forEach((slaveItem, iIndex) => {
                /* 从工艺卡数据集 找到从表相同产品ID,客户ID */
                let iSameIndex = slaveData.findIndex(itemCurrent => itemCurrent.sProductId === slaveItem.sProductId  && itemCurrent.sCustomerId  === slaveItem.sCustomerId);
                if(commonUtils.isNotEmptyObject(selectConfig) && selectConfig.sControlName.includes('BtnCopyFrom.sworkorder')){
                  /* 复制从历史工单 只要把数据赋值到选中行即可 */
                  iSameIndex = iSlaveIndex;
                }
                if(iSameIndex > -1){
                  if(commonUtils.isNotEmptyObject(slaveDetailAssignField)) {
                    // masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterDetailAssignField, slaveItem, newCopyTo) }; // 取赋值字段
                    slaveData[iSameIndex] = { ...slaveData[iSameIndex], ...commonFunc.getAssignFieldValue(slaveDetailAssignField, slaveItem, newCopyTo) }; // 取赋值字段
                  }
                  slaveData[iSameIndex].sOriginalId = commonUtils.isNotEmptyObject(slaveItem.sSlaveId) ? slaveItem.sSlaveId : slaveItem.sId;  /* 原始sId */
                  if (bProductQtySelf) {
                    dProductQty += commonUtils.isNull( slaveData[iSameIndex].dProductQty, 0);
                  } else {
                    dProductQty += commonUtils.isNull( slaveData[iSameIndex].dProductQty, 0) + commonUtils.isNull( slaveData[iSameIndex].dGiveQty, 0) +
                      commonUtils.isNull(slaveData[iSameIndex].dStockupQty, 0);
                  }
                } else if(commonUtils.isNotEmptyObject(slaveDetailAssignField)){ /* 其他数据 新增 */
                  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 = commonUtils.isNotEmptyObject(slaveItem.sSlaveId) ? slaveItem.sSlaveId : slaveItem.sId; /* 原始sId */
                  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) && 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 };
                          }
                        }
                      }else {
                        packRowAdd.dCombineQty = 1; /* 排版数 */
                        if(commonUtils.isNotEmptyObject(packRowAdd) && commonUtils.isNotEmptyObject(packRowAdd.sProductId)){ /* 从表要选择产品 */
                          const { sId, sProductNo, dProductQty, dCombineQty, dFactProductQty,sCombinePartsName  }= packRowAdd;
                          const tableCombineSelectedData =[];
                          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);
                          const sCombinedMemo = commonUtils.isNotEmptyArr(tableCombineSelectedData) ? JSON.stringify(tableCombineSelectedData) : ''; /* JSON对象转换为字符串存放到合版信息中 */
                          const sCombinedMemoNew =commonUtils.isNotEmptyObject(sCombinedMemo)? sCombinedMemo: '合版信息';
                          console.log('66116', sCombinedMemoNew);
                          const icontrolIndex = controlData.findIndex(item => item.sId === controlRow.sId);
                          console.log('icontrolIndex', icontrolIndex);
                          if (icontrolIndex > -1) {
                            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;
                  /* 根据合版表的源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)) {
                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;
              /* 根据从表源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;
              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;
              processRow.sOriginalId = processItem.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);
                      });
                    }
                  }
                }));
              }
            });
          }
          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);
          addState.materials0DelData = materialsDelData;
          addState.materials0Data = materialsData;
          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;
      const iProcessIndex = commonUtils.isNotEmptyArr(processDataOld) ?
        commonUtils.isNotEmptyArr(processSelectedRowKeys) ?  processDataOld.findIndex(item => item.sId === processSelectedRowKeys[0]) : 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) };
              tableDataRow.sParams = item.sParams;
            }
            // 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 = false;
            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);
                        }
                      });
                    }
                  }
                }
              }));
            }
          }else if(name ==='materials0') {
            if(iProcessIndex > -1) {
              tableDataRow.sProcessId = processDataOld[iProcessIndex].sProcessId; /* 工序ID */
              tableDataRow.sProcessTbId = processDataOld[iProcessIndex].sId; /* 工序表格ID */
            }
          }
          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 (commonUtils.isNotEmptyObject(tableDataRow.sWorkOrderParam)) {
                tableDataRow = { ...tableDataRow, ...commonUtils.convertStrToObj(tableDataRow.sWorkOrderParam) };
              }
              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 = false;
                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;

                        // 成品工序的配套工序带入产品名称-开始
                        processRow.sCombinePartsName = slaveObj.sId; /* 成品工序sCombinePartsName 为从表id */
                        processRow.sCombinePartsNameNew = slaveObj.sProductName; /* 成品工序sCombinePartsName 为从表产品名称 */
                        processRow.sCombineProductNameNew = slaveObj.sProductName; /* 成品工序sCombinePartsName 为从表产品名称 */
                        // processRow.sParentProcessId = item.sId;
                        // 成品工序的配套工序带入产品名称-结束

                        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;

                              // 成品工序的配套工序带入产品名称-开始
                              processRow.sCombinePartsName = slaveObj.sId; /* 成品工序sCombinePartsName 为从表id */
                              processRow.sCombinePartsNameNew = slaveObj.sProductName; /* 成品工序sCombinePartsName 为从表产品名称 */
                              processRow.sCombineProductNameNew = slaveObj.sProductName; /* 成品工序sCombinePartsName 为从表产品名称 */
                              // processRow.sParentProcessId = item.sId;
                              // 成品工序的配套工序带入产品名称-结束

                              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' && sName === 'sCombinedMemo') {
      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 === 'control' && sName === 'sPositiveColor' || sName === 'sOppositeColor') {
      this.props.onViewChoose(name, sName, record);
    } else if (name === 'sParam' && sName === 'sParamValue') {
      this.props.onViewChoose(name, sName, record);
    } 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);
    } else if(name === 'process' && sName === 'sParams') {
      if (this.bSWorkOrderParams) {
        this.props.onSaveState({
          sWorkParamsModalVisible: true
        });
      } else {
        this.props.onViewClick(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', []);
        let tableDataRowNew = {};
        tableDataRowNew.sProductId = '';
        tableDataRowNew.sProductNo = '';
        tableDataRowNew.sProductName = '';
        tableData[iIndex] ={...tableDataRowNew, ...tableDataRow } ;
      } else if ((sFieldName === 'sProductId' || sFieldName === 'sProductNo' || sFieldName === 'sProductName')) {
        // const productIdDropDown = commonUtils.getStoreDropDownData(sModelsId, 'slave', sFieldName);
        const iProductIdIndex = dropDownData.findIndex(item => item.sId === tableData[0].sProductId);
        if (tableDataRow.handleType === 'add' && 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;
              }
            }
          }
        }
        /* 从表产品改变带动合版表产品与部件表合版信息 同步改变 */
        const controlDataNew = commonUtils.isNotEmptyArr(addState.controlData) ? addState.controlData : controlDataOld;
        /* 如果packData只有一条数据 则同步合版数据 及增加控制表合版备注 */
        if (commonUtils.isNotEmptyArr(packData) && packData.length === 1 && packData[0].sSlaveId === tableDataRow.sId) {

          let packDataRow = packData[0];
          const sControlId = packDataRow.sControlId;
          packDataRow = this.handlePackDataAdd(tableDataRow, 0, sControlId);
          packDataRow.dCombineQty = 1;
          packData[0] = { ...packData[0], ...packDataRow }

          if (commonUtils.isNotEmptyObject(packData[0])) {
            const { sId, sProductNo, dProductQty, dCombineQty, dFactProductQty, sCombinePartsName } = packData[0];
            const tableCombineSelectedData = [];
            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);
            const sCombinedMemo = commonUtils.isNotEmptyArr(tableCombineSelectedData) ? JSON.stringify(tableCombineSelectedData) : ''; /* JSON对象转换为字符串存放到合版信息中 */
            // const controlDataNew =commonUtils.isNotEmptyArr(addState.controlData)? addState.controlData: controlDataOld;
            if (commonUtils.isNotEmptyArr(controlDataNew)) {
              const iControlIndex = controlDataNew.findIndex(item => item.sId === sControlId);
              if (iControlIndex > -1) {
                controlDataNew[iControlIndex].sCombinedMemo = sCombinedMemo;
                controlDataNew[iControlIndex].sPartsName = tableDataRow.sProductName;
              }
              addState.controlData = controlDataNew;
            }
          }
        } else if (packData.length > 1) {
          const packFilterData = packData.filter(item => item.sSlaveId === tableDataRow.sId);
          if (commonUtils.isNotEmptyArr(packFilterData)) {
            packFilterData.forEach((itemPack, index) => {
              let packDataRow = itemPack;
              const sControlId = packDataRow.sControlId;
              packDataRow = this.handlePackDataAdd(tableDataRow, 0, sControlId);
              // packDataRow.dCombineQty = 1;
              const pIndex = packData.findIndex(item => item.sId === itemPack.sId);
              if (pIndex > -1){
                packData[pIndex] = { ...packData[pIndex], ...packDataRow}; /* 根据选中的从表 找到所有的合版数据，将合版数据中的产品换成切换后的产品 */
                let sCombinedMemoStr = ''; /* 将控制表合版信息中的产品换成新选择的产品 */
                if(commonUtils.isNotEmptyArr(controlDataNew)) {
                  const iControlIndex = controlDataNew.findIndex(item => item.sId === sControlId);
                  if (iControlIndex > -1) {
                    sCombinedMemoStr = controlDataNew[iControlIndex].sCombinedMemo;
                    if(sCombinedMemoStr) {
                      const sCombinedMemoArr = commonUtils.isNotEmptyObject(sCombinedMemoStr) ? JSON.parse(sCombinedMemoStr): {};
                      if(commonUtils.isNotEmptyArr(sCombinedMemoArr)) {
                        const iIndex = sCombinedMemoArr.findIndex(item => item.sId === itemPack.sId);
                        if(iIndex > -1){
                          const addState ={};
                          addState.sProductId = tableDataRow.sProductId; /* 产品id */
                          addState.sCustomerId = tableDataRow.sCustomerId; /* 客户id */
                          addState.sCustomerName = tableDataRow.sCustomerName; /* 客户名称 */
                          addState.sProductName = tableDataRow.sProductName; /* 产品名称 */
                          addState.sProductNo = tableDataRow.sProductNo; /* 产品编号 */
                          sCombinedMemoArr[iIndex] ={...sCombinedMemoArr[iIndex], ...addState};
                          const sCombinedMemo = commonUtils.isNotEmptyArr(sCombinedMemoArr) ? JSON.stringify(sCombinedMemoArr) : ''; /* JSON对象转换为字符串存放到合版信息中 */
                          controlDataNew[iControlIndex].sCombinedMemo =sCombinedMemo;
                          controlDataNew[iControlIndex].sPartsName = tableDataRow.sProductName;
                        }
                      }
                    }
                  }
                }
              }
            });
            addState.controlData = controlDataNew;
          }

        }
        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, packData,
      } = 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;
          }
        } else if ( sFieldName === 'dSinglePQty' ) {   /* 排版数改变时 如果该控制表合版数据只有一条 则改变packData该条的拼版数 改变备注 */
          if(commonUtils.isNotEmptyArr(packData)){
            const packFilterData = packData.filter(item => item.sControlId === tableDataRow.sId);
            if (commonUtils.isNotEmptyArr(packFilterData) && packFilterData.length ===1 ) {
              const iIndex = packData.findIndex(itemPack => itemPack.sId === packFilterData[0].sId);
              const addState ={};
              if(tableDataRow.dSinglePQty > 0){
                addState.dCombineQty = tableDataRow.dSinglePQty;
                addState.handleType = commonUtils.isEmpty(tableDataRow.handleType) ? 'update' : tableDataRow.handleType;
                if(iIndex > -1) {
                  packData[iIndex] ={ ...packData[iIndex] , ...addState};
                  const { sId, sProductNo, dProductQty, dCombineQty, dFactProductQty,sCombinePartsName  }= packData[iIndex];
                  const tableCombineSelectedData =[];
                  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);
                  const sCombinedMemo = commonUtils.isNotEmptyArr(tableCombineSelectedData) ? JSON.stringify(tableCombineSelectedData) : ''; /* JSON对象转换为字符串存放到合版信息中 */
                  tableDataRow.sCombinedMemo =commonUtils.isNotEmptyObject(sCombinedMemo)? sCombinedMemo: '合版信息';
                }
              }
            }
          }
        }
        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, packData,
      });
    } 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 = false;
        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;
          packData[iIndex].handleType = commonUtils.isEmpty(packData[iIndex].handleType) ? 'update' : packData[iIndex].handleType;
        }
      });
    }

    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 = async (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 };

          // 查询是否有配套工序 sParentProcessId字段判断--开始
          const {
            sModelsId, token,
          } = this.props;
          // const dataUrl = `${commonConfig.server_host}salesorder/getProcessAssort?sModelsId=${sModelsId}`;
          // const dataProcessAssort = (await commonServices.postValueService(token, {}, dataUrl)).data;
          let returnProcessAssort = [];
          // if (dataProcessAssort.code === 1) {
          //   returnProcessAssort = dataProcessAssort.dataset.rows[0].processassort;
          // }

          returnProcessAssort.filter(item => item.sParentId === processData[iIndex].sProcessId).forEach(((itemProcessAssort) => {
            const iProcessIndex = processData.findIndex(item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === processData[iIndex].sControlId);
            if (iProcessIndex > -1) {
              processData[iProcessIndex] = { ...processData[iProcessIndex], ...addState };
            }
          }));
          // 查询是否有配套工序 sParentProcessId字段判断--结束
        }
        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 = '';
          }
          if (commonUtils.isNotEmptyObject(tableDataRow.sCombinedMemo)) {
            tableDataRow.sCombinedMemo = '';
          }
          tableData.push(tableDataRow);
          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({
            [`${name}Data`]: tableData, [`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 }, [`${name}SelectedRowKeys`]: tableSelectedNewRowKeys, treeSelectedKeys: tableSelectedNewRowKeys, packData, ...treeState,
          });
        }
      }
    } 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 (commonUtils.isNotEmptyObject(tableDataRow.sCombinedMemo)) {
              tableDataRow.sCombinedMemo = '';
            }
            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,
    });
  };
  handleTreeExpandSingle = (expanded, record) => {
   let { controlShowExpandedRowKeys } = this.props;
    let expandKey = record.sId;
    if(commonUtils.isEmpty(controlShowExpandedRowKeys)) {
      controlShowExpandedRowKeys ={};
      controlShowExpandedRowKeys.expandedRowKeys = [];
    }
    const idx = controlShowExpandedRowKeys.expandedRowKeys.indexOf(expandKey);
    let arr = JSON.parse(JSON.stringify(controlShowExpandedRowKeys.expandedRowKeys));
    if (idx !== -1) {
      arr.splice(idx, 1);
    } else {
      arr.push(expandKey);
    }
    this.props.onSaveState({
      controlShowExpandedRowKeys: { expandedRowKeys: arr }
    })
  };

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

  handleTabChange2 = (value) => {
    this.setState({
      currentTab2: +value
    });
  }

  handleActiveKey = (value) => {
    this.setState({
      activeKey: 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,
    });
  }

  handleParamsOk = () => { // 工艺参数弹窗确定按钮
    const {
      processData,
      processRecord,
      processConfig,
      sParamData,
      enabled,
    } = this.props;
    if(enabled) {
      if (commonUtils.isNotEmptyArr(processData) && commonUtils.isNotEmptyObject(processRecord)) {
        const processSelectDataIndex = processData.findIndex(item => item.sId === processRecord.sId);
        if (processSelectDataIndex > -1) {
          if (commonUtils.isNotEmptyArr(sParamData)) {
            const sParamSeletedData = sParamData.filter(item => item.bSelfCbx);
            if(commonUtils.isNotEmptyObject(sParamSeletedData)) {
              const sParamJsonData = JSON.stringify(sParamSeletedData);
              processData[processSelectDataIndex].sParams = sParamJsonData;
            }
          }
        }
      }
      this.props.onSaveState({
        processData,
        sParamsModalVisible: false,
      });
    } else {
      this.props.onSaveState({
        sParamsModalVisible: false,
      });
    }
  }

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

        // 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.sControlId === this.props.controlSelectedRowKeys[0]).map((item) => {
          afterDataIndex = afterDataIndex + 1;
          return  {...item, iOrder: afterDataIndex}
        });
        let allData = 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 });
    }
  }

  setModalId = (name) => {
    this[`${name}_id`] = new Date().getTime().toString();
  }

  getModalId = (name) => {
    return this[`${name}_id`];
  }

  // 自定义params参数处理
  handleGetParamsValue = ({ sName, sValue, record = {} }) => {
    const jsonData = commonUtils.convertStrToObj(sValue, []);
    if (sName === 'sParams') {
      const { sWorkOrderParam: sWorkOrderParamStr } = record;
      const sWorkOrderParam = commonUtils.convertStrToObj(sWorkOrderParamStr, {});
      const sWorkOrderData = jsonData.find(item => item.sParamType === 'sWorkOrder') || {};
      const { data = {} } = sWorkOrderData;
      const result = [];
      Object.keys(data).forEach(key => {
        if (sWorkOrderParam[key] !== undefined) {
          if (sWorkOrderParam[key] === "电化铝BOM" || sWorkOrderParam[key] === "电化铝版本") {
            result.push(`${sWorkOrderParam[key]}: ${record.sAlumiteBomBillNo}`);
          } else {
            result.push(`${sWorkOrderParam[key]}: ${data[key]}`);
          }
        }
      })
      return result.join(';');
    }

    return sValue;
  }

/**
 * 复制， 控制弹窗编辑
 * @param {*} tableName
 * @returns
 */
  getTableBtnState = (tableName) => {
    let result = false;
    const { enabled, masterData } = this.props;
    result = enabled;

    const { sInstruct: sInstructStr } = this.props[`${tableName}Config`] ;
    const sInstruct = commonUtils.convertStrToObj(sInstructStr, {});
    const { data = [] } = sInstruct;

    const btnConfig = data.find(item => item && item.name === tableName && item.enabled !== undefined);
    if (btnConfig && result) {
      if (!Array.isArray(this.props[`${tableName}Data`]) || !Array.isArray([`${tableName}SelectedRowKeys`])) {
        return ;
      }
      const { enabled: enabledContent } = btnConfig;
      if (typeof enabledContent === 'boolean') {
        result = enabledContent;
      } else if (enabledContent) {
        const tempData = {
          props: {
            enabled
          },
          masterData,
          [tableName]: this.props[`${tableName}Data`]?.find(i =>
            i && (this.props[`${tableName}SelectedRowKeys`].includes(i.sId)
            || this.props[`${tableName}SelectedRowKeys`].includes(i.sSlaveId)))
            || {},
        };
        let strNew = enabledContent;
        Object.keys(tempData).forEach(key => {
          const reg = new RegExp(`${key}\\.`, "g");
          strNew = strNew.replace(reg, `tempData["${key}"].`);
        });
        try {
          const evalStr = eval("`" + strNew + "`");
          result = !!eval(evalStr);
          console.log('=====表格行按钮状态结果', result, { btnName, enabledContent, tempData, strNew, evalStr });
        } catch (error) {
          console.log('=====表格行按钮状态错误', { error, enabledContent, strNew, tempData });
        }
      }
    }
    return result;
  }

  render() {
    const { pageLoading, masterData, fastOrderModalVisible, sModelsType, app  } = this.props;
    const imgSrc = commonBusiness.handleAddIcon(masterData, sModelsType, app );
    const addState = {};
    const { processConfig = {} } = this.props;
    const { gdsconfigformslave = [] } = processConfig;
    const bSWorkOrderParams = gdsconfigformslave.some(item => item.sName === 'sParams' && item.sControlName === 'sWorkOrder');
    if (bSWorkOrderParams) {
      this.bSWorkOrderParams = true;
      addState.onGetParamsValue = this.handleGetParamsValue;
    }
    return (
      <Spin spinning={pageLoading || this.state.pageLoadingPage}>
        <WorkOrderComponent
          {...this.props}
          {...this.state}
          baseTableHeight={this.baseTableHeight}
          isLayout={this.isLayout}
          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}
          onExpandTreeSingleShow={this.handleTreeExpandSingle}
          onEject={this.handleEject}
          onEjectRight={this.handleEjectRight}
          onViewChoose={this.handleViewChoose}
          onTabChange={this.handleTabChange}
          onTabChange2={this.handleTabChange2}
          onActiveKey={this.handleActiveKey}
          onDrag={this.handleDrag}
          onProductDrag={this.handleProductDrag}
          onProcessParamsOk={this.handleProcessParamsOk}
          // onParamsOk={this.handleParamsOk}
          onCancelProcessParamsModalVisible={this.handleCancelProcessParamsModalVisible}
          setModalId={this.setModalId}
          getModalId={this.getModalId}
          getTableBtnState={this.getTableBtnState}
          {...addState}
        />
      </Spin>
    );
  }
}

const WorkOrderComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData, masterConfig } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form, masterConfig);
    return obj;
  },
})((props) => {
  const {
    form,
    onReturnForm,
    masterConfig: masterConfigOld,
    slaveConfig,
    slaveData,
    slavePagination,
    sModelsId,
    sTabId,
    app,
    // AutoTableHeight,
    colorConfigGrdVisible,
    visible,
    checkConditions,
    checkPersonData,
    Loading,
    sModelsType,
    productCombinationVisible,
    combinePartsChooseVisible,
    sisColorChooseVisible,
    // currentTab,
    finishedMaterialsColumn,
    finishedMaterialsConfig,
    finishedProcessColumn,
    finishedProcessConfig,
    isLayout,
    packConfig,
    formData,
    materialsInfoList,
    materialsChildInfoList,
    colorConfig,
    visionConfig,
    processConfig,
  } = props;

  const { currentPane } = app;
  const bFlow = currentPane?.bFlow; /* 是否需要展示审批流程信息 */

  // 关联slave合版进行筛选control的数据
  let controlTableData = [];
  if(commonBusiness.getTableTypes('control', props).data && commonUtils.isNotEmptyObject(props) && commonUtils.isNotEmptyObject(props.slaveData)) {
    const iSlaveIndex = props.slaveData.findIndex(item => item.sId === props.slaveSelectedRowKeys[0]);
    const slaveSelectedRow = props.slaveData[iSlaveIndex] || {sProductNo: 0};
    if(iSlaveIndex !== -1) {
      commonBusiness.getTableTypes('control', props).data.forEach(item => {
        if(item.sCombinedMemo && item.sCombinedMemo !== '' && item.sCombinedMemo !== '合版信息') {
          const sCombinedMemoArr = commonUtils.isJSON(item.sCombinedMemo) ? JSON.parse(item.sCombinedMemo) : [];
          const getSlaveSelectedRowChildren = (allData, sId) => {
            let result = [];
            allData.forEach(item => {
              if (item.sFatherSlaveId === sId) {
                result.push(item);
                result = [...result, ...getSlaveSelectedRowChildren(allData, item.sId)]
              }
            });
            return result;
          };
          const slaveSelectedRowChildren = getSlaveSelectedRowChildren(props.slaveData, slaveSelectedRow.sId);
          const slaveRows = [slaveSelectedRow, ...slaveSelectedRowChildren];
          const len = sCombinedMemoArr.filter(item => item.sProductNo && slaveRows.some(slaveRow => slaveRow.sProductNo === item.sProductNo)).length;
          if(len) {
            controlTableData.push(item);
          }
        } else {
          controlTableData.push(item);
        }
      })
    } else {
      controlTableData = JSON.parse(JSON.stringify(commonBusiness.getTableTypes('control', props).data));
      // controlTableData = commonBusiness.getTableTypes('control', props).data.slice(0);
    }
  }
  // 之前代码默认会选中第一行，第一行可能已经被筛选掉，需要判断
  if(controlTableData.length && props.controlSelectedRowKeys[0] !== controlTableData[0].sId && controlTableData.map(item => item.sId).indexOf(props.controlSelectedRowKeys[0]) === -1) {
    if(commonUtils.isNotEmptyArr(props.slaveSelectedRowKeys)) {
      props.onSaveState({
        controlSelectedRowKeys: [controlTableData[0].sId]
      });
    }
  }

  // 计算控制表记录数量，计算sticky高度
  const controlLen = controlTableData.length ? commonUtils.genTreeByArr(controlTableData, 'sId', 'sControlParentId').length : 0;
  const slaveLen = props.slaveData ? props.slaveData.length : 0;
  let stickyHeight = 0;
  let stickyTabHeight = 0;
  if(isLayout) {
    if (controlLen && controlLen < 5) {
      stickyTabHeight += (slaveLen * 29) + 40;
      stickyHeight += (controlLen * 29) + 40 + 30 - 4;
    } else {
      stickyHeight += 162;
    }
    stickyHeight += 40;
  } else {
    if(props.currentTab === 1) {
      if (controlLen && controlLen < 5) {
        stickyHeight = (controlLen * 29) + 40 + 30 - 4; // 153
      } else {
        stickyHeight = 162 + 30;
      }
    } else {
      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 bSplitMaterials = true; /* 默认拆分材料*/
  if (commonUtils.isNotEmptyObject(masterConfigOld)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bSplitMaterials');
    if (iIndex > -1) {
      bSplitMaterials = props.masterConfig.gdsconfigformslave[iIndex].bVisible;
    }
  }

  let bSplitProcess = true; /* 默认拆分工序 */
  if (commonUtils.isNotEmptyObject(masterConfigOld)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bSplitProcess');
    if (iIndex > -1) {
      bSplitProcess = props.masterConfig.gdsconfigformslave[iIndex].bVisible;
    }
  }

  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;/* 配置了成品材料按钮 */
    }
  }

  /* 做树形 */
  let slaveTreeData = [];
  const bTree = slaveConfig && slaveConfig.sTableType === 'single' && commonUtils.isNotEmptyArr(slaveData) && slaveData.findIndex(item => commonUtils.isNotEmptyObject(item.sFatherSlaveId)) > -1; /* 树形展示 */
  if (bTree) {
    slaveTreeData = commonUtils.genTreeByArr(slaveData, 'sId', 'sFatherSlaveId');
  } else {
    slaveTreeData = slaveData;
  }

  const slaveTableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    data: slaveTreeData,
    tableProps: {
      rowSelection: null, pagination,
      onChange: props.onTitleChange,
      setAdd,
      setCopy,
      setDelete,
      // AutoTableHeight: 132,
      sticky: false,
      bShowTreeAddChild: true,
    },
    onTreeAdd: props.onDataRowAdd,
    onTreeAddChild: props.onDataRowAdd,
    onKeyDown: props.onKeyDown,
  };
  let bShowMaterials  = true;
  const iMaterialsIndex = props && props.masterConfig ? props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseMaterials') : -1;
  bShowMaterials = iMaterialsIndex > -1;

  let bShowProcess  = true;
  const iProcessIndex = props && props.masterConfig ? props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProcess') : -1;
  bShowProcess = iProcessIndex > -1;

  // const mProps = { ...commonBusiness.createMemoProps('slave', props) };
  const controlPropsType = {
    ...commonBusiness.getTableTypes('control', props),
    data: commonUtils.genTreeByArr(controlTableData, 'sId', 'sControlParentId'),
    onKeyDown: props.onKeyDown,
    bMutiSelect1: true, // 设置点击整行勾选框不勾选，只有点击勾选框才勾选
    tableProps: {
      // rowSelection: enabled ? null : '',
      // setAdd,
      sModelsType,
      // setCopyAll,
      // setDelete,
      setProcess : bShowProcess,
      setMaterial : bShowMaterials,
      bShowTreeAdd: true,
      bShowTreeAddChild: true,
      bShowTreeDel: true,
      bShowTreeCopyAll: true,
      // bShowProductProcess, /* 是否显示成品工序 */
      // bShowProductMaterials, /* 是否显示成品工序 */
      chooseProcessConfigRow,
      chooseMaterialsConfigRow,
      // chooseProductProcessConfigRow, /* 成品工序按钮配置 */
      // chooseProductMaterialsConfigRow, /* 成品材料按钮配置 */
      setNoCommonOperate: true, /* 没有新增、修改、删除通用操作按钮 */
      AutoTableHeight: 232,
      // sticky: {
      //   offsetHeader: stickyHeight,
      // },
      sticky: false
      // onRow: (record) => {
      //   return {
      //     onClick: () => { props.onRowClick('control', record); },
      //     onDoubleClick: () => { props.onDoubleClick('control', record); },
      //     onMouseEnter: () => { props.onRowMouseEnter('control', record); },
      //   };
      // },
    },
    onTreeAdd: props.onDataRowAdd,
    onTreeAddChild: props.onDataRowAdd,
    onTreeCopyAll: props.onDataRowCopyAll,
    onTreeDel: props.onDataRowDel,
  };

  /* 展示所有部件结构 */
  const controlShowPropsType = {
    ...commonBusiness.getTableTypes('control', props),
    data: commonUtils.genTreeByArr(controlTableData, 'sId', 'sControlParentId'),
    onKeyDown: props.onKeyDown,
    bMutiSelect1: true, // 设置点击整行勾选框不勾选，只有点击勾选框才勾选
    tableProps: {
      AutoTableHeight: 550,
      expandable: props.controlShowExpandedRowKeys,
    },
    onExpand: props.onExpandTreeSingleShow,
  };


  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 totalname = 'totalTree';
  const totalTreeProps = {
    ...commonBusiness.getTreeTypes('totalTree', props),
    isSearch: false,
    checkable: false,
    disabled: false,
    checkedAll: false,
    unChecked: false,
    [`${totalname}Column`]: props[`${totalname}Column`],
    [`${totalname}Config`]: props[`${totalname}Config`],
    [`${totalname}Data`]: props[`${totalname}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 (bSplitMaterials && 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 (bSplitProcess && 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' && (controlSelectedRowKeys.includes(val.sControlId) || !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 || [];
    }
  };

  /* 根据业务过滤全部材料，油墨 电化铝数据 去重根据sMateriaslId+ sMaterialsStyle */
  const materialsFilter = (data, type, bFinal) => {
    // materials : 0-1部件材料 : 2成品材料;
    // process : 0-1-2 部品工序 : 3成品工序;
    // bfinal: 是否成品
    const { slaveSelectedRowKeys, controlSelectedRowKeys, materials0Data, materials1Data,  materials1ChildData, materials2Data, materials2ChildData, materialsOtherData } = props;
    if (true) {
      let oriData =  commonUtils.isNotEmptyArr(data.data) ? data.data : [];
      let res = [];
      switch (type) {
        case 'materials2': /* 电化铝 */
          if (commonUtils.isNotEmptyArr(materials2ChildData)) {
            const newData = [];
            materials2ChildData.forEach((val) => {
              const iIndex = newData.findIndex(item => item.sMaterialsId === val.sMaterialsId  && item.sControlId  === val.sControlId && item.sMaterialsStyle === val.sMaterialsStyle);
              if(iIndex === -1){
                newData.push(val);
              }

            });
            res = newData;
            console.log('电化铝子集', newData);
            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 = newData.filter((val) => {
                return val.sType !== '2';
              });
            }
          } else {
            res = oriData;
          }
          break;
        case 'materials0': /* 全部材料 */
          if (true) {
            let newData0 = commonUtils.isNotEmptyArr(materials1Data) ? materials1Data : []; /* 专色墨 */
            let newData1 = commonUtils.isNotEmptyArr(materials1ChildData) ? materials1ChildData : [];  /* 油墨 */
            let newDataChild = commonUtils.isNotEmptyArr(materials2ChildData) ? materials2ChildData : [];  /* 电化铝明细 */

            const newDhlData = []; /* 电化铝汇总 */
            newDataChild.forEach((val) => {
              const iIndex = newDhlData.findIndex(item => item.sMaterialsId === val.sMaterialsId  && item.sControlId  === val.sControlId && item.sMaterialsStyle === val.sMaterialsStyle);
              if(iIndex === -1){
                newDhlData.push(val);
              }

            });

            let newOtherData = commonUtils.isNotEmptyArr(materialsOtherData) ? materialsOtherData : []; /* 其他子集 */

            /* 如果其他子级是空的 取不是油墨。电化铝、专色墨部分 */
            if(commonUtils.isNotEmptyArr(newOtherData) && commonUtils.isNotEmptyArr(materials0Data)) {
              newOtherData =  materials0Data.filter(item => item.sZmldlName !== '油墨' &&
                item.sZmldlName !== '自调专色墨' && item.sZmldlName !== '电化铝'  );
            }

            const newDataTemp = (newData0.concat(newData1)).concat(newDhlData);
            let allData = newDataTemp.concat(newOtherData);

            if (bFinal) { /* 成品材料 */
              if (slaveSelectedRowKeys && slaveSelectedRowKeys.length) {
                res = allData.filter((val) => {
                  return val.sType === '3' && (val.sCombinePartsName === slaveSelectedRowKeys[0] || !val.sCombinePartsName);
                });
              } else {
                res = allData.filter((val) => {
                  return val.sType === '3';
                });
              }
            } else { /* 部件材料 */
              // if (controlSelectedRowKeys && controlSelectedRowKeys.length) {
              //   res = oriData.filter((val) => {
              //     return val.sType !== '3' && (controlSelectedRowKeys.includes(val.sControlId) || !val.sControlId);
              //   });
              // } else {
              //   res = allData.filter((val) => {
              //     return val.sType !== '3';
              //   });
              // }
              res = allData;
            }
          } else {
            res = oriData;
          }
          break;
        default:
          res = oriData;
      }
      return res;
    } else {
      return [];
    }
  };


  const materialsFilterNew = (data, type, bFinal) => {
    // materials : 0-1部件材料 : 2成品材料;
    // process : 0-1-2 部品工序 : 3成品工序;
    // bfinal: 是否成品
    const { materials0Data, materials0SelectedRowKeys, materials0ChildData, materials0ChildSelectedRowKeys } = props;
    let oriData = commonUtils.isNotEmptyArr(data.data) ? data.data : [];
    let res = [];
    let newData = [];
    if (type === 'materials1' || type === 'materials2') {
      if (commonUtils.isNotEmptyArr(materials0Data)) {
        const config = data.config;
        const sSqlCondition = config ? config.sSqlCondition : '';
        if (sSqlCondition) {
          const targetTbName = sSqlCondition.split('.')[0]; /* 1.表名 control  */
          const filteredValue = sSqlCondition.split('.')[1]; /* 2.解析filterValue: controlSelectedRowKeys */
          const sParentKey = sSqlCondition.split('.')[2]; /* 2.解析本身表对应的值,如控制表筛选材料表 则材料表的sControlId = 控制表的controlSelectedRowKeys[0] */

          if (targetTbName === 'materials0') {
            const filterData = materials0Data.filter(item => sParentKey && sParentKey.includes(item[filteredValue]));
            if (commonUtils.isNotEmptyArr(filterData)) {
              newData = filterData;
            }
          }
        }

      }
      res = newData;
    } else if (type === 'materials0') { /* 根据sSqlConditionId 过滤材料变更 */
      if (commonUtils.isNotEmptyArr(oriData)) {
        oriData.forEach(i => {
          const value = i && i.sSqlConditionId && materials0ChildData?.find(k => k && k.sId === materials0ChildSelectedRowKeys?.[0])?.sSqlConditionId === i.sSqlConditionId;
          if (value) {
            i.changeFlag = 1;
          } else {
           if (i) i.changeFlag = 0;
          }
        });
        res = oriData;
      }
    } else {
      res = oriData;
    }
    return res;
  }


  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: isLayout ? { offsetHeader: stickyHeight } : true,
    },
  };
  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: isLayout ? { offsetHeader: stickyHeight } : true,
    },
  };

  const materialsTablePropsList = {};
  if (commonUtils.isNotEmptyArr(materialsInfoList)) {
    materialsInfoList.forEach((item, index) => {
      // const slaveTablePagination = {
      //   pageSize: commonUtils.isNotEmptyNumber(props.iPageSize) && props.iPageSize !== 0 ? props.iPageSize : commonConfig.pageSize,
      //   ...slavePagination,
      //   size: isSmall ? 'small' : 'large',
      //   pageSizeOptions: commonConfig.pageSizeOptions,
      //   showSizeChanger: !isSmall,
      //   showQuickJumper: !isSmall,
      //   hideOnSinglePage: true,
      // };
      materialsTablePropsList[`materialsTable${index}Props`] = {
        ...commonBusiness.getTableTypes(`materials${index}`, props),
        // data: materialsFilter(commonBusiness.getTableTypes(`materials${index}`, props), `materials${index}`, false),
         data: materialsFilterNew(commonBusiness.getTableTypes(`materials${index}`, props), `materials${index}`, false),
        // tableBelone: 'list',
        tableProps: {
          setAdd,
          setCopy,
          setDelete,
          AutoTableHeight: props.baseTableHeight,
        },
      };
    });
  }


  const materialsChildTablePropsList = {};
  if (commonUtils.isNotEmptyArr(materialsChildInfoList)) {
    materialsChildInfoList.forEach((item, index) => {
      materialsChildTablePropsList[`${item}TableProps`] = {
        ...commonBusiness.getTableTypes(`${item}`, props),
        data: materialsFilterNew(commonBusiness.getTableTypes(`${item}`, props), item, false),
        // tableBelone: 'list',
        tableProps: {
          setAdd,
          setCopy,
          setDelete,
          AutoTableHeight: '100%',
        },
      };
    });
  }

  /* 是否有拖动功能 是通过配置有没有handleSort功能 */
  const bProcessSort = commonUtils.isNotEmptyObject(processConfig) && commonUtils.isNotEmptyArr(processConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(processConfig.gdsconfigformslave.filter(item => item.sControlName === 'handleSort' && item.bVisible))  ? true : false ;
  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: props.baseTableHeight,
      sticky: isLayout ? { offsetHeader: stickyHeight } : true,
    },
    onDrag: props.onDrag,
    isDragAndDrop: false,
    dragHandle: bProcessSort,
    noVlistTable: bProcessSort,
    tableId: props.processTableId
  };

  let processShowLeft = {};
  let processShowTitle = '';
  if (commonUtils.isNotEmptyObject(props.processConfig)) {
    const iIndex = props.processConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bShowLeft');
    if (iIndex > -1) {
      processShowLeft = props.processConfig.gdsconfigformslave[iIndex];/* 配置了成品工序按钮 */
      if(commonUtils.isNotEmptyObject(processShowLeft)) {

        if(processShowLeft.bVisible) {
          processShowTitle =  processShowLeft.showName;
        }

      }
    }
  }



  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: isLayout ? { offsetHeader: stickyHeight } : true,
    },
    onDrag: props.onProductDrag,
  };

  let finalProcessShowLeft = {};
  if (commonUtils.isNotEmptyObject(finishedProcessConfig)) {
    const iIndex = finishedProcessConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bShowLeft');
    if (iIndex > -1) {
      finalProcessShowLeft = finishedProcessConfig.gdsconfigformslave[iIndex];/* 配置了成品工序按钮 */
    }
  }

  let colorTableProps = {};
  if (colorConfigGrdVisible) {
    colorTableProps = {
      ...commonBusiness.getTableTypes('color', props),
      onKeyDown: props.onKeyDown,
      tableProps: {
        rowSelection: null, setAdd, setCopy, setDelete, AutoTableHeight: props.baseTableHeight,
      },
    };
    // cProps = { ...commonBusiness.createMemoProps('color', props) };
  }

  let visionTableProps = {};

  if (commonUtils.isNotEmptyObject(visionConfig)) {
    visionTableProps = {
      ...commonBusiness.getTableTypes('vision', props),
      onKeyDown: props.onKeyDown,
      tableProps: {
        rowSelection: null, setAdd, setCopy, setDelete, AutoTableHeight: props.baseTableHeight,
      },
    };
  }

  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;

    props.setModalId('materials');
    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: props.getModalId('materials'),
    };
  }

  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 sParamProps = {
    ...commonBusiness.getTableTypes('sParam', props),
    tableProps: {
      rowKey: 'sId',
      // pagination,
      onChange: props.onTitleChange,
      sModelsType,
      AutoTableHeight: 350,
    },
    bRowClick: true,
  };


  /* 带拖动信息的工艺参数 */
  // const sCommonParamProps = {
  //   ...props,
  //   sParamType :'sWorkOrder', /* 参数类型 */
  //   slaveData: props.processSelectedData,
  //   // masterData: { ...props.masterData,  }
  // };


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

  const tabChange2 = (e) => {
    props.onTabChange2(e);
  };

  const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
  let materialsInfo = commonFunc.showMessage(app.commonConst, 'materialsInfo');/* 材料信息 */
  materialsInfo = '纸张';


  let dhlInfo = commonFunc.showMessage(app.commonConst, 'materialsInfo');/* 电化铝 */
  dhlInfo = '电化铝';
  let materialsFlInfo = commonFunc.showMessage(app.commonConst, 'materialsInfo');/* 成品辅料 */
  materialsFlInfo = '成品辅料';

  const processInfo = commonFunc.showMessage(app.commonConst, 'processInfo');/* 工序信息 */
  let productMaterialsInfo = commonFunc.showMessage(app.commonConst, 'productMaterialsInfo') ;/* 成品材料 */
  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');/* 选择合拼产品标题 */

  const dailyInfo = commonFunc.showMessage(app.commonConst, 'dailyInfo');/* 日志信息 */

  // 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;
    }
  }
  let bShowAllTable = true; /* 显示所有表格 */
  if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bShowAllTable');
    if (iIndex > -1) {
      bShowAllTable = props.masterConfig.gdsconfigformslave[iIndex].bVisible;
    }
  }

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

  const panelExtra = (type, title) => {
    let str = '';
    /* 根据materials找到其组所有配置头 */

    let radioConfigArr = [];
    if(commonUtils.isNotEmptyArr(formData)) {
      // radioConfigArr =  formData.filter(item => commonUtils.isNotEmptyObject(item.sGrd) && item.sGrd.includes(type) );
      radioConfigArr =  formData.filter(item => commonUtils.isNotEmptyObject(item.sGrd) && item.sGrd.includes(type) && item.bGrdVisible );
      // console.log('radioConfigArr:', radioConfigArr);
      if(sModelsId === '12710101116950085152680') {
        radioConfigArr =  formData.filter(item => commonUtils.isNotEmptyObject(item.sGrd) && item.sGrd.includes(type) && item.bGrdVisible &&
        item.showName !=='成品材料');
      }
    }
    if (type === 'material') {
      str = (
        <div>
          <Radio.Group defaultValue={props.currentTab} onChange={e => tabChange(e.target.value)}>
            {/*<Radio value={4}>{materialsInfo}</Radio>*/}
            {/*{bSplitMaterials ? <Radio value={2}>{productMaterialsInfo}</Radio> : ''}*/}
            {/*<Radio value={5}>{dhlInfo}</Radio>*/}
            {/*<Radio value={6}>{materialsFlInfo}</Radio>*/}
            {
              radioConfigArr.map((child, index) => {
                const radioTitle =  child.showName;
                const radioValue =  index + 2 + 10;
               // console.log('radioValue', radioTitle, radioValue);
                return(
                  <Radio value={radioValue}>{radioTitle}</Radio>
                )
              })
            }
          </Radio.Group>
        </div>
      )
    } else if (type === 'process') {
      str = (
        <div>
          <Radio.Group defaultValue={props.currentTab2} onChange={e => tabChange2(e.target.value)}>
            <Radio value={1}>{processInfo}</Radio>
            {bSplitProcess ? <Radio value={3}>{productProcessInfo}</Radio> : ''}
          </Radio.Group>
        </div>
      )
    }else if (type === 'daily') {
      let dailyInfoTitle = dailyInfo;
      const { colorConfig } = props;
      if (commonUtils.isNotEmptyObject(colorConfig)) {
        const iIndex = colorConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'daily');
        if (iIndex > -1) {
          dailyInfoTitle = colorConfig.gdsconfigformslave[iIndex].showName;
        }
      }
      str = (
        <div>
          <Radio.Group defaultValue={props.currentTab2} onChange={e => tabChange2(e.target.value)}>
            <Radio value={1}>{dailyInfoTitle}</Radio>
          </Radio.Group>
        </div>
      )
    } else if (type === 'daily-1') {
      let visionTableTitle = '改版记录';
      const { visionConfig } = props;
      if (commonUtils.isNotEmptyObject(visionConfig)) {
        visionTableTitle = visionConfig.showName;
      }
      str = <Radio.Group defaultValue={1} >
        <Radio value={1}>{visionTableTitle}</Radio>
      </Radio.Group>
    } else if (type?.toString().startsWith('material-')) {
      str = <Radio.Group defaultValue={1} >
         <Radio value={1}>{title}</Radio>
      </Radio.Group>
    }
    return str;
  }

  const activeKeyChange = (e) => {
    props.onActiveKey(e);
  };
  const  okButtonStyle ={
    style:{
      display:"none",
      backgroundColor:"red"
    }
  }
  const cancelButtonStyle = {
    htmlType:"退出",
    style: {
      width: 70,
      height: 50,
    }
  }
  const autoHeight = `calc( 100vh - 92px )`;
  const chooseCombinePartsName = commonFunc.showLocalMessage(props, 'chooseCombinePartsName', '选择合版部件名称');
  const DisplayComponentStructure = commonFunc.showLocalMessage(props, "DisplayComponentStructure", "展示部件结构");

  return (
    <Form>
      <Layout className="xly-workorder-list">
        <Header className={styles.header}>
          <Toolbar {...props} loading={false} className="billBtnGroup" style={{ backgroundColor: '#646464', color: 'rgb(255,255,255)' }} />
        </Header>
        <Layout className={styles.clayout}>
          <div className={styles.content} style={{ display:'flex'}}>
            <div id="slaveTabs" className={`${styles.bShow} slaveTabsFlex`} style={{ paddingRight: '10px', overflow: 'auto', maxHeight: 'calc(100vh - 130px)', width: bFlow ? '75%':'100%', }} >
              <div>
                <Avatar src={props.imgSrc} />
              </div>
              <CommonView {...propsType} />
              <div className={[styles.slaveTabs, 'slave-tabs-container'].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', position: 'static', top: props.currentTab === 1 ? 0 : stickyTabHeight + 'px',
              }}
              >
                {
                  bShowAllTable && <div className="processList" style={{ marginBottom: '0px', position: 'sticky', top:  '0px', zIndex: 99 }}>
                    <StaticEditTable {...controlPropsType} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                  </div>
                }
                {
                  isLayout ?
                    <div>
                      <Tabs className={styles.slaveTabs}
                            style={{ paddingTop: '10px', marginRight: '10px', marginTop: '-10px', backgroundColor: '#fff' }}
                            onChange={tabChange}>
                        <TabPane tab="部件材料" key={4} ></TabPane>
                        <TabPane tab="部件工序" key={5} ></TabPane>
                        {bFinalMaterialsTabShow ?  <TabPane tab="成品材料" key={2} ></TabPane> :''}
                        {bFinalProcessTabShow?  <TabPane tab="成品工序" key={3} ></TabPane> :''}
                      </Tabs>
                      {props.currentTab === 4 && bMaterialShow ?
                        <StaticEditTable {...materialsPropsType} setOpterationColumn="Y" bModalAdd noVlist selfTableHeight={82}/> : ''
                      }
                      {finishedMaterialsColumn && props.currentTab === 2 ?
                        <StaticEditTable {...finishedMaterialsPropsType} bFinished bModalAdd setOpterationColumn="Y" selfTableHeight={82} noVlist /> : ''
                      }
                      {props.currentTab === 5 && bProcessShow ?
                        <StaticEditTable {...processPropsType} setOpterationColumn="Y" bModalAdd dragHandle selfTableHeight={330} noVlistTable /> : ''
                      }
                      {finishedProcessColumn && props.currentTab === 3?
                        <StaticEditTable {...finishedProcessPropsType} bFinished bModalAdd setOpterationColumn="Y" dragHandle selfTableHeight={330} noVlist /> : ''
                      }
                    </div>
                    :
                    <Collapse activeKey={props.activeKey} onChange={activeKeyChange} className="custom-collapse">
                      {
                        bShowAllTable ?
                          <Panel collapsible="header"
                            header={(<RightOutlined style={{fontSize: '11px', transition: 'ease 0.3s', transform: `rotate(${(props.activeKey.indexOf('2') !== -1)? '90deg' : '0deg'})`}} />)}
                            showArrow={false}
                            extra={panelExtra('process')}
                            key="2"
                          >
                            { props.currentTab2 === 1 && commonUtils.isNotEmptyObject(processShowLeft) ?
                              <div>
                                <Row gutter={[8, 0]}>
                                  <Col span={processShowLeft.iColValue} order={1} id={props.processTableId}>
                                    <StaticEditTable
                                      {...processPropsType}
                                      setOpterationColumn="Y"
                                      bModalAdd
                                      noVlistTable
                                      tableId={props.processTableId}
                                    />
                                  </Col>
                                  <Col span={24 - (processShowLeft.iColValue)} order={2}>
                                    {commonUtils.isNotEmptyObject(processShowTitle) ?  <Divider  className='workOrderDivider' orientation="center">{processShowTitle}</Divider> : '' }
                                    {
                                      [''].map(() => {
                                        const commonViewDragableProps = {
                                          ...props,
                                          hideTabsNav: true,
                                          comparedTableId: props.processTableId,
                                          sParamData: [
                                            {
                                              sParamType: 'sWorkOrder',
                                              sParamName: '工单参数',
                                            }
                                          ],
                                          tableName: 'process',
                                        }
                                        return <CommonViewDragable {...commonViewDragableProps} />;
                                      })
                                    }
                                  </Col>
                                </Row>
                              </div> : <StaticEditTable tableId={props.processTableId} {...processPropsType} setOpterationColumn="Y" bModalAdd selfTableHeight={330} noVlistTable />
                            }
                            { props.currentTab2 === 3 && bSplitProcess && <StaticEditTable {...finishedProcessPropsType} bFinished bModalAdd setOpterationColumn="Y" dragHandle={false} selfTableHeight={330} noVlist /> }
                          </Panel> : ''
                      }


                      <Panel collapsible="header"
                             header={(<RightOutlined style={{fontSize: '11px', transition: 'ease 0.3s', transform: `rotate(${(props.activeKey.indexOf('1') !== -1)? '90deg' : '0deg'})`}} />)}
                             showArrow={false}
                             extra={panelExtra('material')}
                             key="1"
                      >
                        {/*{ props.currentTab === 11 && <StaticEditTable {...materialsPropsType} setOpterationColumn="Y" bModalAdd noVlist selfTableHeight={82}/> }*/}

                        { props.materialsInfoList?.map((item, index) => {
                          let num = 12 + index;
                          const materialsOtherPropsType = materialsTablePropsList[`materialsTable${index}Props`];
                          return (
                            props.currentTab === num &&
                               <StaticEditTable {...materialsOtherPropsType} setOpterationColumn="Y"  noVlist selfTableHeight={82}/>
                            )
                        }) }
                      </Panel>

                     { props.materialsInfoList?.map((item, index) => {
                       let num = 12 + index;
                       /* 找到子级 左右列 */
                       let materialsChildTableProps ={};
                       let materialsChildTableTitle = '子表记录';
                       if(commonUtils.isNotEmptyArr(materialsChildInfoList)) {
                         const iIndex = materialsChildInfoList.findIndex(child => child.includes(item));
                         if(iIndex > -1) {
                           materialsChildTableProps =  materialsChildTablePropsList[`${item}ChildTableProps`];
                           materialsChildTableTitle = commonUtils.isNotEmptyObject(materialsChildTableProps) &&  commonUtils.isNotEmptyObject(materialsChildTableProps.config) ?  materialsChildTableProps.config.showName : '';
                         }
                       }
                       return (
                         props.currentTab === num &&
                          commonUtils.isNotEmptyObject(materialsChildTableProps)  &&
                         <Panel collapsible="header"
                            header={(<RightOutlined style={{fontSize: '11px', transition: 'ease 0.3s', transform: `rotate(${(props.activeKey.indexOf(`1-${index}`) !== -1)? '90deg' : '0deg'})`}} />)}
                            showArrow={false}
                            extra={panelExtra(`material-${index}`, materialsChildTableTitle)}
                            key={`1-${index}`}
                          >
                            <StaticEditTable {...materialsChildTableProps} setOpterationColumn="Y"  noVlist selfTableHeight={82}/>
                         </Panel>
                         )
                       })
                      }

                      {
                        commonUtils.isNotEmptyArr(visionConfig) ?
                          <Panel collapsible="header"
                                 header={(<RightOutlined style={{fontSize: '11px', transition: 'ease 0.3s', transform: `rotate(${(props.activeKey.indexOf('3-1') !== -1)? '90deg' : '0deg'})`}} />)}
                                 showArrow={false}
                                 extra={panelExtra('daily-1')}
                                 key="3-1"
                          >
                            <StaticEditTable {...visionTableProps} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                          </Panel> : ''
                      }

                      {
                        commonUtils.isNotEmptyArr(colorConfig) ?
                          <Panel collapsible="header"
                                 header={(<RightOutlined style={{fontSize: '11px', transition: 'ease 0.3s', transform: `rotate(${(props.activeKey.indexOf('3') !== -1)? '90deg' : '0deg'})`}} />)}
                                 showArrow={false}
                                 extra={panelExtra('daily')}
                                 key="3"
                          >
                            <StaticEditTable {...colorTableProps} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                          </Panel> : ''
                      }

                    </Collapse>
                }
              </div>
              {
                false ?
                  <div className={styles.slaveTabs} style={{ marginLeft: '10px', marginTop: 10 }}>
                    <Layout>
                      <Sider className={selfstyles.product}>
                        {colorInfo}
                      </Sider>
                      <Content>
                        <StaticEditTable {...colorTableProps} setOpterationColumn="Y" selfTableHeight={82} noVlist />
                      </Content>
                    </Layout>
                  </div> : ''
              }
            </div>
            {
              bFlow ?
                <div id='examInfo' style={{width:'25%', textAlign:'center', height:'900px', maxHeight: 'calc(100vh - 130px)' , backgroundColor:'#f0f0f0'}}>
                  <CommonExamInfo {...props} />
                </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"
            >
              {
                searchProcessType.app.currentPane.sModelsType ==='modal/searchProcess' ?
                  <CommonListSelectTree dragHandle {...searchProcessType} /> :
                  <CommonListSelectMulti 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 modalMaterials_${searchMaterialsType.id}`}
                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 && commonUtils.isNotEmptyObject(packConfig) ?
            <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={chooseCombinePartsName}
              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.bind(this, isYaChang)}>{Loading ? '下单中' : '确认下单'}</Button>
                {Loading ? <Slider tooltipVisible value={props.workOrderAllprogress} /> : ''}
              </Spin>}
            onCancel={props.onCancelFastOrderModal}
          >
            <SplitPaste {...props} />
          </AntdDraggableModal>
          : ''
        }
        <SlavesInfo {...props} />
        {
          props.contextMenuModalVisible ?
            <ContextMenuModal {...props} />
            : ''
        }
        {
          props.workFlowVisible ?
            <AntdDraggableModal
              width="1300"
              visible
              bodyStyle={{
                padding: 0, height: autoHeight, overflow: 'auto', backgroundColor: '#ffffff',
              }}
              onOk={props.onCancelModal.bind(this, 'workFlowVisible')}
              okButtonProps={okButtonStyle}
              cancelButtonProps={cancelButtonStyle}
              onCancel={props.onCancelModal.bind(this, 'workFlowVisible')}
              closable
              style={{ backgroundColor:'#ffffff', top: 0 }}
              // footer={null}
            >
              <WorkFlow {...props}  />
            </AntdDraggableModal>

            : ''
        }
        {
          props.showAllTreeVisible ?
            <AntdDraggableModal
              width={1300}
              title={DisplayComponentStructure}
              visible={ props.showAllTreeVisible}
              onCancel={props.onCancelModal.bind(this, 'showAllTreeVisible')}
              bodyStyle={{
                padding: 0, mxHeight: '650px', overflow: 'auto', backgroundColor: '#ffffff', paddingTop: -34,
              }}
              footer={null}
            >
              <div className="processList" style={{ marginBottom: '0px', position: 'sticky', top:  '0px', zIndex: 99 }}>
                <StaticEditTable {...controlShowPropsType} tableBelone="list"  noVlist />
              </div>
            </AntdDraggableModal>
            : ''
        }
        {
          props.sProcessParamsModalVisible ?
            <AntdDraggableModal
              width="33%"
              title={sProcessParams}
              visible={props.sProcessParamsModalVisible}
              onOk={props.onProcessParamsOk}
              onCancel={props.onCancelProcessParamsModalVisible}
              // footer={null}
            >
              <div className="sProcessParamsModal" style={{ height: '80%', overflowY: 'auto' }}>
                { commonUtils.isNotEmptyArr(props.sProcessParamsSelects) ?
                  props.sProcessParamsSelects.map((child) => {
                    const sMemo = child.sName.toLowerCase().endsWith('memo');
                    let enabledNew = !child.bReadonly;
                    if (child.iTag === 1) {
                      enabledNew = false;
                    } else if (child.iTag === 3) {
                      enabledNew = true;
                    }
                    // const slaveSelectOneDataIndex = slaveData.findIndex(item => item.sId === selectedRowKeys[selectedRowKeys.length - 1]); // 多选选择最后一个
                    const showTypeProps = {
                      name: 'process',
                      form: props.form,
                      record: props.processRecord,
                      sId: props.processRecord.sId,
                      getSqlDropDownData: props.getSqlDropDownData,
                      getSqlCondition: props.getSqlCondition,
                      handleSqlDropDownNewRecord: props.handleSqlDropDownNewRecord,
                      getFloatNum: props.getFloatNum,
                      onChange: props.onDataChange,
                      showConfig: child,
                      formItemLayout: {},
                      textArea: sMemo,
                      enabled: enabledNew,
                      dataValue: props.processRecord[child.sName],
                      bTable: true,
                      formRoute: props.formRoute,
                    };
                    return (
                      <div className="sProcessParamsModalType">
                        <span>{`${child.showName} : `}</span>
                        <ShowType {...showTypeProps} />
                      </div>
                    );
                  }) : ''
                }
              </div>
            </AntdDraggableModal>
            : ''
        }
        {
          props.sParamsModalVisible ?
            <AntdDraggableModal
              width="920px"
              className="paramModal"
              title={sProcessParams}
              visible={props.sParamsModalVisible}
              onOk={props.onParamsOk}
              onCancel={props.onCancelModal.bind(this, 'sParamsModalVisible')}
              // footer={null}
            >
              <div className="xly-bill-list" >
                <StaticEditTable {...sParamProps} footer="hidden" noVlist />
              </div>
            </AntdDraggableModal> : ''
        }

        {
          props.commonParamVisible ?
            <Modal
              width="80%"
              className="commonParamDrag"
              title={sProcessParams}
              visible={props.commonParamVisible}
              onCancel={props.onCancelModal.bind(this, 'commonParamVisible')}
              footer={
                <Button
                  type='primary'
                  onClick={props.onCancelModal.bind(this, 'commonParamVisible')}
                >确定</Button>
              }
            >
              {
                [''].map(() => {
                  const commonViewDragableProps = {
                    ...props,
                    hideTabsNav: false,
                    sParamData: [
                      {
                        sParamType: 'sProcess',
                        sParamName: '工序参数',
                      },
                      {
                        sParamType: 'sReport',
                        sParamName: '上报参数'
                      },
                      {
                        sParamType: 'sWorkOrder',
                        sParamName: '工单参数'
                      },
                      {
                        sParamType: 'sNorm',
                        sParamName: '标准书参数'
                      },
                      {
                        sParamType: 'sTest',
                        sParamName: '测试参数'
                      }
                    ],
                    tableName: 'process',
                  }
                  return <CommonViewDragable {...commonViewDragableProps} />;
                })
              }
            </Modal> : ''
        }
        {
          props.partsInfoModalVisible ?
            <AntdDraggableModal
              width="100%"
              title={props.partsInfoModalTitle}
              visible={props.partsInfoModalVisible}
              onCancel={props.onCancelModal.bind(this, 'partsInfoModalVisible')}
              footer={
                <Button
                  type='primary'
                  onClick={props.onCancelModal.bind(this, 'partsInfoModalVisible')}
                >确定</Button>
              }
            >
              <CommonPartsInfo {...props} />
            </AntdDraggableModal> : ''
        }
        <ModalComponent {...props} />
      </Layout>
      { true ? '' :   <AntdDraggableDiv draggableDivClassName="xly-eject" > <a onClick={props.onEjectRight}> <img src={EjectRight} alt="eject" /></a> </AntdDraggableDiv>}
      { true ? '' :
        <div className="xly-filter-tree">
          <StaticEditTree {...totalTreeProps} />
          <div className="xly-tree-close">
            {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
            <a onClick={props.onEjectRight}> <img src={CloseRight} alt="close"/></a>
          </div>
        </div>
      }
    </Form>
  );
});

// 工艺参数弹窗
const ModalComponent = props => {
  const modalName = 'sWorkParamsModalVisible'; // commonParamVisible
  const sProcessParams = commonFunc.showMessage(props.app.commonConst, 'workParam') || '工单参数' ;
  const BtnFirst= commonFunc.showMessage(props.app.commonConst, 'BtnFirst') || '首条' ;

  const BtnLast= commonFunc.showMessage(props.app.commonConst, 'BtnLast') || '末条' ;

  const BtnPrior= commonFunc.showMessage(props.app.commonConst, 'BtnPrior') || '上一条' ;

  const BtnNext= commonFunc.showMessage(props.app.commonConst, 'BtnNext') || '下一条' ;
  return props[modalName] ?
    <Modal
      width="80%"
      className="commonParamDrag"
      title={sProcessParams}
      visible={props[modalName]}
      onCancel={() => {
        props.onSaveState({ [modalName]: false });
      }}
      footer={
        <Button
          type="primary"
          onClick={() => {
            props.onSaveState({ [modalName]: false });
          }}
        >
          确定
        </Button>
      }
    >
      <div>
        <div className='oper'>
          <Button type='primary' onClick={() => { props.onBtnParamPage(props, props.processTableId, 'first')}} >{BtnFirst}</Button>
          <Button type='primary' onClick={() => { props.onBtnParamPage(props, props.processTableId, 'before')}} >{BtnPrior}</Button>
          <Button type='primary' onClick={() => { props.onBtnParamPage(props, props.processTableId, 'next')}} >{BtnNext}</Button>
          <Button type='primary' onClick={() => { props.onBtnParamPage(props, props.processTableId, 'last')}} >{BtnLast}</Button>
        </div>
        {
          [''].map(() => {
            const commonViewDragableProps = {
              ...props,
              // comparedTableId: props.processTableId,
              hideTabsNav: true,
              comparedTableId: props.processTableId,
              // bSimpleMode: true,
              sParamData: [
                {
                  sParamType: 'sWorkOrder',
                  sParamName: '工单参数'
                },
              ],
              tableName: 'process',
            }

            commonViewDragableProps.enabled = props.getTableBtnState(commonViewDragableProps.tableName);

            return <CommonViewDragable {...commonViewDragableProps} />;
          })
        }
      </div>
    </Modal> : ''

};

export default CommonBase(CommonSales(WorkOrderPack));
