/* eslint-disable */
/**
 * Created by mar105 on 2019-03-27.
 */
import React, { Component } from 'react';
import { Modal, message } from 'antd-v4';
import * as commonUtils from '../../utils/utils'; /* 通用方法 */
import * as commonFunc from './commonFunc'; /* 通用单据方法 */
import commonConfig from '../../utils/config';
import * as commonServices from '../../services/services';
import * as commonBusiness from './commonBusiness';

const { confirm } = Modal;
/* 该组件作用是两层通用结构commonListTree事件层,功能如物料需求计划，两层都可以配制独立的数据源 */
export default (ChildComponent) => {
  return class extends Component {
    constructor(props) {
      super(props);
      this.state = {};
      this.loadingCount = 0;
    }

    componentWillMount() {
      /* 获取配置 */
      this.mounted = true;
      const {
        slaveData, slaveSelectedRowKeys, formRoute, app, sModelsType,
      } = this.props;
      const { currentPane } = app;
      /* 选择合版部件 slaveConfig,slaveColumn,slaveData有值 会将值存储到state中 */
      if (currentPane.name === 'combineParts' || currentPane.name === 'logView' || currentPane.name === 'sisColor' || currentPane.name === 'commonPopup') {
        const bFilterProName = currentPane.bFilterProName;
        const bFilterProValue = currentPane.bFilterProValue;
        this.props.onSaveState({
          slaveData, formRoute, pageLoading: false, slaveSelectedRowKeys, selectedRowKeys: slaveSelectedRowKeys, sModelsType, bFilterProName, bFilterProValue,
        });
      } else if (currentPane.name === 'chooseProductProcess') { /* 选择成品工序 */
        const { slaveFinalConfig, slaveFinalColumn, slaveFinalData } = this.props;
        this.props.onSaveState({
          slaveData,
          formRoute,
          pageLoading: false,
          slaveSelectedRowKeys,
          sModelsType,
          slaveFinalConfig, /* 成品工序 对应的工单从表配置 */
          slaveFinalColumn, /* 成品工序 对应的工单从表表头 */
          slaveFinalData, /* 成品工序 对应的工单从表数据源 */
        });
      }
    }

    async componentWillReceiveProps(nextProps) {
      this.nextProps = nextProps;
      const {
        app, formData, currentId, searchSolution, masterData, sGroupByList, formRoute, slaveConfig: slaveConfigOld, sModelsType,
      } = nextProps;

      let { iPageSize } = nextProps;

      if (commonUtils.isEmptyObject(slaveConfigOld) && formData.length > 0 && (formRoute.indexOf('/indexOee') > -1 || searchSolution !== undefined)) {
        const sId = currentId || nextProps.masterData?.sId || '';
        /* 数据Id */
        const slaveConfig = formData[0];
        const addState = {};
        const slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
        /* 选择工序选中表-拷贝slave配置 */
        const slaveFilterConfig = formData[0];
        const slaveFilterColumn = commonFunc.getHeaderConfig(slaveFilterConfig);
        let filterCondition = [];
        if (commonUtils.isNotEmptyObject(masterData) && !commonUtils.isEmpty(masterData.sSearchSolutionId) && commonUtils.isNotEmptyArr(searchSolution)) {
          const iIndex = searchSolution.findIndex(item => item.sId === masterData.sSearchSolutionId);
          if (iIndex > -1 && !commonUtils.isEmpty(searchSolution[iIndex].sCondition)) {
            filterCondition = JSON.parse(searchSolution[iIndex].sCondition);
          }
        }
        let slaveInfoColumn = {};
        let slaveInfoConfig;

        if (sModelsType !== '/indexOee/wagesSearch' && sModelsType !== '/indexOee/processReportList') { /* 该分支用于除OEE外的列表再次获取时执行 */
          /* 首先以下拉页数为准 否则以后台页数为准 如果以上都没有设置 则依照config配置的页码设置 */
          if (commonUtils.isNotEmptyNumber(formData[0].iPageSize) && formData[0].iPageSize !== 0) {
            iPageSize = formData[0].iPageSize;
          }
          await this.handleGetData(slaveConfig, filterCondition, 1, commonUtils.isNotEmptyNumber(iPageSize) && iPageSize !== 0 ? iPageSize : commonConfig.pageSize, '', false, sGroupByList);
          slaveInfoConfig = formData[1];
          slaveInfoColumn = {};
          if (commonUtils.isNotEmptyObject(slaveInfoConfig)) {
            slaveInfoColumn = commonFunc.getHeaderConfig(slaveInfoConfig);
            // await this.handleGetDataInfo(slaveInfoConfig, filterCondition, 1);
          }
          /* 判断是否要加载过滤树数据 */
          const filterTreeConfigArr = slaveConfig.gdsconfigformslave.filter(item => item.bTree);
          if (commonUtils.isNotEmptyArr(filterTreeConfigArr)) {
            const filterTreeConfig = filterTreeConfigArr[0];
            await this.handleGetFilterTreeData(filterTreeConfig, filterCondition, 1);
          }
          const iIndexBtnFirst = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnFirst');
          if (iIndexBtnFirst < 0) {
            slaveConfig.gdsconfigformslave.push({
              sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnFirst', sControlName: 'BtnFirst',
            });
          }
          const iIndexBtnPrior = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnPrior');
          if (iIndexBtnPrior < 0) {
            slaveConfig.gdsconfigformslave.push({
              sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnPrior', sControlName: 'BtnPrior',
            });
          }
          const iIndexBtnNext = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnNext');
          if (iIndexBtnNext < 0) {
            slaveConfig.gdsconfigformslave.push({
              sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnNext', sControlName: 'BtnNext',
            });
          }
          const iIndexBtnLast = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnLast');
          if (iIndexBtnLast < 0) {
            slaveConfig.gdsconfigformslave.push({
              sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnLast', sControlName: 'BtnLast',
            });
          }
          const iIndexBtnSave = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnSave');
          if (iIndexBtnSave < 0) {
            slaveConfig.gdsconfigformslave.push({
              sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnSave', sControlName: 'BtnSave',
            });
          }
          const iIndexBtnCancel = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnCancel');
          if (iIndexBtnCancel < 0) {
            slaveConfig.gdsconfigformslave.push({
              sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnCancel', sControlName: 'BtnCancel',
            });
          }
          const iIndexBtnCopyFrom = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnCopyFrom');
          if (iIndexBtnCopyFrom < 0) {
            slaveConfig.gdsconfigformslave.push({
              sId: commonUtils.createSid(), bVisible: false, sName: '', showName: 'BtnCopyFrom', sControlName: 'BtnCopyFrom',
            });
          }
        }
        this.props.onSaveState({
          masterConfig: slaveConfig,
          slaveConfig,
          slaveColumn,
          slaveInfoConfig,
          slaveInfoColumn,
          sId,
          pageLoading: false,
          slaveFilterColumn,
          slaveFilterConfig,
          ...addState,
        });
      } else if (JSON.stringify(app.currentPane.conditonValues) !== JSON.stringify(this.props.app.currentPane.conditonValues)) {
        const { slaveConfig, slaveFilterCondition } = nextProps;
        this.handleGetData(slaveConfig, slaveFilterCondition, 1, commonUtils.isNotEmptyNumber(iPageSize) && iPageSize !== 0 ? iPageSize : commonConfig.pageSize, undefined, undefined, undefined, nextProps);
      } else if (JSON.stringify(nextProps.id) !== JSON.stringify(this.props.id)) {
        this.props.onSaveState({ slaveSelectedRowKeys: [] });
      } else if (!commonUtils.isEmpty(this.props.pageNum) && this.props.pageNum !== nextProps.pageNum) {
        const {
          slaveConfig, slaveFilterCondition, sGroupByList, treeFilterCondition, slavePagination, slaveOrderBy,
        } = this.props;
        if (this.props.pageNum >= Math.ceil(slavePagination.total / slavePagination.pageSize)) {
          this.props.onToFirst();
        } else if (commonUtils.isNotEmptyArr(treeFilterCondition)) { /* 判断是否有树过滤条件 */
          this.handleGetData(slaveConfig, slaveFilterCondition, nextProps.pageNum, slavePagination.pageSize, slaveOrderBy, '', sGroupByList, '', treeFilterCondition);
        } else {
          this.handleGetData(slaveConfig, slaveFilterCondition, nextProps.pageNum, slavePagination.pageSize, slaveOrderBy, '', sGroupByList);
        }
      }
    }

    shouldComponentUpdate(nextProps) {
      const { slaveColumn } = nextProps;
      return commonUtils.isNotEmptyArr(slaveColumn);
    }

    /**   获取表数据   */
    handleGetData = async (slaveConfig, slaveFilterCondition, page, pageSize, slaveOrderBy, clearSelectData, sGroupByListNew, nextProps, treeFilterCondition) => {
      const currentProps = commonUtils.isEmpty(nextProps) ? this.props : nextProps;
      const {
        app,
        name,
        formRoute,
        slavePagination,
        selectedRowKeys,
        fatherModelsType,
        iPageSize,
      } = currentProps;
      let { sModelsType } = app.currentPane; /* 特殊处理 选择工序不分页s */
      const sGroupByList = sGroupByListNew !== undefined ? commonUtils.isEmptyArr(sGroupByListNew) ? null : sGroupByListNew : this.props.sGroupByList;
      const conditonValues = app.currentPane.conditonValues;
      const filterCondition = app.currentPane.filterCondition;
      const bFilter = [];
      const pageNum = commonUtils.isEmpty(page) ? 1 : page;
      if (!commonUtils.isEmptyArr(slaveFilterCondition)) {
        bFilter.push(...slaveFilterCondition);
      }
      if (!commonUtils.isEmptyArr(filterCondition)) {
        bFilter.push(...filterCondition);
      }
      if (!commonUtils.isEmptyArr(treeFilterCondition)) {
        bFilter.push(...treeFilterCondition);
      }
      pageSize = commonUtils.isEmpty(pageSize) ? commonUtils.isEmpty(slavePagination) || commonUtils.isEmpty(slavePagination.pageSize) ? iPageSize : slavePagination.pageSize : pageSize;
      if (formRoute === '/indexOee/oeeCurrentState') {
        bFilter.push({
          bFilterName: 'sMachineId',
          bFilterCondition: '=',
          bFilterValue: app.sMachineNameSId,
        });
        sModelsType = this.props.sModelsType;
      }
      if (commonUtils.isNotEmptyObject(sModelsType) && sModelsType === 'modal/searchProcess') { // 选择工序中的取数并获取工艺参数配置
        const addState = await this.props.handleGetDataSet({
          name: 'slave',
          configData: slaveConfig,
          condition: {
            pageNum: 1, pageSize: 10000, bFilter, sFilterOrderBy: slaveOrderBy, sSqlCondition: conditonValues, sGroupList: sGroupByList,
          },
          flag: true,
          isWait: true,
          clearSelectData,
        });
        if (commonUtils.isNotEmptyObject(fatherModelsType)) {
          addState.slaveData.forEach((item, iIndex) => {
            if (commonUtils.isNotEmptyObject(fatherModelsType.includes('quotation/') ? item.sProcessParam : fatherModelsType.includes('manufacture/') ? item.sWorkOrderParam : item.sProcessParam)) {
              item = { ...item, ...commonUtils.convertStrToObj(fatherModelsType.includes('quotation/') ? item.sProcessParam : fatherModelsType.includes('manufacture/') ? item.sWorkOrderParam : item.sProcessParam) };
              addState.slaveData[iIndex] = item;
            }
          });
          addState.slaveConfig = slaveConfig;
        }
        this.props.onSaveState({
          ...addState,
        });
      } else {
        const addState = await this.props.handleGetDataSet({
          name: 'slave',
          configData: slaveConfig,
          condition: {
            pageNum: commonUtils.isNotEmptyObject(sModelsType) && sModelsType === 'modal/searchProcess' ? '' : pageNum, pageSize: commonUtils.isNotEmptyObject(sModelsType) && (sModelsType === 'modal/searchProcess' || sModelsType === '/productionPlan/unifiedPlanning' || sModelsType === 'modal/logView') ? '' : pageSize, bFilter, sFilterOrderBy: slaveOrderBy, sSqlCondition: conditonValues, sGroupList: sGroupByList,
          },
          flag: true,
          clearSelectData,
          isWait: true,
        });

        // 默认展开
        let defaultExpandAllRows = false;
        let iIndex = -1;
        if (commonUtils.isNotEmptyObject(slaveConfig)) {
          iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName ==='defaultExpandAllRows');
          if (iIndex !== -1) {
            defaultExpandAllRows = slaveConfig.gdsconfigformslave[iIndex].bVisible;
          }
        }
        addState.defaultExpandAllRows = defaultExpandAllRows;
        if ((defaultExpandAllRows || iIndex !== -1) && commonUtils.isNotEmptyArr(addState.slaveData)) {
          addState.slaveInfoData = await this.handleGetAllExpandData(addState.slaveData, currentProps);
        }

        this.props.onSaveState(addState);
      }
      if (formRoute === '/indexPage/materialRequirementsPlanning' && clearSelectData) {
        const { slaveFilterCondition, slaveInfoConfig } = this.props;
        if (commonUtils.isNotEmptyObject(slaveInfoConfig)) {
          this.handleGetDataInfo(slaveInfoConfig, slaveFilterCondition, 1);
        }
      }
      // 复制到过后，没有选中的情况下打印菜单置空
      if (commonUtils.isNotEmptyObject(name) && name.indexOf('BtnCopyTo') > -1 && commonUtils.isEmptyArr(selectedRowKeys)) {
        this.props.onSaveState({ menuChildData: [] });
      }
    };

    /**   获取过滤树数据数据   */
    handleGetFilterTreeData= (slaveConfig, slaveFilterCondition, page, slaveOrderBy, props) => {
      const { app } = props === undefined ? this.props : props;
      const conditonValues = app.currentPane.conditonValues;
      const pageNum = commonUtils.isEmpty(page) ? 1 : page;
      this.props.handleGetTreeDataSet({
        name: 'slave',
        configData: slaveConfig,
        condition: {
          pageNum, pageSize: commonConfig.pageSize, bFilter: slaveFilterCondition, sFilterOrderBy: slaveOrderBy, sSqlCondition: conditonValues,
        },
        flag: true,
        clearSelectData: true,
      });
    };

    /**   获取表详情数据   */
    handleGetDataInfo = async (slaveInfoConfig, slaveFilterCondition, page, slaveOrderBy, record, isWait) => {
      let conditonValues = {};
      const sSqlCondition = slaveInfoConfig.sSqlCondition;
      if (commonUtils.isNotEmptyObject(sSqlCondition)) {
        conditonValues = this.props.getSqlCondition(slaveInfoConfig, 'slave', record);
      }
      const iPageSize = slaveInfoConfig.iPageSize !== 0 && commonUtils.isNotEmptyNumber(slaveInfoConfig.iPageSize) ? slaveInfoConfig.iPageSize : commonConfig.pageSize;
      const pageNum = commonUtils.isEmpty(page) ? 1 : page;
      const addStateSlaveInfo = await this.props.handleGetDataSet({
        name: 'slaveInfo',
        configData: slaveInfoConfig,
        condition: {
          pageNum, pageSize: iPageSize, bFilter: slaveFilterCondition, sFilterOrderBy: slaveOrderBy, sSqlCondition: conditonValues,
        },
        isWait: true,
        flag: true,
        clearSelectData: true,
      });
      if (isWait) {
        return addStateSlaveInfo;
      } else {
        this.props.onSaveState({
          pageLoading: false, ...addStateSlaveInfo,
        });
      }
    };
    /* 获取commonGantte列表数据集 */
    handleGanttChar = async (ganttChart, slaveFilterCondition) => {
      const {
        token, sModelsId, formRoute,
      } = this.props;
      const char = {};
      if (commonUtils.isNotEmptyObject(ganttChart)) {
        char.sProcedureName = ganttChart.sProcedureName;
        char.paramsMap = {};
      }
      let charGanttData = {};
      const value = {
        sProName: char.sProcedureName,
        paramsMap: char.prodParamsMap,
        bFilter: slaveFilterCondition,
      };
      const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}&sName=${formRoute}`;
      const { data: returnData } = await commonServices.postValueService(token, value, url);
      if (returnData.code === 1) {
        const { dataset } = returnData;
        if (commonUtils.isNotEmptyObject(dataset)) {
          const outData = returnData.dataset.rows[0].dataSet.outData[0];
          if (outData.sCode === -1) {
            message.error(outData.sReturn);
          } else {
            charGanttData = commonUtils.isEmpty(outData.sReturn) ? [] : JSON.parse(outData.sReturn);
            this.props.onSaveState({ charGanttData });
          }
        }
      } else {
        message.error(returnData.msg);
      }
    };


    handleTitleChange = (slavePagination, filters, sorter) => {
      const {
        slaveConfig, slaveFilterCondition, sGroupByList, //  slaveOrderBy: slaveOrderByOld,
      } = this.props;
      let bGetData = true;
      if (commonUtils.isNotEmptyObject(filters)) {
        for (const key of Object.keys(filters)) {
          if (commonUtils.isNotEmptyArr(filters[key])) {
            bGetData = false;
            break;
          }
        }
      }
      if (!bGetData) return;
      const { treeFilterCondition } = this.props;/* 树过滤条件 */
      const sort = sorter.order === 'ascend' ? 'asc' : 'desc';
      const slaveOrderBy = Object.keys(sorter).length > 0 ? { [sorter.columnKey]: sort } : ''; // 后端未支持空对象， 先用空表示
      if (commonUtils.isNotEmptyArr(treeFilterCondition)) { /* 判断是否有树过滤条件 */
        this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, slavePagination.pageSize, slaveOrderBy, '', sGroupByList, '', treeFilterCondition);
      } else {
        this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, slavePagination.pageSize, slaveOrderBy, '', sGroupByList);
      }
    };

    handleDoubleClick = async (record) => {
      const {
        slaveConfig,
        slaveData,
        dispatch,
        slaveFilterCondition,
        slavePagination,
        slaveOrderBy,
        sModelsType,
        formRoute,
        treeFilterCondition,
        app,
        iPageSize,
        // slaveSelectedData,
        // masterData,
        // employeeConfig,
      } = this.props;
      // oee双击查看开工任务
      // if (formRoute.indexOf('indexOee') > -1) {
      //   if (slaveSelectedData[0].sCompleteCheck !== 'bCompleteCheck' && commonUtils.isNotEmptyArr(slaveSelectedData)) {
      //     this.props.changePage(false, 'startWork', '2', false);
      //     this.props.onSaveState({
      //       masterData: slaveSelectedData[0],
      //     });
      //     if (commonUtils.isNotEmptyObject(record)) {
      //       const bFilter1 = [];
      //       bFilter1.push({
      //         bFilterName: 'sParentId',
      //         bFilterCondition: '=',
      //         bFilterValue: record.sId,
      //       });
      //       const employeeData = (await this.props.handleGetDataSet({
      //         name: 'employee',
      //         configData: employeeConfig,
      //         condition: { bFilter: bFilter1 },
      //         isWait: true,
      //       }));
      //       this.props.onSaveState({
      //         ...employeeData,
      //       });
      //     }
      //   }
      // } else {}
      const picArr = slaveConfig.gdsconfigformslave.filter(item => (item.sName === 'picArr'));
      const getData = this.handleGetData;
      if (picArr.length > 0) {
        let sActiveId = '';
        if (picArr[0].sName === 'picArr' && picArr[0].sDropDownType === 'picArr' && sModelsType !== 'commonList/msg') {
          [{ sActiveId }] = picArr;
          if (sActiveId === '1') {
            sActiveId = sActiveId === '1' ? commonUtils.isEmpty(record.sFormId) ? record.sSrcFormId : record.sFormId : sActiveId;
          }
        } else if (picArr[0].sName === 'picArr' && picArr[0].sDropDownType === 'picArr' && sModelsType === 'commonList/msg' && (record.sType === '消息' || record.sType === '1')) {
          [{ sActiveId }] = picArr;
        } else if (sModelsType === 'commonList/msg' && (record.sType !== '消息' || record.sType !== '1')) {
          sActiveId = '19211681019715633459786050';
        }
        /* 消息列表双击打开时 调用获取websocket消息 */
        if (sModelsType === 'commonList/msg') {
          const { webSocket, userinfo } = app;
          webSocket.onmessageTmp = async (msg) => {
            const rtmsg = JSON.parse(msg.data);
            if (rtmsg.action === 'showImg') {
              const msgData = JSON.parse(msg.data);
              dispatch({ type: 'app/saveMsgCount', payload: { msgCount: msgData.msg } });
            }
          };
          this.props.handleSendSocketMessage('reflush', 'showImg', record.sId, userinfo.sId, '您有消息待审核', null);
          if (this.props.app.currentPane.refresh !== undefined) {
            this.props.app.currentPane.refresh();
          }
        }
        const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}&sName=${formRoute}`;
        dispatch({
          type: 'content/onRouter',
          payload: {
            refresh: getData.bind(this, slaveConfig, slaveFilterCondition, commonUtils.isEmpty(slavePagination) ? 0 : slavePagination.current, slavePagination.pageSize, slaveOrderBy, undefined, undefined, undefined, treeFilterCondition), /*   刷新方法   */
            url: sNameUrl,
            sTabId: commonUtils.createSid(),
            sParentId: this.state.sTabId,
            urlDataType: 'newPane',
            checkedId: record.sId,
            bFilter: slaveFilterCondition,
            pageSize: commonUtils.isNotEmptyNumber(iPageSize) && iPageSize !== 0 ? iPageSize : commonConfig.pageSize,
            pages: slavePagination,
            currentData: slaveData,
            sListFormmasterId: slaveConfig.sId,
            newKey: record.sId,
            currentIndex: slaveData.findIndex(item => item.sId === record.sId),
            sSrcModelsId: this.props.sModelsId,
          },
        });
      }
    };

    /**   表单回带   */
    handleForm = (form) => {
      this.form = form;
    };

    /**  点击新增按钮   */
    handleAdd = (extendsParams) => {
      const {
        slaveConfig, slaveData, dispatch, slaveFilterCondition, slavePagination, slaveOrderBy, formRoute, treeFilterCondition, iPageSize,
      } = this.props;
      const picArr = slaveConfig.gdsconfigformslave.filter(item => (item.sName === 'picArr'));
      const getData = this.handleGetData;
      if (picArr.length > 0) {
        let sActiveId = '';
        if (picArr[0].sName === 'picArr' && picArr[0].sDropDownType === 'picArr') {
          [{ sActiveId }] = picArr;
        }
        const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}&sName=${formRoute}`;
        dispatch({
          type: 'content/onRouter',
          payload: {
            refresh: getData.bind(this, slaveConfig, slaveFilterCondition, commonUtils.isEmpty(slavePagination) ? 0 : slavePagination.current, commonUtils.isEmpty(slavePagination) ? iPageSize : slavePagination.pageSize, slaveOrderBy, undefined, undefined, undefined, treeFilterCondition), /*   刷新方法   */
            url: sNameUrl,
            sTabId: commonUtils.createSid(),
            sParentId: this.state.sTabId,
            urlDataType: 'newPane',
            bFilter: slaveFilterCondition,
            pageSize: iPageSize,
            pages: slavePagination,
            currentData: slaveData,
            sListFormmasterId: slaveConfig.sId,
            ...extendsParams,
            sSrcModelsId: this.props.sModelsId,
          },
        });
      }
    };

    /* 确定要删除 */
    handleOkDel = async (props) => {
      /*   数据参数   */
      const {
        token, sModelsId, slaveConfig, slaveData, slaveSelectedRowKeys, slaveFilterCondition, slavePagination, slaveOrderBy, formRoute, app, iPageSize,
      } = props;
      const allId = [];
      slaveSelectedRowKeys.forEach((key) => {
        const iIndex = slaveData.findIndex(item => item.sSlaveId === key);
        if (iIndex > -1) {
          if (allId.indexOf(slaveData[iIndex].sId) === -1) {
            allId.push(slaveData[iIndex].sId);
          }
        }
      });
      if (commonUtils.isNotEmptyArr(allId)) {
        const value = {
          sClientType: '1',
          data: {
            sMasterTable: slaveConfig.sTbName,
            sId: allId,
            sSlaveTable: 'commonList',
          },
        };
        const { sBillNo, sId } = props.masterData || {};
        const url = `${commonConfig.server_host}business/delMasSlaBusinessData?sModelsId=${sModelsId}&sName=${formRoute}&sBillNo=${sBillNo}&sSysLogSrcId=${sId}`;
        /*   接收返回值   */
        const { data } = await commonServices.postValueService(token, value, url);
        if (data.code === 1) {
          /*   数据删除成功   */
          const oeeCurrentStateFilter = [];
          if (formRoute === '/indexOee/oeeCurrentState') {
            oeeCurrentStateFilter.push({
              bFilterName: 'sMachineId',
              bFilterCondition: '=',
              bFilterValue: app.sMachineNameSId,
            });
          }
          message.success(data.msg);
          this.props.handleGetDataSet({
            name: 'slave',
            configData: slaveConfig,
            condition: {
              pageNum: formRoute === '/indexOee/oeeCurrentState' ? '' : slavePagination.current,
              pageSize: formRoute === '/indexOee/oeeCurrentState' ? '' : commonUtils.isNotEmptyNumber(iPageSize) && iPageSize !== 0 ? iPageSize : commonConfig.pageSize,
              bFilter: formRoute === '/indexOee/oeeCurrentState' ? oeeCurrentStateFilter : slaveFilterCondition,
              slaveOrderBy: formRoute === '/indexOee/oeeCurrentState' ? '' : slaveOrderBy,
            },
            clearSelectData: true,
          });
        } else { /*   失败   */
          this.props.getServiceError(data);
        }
      }
    };

    handleDel = () => {
      const onOkDel = this.handleOkDel;
      const props = this.props;
      confirm({
        title: commonFunc.showMessage(props.app.commonConst, 'SureDel'),
        onOk() {
          onOkDel(props);
        },
        onCancel() {},
      });
    };
    // 销售订单明细获取订单号
    handleGetGoods = () => {
      this.props.onSaveState({ visibleGetGoods: true });
    };

    handleGetGoodsValue = async (value) => {
      const { sModelsId, token, formRoute } = this.props;
      const url = `${commonConfig.server_host}erpOrderProcurement/getPlatOrderOne?sModelsId=${sModelsId}&sName=${formRoute}`;
      const values = { orderHeaderId: value };

      const masterReturn = (await commonServices.postValueService(token, values, url)).data;
      if (masterReturn.code === 1) {
        message.success(masterReturn.msg);
        this.handleButtonClick('BtnRefresh');
      } else {
        this.props.getServiceError(masterReturn);
      }

      this.props.onSaveState({
        visibleGetGoods: false,
      });
    }
    handleGetGoodsCancle = () => {
      this.props.onSaveState({
        visibleGetGoods: false,
      });
    }

    /* 导出Excel */
    handleOut = async () => {
      const {
        slaveConfig, slaveFilterCondition, slaveOrderBy, formRoute, slaveSelectedRowKeys, sGroupByList, formData,
      } = this.props;
      const slaveFilterConditionNew = slaveFilterCondition === undefined ? [] : [...slaveFilterCondition];
      let sids = '';
      let bMutiSelect = false; /* 默认单选或不选  true ：多选 */
      if (commonUtils.isNotEmptyArr(formData)) {
        bMutiSelect = formData[0].bMutiSelect;
      }
      if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys) && bMutiSelect) { /* 导出Excel 只有多选情况下 导出时是根据勾选行 否则导出全部 */
        slaveSelectedRowKeys.forEach((item, i) => {
          if (i === slaveSelectedRowKeys.length - 1) {
            sids = `${sids}${item}`;
          } else {
            sids = `${sids}${item},`;
          }
        });
        const addFilter = {};
        addFilter.bFilterName = 'sSlaveId';
        addFilter.bFilterCondition = 'in';
        addFilter.bFilterValue = sids;
        slaveFilterConditionNew.push(addFilter);
      }
      // let url = `${commonConfig.server_host}excel/export/${slaveConfig.sId}?sModelsId=${slaveConfig.sParentId}&token=${this.props.app.token}&sName=${formRoute}`;
      // if (commonUtils.isNotEmptyArr(slaveFilterConditionNew)) {
      //   url = `${url}&bFilter=${encodeURIComponent(JSON.stringify(slaveFilterConditionNew))}`;
      // }
      // if (slaveOrderBy !== undefined && slaveOrderBy !== '' && Object.keys(slaveOrderBy).length > 0) {
      //   url = `${url}&sFilterOrderBy=${encodeURIComponent(JSON.stringify(slaveOrderBy))}`;
      // }
      // if (commonUtils.isNotEmptyArr(sGroupByList)) {
      //   url = `${url}&sGroupList=${encodeURIComponent(JSON.stringify(sGroupByList))}`;
      // }
      // window.open(url);

      /* 导出使用Post提交 */
      const url = `${commonConfig.server_host}excel/export/${slaveConfig.sId}?sModelsId=${slaveConfig.sParentId}&sName=${formRoute}&token=${encodeURIComponent(this.props.app.token)}`;
      const bFilter = JSON.stringify(slaveFilterConditionNew);
      const sFilterOrderBy = JSON.stringify(slaveOrderBy);
      const sGroupList = JSON.stringify(sGroupByList);
      this.handleOpenOut(url, bFilter, sFilterOrderBy, sGroupList);
    };

    /* Get提交地址栏参数过多,更改Get提交为Post提交 */
    handleOpenOut= (url, bFilter, slaveOrderBy, sGroupByList) => {
      const newWin = window.open();
      let formStr = '';
      // 设置样式为隐藏，打开新标签再跳转页面前，如果有可现实的表单选项，用户会看到表单内容数据
      formStr = `<form style="visibility:hidden;" method="POST" action="${url}">` +
        `<input type="hidden" name="bFilter" value='${bFilter}' />`;
      if (commonUtils.isNotEmptyObject(slaveOrderBy)) {
        formStr += `<input type="hidden" name="sFilterOrderBy" value='${slaveOrderBy}' />`;
      }
      if (commonUtils.isNotEmptyObject(sGroupByList)) {
        formStr += `<input type="hidden" name="sGroupList" value='${sGroupByList}' />`;
      }
      formStr += '</form>';
      newWin.document.body.innerHTML = formStr;
      newWin.document.forms[0].submit();
      return newWin;
    }

    /* 批量审核 */
    handleBatchExamine = () => {
      this.handleAudit(1);
    };

    /* 批量消审 */
    handleBatchCancelExamine = () => {
      this.handleAudit(0);
    };

    deteleObject = (obj) => {
      // eslint-disable-next-line camelcase
      const replace_data = obj;
      const result = []; // 去重后的数组对象集合
      const hash = {};
      // eslint-disable-next-line no-plusplus
      for (let i = 0; i < replace_data.length; i++) {
        const elem = replace_data[i].sId;
        if (!hash[elem]) {
          result.push(replace_data[i]);
          hash[elem] = true;
        }
      }
      return result;
    }
    /**   toolbar批量审核(消审)   */
    handleAudit = async (flag) => {
      /*   待用数据声明   */
      const {
        slaveSelectedData, app, slaveConfig, slavePagination, slaveFilterCondition, slaveOrderBy,
      } = this.props;
      /*   作废订单不能审核   */
      if (commonUtils.isNotEmptyArr(slaveSelectedData)) {
        const slaveSelectedDataNew = this.deteleObject(slaveSelectedData); // 删除sid重复的数据
        let allMsg = '';
        let allErrorMsg = '';
        let dataAuditProcessValue = 0;
        const dataAuditProcessMaxValue = slaveSelectedDataNew.length;
        for (const child of slaveSelectedDataNew) {
          if (child.bInvalid) {
            message.warning(`已作废的单据${child.sBillNo}不能审核！`);
            return '';
          }
          /**   数据审核   */
          const strMsgs = await this.dataAudit(flag, `${child.sId}_${child.sFormId}`, child.sBillNo);
          if (commonUtils.isNotEmptyStr(strMsgs.strMsg)) {
            allMsg += `${strMsgs.strMsg} \n `;
          } else {
            allMsg += '';
          }
          if (commonUtils.isNotEmptyStr(strMsgs.strErrorMsg)) {
            allErrorMsg += `${strMsgs.strErrorMsg} \n `;
          } else {
            allErrorMsg += '';
          }
          dataAuditProcessValue += 1;
          this.props.onSaveState({ bDataAuditProgress: true, dataAuditProcessValue, dataAuditProcessMaxValue });
        }
        if (commonUtils.isNotEmptyStr(allMsg)) {
          message.info(allMsg);
        }
        if (allErrorMsg !== undefined && commonUtils.isNotEmptyStr(allErrorMsg)) {
          message.error(allErrorMsg);
        }
        this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, slavePagination.pageSize, slaveOrderBy, true); /*   刷新方法   */
        this.props.onSaveState({ bDataAuditProgress: false });
      } else {
        message.error(commonFunc.showMessage(app.commonConst, 'pleaseChooseData'));/* 请选择一条数据 */
      }
    };

    /**   数据审核   */
    dataAudit = async (flag, sId_sFormId, sBillNo, tmpCheck, isWait) => {
      const [sId, sFormId] = sId_sFormId.split('_');
      /*   待用数据声明   */
      const {
        sModelsId, app, slaveConfig, formRoute,
      } = this.props;
      /*   数据参数   */
      const picArr = slaveConfig.gdsconfigformslave.filter(item => (item.sName === 'picArr'));
      const value = {
        sClientType: '1',
        paramsMap: {
          iFlag: flag,
          iTmpCheck: commonUtils.isEmptyNumber(tmpCheck) ? 0 : tmpCheck,
          sFormGuid: commonUtils.isEmptyArr(picArr) ? sFormId : picArr[0].sActiveId,
          sGuid: sId,
        },
      };
      /*   数据审核   */
      const url = `${commonConfig.server_host}business/doExamine?sModelsId=${sModelsId}&sName=${formRoute}`;
      const returnData = (await commonServices.postValueService(app.token, value, url)).data;
      const msgs = {};
      if (isWait) {
        return returnData;
      } else {
        /*   接收返回值   */
        if (returnData.code === 1) { /*   成功   */
          if (flag === 1) {
            /*   审核   */
            const { outData } = returnData.dataset.rows[0].dataSet;
            if (commonUtils.isNotEmptyStr(outData[0].sReturn)) {
              msgs.strMsg = commonUtils.isNotEmptyObject(sBillNo) ? `${sBillNo}${outData[0].sReturn}` : `${outData[0].sReturn}`;
              // if (outData[0].sReturn.split('-').length < 2) {
              //   // 正常业务提示，非审核模板
              //   if (this.props.app.currentPane.refresh !== undefined) {
              //     this.props.app.currentPane.refresh();
              //   }
              //   msgs.strMsg = `${sBillNo}审核${outData[0].sReturn}`;
              //   return msgs;
              // }
              // const sReturnArray = outData[0].sReturn.split('|');
              // const sCheckModelId = sReturnArray[0].split('-')[1];
              // if (commonUtils.isNotEmptyStr(sCheckModelId)) {
              //   msgs.strMsg = `${sBillNo}审核失败`;
              // }
            } else {
              // this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, slavePagination.pageSize, slaveOrderBy, true); /*   刷新方法   */
              // message.destroy();
              msgs.strMsg = commonUtils.isNotEmptyObject(sBillNo) ? `${sBillNo}${returnData.msg}` : `${returnData.msg}`;
            }
          } else {
            /*   消审   */
            const { outData } = returnData.dataset.rows[0].dataSet;
            if (commonUtils.isNotEmptyStr(outData[0].sReturn)) {
              msgs.strMsg = commonUtils.isNotEmptyObject(sBillNo) ? `${sBillNo}${outData[0].sReturn}` : `$${outData[0].sReturn}`;
            } else {
              // this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, slavePagination.pageSize, slaveOrderBy, true); /*   刷新方法   */
              msgs.strMsg = commonUtils.isNotEmptyObject(sBillNo) ? `${sBillNo}${returnData.msg}` : `${returnData.msg}`;
            }
          }
        } else { /*   失败   */
          msgs.strErrorMsg = returnData.msg;
          // this.props.getServiceError(returnData);
        }
        return msgs;
      }
    };

    /** 按钮操作事件 */
    handleButtonClick = (name) => {
      if (name === 'BtnOut') {
        this.handleOut();
      } else if (name === 'BtnDesignFunction') {
        this.handleDesignFunction();
      } else if (name === 'BtnRefresh') {
        const {
          slaveConfig, slavePagination, slaveFilterCondition, slaveOrderBy,
        } = this.props;
        this.props.onSaveState({
          clearArray: [], searchText: '', slaveSelectedRowKeys: [], slaveSelectedData: [], slaveInfoSelectedRowKeys: [], slaveInfoSelectedData: [], treeSelectedKeys: [], treeFilterCondition: [], loading: false, pageLoading: true,
        });
        if (slavePagination === undefined) return;
        this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, slavePagination.pageSize, slaveOrderBy, true); /*   刷新方法   */
        // if (formRoute === '/indexPage/materialRequirementsPlanning') {
        //   if (commonUtils.isNotEmptyObject(slaveInfoConfig)) {
        //     this.handleGetDataInfo(slaveInfoConfig, slaveFilterCondition, 1);
        //   }
        // }
        /* 判断是否要加载过滤树数据 */
        const filterTreeConfigArr = slaveConfig.gdsconfigformslave.filter(item => item.bTree);
        if (commonUtils.isNotEmptyArr(filterTreeConfigArr)) {
          const filterTreeConfig = filterTreeConfigArr[0];
          this.handleGetFilterTreeData(filterTreeConfig, slaveFilterCondition, 1);
        }
        const { clearArray } = this.props;
        if (!commonUtils.isEmpty(clearArray)) {
          for (const item of clearArray) {
            const { confirm, clearFilters } = item;
            confirm();
            clearFilters();
          }
        }
      } else if (name === 'BtnSelect') {
        const { slaveSelectedData, app } = this.props;
        if (commonUtils.isNotEmptyArr(slaveSelectedData)) {
          this.props.app.currentPane.select(this.props.app.currentPane.name, this.props.app.currentPane.config, slaveSelectedData);
        } else {
          message.error(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); /* 请选择一条数据 */
        }
      } else if (name === 'BtnSelectCancel') {
        this.props.app.currentPane.selectCancel(this.props.app.currentPane.name);
      } else if (name === 'BtnBatchExamine') {
        this.handleBatchExamine();
      } else if (name === 'BtnBatchCancelExamine') {
        this.handleBatchCancelExamine();
      } else if (name === 'BtnNoForceComplete') {
        this.handleNoForceComplete();
      } else if (name === 'BtnSettleAccounts') {
        this.handleToSettlement(1);
      } else if (name === 'BtnReverseCheckout') {
        this.handleToSettlement(2);
      } else if (name === 'BtnBatchWorkListPriceUpdate') { /* 工单列表价格批量更新 */
        this.handleBatchWorkListsPriceUpdate();
      }
    };
    /* OEE机台任务 点击开工执行的逻辑 */
    handleOeeCopyTo = async (name) => {
      const {
        token, app, sModelsId, slaveSelectedData, slaveConfig, slaveDelData,
      } = this.props;
      const newCopyTo = {};
      const slaveData = [];
      if (commonUtils.isNotEmptyArr(slaveSelectedData)) {
        // 验证是否单据是否使用
        const sMachineId = app.sMachineNameSId;
        const creatId = commonUtils.createSid();
        const dataUrl = `${commonConfig.server_host}bill/billCopyToCheckWork?sModelsId=${sModelsId}`;
        const values = { sMachineId };
        const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
        if (dataReturn.code === 1) {
          const copyToConfig = commonUtils.isNotEmptyObject(slaveConfig) ? slaveConfig.gdsconfigformslave.filter(item => item.sControlName === name) : '';
          const slaveAssignField = commonUtils.isNotEmptyObject(copyToConfig) ? copyToConfig[0].sAssignField : '';
          slaveSelectedData.forEach((slaveItem) => {
            newCopyTo.slave = slaveItem;
            let colorRow = commonFunc.getDefaultData(slaveConfig, newCopyTo); // 取默认值
            colorRow = { ...colorRow, ...commonFunc.getAssignFieldValue(slaveAssignField, slaveItem, newCopyTo) }; // 取赋值字段
            colorRow.handleType = 'add';
            colorRow.sStatus = 'adjustment'; /* 点击开工进来是调机中，原来是生产中 */
            colorRow.sId = creatId;
            colorRow.sTeamId = app.sTeamNameSId;
            colorRow.sMachineId = app.sMachineNameSId;
            colorRow.sParentId = colorRow.sId;
            colorRow.tCreateDate = new Date();
            slaveData.push(colorRow);
          });
          const params = {};
          params.data = [];
          params.data.push(commonBusiness.mergeData('slave', 'plc_machinedata', slaveData, slaveDelData));
          // params.data = slaveData;
          const BtnSave = commonFunc.showMessage(app.commonConst, 'BtnSave');/* 保存 */
          params.optName = BtnSave;
          params.sClientType = '1';
          const returnData = await commonBusiness.saveData({ token, value: params, sModelsId });
          if (commonUtils.isNotEmptyObject(returnData)) {
            if (returnData.code === 1) {
              // const copyTo = {};
              // copyTo.name = name;
              // copyTo.config = commonUtils.isNotEmptyArr(copyToConfig) ? copyToConfig[0] : {};
              // copyTo.slaveData = slaveData;
              // copyTo.copyOtherData = [];
              // dispatch({
              //   type: 'content/onRouter',
              //   payload: {
              //     url: `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}&sName=${formRoute}`, /*   接口地址   */
              //     copyTo,
              //   },
              // });
              // 改变indexOee中的activeKey,
              this.props.onSaveCurrentState(slaveData, true);
            }
          }
        } else {
          this.props.getServiceError(dataReturn);
        }
      }
    }
    handleOeeLabelCopyTo = async (name, sActiveId) => {
      const {
        slaveSelectedData, dispatch,
      } = this.props;
      if (commonUtils.isNotEmptyArr(slaveSelectedData)) {
        const formRouteNew = '/indexOee/labelPrint';
        dispatch({
          type: 'content/onRouter',
          payload: {
            url: `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}&sName=${formRouteNew}`, /*   接口地址   */
            sSrcModelsId: this.props.sModelsId,
          },
        });
      }
    }

    /*   单据页复制到   */
    handleCopyTo = async (name, sActiveId) => {
      /*   待用数据声明   */
      const {
        slaveConfig, slaveSelectedData, token, app, sModelsId, formRoute, slaveInfoConfig, slaveInfoSelectedData, slaveFilterCondition,
        // eslint-disable-next-line no-unused-vars
        slavePagination, slaveOrderBy, treeFilterCondition, dispatch, slaveSelectedRowKeys, slaveInfoSelectedRowKeys, slaveData, slaveInfoData,
      } = this.props;

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

      let isRefresh = true;
      const copyTo = {};
      if (true) {
        const copyToConfig = slaveConfig.gdsconfigformslave.filter(item => item.sControlName.includes(name));
        let copyToData = slaveSelectedData;
        const addcopyOther = [];
        let tbSuffix = '';
        if (formRoute === '/indexPage/materialRequirementsPlanning') {
          if (name === 'BtnCopyTo.ActPurchaseOrder') {
            const detailCopy = {};
            detailCopy.name = 'detail';
            detailCopy.config = slaveInfoConfig;
            detailCopy.data = slaveInfoSelectedData;
            addcopyOther.push(detailCopy);
            tbSuffix = 'detail';
            isRefresh = true;
          } else {
            copyToData = slaveInfoSelectedData;
            isRefresh = true;
          }
          /* 物料需求计划生成采购申请、采购订单去重处理 */
          if (commonUtils.isNotEmptyArr(copyToData)) {
            const copyToDataNew = [];
            copyToData.forEach((item) => {
              const iIndex = copyToDataNew.findIndex(child => child.sWorkOrderMaterialId === item.sWorkOrderMaterialId);
              if (iIndex < 0) {
                copyToDataNew.push(item);
              }
            });
            copyToData = copyToDataNew;
          }
        } else if (name && (name.includes('BtnCopyTo.ActPurchaseDetail') || name.includes('Detail'))) { /* commonListTree 生成 commonSubBill */
          const detailCopy = {};
          detailCopy.name = 'detail';
          detailCopy.config = slaveInfoConfig;
          let sChildData = [];
          if (commonUtils.isNotEmptyArr(slaveInfoSelectedRowKeys)) {
            sChildData = slaveInfoData.filter(item => slaveInfoSelectedRowKeys.includes(item.sSlaveId));
          }

          const copyToTempConfig = slaveConfig.gdsconfigformslave.filter(item => item.sControlName.includes('tmpInfo'));

          /* 从表行没展开则调用接口取该从表的所有子表数据 */
          if (commonUtils.isNotEmptyArr(slaveSelectedData)) {
            let sSqlConditionIds = '';
            slaveSelectedData.forEach((itemSlave) => {
              /* 没有子表的 */
              let slaveInfoFilterData = [];
              if (commonUtils.isNotEmptyArr(slaveInfoData)) {
                slaveInfoFilterData = slaveInfoData.filter(item => item.sSqlConditionId === itemSlave.sSqlConditionId);
              }
              if (commonUtils.isEmptyArr(slaveInfoFilterData)) {
                sSqlConditionIds += `${itemSlave.sSqlConditionId},`;
              }
            });
            sSqlConditionIds = commonUtils.isNotEmptyObject(sSqlConditionIds) ? sSqlConditionIds.substr(0, sSqlConditionIds.length - 1) : '';
            if (commonUtils.isNotEmptyObject(sSqlConditionIds)) {
              const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfo/?sModelsId=${sModelsId}`;
              if (commonUtils.isNotEmptyObject(copyToTempConfig[0])) {
                const sConfigformId = commonUtils.isEmpty(copyToTempConfig) ? '' : copyToTempConfig[0].sParentId;
                // const sControlName = commonUtils.isNotEmptyObject(copyToTempConfig[0]) ? copyToTempConfig[0].sControlName : 'BtnCopyTo.tmpInfo';
                const sControlName = 'BtnCopyTo.tmpInfo';
                const sSqlCondition = { sId: sSqlConditionIds };
                const values = { sConfigformId, sControlName, sSqlCondition };
                if (true) {
                  const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
                  if (dataReturn.code === 1) {
                    const returnData = dataReturn.dataset.rows[0];
                    let slaveInfoOtherData = [];
                    if (commonUtils.isNotEmptyObject(returnData)) {
                      slaveInfoOtherData = returnData.master;
                      if (commonUtils.isNotEmptyArr(slaveInfoOtherData)) {
                        slaveInfoOtherData.forEach((itemOther) => {
                          const iIndex = sChildData.findIndex(item => item.sSlaveId === itemOther.sSlaveId);
                          if (iIndex === -1) {
                            sChildData.push(itemOther);
                          }
                        });
                      }
                    }
                  }
                }
              }
            }
          }
          if (commonUtils.isNotEmptyArr(sChildData)) {
            copyToData = sChildData;
          }
        } else if (name && (name.includes('BtnCopyTo.ActPurchaseInvoice') || name.includes('Total'))) { /* commonListTree 生成 commonSubBill */
          const detailCopy = {};
          detailCopy.name = 'detail';
          detailCopy.config = slaveInfoConfig;
          let sChildData = [];
          if (commonUtils.isNotEmptyArr(slaveInfoSelectedRowKeys)) {
            sChildData = slaveInfoData.filter(item => slaveInfoSelectedRowKeys.includes(item.sSlaveId));
          }

          const copyToTempConfig = slaveConfig.gdsconfigformslave.filter(item => item.sControlName.includes('tmpInfo'));

          /* 从表行没展开则调用接口取该从表的所有子表数据 */
          if (commonUtils.isNotEmptyArr(slaveSelectedData)) {
            let sSqlConditionIds = '';
            slaveSelectedData.forEach((itemSlave) => {
              /* 没有子表的 */
              let slaveInfoFilterData = [];
              if (commonUtils.isNotEmptyArr(slaveInfoData)) {
                slaveInfoFilterData = slaveInfoData.filter(item => item.sSqlConditionId === itemSlave.sSqlConditionId);
              }
              if (commonUtils.isEmptyArr(slaveInfoFilterData)) {
                sSqlConditionIds += `${itemSlave.sSqlConditionId},`;
              }
            });
            sSqlConditionIds = commonUtils.isNotEmptyObject(sSqlConditionIds) ? sSqlConditionIds.substr(0, sSqlConditionIds.length - 1) : '';
            if (commonUtils.isNotEmptyObject(sSqlConditionIds)) {
              const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfo/?sModelsId=${sModelsId}`;
              if (commonUtils.isNotEmptyObject(copyToTempConfig[0])) {
                const sConfigformId = commonUtils.isEmpty(copyToTempConfig) ? '' : copyToTempConfig[0].sParentId;
                // const sControlName = commonUtils.isNotEmptyObject(copyToTempConfig[0]) ? copyToTempConfig[0].sControlName : 'BtnCopyTo.tmpInfo';
                const sControlName = 'BtnCopyTo.tmpInfo';
                const sSqlCondition = { sId: sSqlConditionIds };
                const values = { sConfigformId, sControlName, sSqlCondition };
                if (true) {
                  const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
                  if (dataReturn.code === 1) {
                    const returnData = dataReturn.dataset.rows[0];
                    let slaveInfoOtherData = [];
                    if (commonUtils.isNotEmptyObject(returnData)) {
                      slaveInfoOtherData = returnData.master;
                      if (commonUtils.isNotEmptyArr(slaveInfoOtherData)) {
                        slaveInfoOtherData.forEach((itemOther) => {
                          const iIndex = sChildData.findIndex(item => item.sSlaveId === itemOther.sSlaveId);
                          if (iIndex === -1) {
                            sChildData.push(itemOther);
                          }
                        });
                      }
                    }
                  }
                }
              }
            }
          }
          if (commonUtils.isNotEmptyArr(sChildData)) {
            detailCopy.data = sChildData;
          }
          addcopyOther.push(detailCopy);
        } else if (name === 'BtnCopyTo.ActProduceReport') { /* 若机台中点击暂停 则待产量上报中点击上报提示”工序已暂停，无法上报 */
          if (commonUtils.isNotEmptyArr(copyToData) && copyToData[0].sState === '3') {
            message.warn('工序已暂停，无法开工！');
            return;
          }
        } else if (name && name.includes('BtnCopyTo.copyToOrder')) { /* 雅昌这个按钮执行调用接口逻辑 */
          let sType = '';/* 类型 */
          if (name.includes('Sales')) {
            sType = 'salesorder';
          } else if (name.includes('Work')) {
            sType = 'workorder';
          } else if (name.includes('Quo')) {
            sType = 'quotation';
          }
          const sControlIdsArr = []; /* 部件id集合 */
          const sSlaveIdsArr = []; /* 从表id集合 */
          let sSlaveType = ''; /* 选中表格类型 */
          if (commonUtils.isNotEmptyArr(slaveData)) {
            if (commonUtils.isNotEmptyArr(slaveSelectedData)) { /* 从表选中 */
              sSlaveType = 'slaveTable';
              slaveSelectedData.forEach((item) => {
                const sControlIds = commonUtils.isNotEmptyObject(item.sControlIds) ? item.sControlIds : '';
                if (commonUtils.isNotEmptyObject(sControlIds)) { /* 不为空传入部件ID */
                  const splitData = sControlIds.split('-');
                  if (commonUtils.isNotEmptyArr(splitData)) {
                    splitData.forEach((itemIds) => {
                      sControlIdsArr.push(itemIds);
                    });
                  }
                } else { /* 为空传入从表ID */
                  sSlaveIdsArr.push(item.sSlaveId);
                }
              });
            }
            if (commonUtils.isNotEmptyArr(slaveInfoSelectedRowKeys)) { /* 子表选中 */
              slaveInfoSelectedRowKeys.forEach((itemIds) => {
                sControlIdsArr.push(itemIds);
              });
            }

            const values = {
              sControlIds: sControlIdsArr,
              sSlaveIds: sSlaveIdsArr,
              sSlaveType,
            };
            const dataUrl = `${commonConfig.server_host}salesorder/getCopyToOrder/${sType}?sModelsId=${sModelsId}`;
            const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
            if (dataReturn.code === 1) {
              const returnData = dataReturn.dataset.rows[0];
              copyTo.masterData = returnData.masterData;
              copyTo.slaveData = returnData.slaveData;
              copyTo.controlData = returnData.controlData;
              copyTo.materialsData = returnData.materialsData;
              copyTo.processData = returnData.processData;
              copyTo.packData = returnData.packData;
              if (commonUtils.isEmptyArr(slaveSelectedData)) {
                copyToData = returnData.slaveData;
              }
            }
          } else {
            message.warn('请选择数据！');
            return;
          }
        } else if (commonUtils.isNotEmptyObject(name) && name.includes('BtnCopyTo.tmpInfo')) { /* 根据配置下拉sql获取数据源 */
          const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfo/?sModelsId=${sModelsId}`;
          const sConfigformId = commonUtils.isEmpty(copyToConfig) ? '' : copyToConfig[0].sParentId;
          const sControlName = commonUtils.isNotEmptyObject(name) ? name : 'BtnCopyTo.tmpInfo';
          const sSqlCondition = { sId: slaveSelectedData[0].sSlaveId };
          const values = { sConfigformId, sControlName, sSqlCondition };
          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`;
                  copyTo[sName] = returnData[key];
                }
                if (!copyTo.masterData) {
                  copyTo.masterData = copyToData[0];
                }
              }
            }
          } else {
            message.warn('数据未配置！不能生成！');
            return;
          }
        } else if (commonUtils.isNotEmptyObject(name) && name.includes('BtnCopyTo.onlyChild')) { /* 只拿子表数据 作为从表数据 */
          if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
            message.warn('请选择明细!');
            return;
          } else if (commonUtils.isNotEmptyArr(slaveInfoSelectedRowKeys)) {
            const iIndex = slaveInfoData.findIndex(item => slaveInfoSelectedRowKeys.includes(item.sSlaveId));
            if (iIndex > -1) {
              copyToData = [slaveInfoData[iIndex]];
            }
          }
        } else if (commonUtils.isNotEmptyObject(name) && name.includes('BtnCopyTo.partChild')) { /* 部分子表数据 */
          if (commonUtils.isNotEmptyArr(slaveInfoSelectedRowKeys)) {
            const slaveFilterData = slaveInfoData.filter(item => slaveInfoSelectedRowKeys.includes(item.sSlaveId));
            if (commonUtils.isNotEmptyArr(slaveFilterData)) {
              copyToData = slaveFilterData;
            }
          } else {
            message.warn('请选择明细!');
            return;
          }
        }
        // 不重复字段处理 例如 复制到时只能同一客户复制到
        const iIndex = copyToConfig.findIndex(item => item.sControlName === name);
        if (iIndex > -1 && !commonUtils.isEmpty(copyToConfig[iIndex].sNotRepeatColumn)) {
          const sNotRepeatColumn = copyToConfig[iIndex].sNotRepeatColumn.trim();
          const sNotRepeatValue = copyToData[0][sNotRepeatColumn];
          const iCount = copyToData.filter(item => item[sNotRepeatColumn] === sNotRepeatValue).length;
          if (iCount !== copyToData.length) {
            const iConfigIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === sNotRepeatColumn);
            const sNotRepeatShowName = iConfigIndex > -1 ? slaveConfig.gdsconfigformslave[iConfigIndex].showName : '';
            message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseSame') + sNotRepeatShowName); // 请选择相同
            return;
          }
        }
        const { userinfo } = app;
        const sIdArray = [];
        copyToData.forEach((item) => {
          if (formRoute === '/indexPage/materialRequirementsPlanning') {
            sIdArray.push(item.sWorkOrderMaterialId); /* 物料需求计划生成用sWorkOrderMaterialId作为唯一键 */
          } else if (item.sSlaveId) {
            sIdArray.push(item.sSlaveId);
          } else {
            sIdArray.push(item.sId);
          }
        });
        this.props.app.webSocket.onmessageTmp = (msg) => {
          const rtmsg = JSON.parse(msg.data);
          if (rtmsg.action === 'execute') {
            if (rtmsg.msg === 'continue') {
              const { formRoute } = this.state;
              if (commonUtils.isNotEmptyArr(copyToData)) {
                copyTo.name = name;
                copyTo.config = copyToConfig;
                if (!name.includes('BtnCopyTo.copyToOrder') && !name.includes('BtnCopyTo.tmpInfo')) {
                  copyTo.masterData = copyToData[0];
                  copyTo.slaveData = copyToData;
                  copyTo.copyOtherData = addcopyOther;
                }
                copyTo.srcFormRoute = this.props.formRoute; /* 未清来源路由 */
                dispatch({
                  type: 'content/onRouter',
                  payload: {
                    url: `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}&sName=${formRoute}`, /*   接口地址   */
                    copyTo,
                    refresh: getData.bind(this, slaveConfig, slaveFilterCondition, commonUtils.isEmpty(slavePagination) ? 0 : slavePagination.current, slavePagination.pageSize, slaveOrderBy, isRefresh, undefined, undefined, treeFilterCondition),
                    sSrcModelsId: this.props.sModelsId,
                  },
                });
              } else {
                message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); // 请选择数据
              }
            } else {
              message.warning(rtmsg.handlers + commonFunc.showMessage(app.commonConst, 'InOperation'));/* 在操作,请稍后再操作! */
            }
          }
        };
        const sId = sIdArray.toString();
        const getData = this.handleGetData;
        const dataUrl = `${commonConfig.server_host}bill/billCopyToCheck/?sModelsId=${sModelsId}&sActiveId=${sActiveId}&tbSuffix=${tbSuffix}&sName=${formRoute}`;
        const values = { sSlaveId: sId };
        const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
        if (dataReturn.code === 1) {
          const sendSocketMessage = this.props.handleSendSocketMessage;
          if (dataReturn.dataset.rows.length > 0) {
            confirm({
              title: commonFunc.showMessage(app.commonConst, 'beUsedToNew'), /* 单据已存在，是否填写新单据 */
              onOk() {
                sendSocketMessage('copy', 'execute', sId, userinfo.sId, null, null);
              },
              onCancel() {
              },
            });
          } else {
            sendSocketMessage('copy', 'execute', sId, userinfo.sId, null, null);
          }
        } else {
          this.props.getServiceError(dataReturn);
        }
      } else {
        message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); // 请选择数据
      }
    };
    // CopyTo = (refresh, copyToData, name, copyToConfig, sActiveId, dispatch, app, copyOther) => {
    //   const { formRoute } = this.state;
    //   if (commonUtils.isNotEmptyArr(copyToData)) {
    //     const copyTo = {};
    //     copyTo.name = name;
    //     copyTo.config = copyToConfig;
    //     copyTo.masterData = copyToData[0];
    //     copyTo.slaveData = copyToData;
    //     copyTo.copyOtherData = copyOther;
    //     dispatch({
    //       type: 'content/onRouter',
    //       payload: {
    //         url: `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}&sName=${formRoute}`, /*   接口地址   */
    //         copyTo,
    //         refresh,
    //       },
    //     });
    //   } else {
    //     message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); // 请选择数据
    //   }
    // };
    // handleForceComplete = (name) => {
    //   const { slaveSelectedRowKeys, app, masterConfig } = this.props;
    //   if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
    //     message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); // 请选择记录
    //   } else {
    //     const slaveMemoConfigOld = [];
    //     let btnConfigNameArr = [];
    //     if (name.indexOf('BtnRepair') > -1) {
    //       const btnConfig = masterConfig.gdsconfigformslave.filter(item => item.sControlName === name)[0];// sButtonEnabled  sButtonParam
    //       if (!commonUtils.isEmpty(btnConfig.sActiveKey)) {
    //         btnConfigNameArr = btnConfig.sActiveKey.split(',');
    //       }
    //       if (commonUtils.isNotEmptyArr(btnConfigNameArr)) {
    //         // eslint-disable-next-line array-callback-return
    //         btnConfigNameArr.map((i) => {
    //           const singleConfig = this.props.slaveConfig.gdsconfigformslave.filter(item => (item.sName === i))[0];
    //           slaveMemoConfigOld.push(singleConfig);
    //         });
    //       }
    //     }
    //     const sysLogData = { sId: slaveSelectedRowKeys.toString() };
    //     this.props.onSaveState({
    //       slaveMemoConfig: slaveMemoConfigOld,
    //       sCurrMemoProps: {
    //         bVisibleMemo: true,
    //         sMemoField: 'sReason',
    //         sRecord: sysLogData,
    //         dataSource: sysLogData,
    //         btnName: name,
    //       },
    //     });
    //   }
    // }

    handleNoForceComplete = async () => {
      const {
        sModelsId, slaveSelectedRowKeys, slaveConfig, app, formRoute,
      } = this.props;
      const { token } = this.props.app;
      if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
        message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); // 请选择记录
      } else {
        const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnNoForceComplete');
        const btnConfig = slaveConfig.gdsconfigformslave[iIndex];
        const sRelation = btnConfig.sRelation;
        const url = `${commonConfig.server_host}bill/billForceComplete?sModelsId=${sModelsId}&sName=${formRoute}`;
        const values = { sqlParam: sRelation, sId: slaveSelectedRowKeys.toString(), sType: 'noforce' };

        const dataReturn = (await commonServices.postValueService(token, values, url)).data;
        if (dataReturn.code === 1) {
          message.success(dataReturn.msg);
          this.handleButtonClick('BtnRefresh');
        } else {
          this.props.getServiceError(dataReturn);
        }
      }
    }

    // /* 双击弹出Memo */
    // handleGetMemo = (name, sValue, sMemoFiled, sRecord) => {
    //   const { sCurrMemoProps } = this.props;
    //   sCurrMemoProps.bVisibleMemo = false;
    //   sRecord[sMemoFiled] = sValue;
    //   this.props.onSaveState({ sCurrMemoProps });
    //   this.handleToForceComplete(sValue);
    // };

    /* 设计报表功能 */
    handleDesignFunction = () => {
      this.props.onSaveState({ visibleStatement: true });
    };
    handleBtnPrint = (sActiveId, checked, key) => {
      const {
        app,
        sModelsId,
        masterConfig,
        menuChildData,
        reportData,
        slaveFilterCondition,
        slaveSelectedRowKeys,
        slaveSelectedData,
        formRoute,
        treeFilterCondition,
        slaveData,
      } = this.props;
      const { token } = app;
      const slaveFilterConditionNew = slaveFilterCondition === undefined ? [] : [...slaveFilterCondition];
      // const queryFilter = {};
      // queryFilter[masterConfig.sId] = { sId: masterData.sId };
      // queryFilter[slaveConfig.sId] = { sSqlCondition: { sParentId: masterData.sId } };

      let sids = '';
      slaveSelectedRowKeys.forEach((item, i) => {
        if (commonUtils.isNotEmptyArr(slaveData)) {
          const iIndex = slaveData.findIndex(child => child.sSlaveId === item);
          if (iIndex > -1) {
            if (i === slaveSelectedRowKeys.length - 1) {
              sids = `${sids}${item}`;
            } else {
              sids = `${sids}${item},`;
            }
          }
        }
      });
      if (sids !== '') {
        const addFilter = {};
        addFilter.bFilterName = 'sSlaveId';
        addFilter.bFilterCondition = 'in';
        addFilter.bFilterValue = sids;
        slaveFilterConditionNew.push(addFilter);
      }
      // 将过滤数的赛选条件塞入打印中
      if (key.indexOf('BtnPrint.') > -1 && commonUtils.isNotEmptyArr(treeFilterCondition)) {
        // eslint-disable-next-line array-callback-return
        treeFilterCondition.map((item) => {
          slaveFilterConditionNew.push(item);
        });
      }
      const queryFilter = {};

      queryFilter[masterConfig.sId] = { bFilter: slaveFilterConditionNew };
      const queryFilterJson = encodeURIComponent(JSON.stringify(queryFilter));
      /* 拿到打印报表名称 */
      let printReportName = 'report';
      let slaveOneData = commonUtils.isNotEmptyArr(slaveSelectedData) ? JSON.stringify(slaveSelectedData) : '[]';
      slaveOneData = slaveOneData.replace("'", '');
      if (key.indexOf('BtnPrint.') > -1) {
        if (commonUtils.isNotEmptyArr(reportData)) {
          const iIndex = reportData.findIndex(item => item.sId === sActiveId);
          if (iIndex > -1) {
            printReportName = reportData[iIndex].sReportName;
          }
        }
        const urlPrint = `${commonConfig.file_host}printReport/printPdf/${sActiveId}/${printReportName}.pdf?${checked ? 'fileType=.xlsx&' : ''}queryFilter=${queryFilterJson}&sModelsId=${sModelsId}&sMaintableId=${masterConfig.sId}&token=${encodeURIComponent(token)}&sName=${formRoute}`;
        window.open(urlPrint);
      } else if (key.indexOf('BtnPrintCus.') > -1) {
        if (commonUtils.isNotEmptyArr(menuChildData)) {
          const iIndex = menuChildData.findIndex(item => item.sId === sActiveId);
          if (iIndex > -1) {
            printReportName = menuChildData[iIndex].sReportName;
          }
        }
        // const urlPrint = `${commonConfig.file_host}printReport/printPdf/${printReportName}?${checked ? 'fileType=.xlsx&' : ''}sModelsId=${sModelsId}&printType=noquery&slaveOneData=${slaveOneData}`;
        // window.open(`${encodeURI(`${urlPrint}&queryFilter=${queryFilterJson}`)}&token=${encodeURIComponent(token)}`);

        /* Get提交地址栏参数过多,更改Get提交为Post提交 */
        const url = `${commonConfig.file_host}printReport/printPdf/${printReportName}?${checked ? 'fileType=.xlsx&' : ''}sModelsId=${sModelsId}&printType=noquery&token=${encodeURIComponent(token)}`;
        const param = slaveOneData;
        this.handleOpenPost(url, param);
      }
    };
    /* 工单列表价格批量更新 */
    handleBatchWorkListsPriceUpdate = () => {
      const { slaveData, slaveSelectedRowKeys, app } = this.props;
      if (commonUtils.isEmptyStr(slaveSelectedRowKeys)) {
        return message.warning(commonFunc.showMessage(app.commonConst, 'selectedRowKeysNo'));/* 请选择一条数据进行操作 */
      } else {
        const batchPriceWorkListUpdateData = slaveData.filter(item => slaveSelectedRowKeys.includes(item.sId));
        this.props.onSaveState({ batchPriceWorkListUpdateData, visibleBatchWorkListPriceUpdate: true });
      }
    };

    handleOpenPost= (url, params) => {
      const newWin = window.open();
      let formStr = '';
      // 设置样式为隐藏，打开新标签再跳转页面前，如果有可现实的表单选项，用户会看到表单内容数据
      formStr = `<form style="visibility:hidden;" method="POST" action="${url}">` +
        `<input type="hidden" name="slaveOneData" value='${params}' />` +
        '</form>';
      newWin.document.body.innerHTML = formStr;
      newWin.document.forms[0].submit();
      return newWin;
    }

    // handleGetMemoCancel = () => {
    //   const sCurrMemoProps = { bVisibleMemo: false };
    //   this.props.onSaveState({ sCurrMemoProps });
    // };

    // handleToForceComplete = async (sValue) => {
    //   const {
    //     app, slaveSelectedRowKeys, slaveConfig, sModelsId, slaveInfoSelectedRowKeys, formRoute,
    //   } = this.props;
    //
    //   const { token } = app;
    //   const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnForceComplete' || item.sControlName === 'BtnNoPurchase');
    //   const btnConfig = slaveConfig.gdsconfigformslave[iIndex];
    //   const sRelation = btnConfig.sRelation;
    //
    //   let selectedRowKeys = '';
    //   if (formRoute === '/materialRequirementsPlanning') {
    //     selectedRowKeys = slaveInfoSelectedRowKeys.toString();
    //   } else {
    //     selectedRowKeys = slaveSelectedRowKeys.toString();
    //   }
    //
    //   const url = `${commonConfig.server_host}bill/billForceComplete?sModelsId=${sModelsId}&sName=${formRoute}`;
    //   const values = { sqlParam: sRelation, sId: selectedRowKeys, sReason: sValue };
    //
    //   const masterReturn = (await commonServices.postValueService(token, values, url)).data;
    //   if (masterReturn.code === 1) {
    //     message.success(masterReturn.msg);
    //     this.handleButtonClick('BtnRefresh');
    //   } else {
    //     this.props.getServiceError(masterReturn);
    //   }
    // }

    handleToSettlement = async (sType) => {
      const {
        app, sModelsId, slaveSelectedRowKeys, slaveData, formRoute,
      } = this.props;
      let continueFlag = true;
      let msg = '';

      const selectedData = slaveData.filter(item => slaveSelectedRowKeys.includes(item.sId));
      const point = commonUtils.convertStrToNumber(selectedData[0].sPeriodId);
      if (sType === 1) {
        for (const item of slaveData) {
          const curr = commonUtils.convertStrToNumber(item.sPeriodId);
          if (curr > point && item.bFrozen) {
            continueFlag = false;
            msg = `${item.sPeriodId}已结账`;
            break;
          } else if (curr < point && !item.bFrozen) {
            continueFlag = false;
            msg = `${item.sPeriodId}未结账`;
            break;
          }
        }
      } else if (sType === 2) {
        for (const item of slaveData) {
          const curr = commonUtils.convertStrToNumber(item.sPeriodId);
          if (curr < point && item.bFrozen) {
            continueFlag = false;
            msg = `${item.sPeriodId}已结账`;
            break;
          } else if (curr > point && !item.bFrozen) {
            continueFlag = false;
            msg = `${item.sPeriodId}未结账`;
            break;
          }
        }
      }
      // tStartDate: "2017-01-02 16:00:00"  tEndDate: "2017-02-01 16:00:00"  tStartDate, tEndDate,
      if (continueFlag) {
        const value = {
          sProName: 'Sp_System_AutoMaterialsPriceSingle',
          paramsMap: { tStartDate: selectedData[0].tStartDate, tEndDate: selectedData[0].tEndDate },
        };
        const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}&sName=${formRoute}`;
        const returnData = (await commonServices.postValueService(app.token, value, url)).data;
        if (returnData.code === 1) {
          const outData = returnData.dataset.rows[0].dataSet.outData[0];
          if (outData.sCode === -1) {
            message.error(outData.sReturn);
          }
        } else {
          this.props.getServiceError(returnData);
        }
      } else {
        message.warn(msg);
      }
    }
    handleTreeSelect = (name, selectedKeys, e) => {
      const { slaveFilterCondition, slaveConfig, slavePagination } = this.props;
      const slaveFilterConditionNew = {};
      let ids = '';
      const treeFilterCondition = [];
      this.props.onTreeSelect(name, selectedKeys, e);
      /* 加过滤条件 */
      for (const sId of selectedKeys) {
        const searchId = sId.split('_')[1];
        const searchName = sId.split('_')[0];
        ids = slaveFilterConditionNew[`${searchName}`];
        if (commonUtils.isNotEmptyObject(ids)) {
          ids += `,${searchId}`;
        } else {
          ids = searchId;
        }
        slaveFilterConditionNew[`${searchName}`] = ids;
      }
      if (commonUtils.isNotEmptyObject(slaveFilterConditionNew)) {
        Object.keys(slaveFilterConditionNew).forEach((item) => {
          if (commonUtils.isNotEmptyObject(slaveFilterConditionNew[item])) {
            treeFilterCondition.push({
              bFilterName: item,
              bFilterCondition: 'in',
              bFilterValue: slaveFilterConditionNew[item],
              bFilterType: 'tree',
            });
          }
        });
        if (commonUtils.isNotEmptyArr(treeFilterCondition)) {
          this.props.onSaveState({
            treeFilterCondition,
          });
        }
      }
      this.handleGetData(slaveConfig, slaveFilterCondition, 1, slavePagination.pageSize, '', false, '', '', treeFilterCondition);
      /* 如果有选中树节点，则展开选中节点的父节点，否则默认展开第一个父节点 */
      if (commonUtils.isNotEmptyArr(selectedKeys) && selectedKeys.length > 0) {
        const { treeData } = this.props;
        const expandedKeys = [];
        const len = selectedKeys.length;
        const iIndex = treeData.findIndex(item => item.key === selectedKeys[len - 1] || item.sName === selectedKeys[len - 1].split('_')[0]);
        if (iIndex > -1) { /* 选中的是父节点 */
          expandedKeys.push(treeData[iIndex].key);
        }
        this.props.onSaveState({
          expandedKeys,
        });
      }
    };
    handleTableSelectRowChange = async (name, selectedRowKeys, changeValue) => {
      if (name === 'slave' || name === 'master') {
        const {
          token, sModelsId, [`${name}Total`]: totalData, [`${name}AllTotal`]: totalAllData, [`${name}Config`]: tableConfig, [`${name}Data`]: tableData, formData,
        } = this.props;
        const selectedTotalData = [];
        let bMutiSelect = false; /* 默认单选或不选  true ：多选 */
        if (commonUtils.isNotEmptyArr(formData)) {
          bMutiSelect = formData[0].bMutiSelect;
        }
        if (commonUtils.isNotEmptyArr(tableData) && commonUtils.isNotEmptyArr(selectedRowKeys)) {
          let url = '';
          if (sModelsId === '19211681019715326709731800') {
            let sProcessId = '';
            if (name === 'master') {
              sProcessId = changeValue.sProcessClassifyId;
            } else if (name === 'slave') {
              const sProcessIdIndex = tableData.findIndex(item => item.sSlaveId === selectedRowKeys[0]);
              if (sProcessIdIndex > -1) {
                sProcessId = tableData[sProcessIdIndex].sProcessClassifyId;
              }
            }
            if (commonUtils.isNotEmptyObject(sProcessId)) {
              url = `${commonConfig.file_host_ebc}printReport/getReportByProcessId/${sProcessId}?sModelsId=${sModelsId}`;
              const values = {};
              const masterReturn = (await commonServices.postValueService(token, values, url)).data;
              if (masterReturn.code === 1) {
                const menuChildData = masterReturn.dataset.rows;
                this.props.onSaveState({ menuChildData });
              }
            }
          }
          /* 只有多选情况下 汇总勾选行字段 */
          if (commonUtils.isNotEmptyArr(totalData)) {
            if (commonUtils.isNotEmptyObject(tableConfig) && tableConfig.gdsconfigformslave && bMutiSelect) {
              const tableConfigSum = tableConfig.gdsconfigformslave.filter(item => commonUtils.isNotEmptyObject(item.sName) && item.bSum && item.bVisible);
              const tableFilterData = tableData.filter(item => selectedRowKeys.includes(item.sSlaveId));
              if (commonUtils.isNotEmptyArr(tableConfigSum) && commonUtils.isNotEmptyArr(tableFilterData)) {
                const selectedTotal = {};
                selectedTotal.bSum = true;
                selectedTotal.key = '0000';
                tableConfigSum.forEach((itemConfig) => {
                  const sName = itemConfig.sName;
                  if (commonUtils.isNotEmptyObject(sName)) {
                    tableFilterData.forEach((child) => {
                      if (commonUtils.isNotEmptyNumber(child[sName])) {
                        selectedTotal[sName] = commonUtils.isNull(child[sName], 0) + commonUtils.isNull(selectedTotal[sName], 0);
                      }
                    });
                  }
                });
                if (commonUtils.isNotEmptyObject(selectedTotal)) {
                  selectedTotalData.push(selectedTotal);
                }
              }
            }
          }
        } else if (commonUtils.isEmptyArr(selectedRowKeys)) {
          const menuChildData = [];
          this.props.onSaveState({ menuChildData });
        }
        this.props.onSaveState({ [`${name}Total`]: commonUtils.isNotEmptyArr(selectedRowKeys) && bMutiSelect ? selectedTotalData : totalAllData });
      }
      this.props.onTableSelectRowChange(name, selectedRowKeys);
    }


    // OEE自定义按钮调用存储过程
    handleOEEProcedureCall = async (btnConfig, proName, proInParam) => {
      const { app, sModelsId } = this.props;
      const value = {
        sProName: proName,
        paramsMap: {
          sMachineId: app.sMachineNameSId,
          sProInParam: proInParam,
        },
      };
      const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
      const returnData = (await commonServices.postValueService(app.token, value, url)).data;
      if (returnData.code === 1) {
        message.success(returnData.msg);
        this.handleButtonClick('BtnRefresh');
        this.props.onSaveState({ oeeBtnStatus: true }); /* oeeBtnStatus 按钮点击时置灰 执行数据完成后按钮回置 */
      } else {
        this.props.onSaveState({ loading: false, oeeBtnStatus: true });
        this.props.getServiceError(returnData);
      }
    }
    // 根据配置解析拼接具体参数
    handleProParams = (sKey, arr) => {
      const { [`${sKey}Data`]: tableData, [`${sKey}SelectedRowKeys`]: selectedRowKeys } = this.props;
      const keyData = commonUtils.isNotEmptyArr(tableData) ? tableData.filter(item => selectedRowKeys.includes(item.sId) || selectedRowKeys.includes(item.sSlaveId)) : [];
      if (commonUtils.isNotEmptyArr(keyData)) {
        const addState = {};
        addState.key = sKey;
        const val = [];
        keyData.forEach((currData) => {
          const currVal = {};
          arr.forEach((filed) => {
            currVal[`${filed}`] = currData[`${filed}`];
          });
          val.push(currVal);
        });
        addState.value = val;
        return addState;
      } else {
        return undefined;
      }
    };
    // 进行存储过程按钮存储过程参数解析拼接 根据存储过程按钮参数配置进行解析，配置是json格式 {"sproName":"cal_sss","inMap":"master.sSlaveId,slave.sId"}
    handleOeeBtnEent = (btnConfig) => {
      const { masterData } = this.props;
      const { sButtonParam } = btnConfig;
      const btn = JSON.parse(sButtonParam);
      const sProName = btn.sproName;
      const inParams = [];
      const { inMap } = btn;
      const inlist = inMap.split(',');
      const masterArr = [];
      const slaveArr = [];

      if (inlist.length > 0) {
        inlist.forEach((item) => {
          const itemArr = item.split('.');
          if (itemArr.length > 0) {
            const sname = itemArr[0];
            const stype = itemArr[1];
            if (commonUtils.isNotEmptyStr(sname) && sname === 'master') {
              masterArr.push(stype);
            }
            if (commonUtils.isNotEmptyStr(sname) && sname === 'slave') {
              slaveArr.push(stype);
            }
          }
        });

        if (commonUtils.isNotEmptyArr(masterArr) && commonUtils.isNotEmptyObject(masterData)) {
          const addState = {};
          addState.key = 'master';
          const val = [];
          const currVal = {};
          masterArr.forEach((filed) => {
            currVal[`${filed}`] = masterData[`${filed}`];
          });
          val.push(currVal);
          addState.value = val;
          inParams.push({ ...addState });
        }
        if (commonUtils.isNotEmptyArr(slaveArr)) {
          const addState = this.handleProParams('slave', slaveArr);
          if (commonUtils.isNotEmptyObject(addState)) {
            inParams.push({ ...addState });
          }
        }
      }
      /* OEE模块调用OEE自定义按钮存储过程 */
      if (location.pathname.toLowerCase().indexOf('oee') > -1) {
        this.handleOEEProcedureCall(btnConfig, sProName, JSON.stringify({ params: inParams }));
      }
    };


    // 进行存储过程按钮存储过程参数解析拼接 根据存储过程按钮参数配置进行解析，配置是json格式 {"sproName":"cal_sss","inMap":"master.sSlaveId,slave.sId"}
    // handleBtnEent = (btnConfig, name, sValue) => {
    //   const { masterData, sCurrMemoProps } = this.props;
    //   if (commonUtils.isNotEmptyObject(sCurrMemoProps) && name.indexOf('BtnRepair') > -1) {
    //     sCurrMemoProps.bVisibleMemo = false;
    //     this.props.onSaveState({ sCurrMemoProps });
    //   }
    //   const sButtonParam = btnConfig.sButtonParam;
    //   const btn = JSON.parse(sButtonParam);
    //   const sProName = btn.sproName;
    //   const inParams = [];
    //   const inMap = btn.inMap;
    //   const inlist = inMap.split(',');
    //
    //   const masterArr = [];
    //   const slaveArr = [];
    //   const slaveInfoArr = [];
    //   const controlArr = [];
    //   const materialsArr = [];
    //   const processArr = [];
    //
    //   if (inlist.length > 0) {
    //     inlist.forEach((item) => {
    //       const itemArr = item.split('.');
    //       if (itemArr.length > 0) {
    //         const sname = itemArr[0];
    //         const stype = itemArr[1];
    //         if (commonUtils.isNotEmptyStr(sname) && sname === 'master') {
    //           masterArr.push(stype);
    //         }
    //         if (commonUtils.isNotEmptyStr(sname) && sname === 'slave') {
    //           slaveArr.push(stype);
    //         }
    //         if (commonUtils.isNotEmptyStr(sname) && sname === 'slaveInfo') {
    //           slaveInfoArr.push(stype);
    //         }
    //         if (commonUtils.isNotEmptyStr(sname) && sname === 'control') {
    //           controlArr.push(stype);
    //         }
    //         if (commonUtils.isNotEmptyStr(sname) && sname === 'materials') {
    //           materialsArr.push(stype);
    //         }
    //         if (commonUtils.isNotEmptyStr(sname) && sname === 'process') {
    //           processArr.push(stype);
    //         }
    //       }
    //     });
    //
    //     if (commonUtils.isNotEmptyArr(masterArr) && commonUtils.isNotEmptyObject(masterData)) {
    //       const addState = {};
    //       addState.key = 'master';
    //       const val = [];
    //       const currVal = {};
    //       masterArr.forEach((filed) => {
    //         currVal[`${filed}`] = masterData[`${filed}`];
    //       });
    //       val.push(currVal);
    //       addState.value = val;
    //       inParams.push({ ...addState });
    //     }
    //     if (commonUtils.isNotEmptyArr(slaveArr)) {
    //       const addState = this.handleProParams('slave', slaveArr);
    //       if (commonUtils.isNotEmptyObject(addState)) {
    //         inParams.push({ ...addState });
    //       }
    //     }
    //     if (commonUtils.isNotEmptyArr(slaveInfoArr)) {
    //       const addState = this.handleProParams('slaveInfo', slaveInfoArr);
    //       if (commonUtils.isNotEmptyObject(addState)) {
    //         inParams.push({ ...addState });
    //       }
    //     }
    //     if (commonUtils.isNotEmptyArr(controlArr)) {
    //       const addState = this.handleProParams('control', controlArr);
    //       if (commonUtils.isNotEmptyObject(addState)) {
    //         inParams.push({ ...addState });
    //       }
    //     }
    //     if (commonUtils.isNotEmptyArr(materialsArr)) {
    //       const addState = this.handleProParams('materials', materialsArr);
    //       if (commonUtils.isNotEmptyObject(addState)) {
    //         inParams.push({ ...addState });
    //       }
    //     }
    //     if (commonUtils.isNotEmptyArr(processArr)) {
    //       const addState = this.handleProParams('process', processArr);
    //       if (commonUtils.isNotEmptyObject(addState)) {
    //         inParams.push({ ...addState });
    //       }
    //     }
    //   }
    //
    //   this.handleProcedureCall(btnConfig, sProName, JSON.stringify({ params: inParams, changeValue: sValue }));
    // };
    // 根据配置解析拼接具体参数
    // handleProParams = (sKey, arr) => {
    //   const { [`${sKey}Data`]: tableData, [`${sKey}SelectedRowKeys`]: selectedRowKeys } = this.props;
    //   const keyData = tableData.filter(item => selectedRowKeys.includes(item.sId) || selectedRowKeys.includes(item.sSlaveId));
    //   if (commonUtils.isNotEmptyArr(keyData)) {
    //     const addState = {};
    //     addState.key = sKey;
    //     const val = [];
    //     keyData.forEach((currData) => {
    //       const currVal = {};
    //       arr.forEach((filed) => {
    //         currVal[`${filed}`] = currData[`${filed}`];
    //       });
    //       val.push(currVal);
    //     });
    //     addState.value = val;
    //     return addState;
    //   } else {
    //     return undefined;
    //   }
    // };
    // 存储过程按钮调用存储过程
    // handleProcedureCall = async (btnConfig, proName, proInParam) => {
    //   const { app, sModelsId } = this.props;
    //   const value = { sProName: proName, sProInParam: proInParam };
    //   const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`;
    //   const returnData = (await commonServices.postValueService(app.token, value, url)).data;
    //   if (returnData.code === 1) {
    //     message.success(returnData.msg);
    //     this.handleButtonClick('BtnRefresh');
    //   } else {
    //     this.props.onSaveState({ loading: false });
    //     this.props.getServiceError(returnData);
    //   }
    // }
    /* 点击展开图标时，调用接口获取嵌套字表数据 */
    handleOnExpandTest = async (expanded, record) => {
      const { expKeys } = this.props;
      /* 添加移除展开的sId */
      const { formRoute } = this.props;
      let newExp = commonUtils.isNotEmptyArr(expKeys) ? expKeys : [];
      let rowKeyId = '';
      if (formRoute === '/indexPage/materialRequirementsPlanning') {
        rowKeyId = record.sMaterialsGS;
      }
      if (expanded) {
        if (commonUtils.isNotEmptyObject(rowKeyId)) {
          newExp.push(rowKeyId);
        }
      } else {
        newExp = newExp.filter(item => item !== rowKeyId);
      }
      this.props.onSaveState({ expKeys: newExp });
    }
    handleTableAdd = (name, isWait) => {
      const { formRoute } = this.props;
      if (commonUtils.isNotEmptyObject(formRoute) && formRoute.indexOf('/indexOee') > -1 && name === 'employee') { // oee开工页面人员表点击增加弹窗人员选择框
        this.props.onSaveState({ employeeVisble: true });
      } else if (isWait) { /*  报表设计新增 */
        const tableDataRow = this.props.onDataRowAdd(name, isWait);
        return tableDataRow;
      }
    }

    /* 操作日志点击链接弹出Modal呈现日志明细 */
    handleGetLogDetail=(record) => {
      const { sModelsType } = this.props;
      let { logColumn } = this.props;
      /* 操作日志明细弹窗功能 */
      if (sModelsType === 'commonList/logdetail') {
        const { sDetailMemo } = record;
        let JsonData = [];
        const logData = [];
        const logConfig = {};
        if (commonUtils.isNotEmptyObject(sDetailMemo)) {
          const addState = {};
          addState.logVisible = true;
          if (commonUtils.isEmptyArr(logColumn)) {
            logConfig.sId = commonUtils.createSid();
            logConfig.gdsconfigformslave = [{
              bVisible: false,
              sName: 'sId',
              bNotEmpty: true,
              showName: '表sId',
              bFind: false,
            }, {
              bVisible: false,
              sName: 'sSlaveId',
              bNotEmpty: true,
              showName: '表主键',
              bFind: false,
            }, {
              bVisible: true,
              sName: 'sTableName',
              bNotEmpty: true,
              showName: '表名称',
              bFind: false,
            }, {
              bVisible: true,
              sName: 'sTableType',
              bReadOnly: true,
              showName: '表类型',
              iTag: 1,
              bFind: false,
            }, {
              bVisible: true,
              sName: 'handleType',
              bReadOnly: true,
              showName: '状态',
              iTag: 1,
              bFind: false,
            }, {
              bVisible: true,
              sName: 'sFieldName',
              bReadOnly: true,
              showName: '字段名',
              iTag: 1,
              bFind: false,
            }, {
              bVisible: true,
              sName: 'sFieldValue',
              bReadOnly: true,
              showName: '字段值',
              iTag: 1,
              bFind: false,
            }];
            logColumn = [{
              title: '表名称',
              dataIndex: 'sTableName',
              width: 200,
              bFind: true,
            }, {
              title: '表类型',
              dataIndex: 'sTableType',
              width: 100,
              bFind: true,
            }, {
              title: '状态',
              dataIndex: 'handleType',
              width: 100,
              bFind: true,
            }, {
              title: '字段名',
              dataIndex: 'sFieldName',
              width: 200,
              bFind: true,
            }, {
              title: '字段值',
              dataIndex: 'sFieldValue',
              width: 200,
              bFind: true,
            }];
            addState.logColumn = logColumn;
            addState.logConfig = logConfig;
          }
          try {
            JsonData = JSON.parse(sDetailMemo);
            /* 弹窗字段取值 */
            JsonData.forEach((item) => {
              const columnArr = item.column;
              if (commonUtils.isNotEmptyArr(columnArr)) {
                columnArr.forEach((column) => {
                  // eslint-disable-next-line guard-for-in
                  for (const property in column) {
                    const logObj = {};
                    logObj.sTableName = item.sTable;
                    logObj.sTableType = item.name;
                    logObj.sFieldName = property;
                    logObj.sFieldValue = column[property];
                    const newId = commonUtils.createSid();
                    logObj.sId = newId;
                    logObj.sSlaveId = newId;
                    const handleType = column.handleType;
                    switch (handleType) {
                      case 'add':
                        logObj.handleType = '新增';
                        break;
                      case 'update':
                        logObj.handleType = '修改';
                        break;
                      case 'del':
                        logObj.handleType = '删除';
                        break;
                      default:
                        break;
                    }
                    logData.push(logObj);
                  }
                });
              }
            });
            addState.logData = logData;
          } catch (e) {
            JsonData = [];
          }
          this.props.onSaveState({
            ...addState,
          });
        }
      }
    }

    handleViewClick = (name, sName, record, index, myConfig) => {
      /* 操作日志明细链接弹出Modal */
      if (sName === 'sDetailMemoview') {
        this.handleGetLogDetail(record);
      } else if (sName === 'myTableConfig') {
        this.handleQuickViewClick(name, sName, record, index, myConfig);
      } else {
        this.props.onViewClick(name, sName, record, index);
      }
    }
    /* 获取表格数据 */
    handleGetTableConfig = async (name, sModelsId) => {
      if(commonUtils.isNotEmptyObject(sModelsId)) {
        const newConfig = await this.props.onGetTableConfig(name, sModelsId);
        if(commonUtils.isNotEmptyObject(newConfig)) {
          const newColumn = commonFunc.getHeaderConfig(newConfig);
          this.props.onSaveState({[`${[name]}Config`]: newConfig, [`${[name]}Column`]: newColumn })
        }
      }
    }
    /* 快捷键跳转 */
    handleQuickViewClick = async (name, sName, record, index , myConfigArr) => {
      const {
        slaveConfig,
        slaveData,
        dispatch,
        slaveFilterCondition,
        slavePagination,
        slaveOrderBy,
        sModelsType,
        formRoute,
        treeFilterCondition,
        app,
        iPageSize,
        sModelsId,
        // slaveSelectedData,
        // masterData,
        // employeeConfig,
      } = this.props;
      console.log('myConfigArr',myConfigArr)
      let picArr = [];
      if(commonUtils.isNotEmptyArr(myConfigArr)) {
        picArr = myConfigArr;
      }

      if (picArr.length > 0) {
        const getConfig = this.handleGetTableConfig;
        const tableDataRow = record;
        const iIndex = index;
        const [{ sActiveId }] = picArr;
        let [{ sActiveKey }] = picArr;
        const sFormId = sActiveId === '1' ? commonUtils.isEmpty(tableDataRow.sFormId) ? tableDataRow.sSrcFormId : tableDataRow.sFormId : sActiveId;
        if (commonUtils.isNotEmptyObject(sActiveKey) && sActiveKey.includes('.')) { /* 接口按钮跳转 如果有slave.对应字段 则需要取出对应字段 */
          const index = sActiveKey.lastIndexOf('.');
          sActiveKey = sActiveKey.substring(index + 1, sActiveKey.length);
        }
        const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sFormId}?sModelsId=${sFormId}&sName=${formRoute}`;
        const filterCondition = [];
        const conditionValues = this.props.getSqlCondition(picArr[0], name, tableDataRow);
        if (!commonUtils.isEmpty(conditionValues)) {
          Object.keys(conditionValues).forEach((item) => {
            if ((item === 'tStartDate_pro' || item.substring(0, 1) === 'p')) {
              if (!commonUtils.isEmpty(conditionValues[item]) && conditionValues[item].length >= 2) {
                const tStartDate = moment(conditionValues[item][0]).format(this.sDateFormat);
                const tEndDate = moment(conditionValues[item][1]).add(1, 'days').format(this.sDateFormat);
                filterCondition.push({
                  bFilterName: item,
                  bFilterCondition: '=',
                  bFilterValue: `${tStartDate},${tEndDate}`,
                });
              }
            } else if ((item === 'mStartDate_pro' || item.substring(0, 1) === 'm')) {
              if (!commonUtils.isEmpty(conditionValues[item])) {
                const tStartDate = moment(conditionValues[item]).startOf('month').format(this.sDateFormat);
                const tEndDate = moment(conditionValues[item]).endOf('month').add(1, 'days').format(this.sDateFormat);
                filterCondition.push({
                  bFilterName: `t${item.substring(1, item.length)}`,
                  bFilterCondition: '=',
                  bFilterValue: `${tStartDate},${tEndDate}`,
                });
              }
            } else if (item.substring(0, 1) === 't') {
              filterCondition.push({
                bFilterName: item,
                bFilterCondition: '=',
                bFilterValue: moment(conditionValues[item]).format(this.sDateFormat),
              });
            } else {
              filterCondition.push({
                bFilterName: item,
                bFilterCondition: '=',
                bFilterValue: conditionValues[item],
              });
            }
          });
        }
        this.props.dispatch({
          type: 'content/onRouter',
          payload: {
            url: sNameUrl,
            refresh: getConfig.bind(this, name, sModelsId), /*   刷新方法   */
            sTabId: commonUtils.createSid(),
            // sParentId: this.state.sTabId,
            urlDataType: 'newPane',
            checkedId: myConfigArr[0].sId,
            sName: myConfigArr[0].sName,
            bFilter: slaveFilterCondition,
            pageSize: commonConfig.pageSize,
            pages: slavePagination,
            currentData: [record],
            conditonValues: conditionValues,
            newKey: tableDataRow[sActiveKey],
            currentIndex: iIndex,
            filterCondition,
            sSrcModelsId: this.props.sModelsId,
          },
        });
      }
    };
    handlePartNameClick =(sName, showConfig, record) => {
      if (commonUtils.isNotEmptyObject(sName) && commonUtils.isNotEmptyObject(showConfig) && commonUtils.isNotEmptyObject(record)) {
        this.props.onSaveState({ workScheduleConfig: showConfig, workScheduleRecord: record, workScheduleVisible: true });
      }
    }
    handleCloseModel = (modelVisible) => {
      this.props.onSaveState({ [modelVisible]: false });
    };

    /* 获取树形slaveTreeData数据 */
    handleGetSlaveTreeData = (slaveData) => {
      const slaveTreeData = []; /* 用于界面树形展示的slaveData */
      const expKeys = [];
      const addState = {};
      if (commonUtils.isNotEmptyArr(slaveData)) {
        slaveData.forEach((tableDataRow) => {
          const tableDataRowNew = JSON.parse(JSON.stringify(tableDataRow));
          if (commonUtils.isEmpty(tableDataRow.sParentId)) { /* 一级分类 */
            const childrenData = this.handleGetChildData(slaveData, tableDataRowNew.sId); /* 获取子数据 */
            if (commonUtils.isNotEmptyArr(childrenData)) {
              expKeys.push(tableDataRow.sSlaveId);
              tableDataRowNew.children = childrenData;
            }
            slaveTreeData.push(tableDataRowNew);
          }
        });
      }
      addState.slaveTreeData = slaveTreeData;
      addState.expKeys = expKeys;
      return addState;
    }
    /* 获取子节点数据 */
    handleGetChildData = (data, sId) => {
      if (commonUtils.isNotEmptyArr(data)) {
        const filterData = data.filter(item => item.sParentId === sId);
        if (commonUtils.isNotEmptyArr(filterData)) {
          filterData.forEach((child, index) => {
            const filterChildData = this.handleGetChildData(data, child.sId);
            if (commonUtils.isNotEmptyArr(filterChildData)) {
              filterData[index].children = filterChildData;
            }
          });
        }
        return filterData;
      }
    }

    handleGetAllExpandData = async (slaveData, props) => {
      const { slaveFilterCondition } = props;
      let { slaveInfoConfig } = props;
      if (commonUtils.isEmptyObject(slaveInfoConfig)) {
        slaveInfoConfig = this.nextProps.formData[1];
      }
      const slaveInfoData = [];

      const addStateSlaveInfo = await this.handleGetDataInfo(slaveInfoConfig, slaveFilterCondition, 1, undefined, slaveData[0], true);
      if (commonUtils.isNotEmptyObject(addStateSlaveInfo)) {
        const childrenData = addStateSlaveInfo.slaveInfoData;
        if (commonUtils.isNotEmptyArr(childrenData)) {
          // 过滤掉sSlaveId相同的数据
          childrenData.forEach((child) => {
            const iIndex = slaveInfoData.findIndex(item => item.sSlaveId && item.sSlaveId === child.sSlaveId);
            if (iIndex === -1) {
              slaveInfoData.push(child);
            }
          });

          slaveData.forEach(record => {
            const { sSqlConditionId } = record;
            const childrendFilterData = childrenData.filter(item => item.sSqlConditionId === sSqlConditionId);
            if(commonUtils.isNotEmptyArr(childrendFilterData)) {
              childrendFilterData.forEach((child) => {
                child.sFatherSlaveId = record.sSlaveId;
              });
            }
          })
        }
      }
      return slaveInfoData;
    }

    /* 点击展开图标时，调用接口获取嵌套字表数据 */
    handleOnExpand = async (expanded, record) => {
      const {
        expKeys, slaveInfoConfig, slaveFilterCondition,
      } = this.props;
      let { slaveInfoData } = this.props;
      const { sSlaveId, sSqlConditionId } = record;
      const sProductionPlanId = sSlaveId;
      /* 添加移除展开的sId */
      let newExp = commonUtils.isNotEmptyArr(expKeys) ? expKeys : [];
      if (expanded) {
        newExp.push(record.sSlaveId);
      } else {
        newExp = newExp.filter(item => item !== record.sSlaveId);
      }
      let childrenData = [];
      /* 查看是否已经获取到明细表数据 */
      if (commonUtils.isNotEmptyArr(slaveInfoData)) {
        childrenData = slaveInfoData.filter(item => item.sSqlConditionId === sSqlConditionId);
      }
      if (expanded && commonUtils.isEmptyArr(childrenData)) {
        if (commonUtils.isNotEmptyObject(sProductionPlanId)) {
          const planLoadingSate = {};
          planLoadingSate.sId = sProductionPlanId;
          planLoadingSate.planLoading = true;
          const addStateSlaveInfo = await this.handleGetDataInfo(slaveInfoConfig, slaveFilterCondition, 1, undefined, record, true);
          if (commonUtils.isNotEmptyObject(addStateSlaveInfo)) {
            const returnData = addStateSlaveInfo.slaveInfoData;
            if (commonUtils.isNotEmptyArr(returnData)) {
              childrenData = returnData;
              if (commonUtils.isEmptyArr(slaveInfoData)) {
                slaveInfoData = [];
              }
              childrenData.forEach((child) => {
                const iIndex = slaveInfoData.findIndex(item => item.sSlaveId === child.sSlaveId);
                if (iIndex === -1) {
                  slaveInfoData.push(child);
                }
              });
              const childrendFilterData = childrenData.filter(item => item.sSqlConditionId === record.sSqlConditionId);
              if(commonUtils.isNotEmptyArr(childrendFilterData)){
                childrendFilterData.forEach((child) => {
                  const iIndex = slaveInfoData.findIndex(item => item.sSlaveId === child.sSlaveId);
                  if (iIndex > -1) {
                    slaveInfoData[iIndex].sFatherSlaveId = record.sSlaveId;
                  }
                });
              }
            }
            planLoadingSate.planLoading = false;
            planLoadingSate.expKeys = newExp;
            this.props.onSaveState({
              planLoadingSate, slaveInfoData,
            });
          } else {
            planLoadingSate.planLoading = false;
            this.props.onSaveState({ planLoadingSate });
          }
        }
      } else if (expanded && commonUtils.isNotEmptyArr(slaveInfoData)) {  /* 已获得明细表数据时 */
        childrenData.forEach((child) => {
          const iIndex = slaveInfoData.findIndex(item => item.sSlaveId === child.sSlaveId);
          if (iIndex > -1) {
            slaveInfoData[iIndex].sFatherSlaveId = record.sSlaveId;
          }
        });
      }
    }

    /** 保存校验 */
    handleValidateSave = () => {
      this.form.validateFields((err) => {
        /*   验证通过与不通过走不同的流程   */
        if (err) { /*   验证失败   */
          /*   直接渲染显示错误提示   */
          for (const key of Object.keys(err)) {
            message.error(err[key].errors[0].message);
          }
        } else { /*   验证成功   */
          const {
            slaveConfig, slaveData, slaveDelData, slaveInfoConfig, slaveInfoData, slaveInfoDelData, app, slaveInfoForSaveConfig,
          } = this.props;
          if (commonUtils.isEmptyArr(slaveData)) {
            message.error(commonFunc.showMessage(app.commonConst, 'slaveNotNull')); // 从表不能为空！
            this.props.onSaveState({
              loading: false,
            });
            return;
          }
          if (!commonBusiness.validateTable(slaveConfig, slaveData)) {
            this.props.onSaveState({
              loading: false,
            });
            return;
          }
          // if (commonUtils.isEmptyArr(slaveInfoData)) {
          //   message.error(commonFunc.showMessage(app.commonConst, 'slaveNotNull')); // 从表不能为空！
          //   this.props.onSaveState({
          //     loading: false,
          //   });
          //   return;
          // }
          // if (!commonBusiness.validateTable(slaveInfoConfig, slaveInfoData)) {
          //   this.props.onSaveState({
          //     loading: false,
          //   });
          //   return;
          // }
          const data = [];
          data.push(commonBusiness.mergeData('slave', slaveConfig.sTbName, slaveData, slaveDelData));
          if(commonUtils.isNotEmptyObject(slaveInfoConfig)) {
            data.push(commonBusiness.mergeData('slaveInfo', slaveInfoConfig.sTbName, slaveInfoData, slaveInfoDelData));
          }
          this.handleSaveData({ data, sClientType: '1' });
        }
      });
    };

    /**   toolbar保存   */
    handleSaveData = async (params) => {
      const {
        token, sModelsId,
      } = this.props;
      const returnData = await commonBusiness.saveData({ token, value: params, sModelsId });
      if (commonUtils.isNotEmptyObject(returnData)) {
        this.handleRefresh(1);
        if (this.props.app.currentPane.refresh !== undefined) {
          this.props.app.currentPane.refresh();
        }
        return true;
      } else {
        return false;
      }
    };

    handleRefresh = () => {
      const {
        slaveConfig, slaveInfoConfig, slaveFilterCondition, slaveInfoFilterCondition,
      } = this.props;
      const { expKeys } = this.props;
      this.props.onSaveState({
        sortedInfo: {}, clearArray: [], searchText: '', slaveSelectedRowKeys: [], slaveSelectedData: [], slaveInfoSelectedRowKeys: [], slaveInfoSelectedData: [], tableBtnEnabled: true,
      });
      this.handleGetData('slave', slaveConfig, slaveFilterCondition, undefined, undefined, true, undefined, this.props);
      // this.handleGetData('slaveInfo', slaveInfoConfig, slaveInfoFilterCondition, undefined, undefined, true, undefined, this.props);
      const { clearArray } = this.props;
      if (!commonUtils.isEmpty(clearArray)) {
        for (const item of clearArray) {
          const { confirm, clearFilters } = item;
          confirm();
          clearFilters();
        }
      }
      /* 刷新后关闭所有expKeys */
      // expKeys = [];
      this.props.onSaveState({
        loading: false, expKeys,
      });
    }

    render() {
      return (
        <ChildComponent
          {...this.props}
          {...this.state}
          onReturnForm={this.handleForm}
          onGetData={this.handleGetData}
          onGetDataInfo={this.handleGetDataInfo}
          onTableSelectRowChange={this.handleTableSelectRowChange}
          onGetFilterTreeData={this.handleGetFilterTreeData}
          onTitleChange={this.handleTitleChange}
          onDoubleClick={this.handleDoubleClick}
          onAdd={this.handleAdd}
          onDel={this.handleDel}
          onButtonClick={this.handleButtonClick}
          onCopyTo={this.handleCopyTo}
          // onGetMemo={this.handleGetMemo}
          // onGetMemoCancel={this.handleGetMemoCancel}
          onGetGoods={this.handleGetGoods}
          onGetGoodsValue={this.handleGetGoodsValue}
          onGetGoodsCancle={this.handleGetGoodsCancle}
          onBtnPrint={this.handleBtnPrint}
          onCheck={this.handleTreeCheck}
          onSelect={this.handleTreeSelect}
          onExpand={this.handleOnExpand}
          onOeeCopyTo={this.handleOeeCopyTo}
          onOeeLabelCopyTo={this.handleOeeLabelCopyTo}
          onDataRowAdd={this.handleTableAdd}
          onViewClick={this.handleViewClick}
          onDataChange={this.props.onDataChange}
          onPartNameClick={this.handlePartNameClick}
          onCloseModel={this.handleCloseModel}
          // onBtnEent={this.handleBtnEent}
          onOeeBtnEent={this.handleOeeBtnEent} // onBtnEent={this.handleBtnEent}
          onGetSlaveTreeData={this.handleGetSlaveTreeData}
          onSubmit={this.handleValidateSave}
        />
      );
    }
  };
};
