/* eslint-disable */
/* eslint-disable prefer-destructuring */
import React, { Component } from 'react';
import { UploadOutlined } from '@ant-design/icons';
import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import {
  Row,
  Col,
  Checkbox,
  Layout,
  Spin,
  Tabs,
  Avatar,
  Button,
  Table,
  Upload,
  Input,
  Modal
} from 'antd-v4';
import { message } from '@/utils/common/message';
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 commonBusiness from '@/components/Common/commonBusiness';/* 单据业务功能 */
import commonConfig from '@/utils/config';
import * as commonUtils from '@/utils/utils';/* 通用方法 */
import * as commonServices from '@/services/services';/*   服务类   */
import CommonListSelect from '@/components/Common/CommonListSelect';
import CommonListSelectTree from '@/components/Common/CommonListSelectTree';
import AddIcon from '@/assets/add.svg';
import DisableAddIcon from '@/assets/disableadd.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 DelIcon from '@/assets/delete.svg';
import DisableDelIcon from '@/assets/disabledelete.svg';/* 获取配置及数据 */
import MaterialRemarkIcon from '@/assets/materialremark.svg';
import DisMaRemarklIcon from '@/assets/disablematerialremark.svg';
import ProcessIcon from '@/assets/process.svg';
import DisableProcessIcon from '@/assets/disableprocess.svg';
import MateriallIcon from '@/assets/material.svg';
import DisableMateriallIcon from '@/assets/disablematerial.svg';
// import SlaveMemo from './SlaveMemo';
import AntdDraggableModal from '@/components/Common/AntdDraggableModal';
import StaticEditTree from '@/components/Common/Tree/StaticTree';
import AddChildIcon from '@/assets/addChild.svg';
import DisableAddChildIcon from '@/assets/disableaddChild.svg';
import ContextMenuModal from '@/components/Common/ContextMenuModal';
import CommonViewTable from '@/components/Common/CommonViewTable';
import CommonExamInfo from '@/components/Common/CommonExamInfo';
import customStyles from './index.less';

const width = '18px';
const height = '18px';
const setAdd = {
  title: '增加',
  width: { width },
  height: { height },
  img: <img src={AddIcon} alt="添加" width={width} height={height} />,
  disableimg: <img src={DisableAddIcon} alt="删除" width={width} height={height} />,
};
const setAddChild = {
  title: '增加',
  width: { width },
  height: { height },
  img: <img src={AddChildIcon} alt="添加" width={width} height={height} />,
  disableimg: <img src={DisableAddChildIcon} alt="添加" width={width} height={height} />,
};
const setCopy = {
  title: '复制',
  width: { width },
  height: { height },
  img: <img src={CopyIcon} alt="复制" width="20px" height="20px" />,
  disableimg: <img src={DisableCopyIcon} alt="复制" width="20px" height="20px" />,
};
const setCopyAll = {
  title: '复制部件',
  width: { width },
  height: { height },
  img: <img src={CopyAllIcon} alt="复制部件" width="16px" height="16px" />,
  disableimg: <img src={DisableCopyAllIcon} alt="复制部件" width="16px" height="16px" />,
};
const setDelete = {
  title: '删除',
  width: { width },
  height: { height },
  img: <img src={DelIcon} alt="删除" width={width} height={height} />,
  disableimg: <img src={DisableDelIcon} alt="删除" width={width} height={height} />,
};
const setProcess = {
  title: '工序',
  width: { width },
  height: { height },
  img: <img src={ProcessIcon} alt="选择工序" width="16px" height="16px" />,
  disableimg: <img src={DisableProcessIcon} alt="删除" width="16px" height="16px" />,
};
const setMaterial = {
  title: '材料',
  width: { width },
  height: { height },
  img: <img src={MateriallIcon} alt="选择材料" width="22px" height="22px" />,
  disableimg: <img src={DisableMateriallIcon} alt="选择材料" width="22px" height="22px" />,
};


const { Header, Content, Sider } = Layout;
const { TabPane } = Tabs;
class CommonBill extends Component {
  constructor(props) {
    super(props);
    this.state = {

    };
  }

  componentDidUpdate() {
    if (this.contentRef) {
      const oNavList = this.contentRef.querySelector(".ant-tabs-nav-list");
      if (oNavList) {
        const tabs = Array.from(oNavList.children);
        if (this.tabLength !== tabs.length) {
          this.tabLength = tabs.length;
          tabs.sort((a, b) => {
            const keyA = a.getAttribute("data-node-key") || 999;
            const keyB = b.getAttribute("data-node-key") || 999;
            return keyA < keyB ? -1 : keyA > keyB ? 1 : 0;
          });
          oNavList.innerHTML = "";
          tabs.forEach(tab => oNavList.appendChild(tab));
        }
      }
    }
  }

  /**   行选择   */
  onRowClick = (name, record) => {
    if (name === 'control') {
      this.props.onTableSelectRowChange(name, [record.sId]);
    }
  };

  onChange = (checkedValues) => {
    this.props.onSaveState({
      dataPersonArray: checkedValues,
    });
  };
  getMenuStatus = (menu) => {
    if (menu.sControlName === 'BtnImport') {
      return !this.props.enabled;
    }
  };
  /**   上传后执行函数    */
  handleUploadChangeFile = async (info) => {
    const { file } = info;
    const {
      masterData, sModelsId, app, token, sModelsType, slaveConfig, slaveData,
    } = this.props;
    if (file.response) {
      if (file.response.code === 1) {
        /*   数据查询成功   */
        const errorInfo = file.response.dataset.rows[0].nocanbeInsert;
        if (commonUtils.isNotEmptyObject(errorInfo)) {
          const importErrorData = errorInfo;
          this.props.onSaveState({
            showImportErrorVisible: true,
            importData: importErrorData
          });
          // message.error(errorInfo[0].sReason);
          return;
        }
        /* 把之前存放的数据删除 */
        const slaveDelData = [];
        if (commonUtils.isNotEmptyArr(slaveData)) {
          slaveData.forEach((item) => {
            if (commonUtils.isEmptyObject(item.handleType)) {
              item.handleType = 'del';
              slaveDelData.push(item);
            }
          });
        }
        const returnData = file.response.dataset.rows[0].canbeInsert;
        let iCount = 0;
        let productIdDropDown;
        if (productIdDropDown === undefined && commonUtils.isNotEmptyArr(returnData)) { /* 无论导入多少条数据 都只调用1次接口,获取产品下拉数据集 */
          const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductName');
          if (iIndex > -1) {
            const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[iIndex], returnData[0]);
            productIdDropDown = sqlDropDownData.dropDownData;
          }
        }
        await returnData.forEach(async (tableDataRow) => {
          tableDataRow.handleType = 'add';
          tableDataRow.sId = commonUtils.createSid();
          tableDataRow.sParentId = masterData.sId;
          tableDataRow.key = tableDataRow.sId;
          /* 若导入模板没有序号，则序号从1自增 */
          if (commonUtils.isEmptyObject(tableDataRow.iOrder)) {
            iCount += 1;
            tableDataRow.iOrder = iCount;
          }
          for (const child of Object.keys(tableDataRow)) {
            const index = child.indexOf('_sRealValue_');
            if (index > -1) {
              const property = child.substring(0, child.length - 12);
              tableDataRow[property] = tableDataRow[child];
            }
          }
          if (productIdDropDown !== undefined) {
            const iProductIdIndex = productIdDropDown.findIndex(item => item.sId === tableDataRow.sProductId);
            if (iProductIdIndex === -1 && commonUtils.isNotEmptyObject(sModelsType) && sModelsType.includes('sales/salesOrder')) { /* 只有销售模块生成新产品 盘点 ，期间 不生成新的产品 */
              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,
              });
            }
          }
          // if (!tableDataRow.dNProductPrice) {
          //   tableDataRow.dNProductPrice = tableDataRow.dProductForeignPrice;
          // }
          // const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
          // if (sModelsType.includes('purchase/') || sModelsType.includes('quotation/') || sModelsType.includes('manufacture/') || sModelsType.includes('materialsStock/') || sModelsType.includes('outside/')) {
          //   tableDataRow = await this.props.onMaterialsChange(tableDataRow, sModelsId, masterData, {}, 'dAuxiliaryQty', app, token, models);
          //   tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dAuxiliaryQty', masterData, tableDataRow);
          // } else {
          //   tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dProductQty', masterData, tableDataRow);
          // }
        });
        this.props.onSaveState({ slaveData: returnData, slaveDelData });
      } else { /*   失败s   */
        this.props.getServiceError(file.response);
      }
    }
  };
  handleUploadPropsSales = () => {
    const { masterData, sModelsType } = this.props;
    if (commonUtils.isNotEmptyObject(masterData)) {
      const sCustomerId = commonUtils.isEmptyStr(masterData.sCustomerId) ? undefined : masterData.sCustomerId;
      let existCustomerId = false;
      if (sModelsType.includes('sales/') && commonUtils.isNotEmptyStr(sCustomerId)) {
        existCustomerId = true;
      } else if (!sModelsType.includes('sales/')) {
        existCustomerId = true;
      }
      return {
        disabled: !this.props.enabled || !existCustomerId, /*   是否可用   */
        style: { display: commonUtils.convertBooleanToDisplayBlock(true) }, /*   是否显示   */
      };
    }
  };
  /**   上传后执行函数    */
  handleBeforeUpload = () => {
    // const isLt10M = file.size / 1024 / 1024 < 10;
    // if (!isLt10M) {
    //   message.error(commonFunc.showMessage(this.props.app.commonConst, 'picMax'));/* 图片大小需小于10MB! */
    // }
  };
  /**   图片上传后执行函数    */
  handleUploadChange = (info, name) => {
    const { file } = info;
    if (file.response && file.response.code === 1) {
      const sPicturePath = file.response.dataset.rows[0].savePathStr;
      const spicture = sPicturePath;
      const uploadInfo = {
        sPicturePath,
        sFileName: file.name,
      };
      const { [`${name}Column`]: tableColumn, masterData, [`${name}Data`]: tableData } = this.props;
      if (commonUtils.isNotEmptyArr(tableData) && commonUtils.isEmpty(tableData[tableData.length - 1].sPicturePath)) {
        tableData[tableData.length - 1].sPicturePath = uploadInfo.sPicturePath;
        tableData[tableData.length - 1].spicture = spicture;
        tableData[tableData.length - 1] = {
          ...tableData[tableData.length - 1],
          sPicturePath: uploadInfo.sPicturePath,
          sFileName: uploadInfo.sFileName,
          spicture,
          handleType: commonUtils.isEmpty(tableData[tableData.length - 1].handleType) ? 'update' : tableData[tableData.length - 1].handleType,
        };
      } else {
        const tableDataRow = this.props.onDataRowAdd(name, true);
        tableColumn.forEach((slaveChild) => {
          const ckey = slaveChild.dataIndex;
          if (ckey === 'sProductNo' || ckey === 'sProductName') {
            tableDataRow[ckey] = masterData[ckey] !== undefined ? masterData[ckey] : '';
          } else if (ckey === 'iOrder') {
            tableDataRow[ckey] = '';
          } else if (file.response && file.response.code === 1) {
            if (uploadInfo[ckey] !== undefined) {
              tableDataRow[ckey] = uploadInfo[ckey];
            }
          }
        });
        tableData.push(tableDataRow);
      }
      this.props.onSaveState({ [`${name}Data`]: tableData, enabled: true });
    } else if (file.response && file.response.code === -1) {
      message.error(file.response.msg);
    }
  };
  handleOk = async (flag, tmpCheck, isWait) => {
    const {
      sModelsId, masterData, app, checkConditions, sCheckModelId, checkPersonData, currentId, masterConfig, slaveConfig, checkConfig, sCheckRemark,
    } = 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: sCheckRemark,
          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,
    });
  };
  handleCancel = () => {
    this.props.onSaveState({
      visible: false,
    });
  };

  handleTableModal = async () => {
    const {
      sModelsId, controlData, masterData, slaveData, controlConfig, slaveSelectedRowKeys, enabled, slaveConfig, sModelsType,
    } = this.props;
    const addState = {};
    let treeState = {};
    if (this.props.sModelsType.includes('sales/salesOrder')) {
      const iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
      const iIndex = controlData.findIndex(item => item.sSlaveId === slaveSelectedRowKeys[0]);
      if (iIndex === -1 && iSlaveIndex > -1 && enabled) {
        const allTableData = {};
        allTableData.master = masterData;
        allTableData.slaveData = slaveData;
        let dropdownProductClassifyId;
        const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductClassifyId');
        if (iIndex > -1) {
          const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[iIndex]);
          dropdownProductClassifyId = sqlDropDownData.dropDownData;
        }
        if (commonUtils.isEmptyArr(dropdownProductClassifyId)) {
          const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductClassifyName');
          if (iIndex > -1) {
            const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[iIndex]);
            dropdownProductClassifyId = sqlDropDownData.dropDownData;
          }
        }
        if (commonUtils.isNotEmptyArr(dropdownProductClassifyId)) {
          const iProductClassifyIdIndex = dropdownProductClassifyId.findIndex(item => item.sId === slaveData[iSlaveIndex].sProductClassifyId);
          if (commonUtils.isNotEmptyObject(dropdownProductClassifyId[iProductClassifyIdIndex])) {
            const sAllPartsName = dropdownProductClassifyId[iProductClassifyIdIndex].sAllPartsName;
            if (commonUtils.isNotEmptyStr(sAllPartsName)) {
              const sAssignFieldObj = sAllPartsName.split(',');
              for (const child of sAssignFieldObj) {
                const tableDataRowAdd = commonFunc.getDefaultData(controlConfig, allTableData);
                tableDataRowAdd.handleType = 'add';
                tableDataRowAdd.sId = commonUtils.createSid();
                tableDataRowAdd.sNodeId =  tableDataRowAdd.sId ;
                tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
                tableDataRowAdd.sSlaveId = slaveSelectedRowKeys[0];
                tableDataRowAdd.key = tableDataRowAdd.sId;
                tableDataRowAdd.bDefault = false;
                tableDataRowAdd.iOrder = 0;
                tableDataRowAdd.sPartsName = child;
                tableDataRowAdd.dPartsQty = commonUtils.isNull(slaveData[iSlaveIndex].dProductQty, 0) + commonUtils.isNull(slaveData[iSlaveIndex].dGiveQty, 0) + commonUtils.isNull(slaveData[iSlaveIndex].dStockupQty, 0);
                tableDataRowAdd.sAllId = tableDataRowAdd.sId;
                tableDataRowAdd.sControlParentId = '';
                controlData.push(tableDataRowAdd);
              }
            }
          }
        }
        addState.controlData = controlData;
      }

      if (controlData !== undefined) {
        const iControlIndex = controlData.findIndex(item => item.sSlaveId === slaveSelectedRowKeys[0]);
        if (iControlIndex > -1) {
          addState.controlSelectedRowKeys = [controlData[iControlIndex].sId];
        }
      }
    }

    this.props.onSaveState({
      visibleModal: true,
      ...addState,
      ...treeState,
    });
  };
  handleTableChooseProcess = () => {
    const { processConfig } = this.props;
    const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProcess');

    if (iIndex > -1) {
      this.props.onBtnChoose('process', 'BtnChooseProcess', processConfig.gdsconfigformslave[iIndex]);
    }
  };
  handleCancelModal = (modelVisible) => {
    this.props.onSaveState({
      [modelVisible]: false,
    });
  };
  handleOkModal = async () => {
    const {
      controlData, materialsData, processData, slaveData, slaveSelectedRowKeys,
    } = this.props;
    const ctData = controlData.filter(item => item.handleType !== 'del' && item.sSlaveId === slaveSelectedRowKeys[0]);
    const mtData = materialsData.filter(item => item.handleType !== 'del' && item.sSlaveId === slaveSelectedRowKeys[0]);
    const pData = processData.filter(item => item.handleType !== 'del' && item.sSlaveId === slaveSelectedRowKeys[0] && item.sType !== '3');
    const p3Data = processData.filter(item => item.handleType !== 'del' && item.sSlaveId === slaveSelectedRowKeys[0] && item.sType === '3'); /* 成品工序 */
    if (commonUtils.isNotEmptyArr(ctData)) {
      let mDetail = '';
      let pDetail = '';
      const slaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
      await ctData.forEach((controlItem, n) => {
        if (commonUtils.isNotEmptyObject(controlItem.sPartsName)) {
          const qz = n === 0 ? '' : ' ';
          if (commonUtils.isNotEmptyObject(controlItem.sPartsName)) {
            const yDetail = `${mDetail}${qz}#${controlItem.sPartsName}:`;
            const gDetail = `${pDetail}${qz}#${controlItem.sPartsName}:`;
            let imDetail = '';
            let ipDetail = '';
            const materials = mtData.filter(materialsItem => (materialsItem.sControlId === controlItem.sId));
            // let materialsIdDropDown;
            // const materialsIndex = materialsConfig.gdsconfigformslave.findIndex(item => item.sName === 'sMaterialsName');
            // if (materialsIndex > -1) {
            //   const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'materials', materialsConfig.gdsconfigformslave[materialsIndex]);
            //   materialsIdDropDown = sqlDropDownData.dropDownData;
            // }
            materials.forEach((mItem, i) => {
              const fh = i === 0 ? '' : ',';
              imDetail = `${imDetail}${fh} ${mItem.sMaterialsName}`;
            });
            // processPropsType
            const process = pData.filter(processItem => (processItem.sControlId === controlItem.sId));
            // let processIdDropDown;
            // const processIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProcessName');
            // if (processIndex > -1) {
            //   const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'process', processConfig.gdsconfigformslave[processIndex]);
            //   processIdDropDown = sqlDropDownData.dropDownData;
            // }
            // const processIdDropDown = commonUtils.getStoreDropDownData(sModelsId, 'process', 'sProcessName');
            process.forEach((pItem, i) => {
              const fh = i === 0 ? '' : ',';
              ipDetail = `${ipDetail}${fh} ${pItem.sProcessName}`;
            });
            if (commonUtils.isNotEmptyObject(imDetail)) {
              mDetail = `${yDetail}${imDetail}`;
            }
            if (commonUtils.isNotEmptyObject(ipDetail)) {
              pDetail = `${gDetail}${ipDetail}`;
            }
          }
        }
      });
      /* 成品工序 */
      let ip3Detail = '';
      if (commonUtils.isNotEmptyArr(p3Data)) {
        p3Data.forEach((pItem, i) => {
          const fh = i === 0 ? '' : ',';
          ip3Detail = `${ip3Detail}${fh} ${pItem.sProcessName}`;
        });
      }
      if (commonUtils.isNotEmptyObject(ip3Detail)) {
        if (commonUtils.isNotEmptyObject(pDetail)) {
          pDetail = `${pDetail},${ip3Detail}`;
        } else {
          pDetail = ip3Detail;
        }
      }
      slaveData[slaveIndex].sMaterialsMemo = mDetail;
      slaveData[slaveIndex].sProcessMemo = pDetail;
      slaveData[slaveIndex].handleType = commonUtils.isEmpty(slaveData[slaveIndex].handleType) ? 'update' : slaveData[slaveIndex].handleType;
    } else if (commonUtils.isNotEmptyArr(controlData) && commonUtils.isEmptyArr(ctData)) {
      const sSlaveId = controlData[0].sSlaveId;
      const slaveIndex = slaveData.findIndex(item => item.sId === sSlaveId);
      slaveData[slaveIndex].sMaterialsMemo = '';
      slaveData[slaveIndex].sProcessMemo = '';
      slaveData[slaveIndex].handleType = commonUtils.isEmpty(slaveData[slaveIndex].handleType) ? 'update' : slaveData[slaveIndex].handleType;
    }
    this.props.onSaveState({
      visibleModal: false,
      controlData,
      materialsData,
      processData,
      slaveData,
    });
  };
  /** 控制选择控制表时，显示部件工序与成品工序 */
  handleFilterSlaveData = (name, dataIndex, value, record) => {
    return (commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(value.toLowerCase()));
  };
  /** 控制选择控制表时，显示部件工序与成品工序 */
  handleFilterData = (name, dataIndex, value, record) => {
    const { slaveSelectedRowKeys } = this.props;
    if (name === 'process') {
      return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '3' &&
        commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString().toLowerCase())) ||
        (commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()) &&
          commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString().toLowerCase()));
    } else {
      return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '2' &&
        commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString().toLowerCase())) ||
        (commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()) &&
          commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString().toLowerCase()));
    }
    // (commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()));
  };
  /* 控制表过滤材料表 工序表数据 */
  handleGetFilterData = (name) => {
    const { [`${name}Data`]: data, controlSelectedRowKeys, slaveSelectedRowKeys } = this.props;
    if (data !== undefined) {
      const newArr = data.filter((item) => {
        if (name === 'control') {
          return (commonUtils.isNotEmptyStr(item.sSlaveId) && item.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString()));
        } else {
          return (commonUtils.isNotEmptyStr(item.sControlId) && item.sControlId.toString().toLowerCase().includes(controlSelectedRowKeys.toString()) &&
            commonUtils.isNotEmptyStr(item.sSlaveId) && item.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString()));
        }
      });
      return newArr.length;
    }
  };
  /* 包装工单过滤行 */ /** 控制选择控制表时，显示部件工序与成品工序 */
  handleFilterDataPack = (name, dataIndex, value, 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()));
    }
  };
  /* 控制表过滤材料表 工序表数据 */
  handleGetFilterDataPack = (name) => {
    const { [`${name}Data`]: data, controlSelectedRowKeys } = this.props;
    if (data !== undefined && commonUtils.isNotEmptyArr(controlSelectedRowKeys)) {
      const newArr = data.filter((item) => {
        return (commonUtils.isNotEmptyStr(item.sControlId) && item.sControlId.toString().toLowerCase().includes(controlSelectedRowKeys.toString()));
      });
      return newArr.length;
    }
  };
  /**   添加表格空行   */
  handleTableAdd = async (name, flag, bchild) => {
    /*   外置处理业务   */
    const {
      sModelsId, sModelsType, gdsformconst, slaveData, controlData, controlSelectedRowKeys, [`${name}Data`]: tableData, slaveSelectedRowKeys, slaveConfig,
    } = this.props;
    let tableDataRow = {};
    if (name === 'control') {
      const {
        [`${name}SelectedRowKeys`]: treeSelectedKeys,
      } = this.props;
      if ((bchild === 'childNode' || bchild === 'sameNode') && (commonUtils.isEmptyArr(treeSelectedKeys) || commonUtils.isEmptyArr(controlSelectedRowKeys))) {
        message.warn('请选择部件！'); // 请选择部件
        return;
      }
      tableDataRow = this.props.onDataRowAdd(name, true);
      if (commonUtils.isEmptyObject(tableDataRow)) {
        return;
      }
      let dPartsQty = 0;
      if (commonUtils.isNotEmptyArr(slaveData)) {
        slaveData.forEach((item) => {
          dPartsQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
        });
        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]);
          productIdDropDown = sqlDropDownData.dropDownData;
        }
        if (productIdDropDown) {
          const iProductIdIndex = productIdDropDown.findIndex(item => item.sId === slaveData[0].sProductId);
          if (iProductIdIndex > -1) {
            tableDataRow.sPartsName = productIdDropDown[iProductIdIndex].sProductName;
          }
        }
      }
      const iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
      if (iSlaveIndex > -1) {
        if (sModelsType.includes('sales/salesOrder')) {
          if (!commonUtils.isEmpty(slaveData[iSlaveIndex].dProductQty)) {
            tableDataRow.dPartsQty = commonUtils.isNull(slaveData[iSlaveIndex].dProductQty, 0) + commonUtils.isNull(slaveData[iSlaveIndex].dGiveQty, 0);
          }
        } else {
          tableDataRow.dPartsQty = dPartsQty;
        }
        tableDataRow.sSlaveId = slaveData[iSlaveIndex].sId;
      }
      /* 树形部件节点增加同级部件、增加子级部件 */
      if (sModelsType === 'sales/salesOrderPack') {
        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.sNodeId === pId);
            if (sControlParentId > -1) {
              const sAllId = controlData[sControlParentId].sAllId;
              // if (commonUtils.isEmptyObject(sAllId)) {
              //   message.warn('部件数据生成错误！[sAllId为空]');
              //   return;
              // }
              tableDataRow.sAllId = `${controlData[sControlParentId].sAllId},${tableDataRow.sNodeId}`;
            } else {
              tableDataRow.sAllId = tableDataRow.sNodeId;
            }
          }
        }
        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}`;
          }
        }
      }
      tableData.push(tableDataRow);
      this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId]});
    } else if (name === 'materials' || name === 'process') {
      tableDataRow = this.props.onDataRowAdd(name, true);
      if (commonUtils.isEmptyArr(controlSelectedRowKeys)) {
        const msg = commonFunc.showMessage(gdsformconst, 'pleaseChooseParts');
        message.warn(msg === '' ? '请选择部件' : msg); // 请选择部件
        return;
      }
      const iIndex = controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]);
      const iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
      if (iIndex > -1 && iSlaveIndex > -1) {
        if (commonUtils.isEmpty(controlData[iIndex].sPartsName) === '') {
          message.warn(commonFunc.showMessage(gdsformconst, 'partsNameNotNull')); // 部件名称不能为空
          return;
        }
        tableDataRow.sSlaveId = slaveData[iSlaveIndex].sId;
        tableDataRow.sControlId = controlData[iIndex].sId;
        tableDataRow.sPartsName = controlData[iIndex].sPartsName;
      }
      tableData.push(tableDataRow);
      this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId] });
    } else {
      this.props.onDataRowAdd(name, flag);
    }
  };
  /**   删除表格数据   */
  otherTableDel = (name, tableSelectedRowKeys) => {
    const tableData = this.props[`${name}Data`];
    let tableDelData = this.props[`${name}DelData`];
    tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData;
    for (const sId of tableSelectedRowKeys) {
      /*   看看删除集合和从表中是否都存在该条数据   */
      let tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
      while (tableDataIndex > -1) {
        /*   删除从表中的数据并存入删除集合中   */
        const slaveDataFilter = tableData[tableDataIndex];
        tableData.splice(tableDataIndex, 1);
        slaveDataFilter.handleType = 'del';
        tableDelData.push(slaveDataFilter);
        tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
      }
    }
    return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [] };
  };
  /**   删除表格数据   */
  handleTableDel = (name, isWait, tableSelectedRowKeys, isTree) => {
    const {
      slaveSelectedRowKeys, slaveData, slaveInfoConfig, slaveConfig,
    } = this.props;
    if (name === 'control') {
      // const tableSelectedRowKeys = this.props[`${name}SelectedRowKeys`]; /* 删除时,选中行取删除参数传过来的 */
      const {
        controlData, treeSelectedKeys, [`${name}SelectedRowKeys`]: tableSelectedRowKeys, sModelsType, slaveSelectedRowKeys, slaveData,
      } = this.props;
      if (isTree) {
        /* 删除该节点及所有子节点 */
        const controlChildData = controlData.filter(item => commonUtils.isNotEmptyArr(treeSelectedKeys) && commonUtils.isNotEmptyObject(item.sAllId) && item.sAllId.indexOf(treeSelectedKeys[0]) > -1 && item.sId !== treeSelectedKeys[0]);
        if (commonUtils.isNotEmptyArr(controlData)) {
          controlChildData.forEach((itemNew) => {
            tableSelectedRowKeys.push(itemNew.sId);
          });
        }
      }
      if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) {
        const materialsReturnData = this.otherTableDel('materials', tableSelectedRowKeys);
        const processReturnData = this.otherTableDel('process', tableSelectedRowKeys);
        const controlReturnData = this.props.onDataRowDel(name, isWait, tableSelectedRowKeys);
        this.props.onSaveState({
          ...materialsReturnData,
          ...processReturnData,
          ...controlReturnData,
        });
        return true;
      } else {
        message.warn('请选择要删除的部件！');
        return false;
      }
    } else if (name === 'slave') { /* 删除子表 */
      if( slaveConfig.sTableType === 'multiple' && commonUtils.isNotEmptyObject(slaveInfoConfig)) {
        if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
          let slaveInfoReturnData = {};
          if (commonUtils.isNotEmptyObject(slaveInfoConfig)) {
            slaveInfoReturnData = this.props.onChildTableDel('slaveInfo', slaveSelectedRowKeys, slaveData, 'sFatherSlaveId');
          }
          const slaveReturnData = this.props.onDataRowDel(name, isWait, slaveSelectedRowKeys);
          this.props.onSaveState({
            ...slaveInfoReturnData,
            ...slaveReturnData,
          });
          return true;
        }
      } else if( slaveConfig.sTableType === 'single') { /* 单表删除 */
        if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
          let slaveSelectedRowNewKeys = slaveSelectedRowKeys;
          const newSelectedRowKeys = this.handleDelSlaveChild(slaveData, slaveSelectedRowKeys[0], slaveSelectedRowKeys);
          if(commonUtils.isNotEmptyArr(newSelectedRowKeys)) {
            slaveSelectedRowNewKeys = newSelectedRowKeys;
          }
          const slaveReturnData = this.props.onDataRowDel(name, isWait, slaveSelectedRowNewKeys);
          this.props.onSaveState({
            ...slaveReturnData,
          });
          return true;
        }
      } else {
        const slaveReturnData = this.props.onDataRowDel(name, isWait, slaveSelectedRowKeys);
        this.props.onSaveState({
          ...slaveReturnData,
        });
        return true;
      }
    } else {
      return this.props.onDataRowDel(name, isWait, tableSelectedRowKeys);
    }
  };


  /* 迭代删除从表子表数据  */
  handleDelSlaveChild = (tableData, sId, tableSelectedKeys) => {
    const filterData = tableData.filter(item => item.sFatherSlaveId === sId);
    filterData.forEach((item) => {
      tableSelectedKeys.push(item.sId);
      this.handleDelSlaveChild(tableData, item.sId, tableSelectedKeys);
    });
    return tableSelectedKeys;
  }

  /**   销售订单删除从表数据时也删除控制材料工序表数据   */
  handleSlaveTableDel = (name, isWait, tableSelectedRowKeys) => {
    const {
      sModelsType, controlData, processData, materialsData,
    } = this.props;
    if (sModelsType === 'sales/salesOrder' && name === 'slave') {
      const controlDataDel = controlData.filter(item => item.sSlaveId === tableSelectedRowKeys[0]);
      const controlDataSelectedRowKeys = [];
      if (!commonUtils.isEmpty(controlDataDel)) {
        for (const item of controlDataDel) {
          const materialsDataSelectedRowKey = item.sId;
          controlDataSelectedRowKeys.push(materialsDataSelectedRowKey);
        }
        if (commonUtils.isNotEmptyArr(controlDataSelectedRowKeys)) {
          this.props.onDataRowDel('control', isWait, controlDataSelectedRowKeys, true);
        }
        const materialsDataDel = materialsData.filter(item => item.sSlaveId === tableSelectedRowKeys[0]);
        const materialsDataSelectedRowKeys = [];
        if (!commonUtils.isEmpty(materialsDataDel)) {
          for (const item of materialsDataDel) {
            const materialsDataSelectedRowKey = item.sId;
            materialsDataSelectedRowKeys.push(materialsDataSelectedRowKey);
          }
        }
        if (commonUtils.isNotEmptyArr(materialsDataSelectedRowKeys)) {
          this.props.onDataRowDel('materials', isWait, materialsDataSelectedRowKeys, true);
        }
        const processDataDel = processData.filter(item => item.sSlaveId === tableSelectedRowKeys[0]);
        const processDataSelectedRowKeys = [];
        if (!commonUtils.isEmpty(processDataDel)) {
          for (const item of processDataDel) {
            const processDataSelectedRowKey = item.sId;
            processDataSelectedRowKeys.push(processDataSelectedRowKey);
          }
        }
        if (commonUtils.isNotEmptyArr(processDataSelectedRowKeys)) {
          this.props.onDataRowDel('process', isWait, processDataSelectedRowKeys, true);
        }
      }
    }
    return this.props.onDataRowDel(name, isWait, tableSelectedRowKeys);
  };
  handleSelect = async (name, selectConfig, selectData) => {
    const {
      [`${name}Data`]: tableData,  [`${name}SelectedRowKeys`]: tableSelectedRowKeys, [`${name}Config`]: tableConfig,  masterConfig, controlSelectedRowKeys, sModelsId, token, app, tableName, sModelsType,
    } = this.props;
    let { masterData}= this.props;
    if(commonUtils.isNotEmptyObject(selectConfig.sControlName) && selectConfig.sControlName.toLowerCase().includes('tmplnfobysqlsalesorder')) {
      const { slaveData,   slaveSelectedRowKeys} = this.props;
      const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfoBySql/?sModelsId=${sModelsId}`;
      const sConfigformId = commonUtils.isEmpty(selectConfig) ? '' : selectConfig.sParentId;
      const sControlName = commonUtils.isNotEmptyObject(selectConfig.sControlName) ? selectConfig.sControlName : 'BtnCopyFrom.TmpInfoBySql';
      let sSqlCondition = '';
      const conditonValues0 = this.props.getSqlCondition(selectConfig, 'slave', selectData[0]);
      if(commonUtils.isNotEmptyObject(conditonValues0)) {
        sSqlCondition = conditonValues0;
      } else {
        sSqlCondition = { sId: selectData[0].sId };
      }
      /* 如果只有1行替换，超出1行新增 */
      let iSlaveIndex = -1;
      let slaveRow = {};

      if (commonUtils.isNotEmptyArr(slaveData)) {
        if(commonUtils.isEmptyArr(slaveSelectedRowKeys)){
          iSlaveIndex = 0;
        } else{
          iSlaveIndex = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId));
        }
      }

      if(iSlaveIndex > -1 ){
        slaveRow = slaveData[iSlaveIndex];
      }

      const sRowData = selectData;
      const values = { sConfigformId, sControlName, sRowData };
      const sTmpInfoBySqlBtnName = selectConfig.sControlName;
      const allReturnMap = {};
      if (true) {
        const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
        if (dataReturn.code === 1) {
          const returnData = dataReturn.dataset.rows[0];
          if (commonUtils.isNotEmptyObject(returnData)) {
            for (const key of Object.keys(returnData)) {
              const sName = `${key}Data`;
              const sDelName = `${key}DelData`;
              // allReturnMap[sName] = returnData[key];
              let {[`${key}Data`]: oldData, [`${sDelName}`]: oldDelData } = this.props;

              if(commonUtils.isEmptyArr(oldDelData)) {
                oldDelData = [];
              }
              if(commonUtils.isEmptyArr(oldData)) {
                oldData = [];
              }
              /* 找到赋值字段 */
              const tableConfig =  masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes(sTmpInfoBySqlBtnName +'.' + key));
              const tableField = commonUtils.isNotEmptyArr(tableConfig) ? tableConfig[0].sAssignField : '';
              if(sTmpInfoBySqlBtnName.includes('_edit')) { /* 替换 根据对应字段对比 相同的不管 不同的插入  */
                /* 对应字段 */
                const sActiveKey = selectConfig.sActiveKey;
                const keyData = returnData[key];
                /* 找到赋值字段 */

                let newData = [];
                if(commonUtils.isNotEmptyArr(keyData)) {
                  keyData.forEach((child) => {
                    const filterData = oldData.filter(item => item[sActiveKey] !== child[sActiveKey]);
                    if(commonUtils.isNotEmptyArr(filterData) && filterData.length === oldData.length) {
                      let tableRow ={};
                      tableRow = { ...tableRow, ...commonFunc.getAssignFieldValue(tableField, child) }; // 取赋值字段
                      tableRow.sId = commonUtils.createSid();
                      tableRow.sParentId = masterData.sId;
                      tableRow.handleType = 'add';
                      newData.push(tableRow);
                    }
                  });
                  newData = oldData.concat(newData);
                }
                allReturnMap[sName] = newData;
              } else if(sTmpInfoBySqlBtnName.includes('_del')) { /* 替换 根据对应字段对比 相同的不管 不同的插入  */
                /* 对应字段 */
                oldData.forEach((child) => {
                  child.handleType ='del';
                  oldDelData.push(child);
                });
                allReturnMap[sDelName] = oldDelData;
                oldData = [];
                const keyData = returnData[key];
                if(commonUtils.isNotEmptyArr(keyData)) {
                  keyData.forEach((child) => {
                    let tableRow ={};
                    tableRow = { ...tableRow, ...commonFunc.getAssignFieldValue(tableField, child) }; // 取赋值字段
                    tableRow.sId = commonUtils.createSid();
                    tableRow.sParentId = masterData.sId;
                    tableRow.handleType = 'add';
                    oldData.push(tableRow);
                  });
                }
                allReturnMap[sName] = oldData;
              } else{ /* 插入 数据都插入进去  */
                /* 对应字段 */
                const keyData = returnData[key];

                // 生产补印备料
                if (this.props.sModelsId === '12710101117005582604140' && key !=='master') {
                  oldData.forEach((child) => {
                    child.handleType ='del';
                    oldDelData.push(child);
                  });
                  allReturnMap[sDelName] = oldDelData;
                  oldData = [];
                }
                if(key === 'master') {
                  let newData = keyData;
                  if (commonUtils.isNotEmptyArr(keyData) && Array.isArray(keyData)) {
                    newData = keyData[0]
                  }
                  oldData = { ...oldData, ...commonFunc.getAssignFieldValue(tableField, newData) }; // 取赋值字段
                  masterData.handleType = commonUtils.isEmpty( masterData.handleType) ? 'update' :  masterData.handleType;
                } else if(key === 'slave') { /* 从表 */
                  if(commonUtils.isNotEmptyObject(slaveRow) && commonUtils.isNotEmptyArr(oldData)) {
                    oldData[iSlaveIndex] = { ...slaveRow, ...commonFunc.getAssignFieldValue(tableField, keyData[0]) }; // 取赋值字段
                    oldData[iSlaveIndex].sOriginalId = commonUtils.isNotEmptyObject(keyData[0].sOriginalId) ? keyData[0].sOriginalId: keyData[0].sSlaveId;
                    // 生产补印备料
                    if (this.props.sModelsId === '12710101117005582604140') {
                      oldData[iSlaveIndex].sBomId = selectData[0].sProductCardId;
                      oldData[iSlaveIndex].sProductTechnologyVer = selectData[0].sProductTechnologyVer;
                      oldData[iSlaveIndex].sSelectType = "mainVersion";
                      oldData[iSlaveIndex].handleType = commonUtils.isEmpty(oldData[iSlaveIndex].handleType) ? 'update' : oldData[iSlaveIndex].handleType;
                      oldData[iSlaveIndex].sMainProductTechnologyId = selectData[0].sProductCardId;
                    }
                    slaveData[iSlaveIndex] = oldData[iSlaveIndex];
                  } else {
                    if(commonUtils.isNotEmptyArr(keyData)) {
                      keyData.forEach((child) => {
                        let tableRow ={};
                        tableRow = { ...tableRow, ...commonFunc.getAssignFieldValue(tableField, child) }; // 取赋值字段
                        tableRow.sId = commonUtils.createSid();
                        tableRow.sParentId = masterData.sId;
                        tableRow.sOriginalId = commonUtils.isNotEmptyObject(child.sSlaveId) ? child.sSlaveId : child.sId; /* 原始sId */
                        tableRow.sFatherSlaveId = child.sFatherSlaveId; /* 原始sId */
                        tableRow.handleType = 'add';

                        if (this.props.sModelsId === '12710101117005582604140') {
                          tableRow.sBomId = selectData[0].sProductCardId;
                          tableRow.sProductTechnologyVer = selectData[0].sProductTechnologyVer;
                          tableRow.sSelectType = "mainVersion";
                          tableRow.sMainProductTechnologyId = selectData[0].sProductCardId;
                        }
                        oldData.push(tableRow);
                      });
                    }
                  }
                  /* sFatherSlaveId对应为新的sId */
                  if(commonUtils.isNotEmptyArr(oldData)) {
                    const materialsFilterData = oldData.filter(item => commonUtils.isNotEmptyObject(item.sFatherSlaveId));
                    if (commonUtils.isNotEmptyArr(materialsFilterData)) {
                      materialsFilterData.forEach((filterItem, index) => {
                        const iIndex = oldData.findIndex(item => item.sOriginalId === filterItem.sFatherSlaveId);
                        if (iIndex > -1) {
                          const iNexIndex = oldData.findIndex(item => item.sId === filterItem.sId);
                          if (iNexIndex > -1) {
                            oldData[iNexIndex] = {
                              ...oldData[iNexIndex],
                              sFatherSlaveId: oldData[iIndex].sId
                            }
                          }
                        }

                      });
                    }
                  }
                }else {
                  if(commonUtils.isNotEmptyArr(keyData)) {
                    keyData.forEach((child) => {
                      let tableRow ={};
                      tableRow = { ...tableRow, ...commonFunc.getAssignFieldValue(tableField, child) }; // 取赋值字段
                      tableRow.sId = commonUtils.createSid();
                      tableRow.sParentId = masterData.sId;
                      tableRow.sOriginalId = child.sOriginalId; /* 老的从表sSlaveId */
                      // 生产补印备料
                      if (this.props.sModelsId === '12710101117005582604140') {
                        tableRow.sProductCardId = selectData[0].sProductCardId;
                        tableRow.sZmldlt = child.sZmldlt;
                        tableRow.sSlaveId = commonUtils.isNotEmptyArr(slaveData) && slaveData[0].sId ?  slaveData[0].sId : '';
                        tableRow.sProcessTbId = child.sProcessTbId;
                        tableRow.sParentMaterialsId = child.sParentMaterialsId;
                        tableRow.sInkFatherMaterialsTbId = child.sInkFatherMaterialsTbId;
                        tableRow.sOriginalOldId = child.sId;

                      }

                      if(key === 'control') {
                        tableRow.sSrcControlId = child.sId;
                      } else {
                        tableRow.sSrcControlId = child.sControlId;
                      }
                      tableRow.handleType = 'add';
                      oldData.push(tableRow);
                    });
                  }
                  if(commonUtils.isNotEmptyObject(slaveRow)){
                    /* 将部件、材料、工序的sSlaveId 均换成最新的 */
                    oldData =  commonUtils.genSlaveNewId(oldData, key, 'sSlaveId', 'sOriginalId', slaveData[iSlaveIndex]);
                  }
                }
                allReturnMap[sName] = oldData;
              }

            }

            /* 将工序材料表的sControlId 换成最新的 */
            if(commonUtils.isNotEmptyObject(allReturnMap)) {
              const controlNewData = allReturnMap.controlData;
              const materialsNewData = allReturnMap.materialsData;
              const processNewData = allReturnMap.processData;
              if(commonUtils.isNotEmptyArr(controlNewData)) {

                controlNewData.forEach((controlRow) =>{

                  /* 替换工序数据中sControlId为最新控制表的sId */
                  if(commonUtils.isNotEmptyArr(processNewData)) {
                    const processFilterData = processNewData.filter(materialsRow => materialsRow.sSrcControlId === controlRow.sSrcControlId);
                    if(commonUtils.isNotEmptyArr(processFilterData)) {
                      processFilterData.forEach((filterRow) =>{
                        const index = processNewData.findIndex(materialsRow => materialsRow.sId === filterRow.sId);
                        filterRow.sControlId = controlRow.sId;
                        filterRow.sPartsName = controlRow.sPartsName;
                        if (index > -1) {
                          processNewData[index] = filterRow;
                        }
                      })
                    }
                  }

                  /* 替换材料数据中sControlId为最新控制表的sId */
                  if(commonUtils.isNotEmptyArr(materialsNewData)) {
                    let materialsFilterData = materialsNewData.filter(materialsRow => materialsRow.sSrcControlId === controlRow.sSrcControlId);
                    if(commonUtils.isNotEmptyArr(materialsFilterData)) {
                      materialsFilterData.forEach((filterRow) =>{
                        const index = materialsNewData.findIndex(materialsRow => materialsRow.sId === filterRow.sId);
                        filterRow.sControlId = controlRow.sId;
                        filterRow.sPartsName = controlRow.sPartsName;
                        if (index > -1) {
                          materialsNewData[index] = filterRow;
                          // 材料对应工序的ID要变化
                          const iProcessIndex = processNewData.findIndex(item => item.sControlId === controlRow.sId && item.sSrcProcessTbId === materialsNewData[index].sProcessTbId);
                          if (iProcessIndex > -1) {
                            materialsNewData[index].sProcessTbId = processNewData[iProcessIndex].sId;
                          }
                          materialsNewData[index].sCombinePartsName = commonUtils.isNotEmptyArr(allReturnMap.slaveData) ? allReturnMap.slaveData[0].sId : '';
                        }

                      });
                    }


                    const materialsData = materialsNewData;
                    materialsFilterData = materialsData.filter(item => commonUtils.isNotEmptyObject(item.sParentMaterialsId));
                    if(commonUtils.isNotEmptyArr(materialsFilterData)) {
                      materialsFilterData.forEach((filterItem, index) => {
                        const iIndex = materialsData.findIndex(item => item.sOriginalOldId === 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.sOriginalOldId === 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}
                          }
                        }
                      });
                    }
                  }
                });

                allReturnMap.materialsData = materialsNewData;
                allReturnMap.processData = processNewData;
              }
            }

            if (commonUtils.isNotEmptyArr(allReturnMap.masterData) && Array.isArray(allReturnMap.masterData)) {
              allReturnMap.masterData = allReturnMap.masterData[0];
            }
            console.log('历史工单allReturnMap:', allReturnMap);
            this.props.onSaveState({ ...allReturnMap });
          }

        } else {
          this.props.getServiceError(dataReturn);
        }
      } else {
        message.warn('数据未配置！不能生成！');
        return;
      }
    } else if(commonUtils.isNotEmptyObject(selectConfig.sControlName) && selectConfig.sControlName.toLowerCase().includes('tmpinfobysql')) {
      const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfoBySql/?sModelsId=${sModelsId}`;
      const sConfigformId = commonUtils.isEmpty(selectConfig) ? '' : selectConfig.sParentId;
      const sControlName = commonUtils.isNotEmptyObject(selectConfig.sControlName) ? selectConfig.sControlName : 'BtnCopyFrom.TmpInfoBySql';
      let sSqlCondition = '';
      const conditonValues0 = this.props.getSqlCondition(selectConfig, 'slave', selectData[0]);
      if(commonUtils.isNotEmptyObject(conditonValues0)) {
        sSqlCondition = conditonValues0;
      } else {
        sSqlCondition = { sId: selectData[0].sId };
      }
      const sRowData = selectData;
      const values = { sConfigformId, sControlName, sRowData };
      const sTmpInfoBySqlBtnName = selectConfig.sControlName;
      const allReturnMap = {};
      if (true) {
        const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
        if (dataReturn.code === 1) {
          const returnData = dataReturn.dataset.rows[0];
          if (commonUtils.isNotEmptyObject(returnData)) {
            for (const key of Object.keys(returnData)) {
              const sName = `${key}Data`;
              const sDelName = `${key}DelData`;
              // allReturnMap[sName] = returnData[key];
              let {[`${key}Data`]: oldData, [`${key}Data`]: oldDelData } = this.props;

              if(commonUtils.isEmptyArr(oldDelData)) {
                oldDelData = [];
              }
              if(commonUtils.isEmptyArr(oldData)) {
                oldData = [];
              }
              /* 找到赋值字段 */
              const tableConfig =  masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes(sTmpInfoBySqlBtnName +'.' + key));
              const tableField = commonUtils.isNotEmptyArr(tableConfig) ? tableConfig[0].sAssignField : '';
              if(sTmpInfoBySqlBtnName.includes('_edit')) { /* 替换 根据对应字段对比 相同的不管 不同的插入  */
                /* 对应字段 */
                const sActiveKey = selectConfig.sActiveKey;
                const keyData = returnData[key];
                /* 找到赋值字段 */

                let newData = [];
                if(commonUtils.isNotEmptyArr(keyData)) {
                  keyData.forEach((child) => {
                    const filterData = oldData.filter(item => item[sActiveKey] !== child[sActiveKey]);
                    if(commonUtils.isNotEmptyArr(filterData) && filterData.length === oldData.length) {
                      let tableRow ={};
                      tableRow = { ...tableRow, ...commonFunc.getAssignFieldValue(tableField, child) }; // 取赋值字段
                      tableRow.sId = commonUtils.createSid();
                      tableRow.sParentId = masterData.sId;
                      tableRow.handleType = 'add';
                      newData.push(tableRow);
                    }
                  });
                  newData = oldData.concat(newData);
                }
                allReturnMap[sName] = newData;
              } else { /* 替换 根据对应字段对比 相同的不管 不同的插入  */
                /* 对应字段 */
                oldData.forEach((child) => {
                  child.handleType ='del';
                  oldDelData.push(child);
                });
                allReturnMap[sDelName] = oldDelData;
                oldData = [];
                const keyData = returnData[key];
                if(commonUtils.isNotEmptyArr(keyData)) {
                  keyData.forEach((child) => {
                    let tableRow ={};
                    tableRow = { ...tableRow, ...commonFunc.getAssignFieldValue(tableField, child) }; // 取赋值字段
                    tableRow.sId = commonUtils.createSid();
                    tableRow.sParentId = masterData.sId;
                    tableRow.handleType = 'add';
                    oldData.push(tableRow);
                  });
                }
                allReturnMap[sName] = oldData;
              }

            }
            if (commonUtils.isNotEmptyArr(allReturnMap.masterData) && Array.isArray(allReturnMap.masterData)) {
              allReturnMap.masterData = allReturnMap.masterData[0];
            }
            console.log('allReturnMap:111', allReturnMap);
            this.props.onSaveState({ ...allReturnMap });
          }

        } else {
          this.props.getServiceError(dataReturn);
        }
      } else {
        message.warn('数据未配置！不能生成！');
        return;
      }
    } else if (sModelsType !== '' && sModelsType.includes('sales/') && name === 'productProcessInfo') { /* 销售订单调用工艺卡 */
      const {
        controlConfig, materialsConfig, processConfig, slaveSelectedRowKeys, slaveData,
      } = this.props;
      const iIndex = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId));
      if (iIndex > -1 && commonUtils.isNotEmptyArr(selectData)) {
        const tableDataRow = slaveData[iIndex]; /* 从表选中行 */
        let { controlData, materialsData, processData } = this.props;
        const sId = tableDataRow.sId;
        const bCkxCopyFromTechnology = '1'; // app.systemData.filter(item => item.sName === 'CkxCopyFromTechnology')[0].sValue;
        if (bCkxCopyFromTechnology === '1' && tableDataRow.sProductId !== tableDataRow.sProductName) {
          const controlSelectedData = controlData.filter(item => item.sSlaveId === sId);
          if (commonUtils.isNotEmptyObject(controlSelectedData)) {
            const controlSelectedRowKeys = [];
            controlSelectedData.forEach((item) => {
              controlSelectedRowKeys.push(item.sId);
            });
            const materialsReturnData = this.otherTableDel('materials', controlSelectedRowKeys);
            const processReturnData = this.otherTableDel('process', controlSelectedRowKeys);
            const controlReturnData = this.props.onDataRowDel('control', true, controlSelectedRowKeys);
            controlData = controlReturnData.controlData;
            materialsData = materialsReturnData.materialsData;
            processData = processReturnData.processData;
            this.props.onSaveState({
              ...materialsReturnData,
              ...processReturnData,
              ...controlReturnData,
            });
          }
          const sCustomerId = selectData[0].sCustomerId;
          const sProductId = selectData[0].sProductId;
          const sProductIdArray = [];
          sProductIdArray.push(sProductId);
          const sProductIds = sProductIdArray.toString();
          const condition = {
            sCustomerId, sProductIds,
            sRowData: selectData,
          };
          const dataUrl = `${commonConfig.server_host}salesorder/getProcessCardDataByCustomIdProductId/?sModelsId=${sModelsId}`;
          const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
          const config = this.props.masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes('BtnCopyFrom.productProcessInfo'));
          if (dataReturn.code === 1) {
            const returnData = dataReturn.dataset.rows[0];
            const copyToControlConfig = config.filter(item => item.sControlName.toLowerCase().includes('.control'));
            const copyToMaterialsConfig = config.filter(item => item.sControlName.toLowerCase().includes('.materials'));
            const copyToProcessConfig = config.filter(item => item.sControlName.toLowerCase().includes('.process'));
            const controlAssignField = commonUtils.isNotEmptyArr(copyToControlConfig) ? copyToControlConfig[0].sAssignField : '';
            const materialsAssignField = commonUtils.isNotEmptyArr(copyToMaterialsConfig) ? copyToMaterialsConfig[0].sAssignField : '';
            const processAssignField = commonUtils.isNotEmptyArr(copyToProcessConfig) ? copyToProcessConfig[0].sAssignField : '';
            const newCopyTo = {};
            newCopyTo.master = masterData;
            newCopyTo.slave = commonUtils.isEmptyArr(tableData) ? {} : tableData;
            if (commonUtils.isNotEmptyArr(returnData.controlData)) {
              const treeCopyNodes = new Map();
              // eslint-disable-next-line no-loop-func
              returnData.controlData.forEach((controlItem) => {
                newCopyTo.control = controlItem;
                let controlRow = commonFunc.getDefaultData(controlConfig, newCopyTo); // 取默认值
                controlRow = { ...controlRow, ...commonFunc.getAssignFieldValue(controlAssignField, controlItem, newCopyTo) }; // 取赋值字段
                controlRow.handleType = 'add';
                controlRow.sId = commonUtils.createSid();
                controlRow.sSlaveId = tableDataRow.sId;
                controlRow.sParentId = masterData.sId;
                if (sModelsType === 'sales/salesOrderPack') { /* 树形 */
                  /* CopyTo时sAllId,sControlParentId 设置 */
                  const sAllOldId = controlItem.sAllId;
                  let arr = [];
                  if (commonUtils.isNotEmptyObject(sAllOldId)) {
                    arr = sAllOldId.split(',');
                  }
                  const newId = controlRow.sId;
                  let sOldParentId = '';
                  let sNewParentAllId = '';
                  if (arr.length < 2) { /* 根节点复制 */
                    controlRow.sAllId = newId;
                    sOldParentId = newId;
                    sNewParentAllId = newId;
                  } else {
                    sOldParentId = arr[arr.length - 2];
                    if (treeCopyNodes.has(sOldParentId)) {
                      sNewParentAllId = treeCopyNodes.get(sOldParentId);
                    } else {
                      const obj = arr[arr.length - 1];
                      sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
                    }
                    const sNewArr = sNewParentAllId.split(',');
                    controlRow.sControlParentId = sNewArr[sNewArr.length - 1];
                    sNewParentAllId = `${sNewParentAllId},${newId}`;
                    controlRow.sAllId = sNewParentAllId;
                  }
                  treeCopyNodes.set(controlItem.sId, sNewParentAllId);
                }
                controlData.push(controlRow);

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

                      materialsData.push(materialsRow);
                    });
                }

                if (commonUtils.isNotEmptyArr(returnData.processData)) {
                  returnData.processData.filter(item => item.sControlId === controlItem.sId)
                    .forEach((processItem) => {
                      newCopyTo.process = processItem;
                      let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
                      processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                      processRow.handleType = 'add';
                      processRow.sId = commonUtils.createSid();
                      processRow.sSlaveId = tableDataRow.sId;
                      processRow.sParentId = masterData.sId;
                      processRow.sControlId = controlRow.sId;
                      processRow.sPartsName = controlRow.sPartsName;
                      processData.push(processRow);
                    });
                }
              });
            }
            if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
              // eslint-disable-next-line no-loop-func
              returnData.materialsData.filter(item => item.sType === '2')
                .forEach((materialsItem) => {
                  newCopyTo.materials = materialsItem;
                  let materialsRow = commonFunc.getDefaultData(materialsConfig, newCopyTo); // 取默认值
                  materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
                  materialsRow.handleType = 'add';
                  materialsRow.sId = commonUtils.createSid();
                  materialsRow.sSlaveId = tableDataRow.sId;
                  materialsRow.sParentId = masterData.sId;
                  materialsData.push(materialsRow);
                });
            }
            if (commonUtils.isNotEmptyArr(returnData.processData)) {
              // eslint-disable-next-line no-loop-func
              returnData.processData.filter(item => item.sType === '3')
                .forEach((processItem) => {
                  newCopyTo.process = processItem;
                  let processRow = commonFunc.getDefaultData(processConfig, newCopyTo); // 取默认值
                  processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
                  processRow.handleType = 'add';
                  processRow.sId = commonUtils.createSid();
                  processRow.sSlaveId = tableDataRow.sId;
                  processRow.sParentId = masterData.sId;
                  processData.push(processRow);
                });
            }
            this.props.onSaveState({
              controlData,
              materialsData,
              processData,
            });
          }
        }
      }
    } else if (name === 'productProcessInfoAbandon') { /* 暂未使用的调用工艺卡功能 */
      if (commonUtils.isNotEmptyArr(selectData)) {
        let slaveData = [];
        let controlData = [];
        let materialsData = [];
        let processData = [];
        let sConfigMasterIdSlave = '';
        let sConfigMasterIdControl = '';
        let sConfigMasterIdMaterials = '';
        let sConfigMasterIdProcess = '';
        const selectRowData = selectData[0];
        const sConfigIdString = masterConfig.gdsconfigformslave.filter(item => item.sName === 'sConfigId')[0].showDropDown;
        if (commonUtils.isNotEmptyStr(sConfigIdString)) {
          const sConfigId = JSON.parse(sConfigIdString);
          sConfigMasterIdSlave = sConfigId.sConfigMasterIdSlave;
          sConfigMasterIdControl = sConfigId.sConfigMasterIdControl;
          sConfigMasterIdMaterials = sConfigId.sConfigMasterIdMaterials;
          sConfigMasterIdProcess = sConfigId.sConfigMasterIdProcess;
        }
        if (commonUtils.isEmptyStr(sConfigMasterIdSlave)) {
          message.warning(commonFunc.showMessage(app.commonConst, 'slaveParameterErro'));
        }
        if (commonUtils.isEmptyStr(sConfigMasterIdControl)) {
          message.warning(commonFunc.showMessage(app.commonConst, 'controlParameterErro'));
        }
        if (commonUtils.isEmptyStr(sConfigMasterIdMaterials)) {
          message.warning(commonFunc.showMessage(app.commonConst, 'materialsParameterErro'));
        }
        if (commonUtils.isEmptyStr(sConfigMasterIdProcess)) {
          message.warning(commonFunc.showMessage(app.commonConst, 'processParameterErro'));
        }
        const slaveUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${sConfigMasterIdSlave}?sModelsId=${sModelsId}`;
        const value = { sSqlCondition: { sParentId: selectRowData.sId } };
        const slaveReturnData = (await commonServices.postValueService(token, value, slaveUrl)).data;
        if (slaveReturnData.code === 1) {
          slaveData = slaveReturnData.dataset.rows[0].dataSet;
          slaveData.forEach((item) => {
            item.handleType = 'add';
            item.sId = commonUtils.createSid();
            item.sParentId = masterData.sId;
          });
        } else {
          this.props.getServiceError(slaveReturnData);
        }

        const controlUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${sConfigMasterIdControl}?sModelsId=${sModelsId}`;
        const controlReturnData = (await commonServices.postValueService(token, value, controlUrl)).data;
        if (controlReturnData.code === 1) {
          controlData = controlReturnData.dataset.rows[0].dataSet;
          controlData.forEach((item) => {
            item.handleType = 'add';
            item.sId = commonUtils.createSid();
            item.sParentId = masterData.sId;
          });
        } else {
          this.props.getServiceError(controlReturnData);
        }
        const materialsUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${sConfigMasterIdMaterials}?sModelsId=${sModelsId}`;
        const materialsReturnData = (await commonServices.postValueService(token, value, materialsUrl)).data;
        if (materialsReturnData.code === 1) {
          materialsData = materialsReturnData.dataset.rows[0].dataSet;
          materialsData.forEach((item) => {
            item.handleType = 'add';
            item.sId = commonUtils.createSid();
            item.sParentId = masterData.sId;
          });
        } else {
          this.props.getServiceError(materialsReturnData);
        }
        const processUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${sConfigMasterIdProcess}?sModelsId=${sModelsId}`;
        const processReturnData = (await commonServices.postValueService(token, value, processUrl)).data;
        if (processReturnData.code === 1) {
          processData = processReturnData.dataset.rows[0].dataSet;
          processData.forEach((item) => {
            item.handleType = 'add';
            item.sId = commonUtils.createSid();
            item.sParentId = masterData.sId;
          });
        } else {
          this.props.getServiceError(processReturnData);
        }
        this.props.onSaveState({
          processData, materialsData, controlData, slaveData, [`${name}ChooseVisible`]: false, [`${name}SelectedRowKeys`]: tableSelectedRowKeys,
        });
      }
    } else if (tableName === 'slave' && selectConfig.sControlName === 'BtnChooseMaterials') {
      this.props.onSelect('slave', selectConfig, selectData);
    } else if (sModelsType.includes('cashier/') && selectConfig.sControlName === 'BtnImportFormData') {
      const { slaveData } = this.props;
      let tableDataNew = [];
      if (commonUtils.isNotEmptyArr(slaveData)) {
        tableDataNew = slaveData;
        tableDataNew.forEach((item, index) => {
          const handleType = item.handleType;
          if (commonUtils.isEmptyObject(handleType) || handleType === 'update') {
            tableDataNew[index] = { ...item, handleType: 'del' };
          }
        });
      }
      if (commonUtils.isNotEmptyArr(selectData)) {
        selectData.forEach((item) => {
          let tableDataRow = {}; // 取默认值
          tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item) }; // 取赋值字段
          tableDataRow.handleType = 'add';
          tableDataRow.sId = commonUtils.createSid();
          tableDataRow.sParentId = masterData.sId;
          tableDataNew.push(tableDataRow);
        });
        this.props.onSaveState({ slaveData: tableDataNew, importFormDataVisible: false });
      }
    } else {
      const { controlData, slaveData, slaveSelectedRowKeys } = this.props;
      const iIndex = commonUtils.isNotEmptyArr(controlSelectedRowKeys) ? controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]) : -1;
      if (commonUtils.isNotEmptyArr(selectData)) {
        selectData.forEach((item) => {
          const newCopyTo = {};
          newCopyTo.master = masterData;
          if (iIndex > -1) {
            newCopyTo.control = controlData[iIndex];
          }
          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 (this.props.sModelsType.includes('sales/salesOrder')) {
            const iSlaveIndex = commonUtils.isNotEmptyArr(slaveSelectedRowKeys) ? slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]) : -1;
            if (iSlaveIndex > -1) {
              tableDataRow.sSlaveId = slaveData[iSlaveIndex].sId;
            }
          }
          if (iIndex > -1 && tableDataRow.sType !== '3') {
            tableDataRow.sControlId = controlData[iIndex].sId;
            tableDataRow.sPartsName = controlData[iIndex].sPartsName;
            tableData.push(tableDataRow);
          } else if (tableDataRow.sType === '3') {
            tableData.push(tableDataRow);
          }
          tableSelectedRowKeys.push(tableDataRow.sId);
        });
      }
      const tableDataNew = this.sortData(controlData, tableData);
      this.props.onSaveState({ [`${name}Data`]: tableDataNew, [`${name}ChooseVisible`]: false, [`${name}SelectedRowKeys`]: tableSelectedRowKeys });
    }
  };

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

  sortData = (tableData, processData) => {
    processData.sort((g1, g2) => {
      const iIndex1 = tableData.findIndex(item => item.sId === g1.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g1.sControlId);
      let sPartOrder1 = `0000${iIndex1}`;
      sPartOrder1 = sPartOrder1.substring(sPartOrder1.length - 3);
      let sOrder1 = `000${g1.iOrder}`;
      sOrder1 = sOrder1.substring(sOrder1.length - 3);

      const iIndex2 = tableData.findIndex(item => item.sId === g2.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g2.sControlId);
      let sPartOrder2 = `0000${iIndex2}`;
      sPartOrder2 = sPartOrder2.substring(sPartOrder2.length - 3);
      let sOrder2 = `000${g2.iOrder}`;
      sOrder2 = sOrder2.substring(sOrder2.length - 3);
      return parseInt(sPartOrder1 + g1.sType + sOrder1, 10) - parseInt(sPartOrder2 + g2.sType + sOrder2, 10);
    });
    return processData;
  };
  handleGetDataOk = () => {
    this.props.onDataImport('zero');
  }
  handleGetDataCancel = () => {
    this.props.onDataImport('all');
  }
  colseGetDataVisible = () => {
    this.props.onSaveState({ isGetDataVisible: false });
  }

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

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

  handleMenuClick= (e) => {
    let { sId } = this.props.masterData;
    const Type = e.key;
    const { token } = this.props.app;
    const { sType } = this.props.app.userinfo;
    if (Type === 'formSlave') { /* 根据从表勾选数据 生成从表数据 */
      const { slaveSelectedRowKeys } = this.props;
      if (commonUtils.isEmptyObject(slaveSelectedRowKeys)) {
        message.error(commonFunc.showMessage(this.props.app.commonConst, 'pleaseChooseData'));/* 请选择一条数据 */

        return;
      }
      sId = slaveSelectedRowKeys;
    }
    const downloadUrl = `${commonConfig.server_host}sqlfile/scriptSqlDownload?methodName=${Type
    }&sId=${sId}&token=${token}&sType=${sType}`;
    window.open(downloadUrl);
    this.props.onSaveState({
      downloadUrl,
    });
  };

  handleSqlDownload = (type) => {
    const { masterData } = this.props;
    const { token } = this.props.app;
    const { sType } = this.props.app.userinfo;
    if (commonUtils.isNotEmptyObject(masterData) && commonUtils.isNotEmptyObject(masterData.sId)) {
      let downloadUrl = '';
      if (type === 'all') {
        downloadUrl = `${commonConfig.server_host}sqlfile/scriptSqlDownload?methodName=module&&Type=ALL&sId=${masterData.sParentId !== '' ? masterData.sParentId : masterData.sId}&token=${token}&sType=${sType}`;
      } else {
        downloadUrl = `${commonConfig.server_host}sqlfile/scriptSqlDownload?methodName=module&&Type=ALL&sId=${masterData.sId}&token=${token}&sType=${sType}`;
      }
      window.open(downloadUrl);
    }
  }

  handleDrag = (data) => {
    this.props.onSaveState({
      processData: data,
    });
  }

  handleTableFilterData = (name, data, record) => {
    /*   外置处理业务   */
    if (name === 'slave') {
      let slaveInfoDataNew = [];
      if (commonUtils.isNotEmptyArr(data)) {
        slaveInfoDataNew = data.filter(item => item.sFatherSlaveId && record.sId && item.sFatherSlaveId === record.sId);
      }
      return slaveInfoDataNew;
    }
  }

  handleCheckBoxStatus = (status, dataIndex, name) => {
    const { [`${name}Data`]: dataSource} = this.props;
    if (!Array.isArray(dataSource)) return;
    const result = dataSource.map(i => ({
      ...i,
      [dataIndex]: status,
    }));
    this.props.onSaveState({ [`${name}Data`]: result });
  }

  render() {
    const {
      pageLoading, masterConfig, visible, checkConditions, checkPersonData, visibleModal, processChooseVisible, materialsChooseVisible,
      app, sTabId, sModelsType, enabled, slaveSelectedRowKeys, controlData,
    } = this.props;
    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',
      render: (text, record) => {
        return (
          <Form>
            <Input onChange={(e) => { this.textChange(e, record); }} />
          </Form>
        );
      },
    }];
    let chooseProcessConfig;
    let onChooseProcessIndex;
    /* 获取toolbar 选择工序 */
    if (commonUtils.isNotEmptyObject(masterConfig)) {
      onChooseProcessIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProcess');
      if (onChooseProcessIndex > -1) {
        chooseProcessConfig = this.props.masterConfig.gdsconfigformslave[onChooseProcessIndex];
      }
    }
    /* 获取toolbar 选择材料 */
    let chooseMaterialsConfig;
    const modalWidth = '1132';
    const fixedAutoHeight = sModelsType === 'sales/salesOrderPack' ? 120 : 66;
    if (commonUtils.isNotEmptyObject(masterConfig)) {
      const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseMaterials');
      if (iIndex > -1) {
        chooseMaterialsConfig = masterConfig.gdsconfigformslave[iIndex];
      }
    }
    /* 若销售订单从表选中行被工单或其他调用 则材料与工艺只能查看不能操作s */
    let bUsed = enabled;
    if (sModelsType.includes('sales/salesOrder') && enabled && commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
      const { slaveData } = this.props;
      const iSlaveDataIndex = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId));
      if (iSlaveDataIndex > -1) {
        const sWorkOrderUsed = slaveData[iSlaveDataIndex].sWorkOrderUsed;
        if (commonUtils.isNotEmptyObject(sWorkOrderUsed)) {
          bUsed = false;
        }
      }
    }

    // 找到关联的从表 */
    let controlTableData = [];
    if(visibleModal) {
      if(commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
        controlTableData = controlData.filter(item => item.sSlaveId === slaveSelectedRowKeys[0])
      }else {
        controlTableData = controlData;
      }
    }
    const controlPropsType = {
      ...commonBusiness.getTableTypes('control', this.props),
      tableProps: {
        CalLastWidth: modalWidth, AutoTableHeight: fixedAutoHeight, setCopyAll, setProcess, setMaterial, chooseProcessConfigRow: chooseProcessConfig, chooseMaterialsConfigRow: chooseMaterialsConfig, onRow: (record) => { return { onClick: () => { this.onRowClick('control', record); } }; },
      },
      data: commonUtils.isNotEmptyArr(controlTableData) ?  commonUtils.genTreeByArr(controlTableData, "sNodeId", "sControlParentId") : [],
      filteredValue: slaveSelectedRowKeys,
      onFilterData: this.handleFilterSlaveData,
      OnGetFilterData: this.handleGetFilterData,
      onAddRow: this.handleTableAdd,
      onDelRow: this.handleTableDel,
      onKeyDown: this.props.onKeyDown,
      enabled: bUsed,
    };
    const name = 'controlTree';
    const treeProps = {
      ...commonBusiness.getTreeTypes('tree', this.props),
      isSearch: false,
      checkable: false,
      disabled: false,
      checkedAll: false,
      unChecked: false,
      [`${name}Column`]: this.props[`${name}Column`],
      [`${name}Config`]: this.props[`${name}Config`],
      [`${name}Data`]: this.props[`${name}Data`],
      getFloatNum: this.props.getFloatNum,
      getSqlDropDownData: this.props.getSqlDropDownData,
      getSqlCondition: this.props.getSqlCondition,
      handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
      getDateFormat: this.props.getDateFormat,
      onDoubleClick: this.props.onDoubleClick,
      onSelect: this.handleTreeSelect,
      expandedKeys: this.props.expandedKeys,
      showLine: true,
    };
    const materialsPropsType = {
      ...commonBusiness.getTableTypes('materials', this.props),
      tableProps: { CalLastWidth: modalWidth, AutoTableHeight: fixedAutoHeight },
      filteredValue: this.props.controlSelectedRowKeys,
      onFilterData: this.handleFilterData,
      OnGetFilterData: this.handleGetFilterData,
      onAddRow: this.handleTableAdd,
      onKeyDown: this.props.onKeyDown,
      enabled: bUsed,
      onCopyRow: this.handleTableCopy,
    };
    const processPropsType = {
      ...commonBusiness.getTableTypes('process', this.props),
      tableProps: { CalLastWidth: modalWidth, AutoTableHeight: 132 },
      filteredValue: this.props.controlSelectedRowKeys,
      onFilterData: this.handleFilterData,
      OnGetFilterData: this.handleGetFilterData,
      onAddRow: this.handleTableAdd,
      onChooseProcessRow: this.handleTableChooseProcess,
      onKeyDown: this.props.onKeyDown,
      enabled: bUsed,
      onCopyRow: this.handleTableCopy,
      dragHandle: true,
      onDrag: this.handleDrag,
    };
    let searchProcessType = {};
    // let chooseProcessConfig = {};
    if (commonUtils.isNotEmptyObject(this.props.processChooseData)) {
      // const iIndex = this.props.processConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProcess');
      // if (iIndex > -1) {
      //   chooseProcessConfig = this.props.processConfig.gdsconfigformslave[iIndex];
      // }

      searchProcessType = {
        app: {
          ...this.props.app,
          currentPane: {
            name: 'process',
            config: chooseProcessConfig,
            conditonValues: this.props.getSqlCondition(chooseProcessConfig),
            title: this.props.processChooseData.sMenuName,
            route: this.props.processChooseData.sName,
            formId: this.props.processChooseData.sId,
            key: this.props.sModelsId + this.props.processChooseData.sId,
            sModelsType: this.props.processChooseData.sModelType,
            select: this.handleSelect,
            selectCancel: this.props.onSelectCancel,
          },
        },
        dispatch: this.props.dispatch,
        content: this.props.content,
        id: new Date().getTime().toString(),
        realizeHeight: this.props.realizeHeight, /* 拖动偏移高度 */
      };
    }


    let searchMaterialsType = {};
    // let chooseMaterialsConfig = {};
    if (commonUtils.isNotEmptyObject(this.props.materialsChooseData) && this.props.tableName !== 'slave') {
      // const iIndex = this.props.materialsConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseMaterials');
      // if (iIndex > -1) {
      //   chooseMaterialsConfig = this.props.materialsConfig.gdsconfigformslave[iIndex];
      // }

      searchMaterialsType = {
        app: {
          ...this.props.app,
          currentPane: {
            name: 'materials',
            config: chooseMaterialsConfig,
            conditonValues: this.props.getSqlCondition(chooseMaterialsConfig),
            title: this.props.materialsChooseData.sMenuName,
            route: this.props.materialsChooseData.sName,
            formId: this.props.materialsChooseData.sId,
            key: this.props.sModelsId + this.props.materialsChooseData.sId,
            sModelsType: this.props.materialsChooseData.sModelsType,
            select: this.handleSelect,
            selectCancel: this.props.onSelectCancel,
          },
        },
        dispatch: this.props.dispatch,
        content: this.props.content,
        id: new Date().getTime().toString(),
        realizeHeight: this.props.realizeHeight,
      };
    }
    const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
    const setMaterailRemark = commonFunc.showMessage(app.commonConst, 'setMaterailRemark');/* 选择材料与工艺 */
    const setProcessTitle = commonFunc.showMessage(app.commonConst, 'setProcess');/* 选择工序标题 */
    const setMaterialTitle = commonFunc.showMessage(app.commonConst, 'setMaterial');/* 选择材料标题 */
    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');/* 审核人 */
    // eslint-disable-next-line jsx-a11y/anchor-is-valid
    const operateAdd = <a title="添加同级" alt="" onClick={this.props.enabled ? this.handleTableAdd.bind(this, 'control', false, 'sameNode') : null}>{this.props.enabled ? setAdd.img : setAdd.disableimg} </a>;
    // eslint-disable-next-line jsx-a11y/anchor-is-valid
    const operateAddChild = <a title="添加子级" onClick={this.props.enabled ? this.handleTableAdd.bind(this, 'control', false, 'childNode') : null}>{this.props.enabled ? setAddChild.img : setAddChild.disableimg }</a>;
    // eslint-disable-next-line jsx-a11y/anchor-is-valid
    const operateCopy = <a title="复制" onClick={this.props.enabled ? this.props.onDataRowCopy.bind(this, 'control', false, true) : null}>{this.props.enabled ? setCopy.img : setCopy.disableimg}</a>;
    // eslint-disable-next-line jsx-a11y/anchor-is-valid
    const operateUpdate = <a title="复制全部" onClick={this.props.enabled ? this.props.onDataRowCopyAll.bind(this, 'control', false, true) : null}>{this.props.enabled ? setCopyAll.img : setCopyAll.disableimg }</a>;
    // eslint-disable-next-line jsx-a11y/anchor-is-valid
    const operateDel = <a title="删除" onClick={this.props.enabled ? this.handleTableDel.bind(this, 'control', true, '', true) : null}>{this.props.enabled ? setDelete.img : setDelete.disableimg}</a>;

    const controlInfo = commonFunc.showMessage(app.commonConst, 'controlInfo');/* 部件信息 */
    const materialsInfo = commonFunc.showMessage(app.commonConst, 'materialsInfo');/* 材料信息 */
    const processInfo = commonFunc.showMessage(app.commonConst, 'processInfo');/* 工序信息 */

    return (
      <div>
        <Spin spinning={pageLoading}>
          <div>
            <BillComponent
              {...this.props}
              {...this.state}
              onUploadChangeFile={this.handleUploadChangeFile} /* xls文件导入 */
              onUploadChange={this.handleUploadChange} /* 表格图片上传 */
              onBeforeUpload={this.handleBeforeUpload}
              onGetDataCancel={this.handleGetDataCancel}
              onGetDataOk={this.handleGetDataOk}
              colseGetDataVisible={this.colseGetDataVisible}
              getMenuStatus={this.getMenuStatus}
              onUploadPropsSales={this.handleUploadPropsSales}
              onDataRowModal={this.handleTableModal}
              onDataRowDel={this.handleSlaveTableDel}
              onDoubleClick={this.onDoubleClick}
              onSelectTree={this.handleTreeSelect}
              handleCancelModal={this.handleCancelModal}
              setMaterialTitle={setMaterialTitle}
              onSelect={this.handleSelect}

              handleMenuClick={this.handleMenuClick}
              handleSqlDownload={this.handleSqlDownload}
              onTableFilterData={this.handleTableFilterData}
              onDelRow={this.handleTableDel}
              setContentRef={(ref) => {
                this.contentRef = ref;
              }}
              handleCheckBoxStatus={this.handleCheckBoxStatus}
            />
            {
              visible ?
                <AntdDraggableModal
                  title={check}
                  visible={visible}
                  onCancel={this.handleCancel}
                  onSaveState={this.props.onSaveState}
                  footer={[
                    <Button key="back" onClick={this.handleCancel}>{BtnClose}</Button>,
                    <Button key="submit" type="primary" onClick={this.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={this.onChange}>
                      <Row>
                        { commonUtils.isNotEmptyObject(checkPersonData) ?
                          checkPersonData.map((item) => {
                            return (
                              <Col span={8}>
                                <Checkbox value={item.sUserId}>{item.sUserName}</Checkbox>
                              </Col>
                            );
                          })
                          : ''
                      }
                      </Row>
                    </Checkbox.Group>
                  </div>
                </AntdDraggableModal>
              : ''
            }
            {
              visibleModal ?
                <AntdDraggableModal
                  title={setMaterailRemark}
                  width="1200"
                  bodyStyle={{ paddingBottom: 0, zIndex: 1000 }}
                  visible={pane.notCurrentPane ? false : visibleModal}
                  onCancel={this.handleCancelModal.bind(this, 'visibleModal')}
                  onSaveState={this.props.onSaveState}
                  forbidResize
                  footer={[
                    <Button key="back" onClick={this.handleCancelModal.bind(this, 'visibleModal')}>{BtnClose}</Button>,
                    <Button key="submit" type="primary" onClick={this.handleOkModal.bind(this)}>
                      {btnSure}
                    </Button>,
                  ]}
                >
                  {
                    (pane.notCurrentPane ? false : processChooseVisible) ?
                      <AntdDraggableModal
                        width={1100}
                        className="MProcess"
                        bodyStyle={{ paddingBottom: 0, maxHeight: 520, zIndex: 2000 }}
                        title={commonUtils.isEmptyObject(searchProcessType) ? setProcessTitle : searchProcessType.app.currentPane.title}
                        onCancel={this.handleCancelModal.bind(this, 'processChooseVisible')}
                        visible={pane.notCurrentPane ? false : processChooseVisible}
                        onSaveState={this.props.onSaveState}
                        footer={null}
                      >
                        <CommonListSelectTree {...searchProcessType} />
                      </AntdDraggableModal>
                      : ''
                  }
                  {
                    (pane.notCurrentPane ? false : materialsChooseVisible) ?
                      <AntdDraggableModal
                        bodyStyle={{ paddingBottom: 0, maxHeight: 520, zIndex: 2000 }}
                        className="MProcess"
                        width={1100}
                        title={commonUtils.isEmptyObject(searchMaterialsType) ? setMaterialTitle : searchMaterialsType.app.currentPane.title}
                        onCancel={this.handleCancelModal.bind(this, 'materialsChooseVisible')}
                        visible={pane.notCurrentPane ? false : materialsChooseVisible}
                        onSaveState={this.props.onSaveState}
                        footer={null}
                      >
                        <CommonListSelect {...searchMaterialsType} />
                      </AntdDraggableModal>
                      : ''
                  }
                  <div id="ModalMaterialRemark" >
                    {
                        sModelsType === 'sales/salesOrderPack' && false ?
                          <div style={{
 marginTop: 0, height: '180px', overflowY: 'hidden', overflowX: 'hidden',
}}
                          >
                            <div className="xly-bill-pack">
                              <Sider className="controlhandcover">
                                <div className="xly-control">
                                  <div style={{ backgroundColor: '#f5f5f5', height: '30px', lineHeight: '30px' }}>
                                    <span style={{
 fontSize: '12px', color: 'rgba(0, 0, 0, 0.85)', fontWeight: '600', paddingLeft: '8px',
}}
                                    >部件信息
                                    </span>
                                  </div>
                                  <div className="xly-control-tree"><StaticEditTree {...treeProps} /></div>
                                  <div className="xly-control-operate" >
                                    <span>{operateAdd}</span>
                                    <span>{operateAddChild}</span>
                                    <span>{operateCopy}</span>
                                    <span>{operateUpdate}</span>
                                    <span>{operateDel}</span>
                                  </div>
                                </div>
                              </Sider>
                              <div style={{ overflowX: 'auto', overflowY: 'hidden' }}>
                                <StaticEditTable {...controlPropsType} footer="hidden" setOpterationColumn="Y" />
                              </div>
                            </div>
                          </div> :
                          <div className='xly-commonbill-choose' style={{ marginTop: 0, overflowY: 'hidden' }} >
                            <Layout>
                              <Sider style={{width: 32}}>
                                {controlInfo}
                              </Sider>
                              <Content>
                                <StaticEditTable {...controlPropsType} footer="hidden" setOpterationColumn="Y" />
                              </Content>
                            </Layout>
                          </div>
                      }
                    <div className='xly-commonbill-choose' style={{ marginTop: 10, overflowY: 'hidden' }}>
                      <Layout>
                        <Sider style={{width: 32, backgroundColor: '#fff8e6'}}>
                          {materialsInfo}
                        </Sider>
                        <Content>
                          <StaticEditTable {...materialsPropsType} setOpterationColumn="Y" />
                        </Content>
                      </Layout>
                    </div>
                    <div className='xly-commonbill-choose' style={{ marginTop: 10, overflowY: 'hidden' }} id="chooseProcessModal">
                    <Layout>
                        <Sider style={{width: 32, backgroundColor: '#fff8e6'}}>
                          {processInfo}
                        </Sider>
                        <Content>
                          <StaticEditTable {...processPropsType} setOpterationColumn="Y" noVlistTable />
                        </Content>
                      </Layout>
                    </div>
                  </div>
                </AntdDraggableModal>
              : ''}
          </div>
        </Spin>
      </div>
    );
  }
}

const BillComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData, masterConfig } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form, masterConfig);
    return obj;
  },
})((props) => {
  const {
    form,
    onReturnForm,
    slaveData,
    slavePagination,
    onlyMaster,
    sModelsId,
    app,
    onlyMasterAndSlave,
    masterConfig,
    slaveConfig,
    checkConfig,
    isSmall,
    isGetDataVisible,
    onGetDataCancel,
    onGetDataOk,
    colseGetDataVisible,
    sModelsType,
    masterData,
    bDelegate, /* 是否已经转办 */
    slaveInfoList,
  } = props;
  /*   回带表单   */
  onReturnForm(form);

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

  if(bDelegate) {
    bFlow = false;
  }

  let pageSize = commonConfig.pageSize;
  if (props.slaveConfig && props.slaveConfig.iPageSize) {
    pageSize = props.slaveConfig.iPageSize;
  }
  const pagination = {
    pageSize,
    total: commonUtils.isEmptyArr(slaveData) ? 0 : slaveData.length,
    current: commonUtils.isEmptyObject(slavePagination) ? 1 : slavePagination.current,
    ...slavePagination,
    // showQuickJumper: true,
    hideOnSinglePage: false,
    size: isSmall ? 'small' : 'large',
    pageSizeOptions: commonConfig.pageSizeOptions,
    showSizeChanger: !isSmall,
    showQuickJumper: !isSmall,
  };
  const templateProps = props.formData.filter(item => item.sGrd === 'importTemplate')[0];
  let setMaterialRemark = {
    title: '材料与工艺',
    width: { width },
    height: { height },
    img: <img src={MaterialRemarkIcon} alt="材料与工艺" width={width} height={height} />,
    disableimg: <img src={DisMaRemarklIcon} alt="材料与工艺不可用" width={width} height={height} />,
  };
  /* 获取toolbar 选择材料 */
  let searchMaterialsType = {};
  let chooseMaterialsConfig = {};
  if (commonUtils.isNotEmptyObject(slaveConfig)) {
    const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseMaterials');
    if (iIndex > -1) {
      chooseMaterialsConfig = slaveConfig.gdsconfigformslave[iIndex];
    }
  }
  if (commonUtils.isNotEmptyObject(props.materialsChooseData)) {
    searchMaterialsType = {
      app: {
        ...props.app,
        currentPane: {
          name: 'materials',
          config: chooseMaterialsConfig,
          conditonValues: props.getSqlCondition(chooseMaterialsConfig),
          title: props.materialsChooseData.sMenuName,
          route: props.materialsChooseData.sName,
          formId: props.materialsChooseData.sId,
          key: sModelsId + props.materialsChooseData.sId,
          sModelsType: props.materialsChooseData.sModelType,
          select: props.onSelect,
          selectCancel: props.onSelectCancel,
        },
      },
      dispatch: props.dispatch,
      content: props.content,
      id: new Date().getTime().toString(),
      realizeHeight: props.realizeHeight, /* 拖动偏移高度 */
    };
  }

  /* 调用产品工艺卡  */
  let productProcessInfoType = {};
  let productProcessInfoConfig = {};
  let processCardSearchResult = commonFunc.showMessage(app.commonConst, 'processCardSearchResult');/* 复制从工艺卡查询结果 */
  if (commonUtils.isNotEmptyObject(props.productProcessInfoChooseData)) {
    const productProcessInfoCopyFromKey = props.productProcessInfoCopyFromKey;
    const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === productProcessInfoCopyFromKey);
    if (iIndex > -1) {
      productProcessInfoConfig = props.masterConfig.gdsconfigformslave[iIndex];
      processCardSearchResult = commonUtils.isNotEmptyObject(productProcessInfoConfig) && commonUtils.isNotEmptyObject(productProcessInfoConfig.sActiveName) ? productProcessInfoConfig.sActiveName : processCardSearchResult;
    }
    productProcessInfoType = {
      app: {
        ...props.app,
        currentPane: {
          name: 'productProcessInfo',
          config: productProcessInfoConfig,
          conditonValues: props.getSqlCondition(productProcessInfoConfig),
          title: props.productProcessInfoChooseData.sMenuName,
          route: props.productProcessInfoChooseData.sName,
          formId: props.productProcessInfoChooseData.sId,
          key: sModelsId + props.productProcessInfoChooseData.sId,
          sModelsType: props.productProcessInfoChooseData.sModelType,
          select: props.onSelect,
          selectCancel: props.onSelectCancel,
        },
      },
      dispatch: props.dispatch,
      content: props.content,
      id: new Date().getTime().toString(),
    };
  }


  /* 显示导入报错信息 */
  let importExcelProps = {};
  let importExcelTitle = commonUtils.isNotEmptyObject(commonFunc.showMessage(app.commonConst, 'processCardSearchResult')) ?
    commonFunc.showMessage(app.commonConst, 'importErrorMsg') : '导入校验信息'; /* 导入校验信息 */
  if (commonUtils.isNotEmptyObject(props)) {
    importExcelProps = {
      ...commonBusiness.getTableTypes('import', props),
      tableProps: {
        setAdd, setCopy, setCopyAll, setDelete, setMaterialRemark, setMaterial, chooseMaterialsConfigRow: chooseMaterialsConfig, pagination:null, onChange: props.onTitleChange,
        AutoTableHeight: 400,
      },
      onDelRow: props.onDelRow,
      onKeyDown: props.onKeyDown,
      onContextMenu: props.onContextMenu,
      masterData: props.masterData, // 为通用弹窗提供主表数据(孟总需求：产品新增需要带上客户信息)
      tableBelone: 'list',
    };
  }


  /* 导入收付款未清数据 */
  let importPopupProps = {};
  let importPopupTitle = '导入未清数据';
  if (commonUtils.isNotEmptyObject(props)) {
    let importPopupConfig = {};
    const {
      masterConfig, sModelsId,
    } = props;
    if (commonUtils.isNotEmptyObject(masterConfig)) {
      const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnImportFormData' && item.bVisible);
      if (iIndex > -1) {
        importPopupConfig = masterConfig.gdsconfigformslave[iIndex];
        importPopupTitle = commonUtils.isNotEmptyObject(importPopupConfig) && commonUtils.isNotEmptyObject(importPopupConfig.sActiveName) ? importPopupConfig.sActiveName : importPopupTitle;
        importPopupProps = {
          app: {
            ...props.app,
            currentPane: {
              name: 'commonPopup',
              config: importPopupConfig,
              conditonValues: {},
              title: importPopupTitle,
              route: '/indexPage/commonList',
              formRoute: '/indexPage/commonList',
              formId: importPopupConfig.sActiveId,
              key: sModelsId + importPopupConfig.sId,
              sModelsType: 'search/importFormData',
              select: props.onSelect,
              selectCancel: props.handleCancelModal.bind(this, 'importFormDataVisible'),
              bFilterProName: props.bFilterProName, /* 存储过程查询ID  */
              bFilterProValue: props.bFilterProValue, /* 存储过程查询VALUE */
            },
          },
          dispatch: props.dispatch,
          content: props.content,
          id: new Date().getTime().toString(),
          realizeHeight: props.realizeHeight, /* 拖动偏移高度 */
        };
      }
    }
  }

  // const saleOrder = commonFunc.showMessage(app.commonConst, 'saleOrder');/* 销售订单 s*/
  setMaterialRemark = props.sModelsType !== undefined && props.sModelsType.includes('sales/salesOrder') ? setMaterialRemark : null;
  /* 通过从表是否配置材料与工艺按钮的显示不显示来判断是否有选择材料与工艺 */
  const materialRemarkArr = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave.filter(item =>  item.sControlName &&
    item.sControlName.includes('BtnSetMaterialRemark')) : [];
  if(commonUtils.isNotEmptyArr(materialRemarkArr)) {
    setMaterialRemark = materialRemarkArr[0].bVisible ? setMaterialRemark : null;
  }
  const bBillTree = commonUtils.isNotEmptyObject(slaveConfig) && slaveConfig.sTableType && slaveConfig.sTableType.includes('multiple'); /* 是否是树形的单据 */
  const bSingleTree = commonUtils.isNotEmptyObject(slaveConfig) && slaveConfig.sTableType === 'single'; /* 单表数据 */
  const bShowTreeAddChild = commonUtils.isNotEmptyObject(slaveConfig) && commonUtils.isNotEmptyArr(slaveConfig.gdsconfigformslave.filter(item => item.sControlName.includes('BtnAddChildNode') && item.bVisible)) ? true : false ; /* 是否是树形的单据 */

  const slaveTableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    tableProps: {
      setAdd, setCopy, setCopyAll, setDelete, setMaterialRemark, setMaterial, chooseMaterialsConfigRow: chooseMaterialsConfig,
      pagination, onChange: props.onTitleChange, bShowTreeAddChild:bShowTreeAddChild,
    },
    data: bSingleTree && commonUtils.isNotEmptyArr(slaveData) ?  commonUtils.genTreeByArr(slaveData, 'sNodeId', 'sFatherSlaveId') : slaveData,
    onDelRow: props.onDelRow,
    onTableFilterData: bBillTree ?  props.onTableFilterData : null,
    templateProps,
    sTableType : commonUtils.isNotEmptyObject(slaveConfig) && commonUtils.isNotEmptyObject(slaveConfig.sTableType) ? slaveConfig.sTableType : 'zero',
    onKeyDown: props.onKeyDown,
    onContextMenu: props.onContextMenu,
    masterData: props.masterData, // 为通用弹窗提供主表数据(孟总需求：产品新增需要带上客户信息)
    onTreeAddChild: props.onDataRowAddChild,
    customConfig: props.customConfig,
    handleCheckBoxStatus: props.handleCheckBoxStatus,
  };

  const slaveTablePropsList = {};
  if (commonUtils.isNotEmptyArr(slaveInfoList)) {
    slaveInfoList.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,
      };
      const bHasSlaveChild = commonUtils.isNotEmptyArr(props.slaveChildInfoList) && props.slaveChildInfoList.some(item => item.split('Child')[0] === `slave${index}`);
      slaveTablePropsList[`slaveTable${index}Props`] = {
        ...commonBusiness.getTableTypes(`slave${index}`, props),
        tableProps: {
          pagination: slaveTablePagination, onChange: props.onTitleChange1.bind(this, `slave${index}`),
          AutoTableHeight: bHasSlaveChild  ? 150 : 375,
        },
      };
    });
  }



  let gdsconfigformmasterId = '';
  if (templateProps !== undefined) {
    gdsconfigformmasterId = templateProps.sId;
  }

  const sNotEmpty = 'sParentId,sProductId';
  let uploadUrl = `${commonConfig.server_host}import/checkExcel?sModelsId=${sModelsId}&gdsconfigformmasterId=${gdsconfigformmasterId}&sNotEmpty=${sNotEmpty}&token=${app.token}`;
  /* 送货单需要传客户id  */
  if (commonUtils.isNotEmptyObject(sModelsType) && sModelsType === 'sales/salesSgoods' && commonUtils.isNotEmptyObject(masterData)) {
    const sCustomerId = masterData.sCustomerId;
    if (commonUtils.isNotEmptyObject(sCustomerId)) {
      uploadUrl = `${commonConfig.server_host}import/checkExcel?sModelsId=${sModelsId}&gdsconfigformmasterId=${gdsconfigformmasterId}&sNotEmpty=${sNotEmpty}&sCustomerId=${sCustomerId}&token=${app.token}`;
    }
  }
  const outProps = {
    action: uploadUrl,
    onChange: props.onUploadChangeFile, /* 文件上传 */
    accept: 'xls/*',
    showUploadList: false,
    beforeUpload: () => {
      /* 查看时不可上传 */
      if (!props.enabled) return false;
    },
  };
  const uploadPropsSales = props.onUploadPropsSales();
  let MainContent = commonUtils.isNotEmptyArr(masterConfig?.gdsconfigformslave.filter(item => item.sControlName === 'MainContent'))
    ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'MainContent')[0].showName
    :  commonFunc.showMessage(app.commonConst, 'MainContent');
  const isGetData = commonFunc.showMessage(app.commonConst, 'isGetData');/* 确认获取库存为零的数据吗 */
  const isFilterGetDataZero = commonFunc.showMessage(app.commonConst, 'isFilterGetDataZero');
  const isAllGetData = commonFunc.showMessage(app.commonConst, 'isAllGetData');
  let CheckInfo = commonFunc.showMessage(app.commonConst, 'CheckInfo');/* 审批信息 */
  const BtnimportData = commonFunc.showMessage(app.commonConst, 'importData');/* 导入数据 */
  const ImportData = commonUtils.isNotEmptyObject(masterConfig) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes('ImportData') && item.bVisible) : '';/* 后台是否配置导入 */
  const masterConfigOld = { ...masterConfig };
  /* 取 masterConfig中有多少个Tab页签配置 */
  const masterShowConfig = commonUtils.isNotEmptyObject(masterConfigOld)
    ? masterConfigOld.gdsconfigformslave.filter(item => item.bVisible && item.sName !== "")
    : [];

  const diliverConfigTypeArr = []; /* 有Tab的配置 */
  masterShowConfig.forEach(child => {
    if (child.sControlName.indexOf("_") > -1) {
      const tableType = child.sControlName.split("_")[1];
      const isIndex = diliverConfigTypeArr.findIndex(item => item === tableType);
      if (isIndex === -1) {
        diliverConfigTypeArr.push(tableType);
      }
    }
  });


  /* 主表页签+表格页签排序规则，表格页签以10位一个间隔，10,20,30,40,50,60，如果想进行排序 则页签顺序介入其间即可 */
  /* 找到各个主表页签Tab所处的区间 */
  let diliverConfigTypeArr1 = [];
  let diliverConfigTypeArr2 = [];
  let diliverConfigTypeArr3 = [];
  let diliverConfigTypeArr4 = [];
  let diliverConfigTypeArr5 = [];
  let diliverConfigTypeArr6 = [];
  for (const item of diliverConfigTypeArr) {
    let numStr = item.replace(/[^\d]/g, "").trim();
    let num = Number(numStr);
    if (!commonUtils.isEmpty(num)) {
      if (num < 10) {
        /* 0- 10 */
        diliverConfigTypeArr1.push(item);
      } else if (num < 20) {
        /* 10- 20 */
        diliverConfigTypeArr2.push(item);
      } else if (num < 30) {
        /* 20- 30 */
        diliverConfigTypeArr3.push(item);
      } else if (num < 40) {
        /* 30- 40 */
        diliverConfigTypeArr4.push(item);
      } else if (num < 50) {
        /* 40- 50 */
        diliverConfigTypeArr5.push(item);
      } else if (num < 60) {
        /* 50- 60 */
        diliverConfigTypeArr6.push(item);
      }
    }
  }



  if (false && commonUtils.isNotEmptyObject(masterConfig)) {
    const iIndex0 = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'zSlaveInfo0');
    if (iIndex0 > -1) {
      MainContent = masterConfig.gdsconfigformslave[iIndex0].showName;
    }
    const iIndex1 = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'zSlaveInfo1');
    if (iIndex1 > -1) {
      CheckInfo = masterConfig.gdsconfigformslave[iIndex1].showName;
    }
  }

  const slaveInfo0 = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo0')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo0')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveInfo0'); /* 表三 */
  const slaveInfo1 = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo1')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo1')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveInfo1'); /* 表四 */
  const slaveInfo2 = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo2')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo2')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveInfo2'); /* 表五 */
  const slaveInfo3 = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo3')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo3')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveInfo3'); /* 表六 */
  const slaveInfo4 = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo4')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo4')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveInfo4'); /* 表七 */
  const slaveInfo5 = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo5')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo5')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveInfo5'); /* 表八 */
  const slaveInfo6 = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo6')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo6')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveInfo6'); /* 表九 */
  const slaveInfo7 = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo7')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo7')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveInfo7'); /* 表十 */
  const slaveInfo8 = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo8')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveInfo8')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveInfo8'); /* 表十一 */
  const zSlaveChild = masterConfig && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveChild')) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'zSlaveChild')[0].showName : commonFunc.showMessage(app.commonConst, 'zSlaveChild'); /* 子表 */

  const slaveInfoArr = [
    slaveInfo0,
    slaveInfo1,
    slaveInfo2,
    slaveInfo3,
    slaveInfo4,
    slaveInfo5,
    slaveInfo6,
    slaveInfo7,
    slaveInfo8
  ];

  const getTabPaneExtra = (tableName) => {
    const {
      [`${tableName}Data`]: data,
      [`${tableName}SelectedRowKeys`]: selectedRowKeys
    } = props;

    let { [`${tableName}Config`]: config } = props;
    config = props.onMergeSlaveConfig(config);
    if (!commonUtils.isNotEmptyObject(config) || !commonUtils.isNotEmptyArr(config.gdsconfigformslave)) {
      return "";
    }

    const controlArr = config.gdsconfigformslave.filter(
      item => (
        item.bControl &&
        item.sControlName &&
        item.sControlName.indexOf('Btn') === -1 &&
        item.sControlName.indexOf('_') !== -1
      ) || (
        item.sControlName &&
        item.sControlName.indexOf('DividerArea') !== -1 &&
        item.sControlName.indexOf('.hide') === -1
      )
    );

    if (commonUtils.isEmptyArr(controlArr)) {
      return "";
    }

    const controlGroup = controlArr.reduce((result, item) => {
      const { sControlName } = item;
      const splitList = sControlName.split('_');
      const key = splitList[1];
      if (!result[key]) {
        result[key] = [];
      }
      result[key].push(item);
      return result;
    }, {});

    let viewRow = {};
    if (commonUtils.isNotEmptyArr(selectedRowKeys)) {
      const iIndex = data.findIndex(item => selectedRowKeys.includes(item.sId));
      if (iIndex > -1) {
        viewRow = data[iIndex];
      } else {
        viewRow = data[0];
      }
    } else if (commonUtils.isNotEmptyArr(data)) {
      viewRow = data[0];
    }

    return Object.keys(controlGroup).map((tabNameKey) => {
      let tabName = tabNameKey.replace(/\d+/g, "");
      const num = tabNameKey.replace(/[^\d]/g, "").trim();
      const tableConfigArr = config?.gdsconfigformslave.filter(row => row.sControlName === tabNameKey.trim());
      if(commonUtils.isNotEmptyArr(tableConfigArr)) {
        tabName= tableConfigArr[0].showName;
      }
      const viewProps = {
        ...props,
        viewConfigs: controlGroup[tabNameKey],
        tableConfig: config,
        iColValueView: 24,
        viewRow,
        tableName,
      };

      return (
        <TabPane
          tab={tabName}
          key={num}
          className={`xly-bill-list commonNewBillContainer ${customStyles.commonViewTable}`}
        >
          <div className="TabPaneStyle">
            <CommonViewTable {...viewProps} />
          </div>
        </TabPane>
      );
    });
  }

  const flexRowStyle = bFlow ? {display:'flex', flexDirection:'row'} : {};
  /*
  if (props.sModelsType === 'sales/salesOrder') {
    const btnUpload = (
      <Upload {...outProps}>
        <Button {...uploadPropsSales}>
          <Icon type="upload" /> 导入数据
        </Button>
      </Upload>);
    slaveTableProps.tableProps.newButton = btnUpload;
  }
  */
  return (
    <Form>
      <Layout>
        <Header className={styles.header}>
          <div className="billToolBar">
            <Toolbar {...props} className="billBtnGroup btnGroupHasImport" pageFrom="billList" />
            { commonUtils.isNotEmptyArr(ImportData) ?
              <div id="btnImportData" className={`importData ${props.enabled}`} >
                <Upload {...outProps}><UploadOutlined />{BtnimportData}
                  <Button {...uploadPropsSales} />
                </Upload>
              </div> : ''}
          </div>
        </Header>
        <Layout className={styles.clayout}  style={flexRowStyle}>
          <Content className={styles.content} style={{ overflowY: 'unset', width: bFlow ? '75%':'100%',  }} ref={(ref) => { props.setContentRef(ref); }}>
            <div style={{
              border: '1px solid #c2c3c5',
              margin: '0 10px',
              marginTop: 8,
              backgroundColor: '#ffffff',
            }}
            >
              <div className="bill-search-group" >
                <CommonView {...props} />
              </div>
            </div>
            { onlyMaster ?
              <div id="slaveTabs" className={styles.bShow}>
                <div>
                  <Avatar src={props.imgSrc} className={customStyles.bShowImg} />
                </div>
              </div> :
              <div id="slaveTabs" className={styles.bShow}>
                <div>
                  <Avatar src={props.imgSrc} />
                </div>
                <Tabs className={styles.slaveTabs} style={{ overflowY: 'unset' }} tabBarStyle={{ margin: '0 10px' }} >
                  {commonUtils.isNotEmptyArr(diliverConfigTypeArr1)
                    ? diliverConfigTypeArr1.map(item => {
                      // 匹配数字
                      // eslint-disable-next-line no-unused-vars
                      let num = item.replace(/[^\d]/g, "").trim();
                      let tabName = item.replace(/\d+/g, "");
                      /* 从主表配置 找到控件名=tabName,否则取他的showName */
                      const tableConfigArr = masterConfig?.gdsconfigformslave.filter(row => row.sControlName === item.trim());
                      if (commonUtils.isNotEmptyArr(tableConfigArr)) {
                        tabName = tableConfigArr[0].showName;
                      }
                      return (
                        <TabPane tab={tabName} key={num} className="xly-bill-list">
                          <div>
                            <CommonView
                              {...props}
                              // 使高度和从表高度一直
                              // isAutoHeight="ture"
                              tableConfigType={item}
                              tableConfigTypeArr={diliverConfigTypeArr}
                            />
                          </div>
                        </TabPane>
                      );
                    })
                    : ""}
                  <TabPane tab={MainContent} key={10} className="xly-bill-list">
                    <div className="TabPaneStyle">
                      <StaticEditTable {...slaveTableProps} setOpterationColumn={props.sModelsType !== 'cost/cosexpenseshare' ? 'Y' : ''} />
                    </div>
                  </TabPane>
                  {commonUtils.isNotEmptyArr(diliverConfigTypeArr2)
                    ? diliverConfigTypeArr2.map(item => {
                      // 匹配数字
                      // eslint-disable-next-line no-unused-vars
                      let num = item.replace(/[^\d]/g, "").trim();
                      let tabName = item.replace(/\d+/g, "");
                      /* 从主表配置 找到控件名=tabName,否则取他的showName */
                      const tableConfigArr = masterConfig?.gdsconfigformslave.filter(row => row.sControlName === item.trim());
                      if (commonUtils.isNotEmptyArr(tableConfigArr)) {
                        tabName = tableConfigArr[0].showName;
                      }
                      return (
                        <TabPane tab={tabName} key={num} className="xly-bill-list">
                          <div>
                            <CommonView
                              {...props}
                              // 使高度和从表高度一直
                              // isAutoHeight="ture"
                              tableConfigType={item}
                              tableConfigTypeArr={diliverConfigTypeArr2}
                            />
                          </div>
                        </TabPane>
                      );
                    })
                    : ""}
                  {getTabPaneExtra('slave')}
                  {
                    slaveInfoList?.map((item, index) => {
                      const slaveTableProps = slaveTablePropsList[`slaveTable${index}Props`];
                      const tabTitle = slaveInfoArr[index];
                      return (
                        <TabPane tab={tabTitle} className="xly-bill-list" key={30}>
                          <StaticEditTable {...slaveTableProps} footer="hidden" setOpterationColumn="Y" />
                        </TabPane>);

                    })
                  }

                  {
                    commonUtils.isNotEmptyObject(checkConfig) ?
                      (
                        <>
                          <TabPane tab={CheckInfo} key={50} className="xly-bill-list">
                            <div className="TabPaneStyle">
                              <StaticEditTable {...commonBusiness.getTableTypes('check', props)}  />
                            </div>
                          </TabPane>
                          {getTabPaneExtra('check')}
                        </>
                      ) : ''
                  }
                </Tabs>
              </div> }
            { onlyMasterAndSlave ?
              <div id="slaveTabs" className={styles.bShow}>
                <div>
                  <Avatar src={props.imgSrc} />
                </div>
                <Tabs className={styles.slaveTabs} style={{ margin: '0px!important', overflowX: 'hidden', overflowY: 'unset' }} tabBarStyle={{ margin: '0 10px' }} >
                  <TabPane tab={MainContent} key={10} className="xly-bill-list">
                    <StaticEditTable {...slaveTableProps} setOpterationColumn={props.sModelsType !== 'cashier/receipt' && props.sModelsType !== 'cashier/payment' ? 'Y' : ''} />
                  </TabPane>
                   {getTabPaneExtra('slave')}
                </Tabs>
              </div> : '' }
          </Content>
          {
            bFlow ?
              <div id='examInfo' style={{width:'25%', textAlign:'center', height:'900px', maxHeight: 'calc(100vh - 130px)' , backgroundColor:'#f0f0f0'}}>
                <CommonExamInfo {...props} />
              </div>
              : ''
          }
        </Layout>
      </Layout>
      {
        isGetDataVisible ?
          <AntdDraggableModal
            visible={isGetDataVisible}
            title="获取数据"
            onOk={onGetDataOk}
            onCancel={colseGetDataVisible}
            footer={[
              <Button key="back" onClick={onGetDataCancel}>
                {isAllGetData}
              </Button>,
              <Button key="submit" type="primary" onClick={onGetDataOk}>
                {isFilterGetDataZero}
              </Button>,
            ]}
          >
            <p>{isGetData}</p>
          </AntdDraggableModal>
          : ''
      }
      {
        props.materialsChooseVisible && !props.visibleModal ?
          <AntdDraggableModal
            width={1300}
            title={props.setMaterialTitle}
            visible={props.materialsChooseVisible}
            onCancel={props.handleCancelModal.bind(this, 'materialsChooseVisible')}
            onSaveState={props.onSaveState}
            footer={null}
          >
            <CommonListSelect {...searchMaterialsType} />
          </AntdDraggableModal>
          : ''
      }


      {
        props.productProcessInfoChooseVisible ?
          <AntdDraggableModal
            width={1200}
            title={processCardSearchResult}
            visible={props.productProcessInfoChooseVisible}
            onCancel={props.handleCancelModal.bind(this, 'productProcessInfoChooseVisible')}
            footer={null}
            wrapClassName="worker-order-pack-modal"
          >
            <CommonListSelect {...productProcessInfoType} />
          </AntdDraggableModal> : ''
      }

      {
        props.importFormDataVisible ?
          <AntdDraggableModal
            width={1300}
            zIndex={1000}
            title={importPopupTitle}
            visible={props.importFormDataVisible}
            onCancel={props.handleCancelModal.bind(this, 'importFormDataVisible')}
            onSaveState={props.onSaveState}
            footer={null}
          >
            <CommonListSelect {...importPopupProps} />
          </AntdDraggableModal>
          : ''
      }
      {
        props.contextMenuModalVisible ?
          <ContextMenuModal {...props} />
          : ''
      }
      {
        props.showImportErrorVisible ?
          <AntdDraggableModal
            width={1480}
            zIndex={1000}
            title={importExcelTitle}
            bodyStyle ={{ height:'450px' }}
            visible={props.showImportErrorVisible}
            onCancel={props.handleCancelModal.bind(this, 'showImportErrorVisible')}
            onOk={props.handleCancelModal.bind(this, 'showImportErrorVisible')}
            onSaveState={props.onSaveState}
            // footer={null}
          >
            <StaticEditTable {...importExcelProps} />
          </AntdDraggableModal>
          : ''
      }
    </Form>
  );
});

export default CommonBase(CommonSales(CommonBill));
