/* eslint-disable */
import React, { useEffect, useState, useRef } from "react";
import { Button, message, Tabs } from "antd-v4";
import * as commonBusiness from "@/components/Common/commonBusiness";
import * as commonUtils from "@/utils/utils";
import * as commonFunc from "@/components/Common/commonFunc";
import commonConfig from "@/utils/config";
import * as commonServices from "@/services/services";
import StaticEditTable from "@/components/Common/CommonTable";
import CommonViewTable from "@/components/Common/CommonViewTable";
import CommonViewDragable from "@/components/Common/CommonViewDragable";
import AntdDraggableModal from "@/components/Common/AntdDraggableModal";
import CommonPartsInfo from "@/components/Common/CommonPartsInfo";
import CommonListSelect from "@/components/Common/CommonListSelect";
import CommonListSelectMulti from "@/components/Common/CommonListSelectMulti";
import CommonListSelectFlex from "@/components/Common/CommonListSelectFlex";
import CommonListSelectProductProcess from '@/components/Common/CommonListSelectAssignment';
import ContextMenuModal from "@/components/Common/ContextMenuModal";
import WorkFlow from "@/components/Common/Flows/CommonFlow";
import SvgIcon from "@/components/SvgIcon";
import customStyles from "../Common/CommonBill/index.less";
import * as rglUtils from "../Common/CommonViewDragable/rglUtils";

const { TabPane } = Tabs;
//  PBOM/生产工单共用方法
const CommonPackEvent = props => {
  const returnProps = {};

  const propsRef = useRef(props);
  useEffect(
    () => {
      propsRef.current = props;
    },
    [props]
  );

  useEffect(() => {
    const handleDoubleClick = () => {
      console.log(
        "=====packProps",
        Object.keys(propsRef.current).reduce((pre, key) => {
          const value = propsRef.current[key];
          if (Array.isArray(value) || (typeof value === "object" && value !== null)) {
            pre[key] = value;
          }
          return pre;
        }, {})
      );
      console.log(
        "=====packPropsData",
        Object.keys(propsRef.current).reduce((pre, key) => {
          const value = propsRef.current[key];
          if (key?.endsWith("Data")) {
            if (Array.isArray(value) || (typeof value === "object" && value !== null)) {
              pre[key] = value;
            }
          }
          return pre;
        }, {})
      );
    };

    window.addEventListener("dblclick", handleDoubleClick);

    return () => {
      window.removeEventListener("dblclick", handleDoubleClick);
    };
  }, []);

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

    return sValue;
  };
  returnProps.onGetParamsValue = handleGetParamsValue;
  // 对processData数组进行排序
  const sortData = (tableData, processData) => {
    processData.sort((g1, g2) => {
      const iIndex1 = tableData.findIndex(item => item.sId === g1.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g1.sControlId);
      if (g1.iOrder === undefined) {
        g1.iOrder = "";
      }
      if (g2.iOrder === undefined) {
        g2.iOrder = "";
      }
      let sPartOrder1 = `0000${iIndex1}`;
      sPartOrder1 = sPartOrder1.substring(sPartOrder1.length - 3);
      let sOrder1 = `00000${g1.iOrder.toString()}`;
      sOrder1 = sOrder1.indexOf(".") > -1 ? sOrder1 : `${sOrder1}.00`;
      sOrder1 = sOrder1.replace(".", "");
      sOrder1 = sOrder1.substring(sOrder1.length - 5);
      const iIndex2 = tableData.findIndex(item => item.sId === g2.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g2.sControlId);
      let sPartOrder2 = `0000${iIndex2}`;
      sPartOrder2 = sPartOrder2.substring(sPartOrder2.length - 3);
      let sOrder2 = `00000${g2.iOrder.toString()}`;
      sOrder2 = sOrder2.indexOf(".") > -1 ? sOrder2 : `${sOrder2}.00`;
      sOrder2 = sOrder2.replace(".", "");
      sOrder2 = sOrder2.substring(sOrder2.length - 5);
      return parseFloat(sPartOrder1 + sOrder1) - parseFloat(sPartOrder2 + sOrder2);
    });
    return processData;
  };
  returnProps.sortData = sortData;

  // 调用计算接口
  const handleCalculation = async (modeType, bSave) => {
    if (modeType === "workOrder") {
      const dataUrl = `${commonConfig.server_host}business/addWorksheet?sModelsId=${props.sModelsId}`;
      const {
        app,
        masterConfig,
        slaveConfig,
        packConfig,
        controlConfig,
        processConfig,
        colorConfig,
        sModelsType,
        colorData,
        slaveDelData,
        controlDelData,
        processDelData,
        colorDelData,
        packDelData,
        addStateMap,
        materials0Config,
        materials0DelData,
      } = props;
      let { slaveData, packData, controlData, processData, masterData, materials0Data } = props;
      const sMakePerson = masterData.sMakePerson;
      const dataCalculation = [];
      if (
        (masterData.sFormId === "101251240115015840916341460" || sModelsType.includes("manufacture/workOrderSupple")) &&
        commonUtils.isNotEmptyArr(colorData)
      ) {
        controlData.forEach(item => {
          item.iPositiveColor = colorData.filter(item => !item.bNotColor).length;
        });
      }
      dataCalculation.push(commonBusiness.mergeData("master", `${masterConfig.sTbName.toLowerCase()}_Tmp`, [masterData], [], true));
      dataCalculation.push(commonBusiness.mergeData("slave", `${slaveConfig.sTbName.toLowerCase()}_tmp`, slaveData, [], true));
      dataCalculation.push(commonBusiness.mergeData("control", `${controlConfig.sTbName.toLowerCase()}_tmp`, controlData, [], true));
      dataCalculation.push(commonBusiness.mergeData("pack", `${packConfig.sTbName.toLowerCase()}_tmp`, packData, [], true));
      dataCalculation.push(commonBusiness.mergeData("materials", `${materials0Config.sTbName.toLowerCase()}_tmp`, materials0Data, [], true));
      dataCalculation.push(commonBusiness.mergeData("process", `${processConfig.sTbName.toLowerCase()}_tmp`, processData, [], true));
      const value = { data: dataCalculation, sClientType: "1", sGuid: masterData.sId };
      const dataReturn = (await commonServices.postValueService(props.app.token, value, dataUrl)).data;
      if (dataReturn.code === 1) {
        /*   成功   */
        const valueReturn = dataReturn.dataset.rows[0];
        const masterDataArr = valueReturn[`${masterConfig.sTbName.toLowerCase()}_tmp`];
        if (commonUtils.isNotEmptyArr(masterDataArr)) {
          masterData = masterDataArr[0];
        }
        if (masterData.handleType === "update" && !commonUtils.isEmpty(sMakePerson)) {
          masterData.sMakePerson = sMakePerson;
        }
        slaveData = valueReturn[`${slaveConfig.sTbName.toLowerCase()}_tmp`];
        packData = valueReturn[`${packConfig.sTbName.toLowerCase()}_tmp`];
        controlData = valueReturn[`${controlConfig.sTbName.toLowerCase()}_tmp`];
        materials0Data = valueReturn[`${materials0Config.sTbName.toLowerCase()}_tmp`];
        processData = valueReturn[`${processConfig.sTbName.toLowerCase()}_tmp`];

        /* 计算成功后自动调用保存 */
        if (bSave) {
          const data = [];
          data.push(commonBusiness.mergeData("master", masterConfig.sTbName, [masterData]));
          data.push(commonBusiness.mergeData("slave", slaveConfig.sTbName, slaveData, slaveDelData));
          data.push(commonBusiness.mergeData("control", controlConfig.sTbName, controlData, controlDelData));
          data.push(commonBusiness.mergeData("materials", materials0Config.sTbName, materials0Data, materials0DelData));
          data.push(commonBusiness.mergeData("process", processConfig.sTbName, processData, processDelData));
          if (commonUtils.isNotEmptyObject(colorConfig)) {
            data.push(commonBusiness.mergeData("color", colorConfig.sTbName, colorData, colorDelData));
          }
          if (commonUtils.isNotEmptyObject(packConfig)) {
            data.push(commonBusiness.mergeData("pack", packConfig.sTbName, packData, packDelData));
          }
          if (commonUtils.isNotEmptyObject(addStateMap)) {
            for (const childConfig of Object.keys(addStateMap)) {
              const tableName = childConfig.replace("Config", "").trim();
              const { [`${tableName}Data`]: tableData, [`${tableName}Config`]: tableConfig, [`${tableName}DelData`]: tableDelData } = props;
              if (tableConfig.sTbName !== "noTable" && tableConfig.sTbName !== "MftWorkOrderMaterials") {
                data.push(commonBusiness.mergeData(tableName, tableConfig.sTbName, tableData, tableDelData));
              }
            }
          }

          props.onSaveData({
            data,
            sClientType: "1",
            loading: false,
            sSysLogSrcId: masterData.sId,
          });
          props.onSaveState({
            slaveData,
            packData,
            controlData,
            materials0Data,
            processData,
            masterData,
            loading: false,
            calculated: true,
          });
        } else {
          props.onSaveState({
            slaveData,
            packData,
            controlData,
            materials0Data,
            processData,
            masterData,
            loading: false,
            calculated: true,
          });

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

    const dataUrl = `${commonConfig.server_host}business/addWorksheet?sModelsId=${props.sModelsId}`;
    const { masterConfig, slaveConfig, controlConfig, materialsConfig, processConfig, packConfig, app } = props;
    let { slaveData, controlData, materialsData, processData, masterData, packData } = props;

    const tableList = ["master", "slave", "control", "materials", "process", "pack"];

    const data = tableList.map(tablename => {
      const tableConfig = props[`${tablename}Config`];
      const tableData = props[`${tablename}Data`];
      return commonBusiness.mergeData(
        tablename,
        `${tableConfig.sTbName.toLowerCase()}_Tmp`,
        tablename === "master" ? [tableData] : tableData,
        [],
        true
      );
    });

    const value = { data, sClientType: "1", sGuid: masterData.sId };
    const dataReturn = (await commonServices.postValueService(props.app.token, value, dataUrl)).data;
    if (dataReturn.code === 1) {
      /*   成功   */
      const valueReturn = dataReturn.dataset.rows[0];
      const masterDataArr = valueReturn[`${masterConfig.sTbName.toLowerCase()}_tmp`];
      if (commonUtils.isNotEmptyArr(masterDataArr)) {
        masterData = masterDataArr[0];
      }
      slaveData = valueReturn[`${slaveConfig.sTbName.toLowerCase()}_tmp`];
      controlData = valueReturn[`${controlConfig.sTbName.toLowerCase()}_tmp`];
      materialsData = valueReturn[`${materialsConfig.sTbName.toLowerCase()}_tmp`];
      processData = valueReturn[`${processConfig.sTbName.toLowerCase()}_tmp`];
      processData = props.sortData(controlData, processData);
      packData = valueReturn[`${packConfig.sTbName.toLowerCase()}_tmp`];
      props.onSaveState({
        slaveData,
        controlData,
        materialsData,
        processData,
        masterData,
        loading: false,
        packData,
      });

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

  returnProps.handleCalculation = handleCalculation;

  const handlePackDataAdd = (item, index, sControlId, handleType) => {
    const tableDataRow = {};
    if (handleType === "add") {
      tableDataRow.sId = commonUtils.createSid();
      tableDataRow.handleType = "add";
      tableDataRow.sSlaveId = item.sId;
      tableDataRow.iOrder = item.iOrder;
    }
    tableDataRow.sParentId = item.sParentId;
    if (commonUtils.isNotEmptyObject(sControlId)) {
      tableDataRow.sControlId = sControlId;
    }
    tableDataRow.sProductId = item.sProductId; /* 产品id */
    tableDataRow.sCustomerId = item.sCustomerId; /* 客户id */
    tableDataRow.sCustomerName = item.sCustomerName; /* 客户名称 */
    tableDataRow.sProductName = item.sProductName; /* 产品名称 */
    tableDataRow.sProductNo = item.sProductNo; /* 产品编号 */
    tableDataRow.dProductWidth = item.dProductWidth; /* 产品宽 */
    tableDataRow.dProductLength = item.dProductLength; /* 产品长 */
    /* 主表配置bProductQtyAdd 则代表产品数量不叠加备货数 赠送数 */
    let bProductQtySelf = false;
    if (commonUtils.isNotEmptyObject(props.masterConfig) && commonUtils.isNotEmptyArr(props.masterConfig.gdsconfigformslave)) {
      const iIndex = props.masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "bProductQtySelf");
      if (iIndex > -1) {
        bProductQtySelf = true;
      }
    }
    if (bProductQtySelf) {
      tableDataRow.dProductQty = commonUtils.isNull(item.dProductQty, 0);
    } else {
      tableDataRow.dProductQty =
        commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0); /* 生产数量 */
    }
    tableDataRow.sProductUnit = item.sProductUnit; /* 单位 */
    tableDataRow.sProductStyle = item.sProductStyle; /* 产品规格 */
    return tableDataRow;
  };
  returnProps.handlePackDataAdd = handlePackDataAdd;

  // 删除相关的表格数据
  const otherTableDel = (name, tableSelectedRowKeys, sField = "sControlId") => {
    const { [`${name}Data`]: tableData = [], [`${name}DelData`]: tableDelData = [] } = props;

    if (commonUtils.isEmptyArr(tableData)) return {};

    for (const sId of tableSelectedRowKeys) {
      /*   看看删除集合和从表中是否都存在该条数据   */
      let tableDataIndex = tableData.findIndex(item => item[sField] === sId);
      while (tableDataIndex > -1) {
        /*   删除从表中的数据并存入删除集合中   */
        const slaveDataFilter = tableData[tableDataIndex];
        tableData.splice(tableDataIndex, 1);
        slaveDataFilter.handleType = "del";
        tableDelData.push(slaveDataFilter);
        tableDataIndex = tableData.findIndex(item => item[sField] === sId);
      }
    }
    return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [] };
  };

  returnProps.otherTableDel = otherTableDel;

  // 重新计算实际生产数
  const handleGetdFactProductQty = (selectedRowKeys, tableData) => {
    const maxArr = [];
    if (commonUtils.isNotEmptyArr(selectedRowKeys)) {
      const tableFilter = tableData.filter(item => selectedRowKeys.includes(item.sId) && item.dCombineQty > 0);
      if (selectedRowKeys.length === 1 || tableFilter.length === 1) {
        /*  当选中行只有一行时,实际生产数等于生产数 */
        const iSlaveIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
        if (iSlaveIndex > -1) {
          const dProductQty = tableData[iSlaveIndex].dProductQty;
          tableData[iSlaveIndex] = { ...tableData[iSlaveIndex], dFactProductQty: dProductQty };
        }
      } else {
        for (const sId of selectedRowKeys) {
          const iSlaveIndex = tableData.findIndex(item => item.sId === sId);
          if (iSlaveIndex > -1) {
            const slaveDataRow = tableData[iSlaveIndex];
            const { dCombineQty, dProductQty } = slaveDataRow;
            if (dCombineQty > 0) {
              let dNum = commonUtils.convertFixNum(dCombineQty !== 0 ? dProductQty / dCombineQty : 0, 2); /* 生产数/排版数 取最大值 */
              dNum = Math.ceil(dNum);
              maxArr.push(dNum);
            }
          }
        }
        let dMax = 0;
        if (commonUtils.isNotEmptyArr(maxArr)) {
          dMax = Math.max(...maxArr);
        }
        dMax = commonUtils.isNotNum(dMax) ? 0 : dMax;
        for (const sId of selectedRowKeys) {
          const iSlaveIndex = tableData.findIndex(item => item.sId === sId);
          if (iSlaveIndex > -1) {
            const slaveDataRow = tableData[iSlaveIndex];
            let { dCombineQty } = slaveDataRow;
            if (dCombineQty > 0) {
              dCombineQty = commonUtils.isNotNum(dCombineQty) ? 0 : dCombineQty;
              const dFactProductQty = commonUtils.convertFixNum(dCombineQty * dMax, 2); /* 实际生产数 =最大值 * 排版数 */
              tableData[iSlaveIndex] = { ...tableData[iSlaveIndex], dFactProductQty };
            }
          }
        }
      }
      props.onSaveState({ packData: tableData });
    }
  };
  returnProps.handleGetdFactProductQty = handleGetdFactProductQty;

  // 公共方法-获取svg
  const handleGetSvgIcon = (iconClass, fill, size, offsetY, alt) => {
    return <SvgIcon iconClass={iconClass} fill={fill} size={size} offsetY={offsetY} alt={alt} />;
  };

  const handleGetIcon = () => {
    return {
      setAdd: {
        title: "增加",
        img: handleGetSvgIcon("plus", "#8c949e", 14, 3, "添加"),
        disableimg: handleGetSvgIcon("plus", "rgb(189, 189, 189)", 14, 3, "添加"),
      },
      setCopy: {
        title: "复制",
        img: handleGetSvgIcon("copy", "#8c949e", 14, 3, "复制"),
        disableimg: handleGetSvgIcon("copy", "rgb(189, 189, 189)", 14, 3, "复制"),
      },
      setDelete: {
        title: "删除",
        img: handleGetSvgIcon("close", "#8c949e", 14, 3, "删除"),
        disableimg: handleGetSvgIcon("close", "rgb(189, 189, 189)", 14, 3, "删除"),
      },
    };
  };

  returnProps.handleGetIcon = handleGetIcon;

  // 公共方法-过滤数据
  const dataFilter = (props, data, type, bFinal) => {
    // materials : 0-1部件材料 : 2成品材料;
    // process : 0-1-2 部品工序 : 3成品工序;
    // bfinal: 是否成品
    const { slaveSelectedRowKeys, controlSelectedRowKeys, finishedMaterialsColumn, finishedProcessColumn, masterConfig } = props;
    const oriData = data.data || [];
    let bSplitMaterials = false; /* 默认拆分材料*/
    const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "bSplitMaterials");
    if (iIndex > -1) {
      bSplitMaterials = masterConfig.gdsconfigformslave[iIndex].bVisible;
    }

    let bSplitProcess = false; /* 默认拆分工序 */
    const iIndex1 = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "bSplitProcess");
    if (iIndex1 > -1) {
      bSplitProcess = masterConfig.gdsconfigformslave[iIndex1].bVisible;
    }

    if (data.data) {
      let res = [];
      switch (type) {
        case "process":
          if (bFinal) {
            /* 成品工序 */
            if (slaveSelectedRowKeys && slaveSelectedRowKeys.length) {
              res = oriData.filter(val => {
                return val.sType === "3" && (val.sCombinePartsName === slaveSelectedRowKeys[0] || !val.sCombinePartsName);
              });
            } else {
              res = oriData.filter(val => {
                return val.sType === "3";
              });
            }
          } else {
            /* 部件工序 */
            if (controlSelectedRowKeys && controlSelectedRowKeys.length) {
              res = oriData.filter(val => {
                if (bSplitProcess) {
                  return val.sType !== "3" && (controlSelectedRowKeys.includes(val.sControlId) || !val.sControlId);
                } else {
                  return controlSelectedRowKeys.includes(val.sControlId) || !val.sControlId;
                }
              });
            } else {
              if (bSplitProcess) {
                res = oriData.filter(val => {
                  return val.sType !== "3";
                });
              } else {
                res = oriData;
              }
            }
          }
          break;
        default:
          res = oriData;
      }
      return res;
    } else {
      return oriData || [];
    }
  };

  returnProps.dataFilter = dataFilter;

  // 公共方法-过滤数据-工单用
  const dataFilter1 = (data, type, bFinal) => {
    // materials : 0-1部件材料 : 2成品材料;
    // process : 0-1-2 部品工序 : 3成品工序;
    // bfinal: 是否成品

    const { slaveSelectedRowKeys, controlSelectedRowKeys, finishedMaterialsColumn, finishedProcessColumn, masterConfig } = props;
    let bSplitMaterials = true; /* 默认拆分材料*/
    const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "bSplitMaterials");
    if (iIndex > -1) {
      bSplitMaterials = masterConfig.gdsconfigformslave[iIndex].bVisible;
    }

    let bSplitProcess = true; /* 默认拆分工序 */
    const iIndex1 = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === "bSplitProcess");
    if (iIndex1 > -1) {
      bSplitProcess = masterConfig.gdsconfigformslave[iIndex1].bVisible;
    }

    const oriData = data.data || [];
    if (data.data) {
      let res = [];
      switch (type) {
        case "materials":
          if (bSplitMaterials && finishedMaterialsColumn) {
            if (bFinal) {
              /* 成品材料 */
              if (slaveSelectedRowKeys && slaveSelectedRowKeys.length) {
                res = oriData.filter(val => {
                  return val.sType === "2" && (val.sCombinePartsName === slaveSelectedRowKeys[0] || !val.sCombinePartsName);
                });
              } else {
                res = oriData.filter(val => {
                  return val.sType === "2";
                });
              }
            } else {
              /* 部件材料 */
              res = oriData.filter(val => {
                return val.sType !== "2";
              });
            }
          } else {
            res = oriData;
          }
          break;
        case "process":
          if (bSplitProcess && finishedProcessColumn) {
            if (bFinal) {
              /* 成品工序 */
              if (slaveSelectedRowKeys && slaveSelectedRowKeys.length) {
                res = oriData.filter(val => {
                  return val.sType === "3" && (val.sCombinePartsName === slaveSelectedRowKeys[0] || !val.sCombinePartsName);
                });
              } else {
                res = oriData.filter(val => {
                  return val.sType === "3";
                });
              }
            } else {
              /* 部件工序 */
              if (controlSelectedRowKeys && controlSelectedRowKeys.length) {
                res = oriData.filter(val => {
                  if (bSplitProcess) {
                    return val.sType !== "3" && (controlSelectedRowKeys.includes(val.sControlId) || !val.sControlId);
                  } else {
                    return controlSelectedRowKeys.includes(val.sControlId) || !val.sControlId;
                  }
                });
              } else {
                if (bSplitProcess) {
                  res = oriData.filter(val => {
                    return val.sType !== "3";
                  });
                } else {
                  res = oriData;
                }
              }
              if (isQianCai) {
                const pre = res.filter(item => item.sType == "0").sort((a, b) => a.iOrder - b.iOrder);
                const after = res.filter(item => item.sType == "1" || item.sType == "2").sort((a, b) => a.iOrder - b.iOrder);
                res = pre.concat(after);
              }
            }
          } else {
            res = oriData;
          }
          break;
        default:
          res = oriData;
      }
      return res;
    } else {
      return oriData || [];
    }
  };

  returnProps.dataFilter1 = dataFilter1;

  // 公共方法-过滤材料数据
  const materialsFilterNew = (props, data, type) => {
    const { materials0Data = [], processSelectedRowKeys, processData, controlSelectedRowKeys, controlData } = props;
    let oriData = materials0Data; // commonUtils.isNotEmptyArr(data.data) ? data.data : [];
    let res = [];
    let newData = [];
    let processRow = {};
    let controlRow = {};

    if (commonUtils.isNotEmptyArr(controlData) && commonUtils.isNotEmptyArr(controlSelectedRowKeys)) {
      /* 没有工序选中行 则不进行数据过滤 */
      const iIndex = controlData.findIndex(item => controlSelectedRowKeys.includes(item.sId));
      if (iIndex > -1) {
        controlRow = controlData[iIndex];
      }
    }

    if (commonUtils.isNotEmptyArr(processData) && commonUtils.isNotEmptyArr(processSelectedRowKeys)) {
      /* 没有工序选中行 则不进行数据过滤 */
      const iIndex = processData.findIndex(item => processSelectedRowKeys.includes(item.sId));
      if (iIndex > -1) {
        processRow = processData[iIndex];
      }
    }
    if (type === "materials0") {
      /* 根据工序表选中行的部件id +工序id 过滤全部材料数据 */
      if (commonUtils.isNotEmptyObject(processRow)) {
        const filterData = oriData.filter(
          item =>
            (processRow.sType === "3" || (processRow.sType !== "3" && item.sControlId === processRow.sControlId)) &&
            item.sProcessId === processRow.sProcessId &&
            item.sProcessTbId === processRow.sId &&
            commonUtils.isEmptyObject(item.sParentMaterialsId)
        );
        if (commonUtils.isNotEmptyArr(filterData)) {
          newData = filterData.filter(
            item =>
              (commonUtils.isEmptyObject(item.sInkBOMId) &&
                commonUtils.isEmptyObject(item.sInkBOMsSlaveId) &&
                commonUtils.isEmptyObject(item.sInkBOMsMaterialsId)) ||
              (commonUtils.isNotEmptyObject(item.sInkBOMsMaterialsId) &&
                commonUtils.isNotEmptyObject(item.sInkBOMId) &&
                commonUtils.isNotEmptyObject(item.sInkBOMsSlaveId))
          );
        }
        res = newData;
      } else if (commonUtils.isNotEmptyObject(controlRow)) {
        const filterData = oriData.filter(item => item.sControlId === controlRow.sId && commonUtils.isEmptyObject(item.sParentMaterialsId));
        if (commonUtils.isNotEmptyArr(filterData)) {
          newData = filterData.filter(
            item =>
              (commonUtils.isEmptyObject(item.sInkBOMId) &&
                commonUtils.isEmptyObject(item.sInkBOMsSlaveId) &&
                commonUtils.isEmptyObject(item.sInkBOMsMaterialsId)) ||
              (commonUtils.isNotEmptyObject(item.sInkBOMsMaterialsId) &&
                commonUtils.isNotEmptyObject(item.sInkBOMId) &&
                commonUtils.isNotEmptyObject(item.sInkBOMsSlaveId))
          );
        }
        res = newData;
      } else {
        res = commonUtils.isEmptyArr(oriData) ? oriData : oriData.filter(item => commonUtils.isEmptyObject(item.sParentMaterialsId));
        res = commonUtils.isEmptyArr(oriData)
          ? oriData
          : res.filter(
              item =>
                (commonUtils.isEmptyObject(item.sInkBOMId) &&
                  commonUtils.isEmptyObject(item.sInkBOMsSlaveId) &&
                  commonUtils.isEmptyObject(item.sInkBOMsMaterialsId)) ||
                (commonUtils.isNotEmptyObject(item.sInkBOMsMaterialsId) &&
                  commonUtils.isNotEmptyObject(item.sInkBOMId) &&
                  commonUtils.isNotEmptyObject(item.sInkBOMsSlaveId))
            );
      }
    } else if (type === "materials1" || type === "materials2" || type === "materials3") {
      /* 过滤后的 materials0Data */
      let materials0FilterData = [];
      if (commonUtils.isNotEmptyObject(processRow) && commonUtils.isNotEmptyArr(materials0Data)) {
        const filterData = materials0Data.filter(
          item =>
            item.sControlId === processRow.sControlId &&
            item.sProcessId === processRow.sProcessId &&
            item.sProcessTbId === processRow.sId &&
            commonUtils.isEmptyObject(item.sParentMaterialsId)
        );
        if (commonUtils.isNotEmptyArr(filterData)) {
          materials0FilterData = filterData;
        }
      } else if (commonUtils.isNotEmptyObject(controlRow) && commonUtils.isNotEmptyArr(materials0Data)) {
        const filterData = materials0Data.filter(item => item.sControlId === controlRow.sId && commonUtils.isEmptyObject(item.sParentMaterialsId));
        if (commonUtils.isNotEmptyArr(filterData)) {
          materials0FilterData = filterData;
        }
      } else {
        materials0FilterData = materials0Data;
      }
      if (commonUtils.isNotEmptyArr(materials0FilterData)) {
        const config = data.config;
        const sSqlCondition = config ? config.sSqlCondition : "materials0.sBclassifyName.油墨";
        if (sSqlCondition) {
          let targetTbName = sSqlCondition.split(".")[0]; /* 1.表名 control  */
          if (commonUtils.isEmptyObject(targetTbName)) {
            targetTbName = "materials0";
          }
          let filteredValue = sSqlCondition.split(".")[1]; /* 2.解析filterValue: controlSelectedRowKeys */
          let sParentKey = sSqlCondition.split(
            "."
          )[2]; /* 2.解析本身表对应的值,如控制表筛选材料表 则材料表的sControlId = 控制表的controlSelectedRowKeys[0] */
          /* 双重条件 */
          if (commonUtils.isEmptyObject(targetTbName)) {
            if (type === "materials1") {
              /* materials0.sBclassifyName.油墨 */
              filteredValue = "sBclassifyName";
              sParentKey = "油墨";
            } else if (type === "materials2") {
              /* materials0.sBclassifyName.电化铝 */
              filteredValue = "sBclassifyName";
              sParentKey = "电化铝";
            }
          }
          if (targetTbName === "materials0") {
            let filterData = [];
            if (type === "materials1") {
              /* 油墨 */
              filterData = materials0FilterData.filter(
                item =>
                  sParentKey &&
                  sParentKey.includes(item[filteredValue]) &&
                  ((commonUtils.isNotEmptyObject(item.sInkBOMsMaterialsId) &&
                    commonUtils.isNotEmptyObject(item.sInkBOMId) &&
                    commonUtils.isNotEmptyObject(item.sInkBOMsSlaveId)) ||
                    (commonUtils.isEmptyObject(item.sInkBOMsMaterialsId) &&
                      commonUtils.isEmptyObject(item.sInkBOMId) &&
                      commonUtils.isEmptyObject(item.sInkBOMsSlaveId)))
              );
            } else if (type === "materials2") {
              /* 电化铝 */
              filterData = materials0FilterData.filter(
                item => sParentKey && sParentKey.includes(item[filteredValue]) && commonUtils.isEmptyObject(item.sParentMaterialsId)
              );
            } else if (type === "materials3") {
              /* 包材 */
              filterData = materials0FilterData.filter(
                item => sParentKey && sParentKey.includes(item[filteredValue]) && commonUtils.isEmptyObject(item.sParentMaterialsId)
              );
            }
            newData = filterData;
          }
        }
      }
      res = newData;
    } else if (type === "materials1Child") {
      /* 过滤油墨子集 */
      /* 过滤后的 materials0Data */
      let materials0FilterData = [];
      if (commonUtils.isNotEmptyObject(processRow) && commonUtils.isNotEmptyArr(materials0Data)) {
        const filterData = materials0Data.filter(
          item => item.sControlId === processRow.sControlId && item.sProcessId === processRow.sProcessId && item.sProcessTbId === processRow.sId
        );
        if (commonUtils.isNotEmptyArr(filterData)) {
          materials0FilterData = filterData;
        }
      } else if (commonUtils.isNotEmptyObject(controlRow) && commonUtils.isNotEmptyArr(materials0Data)) {
        const filterData = materials0Data.filter(item => item.sControlId === controlRow.sId);
        if (commonUtils.isNotEmptyArr(filterData)) {
          materials0FilterData = filterData;
        }
      } else {
        materials0FilterData = materials0Data;
      }
      if (commonUtils.isNotEmptyArr(materials0FilterData)) {
        const config = data.config;
        const sSqlCondition = config && commonUtils.isNotEmptyObject(config.sSqlCondition) ? config.sSqlCondition : "materials0.sBclassifyName.油墨";
        if (sSqlCondition) {
          let targetTbName = sSqlCondition.split(".")[0]; /* 1.表名 control  */
          if (commonUtils.isEmptyObject(targetTbName)) {
            targetTbName = "materials0";
          }
          let filteredValue = sSqlCondition.split(".")[1]; /* 2.解析filterValue: controlSelectedRowKeys */
          let sParentKey = sSqlCondition.split(
            "."
          )[2]; /* 2.解析本身表对应的值,如控制表筛选材料表 则材料表的sControlId = 控制表的controlSelectedRowKeys[0] */
          if (commonUtils.isEmptyObject(targetTbName)) {
            if (type === "materials1") {
              /* materials0.sBclassifyName.油墨 */
              filteredValue = "sBclassifyName";
              sParentKey = "油墨";
            } else if (type === "materials2") {
              /* materials0.sBclassifyName.电化铝 */
              filteredValue = "sBclassifyName";
              sParentKey = "电化铝";
            }
          }
          if (targetTbName === "materials0") {
            const filterData = materials0FilterData.filter(
              item => sParentKey && sParentKey.includes(item[filteredValue]) && commonUtils.isEmptyObject(item.sParentMaterialsId)
            );
            if (commonUtils.isNotEmptyArr(filterData)) {
              newData = filterData;
            }
          }
        }
      }

      if (type === "materials1Child") {
        /* 油墨过滤子集  相同sInkBOMId， sInkBOMsSlaveId， 有sInkBOMsMaterialsId是父集 */
        const { materials0Data, materials1SelectedRowKeys } = props;
        let materials1Row = {}; /* 油墨子级 */
        if (commonUtils.isNotEmptyArr(materials0Data) && commonUtils.isNotEmptyArr(materials1SelectedRowKeys)) {
          /* 没有工序选中行 则不进行数据过滤 */
          const iIndex = materials0Data.findIndex(item => materials1SelectedRowKeys.includes(item.sId));
          if (iIndex > -1) {
            materials1Row = materials0Data[iIndex];
          }
        }

        res = newData.filter(item => item.sInkFatherMaterialsTbId === materials1Row.sId);
      }
    } else if (type === "materials0Child") {
      /* 全部材料 过滤替代料 */
      const { materials0Data, materials0SelectedRowKeys } = props;
      let materials0Row = {}; /* 油墨子级 */
      if (commonUtils.isNotEmptyArr(materials0Data) && commonUtils.isNotEmptyArr(materials0SelectedRowKeys)) {
        /* 没有工序选中行 则不进行数据过滤 */
        const iIndex = materials0Data.findIndex(item => materials0SelectedRowKeys.includes(item.sId) && item.sProcessId ===
          processRow.sProcessId && item.sProcessTbId === processRow.sId);
        if (iIndex > -1) {
          materials0Row = materials0Data[iIndex];
        }
      }
      if (commonUtils.isNotEmptyObject(materials0Row)) {
        /* 根据工序过滤所有替代料 */
        if (commonUtils.isNotEmptyObject(materials0Row.sAluminumBomId)) {
          /* 电化铝替代料过滤 */
          res = oriData.filter(
            item =>
              item.sParentMaterialsId === materials0Row.sId ||
              (commonUtils.isNotEmptyObject(item.sParentMaterialsId) &&
                commonUtils.isNotEmptyObject(item.sMaterialsNo) &&
                item.sMaterialsNo1 === materials0Row.sMaterialsNo)
          );
        } else {
          res = oriData.filter(item => item.sParentMaterialsId === materials0Row.sId);
        }
      } else if (commonUtils.isNotEmptyObject(processRow)) {
        /* 根据工序过滤所有替代料 */
        res = oriData.filter(
          item =>
            item.sProcessId === processRow.sProcessId && item.sProcessTbId === processRow.sId && commonUtils.isNotEmptyObject(item.sParentMaterialsId)
        );
      } else if (commonUtils.isNotEmptyObject(controlRow)) {
        res = oriData.filter(item => item.sControlId === controlRow.sId && commonUtils.isNotEmptyObject(item.sParentMaterialsId));
      }
    } else {
      res = oriData;
    }
    return res;
  };
  returnProps.materialsFilterNew = materialsFilterNew;


  // 公共方法-过滤工序数据
  const processFilteNew = (props, data, type,  bFinal) => {
    // materials : 0-1部件材料 : 2成品材料;
    // process : 0-1-2 部品工序 : 3成品工序;
    // bfinal: 是否成品
    const { slaveSelectedRowKeys, controlSelectedRowKeys } = props;
    const oriData = data.data || [];
    if (data.data) {
      let res = [];
      switch (type) {
        case 'materials':
          if (bFinal) {
            if (bFinal) { /* 成品材料 */
              if (slaveSelectedRowKeys && slaveSelectedRowKeys.length) {
                res = oriData.filter((val) => {
                  return val.sType === '2' && (val.sCombinePartsName === slaveSelectedRowKeys[0] || !val.sCombinePartsName);
                });
              } else {
                res = oriData.filter((val) => {
                  return val.sType === '2';
                });
              }
            } else { /* 部件材料 */
              res = oriData.filter((val) => {
                return val.sType !== '2';
              });
            }
          } else {
            res = oriData;
          }
          break;
        case 'process':
          if (bFinal) {
            if (bFinal) { /* 成品工序 */
              if (slaveSelectedRowKeys && slaveSelectedRowKeys.length) {
                res = oriData.filter((val) => {
                  return val.sType === '3' && (val.sCombinePartsName === slaveSelectedRowKeys[0] || !val.sCombinePartsName);
                });
              } else {
                res = oriData.filter((val) => {
                  return val.sType === '3';
                });
              }
            } else { /* 部件工序 */
              if (controlSelectedRowKeys && controlSelectedRowKeys.length) {
                res = oriData.filter((val) => {
                  return val.sType !== '3' && (controlSelectedRowKeys.includes(val.sControlId) || !val.sControlId);
                });
              } else {
                res = oriData.filter((val) => {
                  return val.sType !== '3';
                });
              }

            }
          } else {
            // 成品工序放最下面
            const processData = oriData.filter(item => item.sControlId !== props.controlSelectedRowKeys[0])
            const idsToRemove = processData.map(item => item.sControlId);
            const allData = oriData.filter(item => !idsToRemove.includes(item.sControlId))
            res = allData.concat(processData);
            const res3 = res.filter(item => item.sType === '3');
            const resOther = res.filter(item => item.sType !== '3');
            res = [...resOther, ...res3];
          }
          break;
        default:
          res = oriData;
      }
      return res;
    } else {
      return oriData || [];
    }
  }
  returnProps.processFilteNew = processFilteNew;

  // 公共方法-递归数据
  const handleGetSlaveSelectedRowChildren = (allData, sId) => {
    let result = [];
    allData.forEach(item => {
      if (item.sFatherSlaveId === sId) {
        result.push(item);
        result = [...result, ...handleGetSlaveSelectedRowChildren(allData, item.sId)];
      }
    });
    return result;
  };

  returnProps.handleGetSlaveSelectedRowChildren = handleGetSlaveSelectedRowChildren;

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

  returnProps.handleSearchNodes = handleSearchNodes;

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

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

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

      if (tableDataRow.dSinglePQty > 0) {
        if (tableDataRow.iPage > 1) {
          // 笔记本  用 非样本 来做， 倍率是每页都一样才可以用      原先 /2 是指页数， 现在直接按张数
          tableDataRow.dMachineQty = commonUtils.convertFixNum((tableDataRow.dPartsQty * tableDataRow.iPage) / tableDataRow.dSinglePQty, 0);
        } else {
          tableDataRow.dMachineQty = commonUtils.convertFixNum(commonUtils.isNull(tableDataRow.dPartsQty, 0) / tableDataRow.dSinglePQty, 0);
          tableDataRow.dSumMachineQty = tableDataRow.dMachineQty * tableDataRow.iStick;
        }
      }
    }

    return tableDataRow;
  };

  returnProps.singlePQtyChange = singlePQtyChange;

  /* 公共展示表格额外Tab层功能 */
  const getCustomTabPaneExtra = 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 (
      <Tabs size="small" style={{ marginTop: 10, marginBottom: 12 }}>
        {Object.keys(controlGroup).map(tabNameKey => {
          console.log("eeee", 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>
          );
        })}
      </Tabs>
    );
  };

  returnProps.getCustomTabPaneExtra = getCustomTabPaneExtra;

  // 拖拽方法
  const handleDrag = (data, tableName) => {
    let { controlSelectedRowKeys, controlData } = props;
    if (props.enabled && controlSelectedRowKeys.length) {
      if (tableName === "process" || tableName === "materialsO") {
        if (commonUtils.isNotEmptyArr(data)) {
          let allData = props.processData;
          /* 控制表选中行 移动排序 */
          const filterData = data.filter(item => item.sType !== "3" && item.sControlId === props.controlSelectedRowKeys[0]);
          if (commonUtils.isNotEmptyArr(filterData)) {
            filterData.forEach((item, iIndex) => {
              item.iOrder = iIndex + 1;
              const iFilterIndex = commonUtils.isNotEmptyArr(allData) ? allData.findIndex(row => item.sId === row.sId) : -1;
              if (iFilterIndex > -1) {
                allData[iFilterIndex] = { ...item, iOrder: iIndex + 1 };
              }
            });
          }

          const filterProductData = data.filter(item => item.sType === '3');

          if (commonUtils.isNotEmptyArr(filterProductData)) {
            filterProductData.forEach((item, iIndex) => {
              item.iOrder = iIndex + 1;
              const iFilterIndex = commonUtils.isNotEmptyArr(allData) ? allData.findIndex(row => item.sId === row.sId) : -1;
              if (iFilterIndex > -1) {
                allData[iFilterIndex] = { ...item, iOrder: iIndex + 20000 };
              }
            });
          }

          /* 找到所属控制表的iOrder * 10000 */
          allData.forEach((item, iIndex) => {
            const iControlIndex = commonUtils.isNotEmptyArr(controlData) ? controlData.findIndex(row => item.sControlId === row.sId) : -1;
            if (iControlIndex > -1) {
              const iControlOrder = controlData[iControlIndex].iOrder * 100;
              allData[iIndex].iControlOrder = iControlOrder;
              allData[iIndex].iOrder = iControlOrder + item.iOrder;
            }
          });

          allData = allData.sort((a, b) => a.iOrder - b.iOrder);
          allData.forEach((item, iIndex) => {
            allData[iIndex] = { ...item, iOrder: iIndex + 1, handleType: commonUtils.isEmpty(item.handleType) ? "update" : item.handleType };
          });
          props.onSaveState({ processData: allData });
        }
      } else {
        // process : 0-1-2 部品工序 : 3成品工序;
        let processData = props.processData.slice(0);

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

        let afterDataIndex = 0;
        let afterData = data
          .filter(item => item.sType !== "3" && item.sType !== "0" && item.sControlId === props.controlSelectedRowKeys[0])
          .map(item => {
            afterDataIndex = afterDataIndex + 1;
            return { ...item, iOrder: afterDataIndex };
          });
        let allData = preData.concat(afterData);
        allData.forEach((item, index) => {
          if (item.sControlId === props.controlSelectedRowKeys[0]) {
            if (!allData[index].handleType) {
              allData[index].handleType = "update";
            }
          }
        });
        processData = processData.filter(item => item.sControlId !== props.controlSelectedRowKeys[0]);
        processData = processData.concat(allData);
        props.onSaveState({ processData });
      }
    }
  };

  returnProps.onDrag = handleDrag;

  return {
    ...props,
    ...returnProps,
  };
};

const CommonModal = props => {
  return (
    <div>
        {/* 工艺指导书弹窗组件 */}
        <PartsInfoModal {...props} />
        {/* 选择工序弹窗组件 */}
        <ProcessChooseModal {...props} />
        {/* 选择成品工序弹窗组件 */}
        <ProductProcessChooseModal {...props} />
        {/* 选择成品材料弹窗组件 */}
        <ProductMaterialsChooseModal {...props} />
        {/* 选择材料弹窗组件 */}
        <MaterialsChooseModal {...props} />
        {/* 选择工艺参数弹窗(旧） */}
        <ParamsChooseModal {...props} />
        {/* 选择工艺参数弹窗(新） */}
        <ParamsChooseNewModal {...props} />
        {/* 选择合版部件弹窗 */}
        <CombinePartsChooseModal {...props} />
        {/* 部件行选择合版信息弹窗 */}
        <ProductCombinationModal {...props} />
        {/* 复制从弹窗 */}
        <CopyFromModal {...props} />
        {/* Ctrl+R全部更新弹窗 */}
        <ModifyAllModal {...props} />
        {/* 工作流弹窗 */}
        <WorkFlowModal {...props} />
        {/* 选择色序弹窗 */}
        <SisColorModal {...props} />
    </div>
  );
};

// 工艺指导书弹窗
const PartsInfoModal = props => {
  const { enabled, partsInfoModalVisible, partsInfoModalTitle } = props;
  if (!partsInfoModalVisible) return "";

  const [enabledNew, setEnabledNew] = useState(false);

  const onCancel = () => {
    props.onSaveState({
      partsInfoModalVisible: false,
    });
  };

  const handleFooter = () => {
    const BtnSure = commonFunc.showLocalMessage(props, "BtnSure", "确定");
    const BtnSave = commonFunc.showLocalMessage(props, "BtnSave", "确定");
    const BtnUpd= commonFunc.showLocalMessage(props, "BtnUpd", "修改");
    if (props.enabled || props.masterData?.partsInfoLock) {
      return [
        <Button type="primary" onClick={onCancel}>
          {BtnSure}
        </Button>,
      ];
    }

    return [
      <Button
        onClick={() => {
          setEnabledNew(true);
        }}
      >
        {BtnUpd}
      </Button>,
      <Button
        type="primary"
        onClick={() => {
          props.onSubmit(true);
          onCancel();
        }}
      >
        {BtnSave}
      </Button>,
    ];
  };

  return (
    <AntdDraggableModal width="100%" title={partsInfoModalTitle} visible={partsInfoModalVisible} onCancel={onCancel} footer={[...handleFooter()]}>
      <CommonPartsInfo {...props} enabled={enabled || enabledNew} />
    </AntdDraggableModal>
  );
};

// 选择工序弹窗
const ProcessChooseModal = props => {
  const { processChooseVisible } = props;
  if (!processChooseVisible) return "";

  const { app, sModelsId, sModelsType, sTabId, content, processChooseData, masterConfig, processData, controlSelectedRowKeys } = props;
  const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
  const { notCurrentPane } = pane;

  let setProcessTitle = commonFunc.showMessage(app.commonConst, "setProcess"); //选择工序标题

  let searchProcessType = {};
  if (commonUtils.isNotEmptyObject(processChooseData)) {
    const chooseProcessConfig = masterConfig.gdsconfigformslave.find(item => item.sControlName === "BtnChooseProcess") || {};
    setProcessTitle = chooseProcessConfig.showName || setProcessTitle;
    const { sMenuName, sName, sId, sModelType } = processChooseData;

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

  const onCancel = () => {
    props.onSaveState({ processChooseVisible: false });
  };

  return (
    <AntdDraggableModal
      width={1300}
      title={setProcessTitle}
      visible={notCurrentPane ? false : processChooseVisible}
      onCancel={onCancel}
      footer={null}
    >
      <CommonListSelectMulti dragHandle {...searchProcessType} />
    </AntdDraggableModal>
  );
};

// 选择成品工序弹窗
const ProductProcessChooseModal = props => {
  const { productProcessChooseVisible } = props;
  if (!productProcessChooseVisible) return "";

  const { app, sModelsId, sModelsType, sTabId, content, productProcessChooseData, masterConfig, processData, controlSelectedRowKeys } = props;
  const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
  const { notCurrentPane } = pane;

  let setProcessTitle = commonFunc.showMessage(app.commonConst, "setProcess"); //选择工序标题

  let chooseProdutProcessType = {};
  let chooseProdutProcessConfig = {};
  if (commonUtils.isNotEmptyObject(productProcessChooseData)) {
    chooseProdutProcessConfig = masterConfig.gdsconfigformslave.find(item => item.sControlName === "BtnChooseProductProcess") || {};
    setProcessTitle = chooseProdutProcessConfig.showName || setProcessTitle;
    const { sMenuName, sName, sId, sModelType } = productProcessChooseData;

    let slaveFinalData = [];
    let slaveFinalSelectedRowKeys =[];
    if (commonUtils.isNotEmptyArr(props.slaveData)) {
      slaveFinalData = JSON.parse(JSON.stringify(props.slaveData));
      if (commonUtils.isNotEmptyArr(slaveFinalData) && slaveFinalData.length > 0) {
        slaveFinalData.forEach((item) => {
          item.sSlaveId = commonUtils.createSid(); /* 添加成品工序从表 */
        });
      }
      /* 选择成品工序 只有一条从表 则默认选中 */
      if(slaveFinalData.length ===1){
        slaveFinalSelectedRowKeys.push(slaveFinalData[0].sSlaveId);
      }

    }

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

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

  const onCancel = () => {
    props.onSaveState({ productProcessChooseVisible: false });
  };

  return (
    <AntdDraggableModal
      width={1300}
      title={setProcessTitle}
      visible={notCurrentPane ? false : productProcessChooseVisible}
      onCancel={onCancel}
      footer={null}
    >
      <CommonListSelectProductProcess {...chooseProdutProcessType} productProcess />
    </AntdDraggableModal>
  );
};


// 选择成品工序弹窗
const ProductMaterialsChooseModal = props => {
  const { productMaterialsChooseVisible } = props;
  if (!productMaterialsChooseVisible) return "";

  const { app, sModelsId, sModelsType, sTabId, content, productMaterialsChooseData, masterConfig, processData, controlSelectedRowKeys } = props;
  const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
  const { notCurrentPane } = pane;

  let setMaterialsTitle = ''; //选择工序标题

  let chooseProductMaterialsType = {};
  let chooseProductMaterialsConfig = {};
  if (commonUtils.isNotEmptyObject(productMaterialsChooseData)) {
    chooseProductMaterialsConfig = masterConfig.gdsconfigformslave.find(item => item.sControlName === "BtnChooseProductMaterials") || {};
    setMaterialsTitle = chooseProductMaterialsConfig.showName || setMaterialsTitle;
    const { sMenuName, sName, sId, sModelType } = productMaterialsChooseData;

    let slaveFinalData = [];
    let slaveFinalSelectedRowKeys =[];
    if (commonUtils.isNotEmptyArr(props.slaveData)) {
      slaveFinalData = JSON.parse(JSON.stringify(props.slaveData));
      if (commonUtils.isNotEmptyArr(slaveFinalData) && slaveFinalData.length > 0) {
        slaveFinalData.forEach((item) => {
          item.sSlaveId = commonUtils.createSid(); /* 添加成品工序从表 */
        });
      }
      /* 选择成品工序 只有一条从表 则默认选中 */
      if(slaveFinalData.length ===1){
        slaveFinalSelectedRowKeys.push(slaveFinalData[0].sSlaveId);
      }

    }

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

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

  const onCancel = () => {
    props.onSaveState({ productMaterialsChooseVisible: false });
  };

  return (
    <AntdDraggableModal
      width={1300}
      title={setMaterialsTitle}
      visible={notCurrentPane ? false : productMaterialsChooseVisible}
      onCancel={onCancel}
      footer={null}
    >
      <CommonListSelectProductMaterial {...chooseProductMaterialsType} productMaterials />
    </AntdDraggableModal>
  );
};

// 选择材料弹窗
const MaterialsChooseModal = props => {
  const { materialsChooseVisible } = props;
  if (!materialsChooseVisible) return "";

  const { app, sModelsId, sModelsType, sTabId, content, materialsChooseData, masterConfig, materialsData, controlSelectedRowKeys } = props;
  const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
  const { notCurrentPane } = pane;

  let setMaterialsTitle = commonFunc.showMessage(app.commonConst, "setMaterial"); //选择工序标题

  let searchMaterialsType = {};
  if (commonUtils.isNotEmptyObject(materialsChooseData)) {
    const choosematerialsConfig = masterConfig.gdsconfigformslave.find(item => item.sControlName === "BtnChooseMaterials") || {};
    setMaterialsTitle = choosematerialsConfig.showName || setMaterialsTitle;
    const { sMenuName, sName, sId, sModelType } = materialsChooseData;

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

  const onCancel = () => {
    props.onSaveState({ materialsChooseVisible: false });
  };

  return (
    <AntdDraggableModal
      width={1300}
      title={setMaterialsTitle}
      visible={notCurrentPane ? false : materialsChooseVisible}
      onCancel={onCancel}
      footer={null}
    >
      <CommonListSelect dragHandle {...searchMaterialsType} />
    </AntdDraggableModal>
  );
};

// 选择工艺参数弹窗（旧）
const ParamsChooseModal = props => {
  const { sParamsModalVisible, sModelsType, app } = props;
  if (!sParamsModalVisible) return "";

  const sProcessParams = commonFunc.showMessage(app.commonConst, "sProcessParams"); // 选择工艺参数标题

  const onCancel = () => {
    props.onSaveState({ sParamsModalVisible: false });
  };

  const sParamProps = {
    ...commonBusiness.getTableTypes("sParam", props),
    tableProps: {
      rowKey: "sId",
      onChange: props.onTitleChange,
      sModelsType,
      AutoTableHeight: 350,
    },
    bRowClick: true,
  };

  return (
    <AntdDraggableModal
      width="920px"
      className="paramModal"
      title={sProcessParams}
      visible={sParamsModalVisible}
      onOk={props.onParamsOk}
      onCancel={onCancel}
    >
      <div className="xly-bill-list">
        <StaticEditTable {...sParamProps} footer="hidden" noVlist />
      </div>
    </AntdDraggableModal>
  );
};

// 选择工艺参数弹窗（新）
const ParamsChooseNewModal = props => {
  const modalName = "sWorkParamsModalVisible"; // commonParamVisible
  const sProcessParams = commonFunc.showMessage(props.app.commonConst, 'workParam') || '工单参数' ;

  const getTableBtnState = tableName => {
    let result = false;
    const { enabled, masterData } = props;
    result = enabled;

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

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

  const convertRecordDefaultToSParams = (recordDefault, sParamType, extraData = {}) => {
    const data = {
      ...recordDefault,
      ...extraData,
    };
    const sParamsData = [
      {
        sParamType,
        data,
      },
    ];
    return JSON.stringify(sParamsData);
  };

  const getDefaultParams = () => {
    const tableName = "process";
    const tableData = props[`${tableName}Data`];
    const iIndex = commonUtils.getSelectedDataIndex(props, tableName);
    const sParamType = "sWorkOrder";
    if (iIndex !== -1) {
      const selectedData = commonUtils.getSelectedData(props, tableName);
      if (commonUtils.isNotEmptyObject(selectedData)) {
        /* 将默认值带到sParams中 */
        if (commonUtils.isEmptyObject(selectedData.sParams)) {
          const result = rglUtils.getReactGridLayout(sParamType, selectedData, props.sModelsId, props.formRoute);
          const { recordDefault } = result;
          const sParamsStr = convertRecordDefaultToSParams(recordDefault, sParamType);
          // 将弹窗打开没做任何操作的默认值 组装为params数据
          if (commonUtils.isNotEmptyObject(sParamsStr)) {
            tableData[iIndex].sParams = sParamsStr;
            tableData[iIndex].handleType = tableData[iIndex].handleType || "update";
            props.onSaveState({ [`${tableName}Data`]: tableData });
          }
        }
      }
    }
  };


  const BtnFirst= commonFunc.showMessage(props.app.commonConst, 'BtnFirst') || '首条' ;

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

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

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

  const BtnSure = commonFunc.showLocalMessage(props, 'BtnSure', '确定');

  return props[modalName] ? (
    <AntdDraggableModal
      width="80%"
      className="commonParamDrag"
      title={sProcessParams}
      visible={props[modalName]}
      onCancel={() => {
        props.onSaveState({ [modalName]: false });
      }}
      footer={
        <Button
          type="primary"
          onClick={() => {
            getDefaultParams();
            props.onSaveState({ [modalName]: false });
          }}
        >
          {BtnSure}
        </Button>
      }
    >
      <div>
        <div className="oper">
          <Button
            type="primary"
            onClick={() => {
              props.onBtnParamPage(props, props.processTableId, "first");
            }}
          >
            {BtnFirst}
          </Button>
          <Button
            type="primary"
            onClick={() => {
              props.onBtnParamPage(props, props.processTableId, "before");
            }}
          >
            {BtnPrior}
          </Button>
          <Button
            type="primary"
            onClick={() => {
              props.onBtnParamPage(props, props.processTableId, "next");
            }}
          >
            {BtnNext}
          </Button>
          <Button
            type="primary"
            onClick={() => {
              props.onBtnParamPage(props, props.processTableId, "last");
            }}
          >
            {BtnLast}
          </Button>
        </div>
        {[""].map(() => {
          const commonViewDragableProps = {
            ...props,
            hideTabsNav: true,
            comparedTableId: props.processTableId,
            sParamData: [
              {
                sParamType: "sWorkOrder",
                sParamName: "工单参数",
              },
            ],
            tableName: "process",
          };

          commonViewDragableProps.enabled = getTableBtnState(commonViewDragableProps.tableName);

          return <CommonViewDragable {...commonViewDragableProps} />;
        })}
      </div>
    </AntdDraggableModal>
  ) : (
    ""
  );
};

// 合版部件选择框
const CombinePartsChooseModal = props => {
  const { combinePartsChooseVisible } = props;
  if (!combinePartsChooseVisible) return "";
  const { app } = props;

  let combinePartsConfig = {};
  if (commonUtils.isNotEmptyObject(props.packConfig)) {
    combinePartsConfig = JSON.parse(JSON.stringify(props.packConfig));
    const gdsconfigformslaveFilter = combinePartsConfig.gdsconfigformslave.filter(
      item => item.sName === "sId" || item.sName === "sCustomerName" || item.sName === "sProductName" || item.sName === "sCombinePartsName"
    );
    combinePartsConfig.gdsconfigformslave = gdsconfigformslaveFilter;
    combinePartsConfig.bMutiSelect = false;
  }
  let combinePartsColumn = [];
  if (commonUtils.isNotEmptyObject(props.packColumn)) {
    combinePartsColumn = JSON.parse(JSON.stringify(props.packColumn));
    const packColumnFilter = props.packColumn.filter(
      item =>
        item.dataIndex === "sId" || item.dataIndex === "sCustomerName" || item.dataIndex === "sProductName" || item.dataIndex === "sCombinePartsName"
    );
    combinePartsColumn = packColumnFilter;
  }

  const handleSelectCombineParts = async (name, selectConfig, selectData) => {
    const { processData, processSelectedRowId, materialsData, materialsSelectedRowId, openTable } = props;
    let sCombinedStr = "";
    let sCombinedId = "";
    if (selectData !== undefined) {
      if (commonUtils.isNotEmptyArr(selectData)) {
        selectData.forEach(item => {
          const { sId } = item;
          let { sProductName } = item;
          let { sCombinePartsName } = item;
          sProductName = commonUtils.isNotEmptyObject(sProductName) ? sProductName : "";
          sCombinePartsName = commonUtils.isNotEmptyObject(sCombinePartsName) ? sCombinePartsName : "";
          if (commonUtils.isNotEmptyObject(sCombinePartsName)) {
            sCombinedStr += `${sProductName}-${sCombinePartsName},`;
            sCombinedId += `${sId},`;
          } else {
            sCombinedStr += `${sProductName},`;
            sCombinedId += `${sId},`;
          }
        });
        if (commonUtils.isNotEmptyObject(sCombinedStr)) {
          sCombinedStr = commonUtils.isNotEmptyObject(sCombinedStr) ? sCombinedStr.substr(0, sCombinedStr.length - 1) : "";
        }
        if (commonUtils.isNotEmptyObject(sCombinedId)) {
          sCombinedId = commonUtils.isNotEmptyObject(sCombinedId) ? sCombinedId.substr(0, sCombinedId.length - 1) : "";
        }
      }
      if (commonUtils.isNotEmptyObject(openTable) && openTable === "materials") {
        const iIndex = materialsData.findIndex(item => item.sId === materialsSelectedRowId);
        if (iIndex > -1) {
          if (!materialsData[iIndex]) {
            return;
          }
          const addState = {};
          let { handleType } = materialsData[iIndex];
          handleType = commonUtils.isEmpty(handleType) ? "update" : handleType;
          addState.handleType = handleType;
          addState.sCombinePartsNameNew = sCombinedStr;
          addState.sCombineProductNameNew = sCombinedStr;
          addState.sCombinePartsName = sCombinedId;
          materialsData[iIndex] = { ...materialsData[iIndex], ...addState };
        }
        props.onSaveState({
          materialsData,
          combinePartsChooseVisible: false,
        });
      } else {
        const iIndex = processData.findIndex(item => item.sId === processSelectedRowId);
        if (iIndex > -1) {
          if (!processData[iIndex]) {
            return;
          }
          const addState = {};
          let { handleType } = processData[iIndex];
          handleType = commonUtils.isEmpty(handleType) ? "update" : handleType;
          addState.handleType = handleType;
          addState.sCombinePartsNameNew = sCombinedStr;
          addState.sCombineProductNameNew = sCombinedStr;
          addState.sCombinePartsName = sCombinedId;
          processData[iIndex] = { ...processData[iIndex], ...addState };

          let returnProcessAssort = [];

          returnProcessAssort.filter(item => item.sParentId === processData[iIndex].sProcessId).forEach(itemProcessAssort => {
            const iProcessIndex = processData.findIndex(
              item => item.sProcessId === itemProcessAssort.sProcessId && item.sControlId === processData[iIndex].sControlId
            );
            if (iProcessIndex > -1) {
              processData[iProcessIndex] = {
                ...processData[iProcessIndex],
                ...addState,
              };
            }
          });
          // 查询是否有配套工序 sParentProcessId字段判断--结束
        }
        props.onSaveState({
          processData,
          combinePartsChooseVisible: false,
        });
      }
    }
  };

  const onCancel = () => {
    props.onSaveState({ combinePartsChooseVisible: false });
  };

  const combinePartsTableProps = {
    app: {
      ...app,
      currentPane: {
        ...app.currentPane,
        formRoute: "/indexPage/commonList",
        route: "/indexPage/commonList",
        name: "combineParts",
        config: combinePartsConfig,
        select: handleSelectCombineParts,
        selectCancel: onCancel,
      },
    },
    formRoute: "/indexPage/commonList",
    slaveConfig: combinePartsConfig,
    slaveColumn: combinePartsColumn,
    slaveData: props.combinePartsData,
    slaveSelectedRowKeys: props.combinePartsSelectedRowKeys,
    selectedRowKeys: props.combinePartsSelectedRowKeys,
    pageLoading: false,
    dispatch: props.dispatch,
    content: props.content,
    id: new Date().getTime().toString(),
  };
  const chooseCombinePartsName = commonFunc.showLocalMessage(props, 'chooseCombinePartsName', '选择合版部件名称');

  return (
    <AntdDraggableModal width={1150} title={chooseCombinePartsName} visible={combinePartsChooseVisible} onCancel={onCancel} footer={null}>
      <CommonListSelect {...combinePartsTableProps} />
    </AntdDraggableModal>
  );
};

// 合版信息弹窗
const ProductCombinationModal = props => {
  const { productCombinationVisible } = props;
  if (!productCombinationVisible) return "";

  const { app } = props;
  const setProductCombinationTitle = commonFunc.showMessage(app.commonConst, "setProductCombination"); //选择合拼产品标题

  const onCancel = () => {
    props.onSaveState({ productCombinationVisible: false });
  };

  const onSelectProductCombination = () => {
    const { controlData, sCombinationsControlId, packData, enabled } = props;
    let sCombinedMemo = "";
    const tableCombineSelectedData = [];
    const maxArr = [];
    const maxMap = new Map();
    let dSumCombineQty = 0;
    const packFilterData = packData.filter(item => item.sControlId === sCombinationsControlId);
    for (const tableDataRow of packFilterData) {
      const { sId, sProductNo, dCombineQty, dProductQty, dFactProductQty, sCombinePartsName } = tableDataRow;
      if (dCombineQty > 0) {
        /* 排版数大于0时,把数据带回到控制表 */
        const jsonObj = {};
        jsonObj.sId = sId;
        jsonObj.sProductNo = sProductNo; /* 产品编号 */
        jsonObj.dCombineQty = commonUtils.isNotEmptyNumber(dCombineQty) ? dCombineQty : 0; /* 排版数 */
        jsonObj.dProductQty = commonUtils.isNotEmptyNumber(dProductQty) ? dProductQty : 0; /* 生产数 */
        jsonObj.dFactProductQty = commonUtils.isNotEmptyNumber(dFactProductQty) ? dFactProductQty : 0; /* 实际生产数 */
        jsonObj.sCombinePartsName = sCombinePartsName; /* 合版部件名称 */
        dSumCombineQty += dCombineQty;
        tableCombineSelectedData.push(jsonObj);
        maxMap.set(Math.floor(dProductQty / dCombineQty), jsonObj);
        maxArr.push(Math.floor(dProductQty / dCombineQty));
      }
    }

    let iMax = 0;
    if (commonUtils.isNotEmptyArr(maxArr)) {
      iMax = Math.max(...maxArr);
    }
    sCombinedMemo = commonUtils.isNotEmptyArr(tableCombineSelectedData)
      ? JSON.stringify(tableCombineSelectedData)
      : ""; /* JSON对象转换为字符串存放到合版信息中 */
    const iControlIndex = controlData.findIndex(item => item.sId === sCombinationsControlId);
    if (iControlIndex > -1 && enabled) {
      const addState = {};
      const maxObj = maxMap.get(iMax);
      let { handleType } = controlData[iControlIndex];
      handleType = commonUtils.isEmpty(handleType) ? "update" : handleType;
      addState.handleType = handleType;
      addState.sCombinedMemo = sCombinedMemo;
      if (commonUtils.isNotEmptyObject(maxObj)) {
        addState.dSinglePQty = commonUtils.isNotEmptyObject(maxObj) ? maxObj.dCombineQty : 0;
      } else {
        const packFilterData = packData.findIndex(item => item.sControlId === sCombinationsControlId);
        if (commonUtils.isNotEmptyArr(packFilterData) && packFilterData.length === 1) {
          addState.dSinglePQty = packFilterData[0].dCombineQty;
        } else {
          addState.dSinglePQty = 1; /* 没合拼给默认值1 */
        }
      }
      addState.iCombineNum = dSumCombineQty;
      controlData[iControlIndex] = {
        ...controlData[iControlIndex],
        ...addState,
      };
    }
    props.onSaveState({
      productCombinationVisible: false,
      packData,
      controlData,
    });
  };

  const { setCopy, setDelete } = props.handleGetIcon();

  const packTableProps = {
    ...commonBusiness.getTableTypes("pack", props),
    filteredValue: props.controlSelectedRowKeys,
    onFilterData: props.onFilterData,
    onKeyDown: props.onKeyDown,
    tableProps: {
      setCopy,
      setDelete,
      CalLastWidth: "1150",
      AutoTableHeight: "300px",
    },
    bRowClick: true,
    footer: "hidden",
    setOpterationColumn: "Y",
  };

  return (
    <AntdDraggableModal
      width={1150}
      title={setProductCombinationTitle}
      visible={productCombinationVisible}
      onCancel={onCancel}
      forbidResize
      onOk={onSelectProductCombination}
      onSaveState={props.onSaveState}
    >
      <div className="xly-bill-list">
        <div style={{ marginTop: 0, height: "320px", overflowY: "hidden" }}>
          <StaticEditTable {...packTableProps} />
        </div>
      </div>
    </AntdDraggableModal>
  );
};

// 复制从弹窗
const CopyFromModal = props => {
  const { productProcessInfoChooseVisible } = props;
  if (!productProcessInfoChooseVisible) return "";

  const { app, sModelsId, masterConfig, productProcessInfoChooseData } = props;

  const onCancel = () => {
    props.onSaveState({ productProcessInfoChooseVisible: false });
  };

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

    productProcessInfoType = {
      app: {
        ...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(),
    };
  }

  return (
    <AntdDraggableModal width={1200} title={processCardSearchResult} visible={productProcessInfoChooseVisible} onCancel={onCancel} footer={null}>
      <CommonListSelect {...productProcessInfoType} />
    </AntdDraggableModal>
  );
};

// 修改全部弹窗
const ModifyAllModal = props => {
  const { contextMenuModalVisible } = props;
  if (!contextMenuModalVisible) return "";
  return <ContextMenuModal {...props} />;
};

// 工艺流程图弹窗
const WorkFlowModal = props => {
  const { workFlowVisible } = props;
  if (!workFlowVisible) return "";

  const onCancel = () => {
    props.onSaveState({ workFlowVisible: false });
  };

  const okButtonStyle = {
    style: {
      display: "none",
      backgroundColor: "red",
    },
  };
  const cancelButtonStyle = {
    htmlType: "退出",
    style: {
      width: 70,
      height: 50,
    },
  };
  const autoHeight = `calc( 100vh - 92px )`;

  return (
    <AntdDraggableModal
      width="1300"
      open={workFlowVisible}
      bodyStyle={{
        padding: 0,
        height: autoHeight,
        overflow: "auto",
        backgroundColor: "#ffffff",
      }}
      onOk={onCancel}
      okButtonProps={okButtonStyle}
      cancelButtonProps={cancelButtonStyle}
      onCancel={onCancel}
      closable
      style={{ backgroundColor: "#ffffff", top: 0 }}
    >
      <WorkFlow {...props} />
    </AntdDraggableModal>
  );
};

// 色序弹窗
const SisColorModal = props => {
  const { sisColorChooseVisible, app, sTabId, processConfig, sModelsId } = props;
  if (!sisColorChooseVisible) return "";

  const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];

  const setSisColorTitle = commonFunc.showMessage(app.commonConst, "setSisColor");

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

  const onCancel = () => {
    props.onSaveState({ sisColorChooseVisible: false });
  };

  return (
    <AntdDraggableModal
      width={1300}
      title={setSisColorTitle}
      visible={pane.notCurrentPane ? false : sisColorChooseVisible}
      onCancel={onCancel}
      footer={null}
    >
      <CommonListSelectFlex {...searchColorsType} />
    </AntdDraggableModal>
  );
};

export { CommonPackEvent, CommonModal };
