/* eslint-disable */
/* eslint-disable no-const-assign,prefer-destructuring */
/**
 * Created by mar105 on 2019-01-04.
 */

import React, { Component } from 'react';
import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import {
  Layout,
  Spin,
  Tabs,
  Avatar,
  message,
  Modal,
  Button,
  Table,
  Checkbox,
  Row,
  Col,
} from 'antd-v4';
import CommonSales from './../Common/CommonBillEvent';/* 继承销售模块业务功能 */
import * as commonFunc from './../Common/commonFunc';/* 通用单据方法 */ /* 通用单据方法 */
import Toolbar from './../Common/ToolBar/ToolBarNew';
import StaticEditTable from '../Common/CommonTable';/* 可编辑表格 */
import styles from './../../index.less';
import CommonView from './../Common/CommonView';
import CommonBase from './../Common/CommonBase';/* 获取配置及数据 */
import * as commonUtils from './../../utils/utils';/* 通用方法 */
import * as commonBusiness from './../Common/commonBusiness';/* 单据业务功能 */
import commonConfig from './../../utils/config';
import * as commonServices from './../../services/services';
import AntdDraggableModal from '../Common/AntdDraggableModal';/*   服务类   */


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

class ProductionReport extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentWillReceiveProps(nextProps) {
    let {
      employeeColumn,
    } = nextProps;
    const { formData, currentId } = nextProps;
    if (commonUtils.isEmptyArr(employeeColumn) && formData.length > 0) {
      const sId = currentId || nextProps.masterData?.sId || '';
      /* 数据Id */
      const masterConfig = formData.filter(item => !item.bGrd)[0];
      /* bGrd代表是否是表格 */
      const slaveConfig = formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult')[0];
      const slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
      let checkConfig ={};
      let checkColumn ={};
      if(commonUtils.isNotEmptyArr( formData.filter(item => item.bGrd && item.sTbName === 'sysbillcheckresult'))) {
        checkConfig = formData.filter(item => item.bGrd && item.sTbName === 'sysbillcheckresult')[0];
        checkColumn = commonFunc.getHeaderConfig(checkConfig);
      }

      const employeeConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductionreportemployee'.toUpperCase())[0];
      employeeColumn = commonFunc.getHeaderConfig(employeeConfig, employeeColumn);

      let addState = {};
      if (sId === '') {
        const config = {};
        config.masterConfig = masterConfig;
        config.slaveConfig = slaveConfig;
        addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
      } else {
        this.props.onGetData(masterConfig, slaveConfig, checkConfig);
        this.handleGetData(employeeConfig);
      }
      this.props.onSaveState({
        masterConfig,
        slaveConfig,
        slaveColumn,
        checkConfig,
        checkColumn,
        sId,
        pageLoading: false,
        employeeConfig,
        employeeColumn,
        ...addState,
      });
    }
  }

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

  onTabChange = async (key) => {
    if (key == 99) {
      return;
    }
    let addState = {};
    let tag = `slave${key}`;

    const { [`${tag}Config`] : tableConfig, [`${tag}Data`] : tableData, [`${tag}FilterCondition`]: tableFilterCondition, slaveOrderBy, [`${tag}Pagination`] : tablePagination, slaveSelectedRowKeys } = this.props;
    if(commonUtils.isEmptyArr(tableData)) {
      const iPageSize =  tableConfig.bPagination ? tableConfig.iPageSize : 10000 ; /* 根据后台主表配置bPagination判断 是否分页, 不分页默认10000，分页根据分页来  */
      this.props.onSaveState({ pageLoading: true });
      addState = await this.props.onGetDataOne(tag, tableConfig, tableFilterCondition, commonUtils.isEmpty(tablePagination) ? 1 : tablePagination.current, commonUtils.isEmpty(tablePagination) ? iPageSize : tablePagination.pageSize, slaveOrderBy, undefined, true);
    }
    this.props.onSaveState({ activeKey: key ,...addState,  pageLoading: false});
  };

  /* 获取表数据 */
  handleGetData = (employeeConfig, extraState = {}) => {
    const { currentId } = this.props; /* 当前页签数据 */
    const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */
    this.props.handleGetDataSet({
      name: 'employee', configData: employeeConfig, condition: { sSqlCondition: { sParentId: sId } },
    });
    this.props.onSaveState({ pageLoading: false, loading: false, ...extraState });
  };

  handleForm = (form) => {
    this.form = form;
  };

  handleSave = async () => {
    await this.form.validateFields(async (err) => {
      /*   验证通过与不通过走不同的流程   */
      if (err) { /*   验证失败   */
        /*   直接渲染显示错误提示   */
        for (const key of Object.keys(err)) {
          message.warning(err[key].errors[0].message);
        }
      } else { /*   验证成功   */
        const {
          masterConfig, masterData, slaveConfig, slaveData, slaveDelData, employeeConfig, employeeData, employeeDelData, token, sModelsId,
        } = this.props;
        if (!commonBusiness.validateTable(slaveConfig, slaveData, this.props, '2') || !commonBusiness.validateTable(employeeConfig, employeeData, this.props, '3')) {
          return;
        }

        for (const tableDataRow of slaveData) {
          const sWageId = tableDataRow.sWageId;
          if (commonUtils.isNotEmptyObject(sWageId)) {
            tableDataRow.dWageMoney = await commonBusiness.getFormulaValue({
              token, sModelsId, masterData, tableDataRow, sComputeId: sWageId,
            });
          }
          const sFactCapacityId = tableDataRow.sFactCapacityId;
          if (commonUtils.isNotEmptyObject(sFactCapacityId)) { /* 调用工时公式,计算工时 */
            tableDataRow.dHour = await commonBusiness.getFormulaValue({
              token, sModelsId, masterData, tableDataRow, sComputeId: sFactCapacityId,
            });
          }
          const dWageMoneyTotal = tableDataRow.dWageMoney;
          let dProportionTotal = 0;
          const employeeSlaveData = employeeData.filter(item => item.sSlaveId === tableDataRow.sId);
          employeeSlaveData.forEach((item) => {
            if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
              dProportionTotal += item.dProportion;
            }
          });
          employeeSlaveData.forEach((item) => {
            if (commonUtils.isNotEmptyNumber(item.dProportion)) {
              const index1 = employeeData.findIndex(item1 => item1.sId === item.sId);
              employeeData[index1] = {
                ...item,
                dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dWageMoney, 0), 6),
                dTimeMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dTimeMoney, 0), 6),
                dLossMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dLossMoney, 0), 6),
                dOtherMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dOtherMoney, 0), 6),
                dJobMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dJobMoney, 0), 6),
                handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
              };
            }
          });
          /* 选择计件方案后 算总金额 */
          const dWageMoney = commonUtils.isNotEmptyNumber(dWageMoneyTotal) ? commonUtils.convertFixNum(dWageMoneyTotal, 6) : 0;
          const dTimeMoney = commonUtils.isNotEmptyNumber(tableDataRow.dTimeMoney) ? commonUtils.convertFixNum(tableDataRow.dTimeMoney, 6) : 0;
          const dLossMoney = commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney) ? commonUtils.convertFixNum(tableDataRow.dLossMoney, 6) : 0;
          tableDataRow.dAllMoney = commonUtils.convertFixNum((dWageMoney + dTimeMoney) - dLossMoney, 6);
          tableDataRow.handleType = commonUtils.isEmpty(tableDataRow.handleType) ? 'update' : tableDataRow.handleType;
        }

        const data = [];
        data.push(commonBusiness.mergeData('master', masterConfig.sTbName, [masterData]));
        data.push(commonBusiness.mergeData('slave', slaveConfig.sTbName, slaveData, slaveDelData));
        data.push(commonBusiness.mergeData('employee', employeeConfig.sTbName, employeeData, employeeDelData));
        await this.props.onSaveData({ data, sClientType: '1' });
        this.handleGetData(employeeConfig);
      }
    });
  };

  /** 控制选择控制表时，显示部件工序与成品工序 */
  handleFilterData = (name, dataIndex, value, record) => {
    return (commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(value.toLowerCase()));
  };

  /**   添加表格空行   */
  handleTableAdd = async (name, isWait) => {
    /*   外置处理业务   */
    const {
      slaveData, slaveSelectedRowKeys, sModelsId, token,
    } = this.props;
    let {
      employeeData,
    } = this.props;
    if (name === 'employee') {
      if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
        message.warn('请选择班组');
        return;
      }
      if (slaveSelectedRowKeys.length !== 1) {
        message.warn('请选择一条数据');
        return;
      }
      const iIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
      if (iIndex > -1) {
        if (commonUtils.isEmpty(slaveData[iIndex].sTeamName)) {
          message.warn('班组名称不能为空');
          return;
        }
      }
      const employeeSlaveData = employeeData.filter(item => item.sSlaveId === slaveSelectedRowKeys[0]);
      if (commonUtils.isEmptyObject(employeeSlaveData)) {
        const sTeamId = slaveData[iIndex].sTeamId;
        const sSlaveId = slaveData[iIndex].sId;
        const sParentId = slaveData[iIndex].sParentId;
        const url = `${commonConfig.server_host}eleteamemployee/getEleteamemployee?sModelsId=${sModelsId}&sTeamId=${sTeamId}&sSlaveId=${sSlaveId}&sParentId=${sParentId}`;
        const dataReturn = (await commonServices.getService(token, url)).data;
        if (dataReturn.code === 1) {
          const returnData = dataReturn.dataset.rows;
          if (commonUtils.isNotEmptyObject(returnData)) {
            returnData.forEach((child) => {
              employeeSlaveData.push({
                sId: child.sId,
                sParentId: child.sParentId,
                sSlaveId: child.sSlaveId,
                sEmployeeId: child.sEmployeeId,
                handleType: 'add',
              });
            });
            employeeData = employeeData.concat(employeeSlaveData);
          } else {
            const employeeSlaveDataAdd = {};
            employeeSlaveDataAdd.sId = commonUtils.createSid();
            employeeSlaveDataAdd.sParentId = slaveData[iIndex].sParentId;
            employeeSlaveDataAdd.sSlaveId = slaveData[iIndex].sId;
            employeeSlaveDataAdd.handleType = 'add';
            employeeData = employeeData.concat(employeeSlaveDataAdd);
          }
        }
        this.props.onSaveState({ [`${name}Data`]: employeeData });
      } else {
        const employeeSlaveDataAdd = {};
        employeeSlaveDataAdd.sId = commonUtils.createSid();
        employeeSlaveDataAdd.sParentId = slaveData[iIndex].sParentId;
        employeeSlaveDataAdd.sSlaveId = slaveData[iIndex].sId;
        employeeSlaveDataAdd.handleType = 'add';
        employeeData = employeeData.concat(employeeSlaveDataAdd);
        this.props.onSaveState({ [`${name}Data`]: employeeData });
      }
    } else {
      return this.props.onDataRowAdd(name, isWait);
    }
  };
  /**   删除表格数据   */
  otherTableDel = (name, tableSelectedRowKeys) => {
    const tableData = this.props[`${name}Data`];
    let tableDelData = this.props[`${name}DelData`];
    tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData;
    for (const sId of tableSelectedRowKeys) {
      /*   看看删除集合和从表中是否都存在该条数据   */
      let tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
      while (tableDataIndex > -1) {
        /*   删除从表中的数据并存入删除集合中   */
        const slaveDataFilter = tableData[tableDataIndex];
        tableData.splice(tableDataIndex, 1);
        slaveDataFilter.handleType = 'del';
        tableDelData.push(slaveDataFilter);
        tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
      }
    }
    return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [] };
  };
  /**   删除表格数据   */
  handleTableDel = (name, flag, tableSelectedRowKeys) => {
    if (name === 'slave') {
      const tableSelectedRowKeys = this.props[`${name}SelectedRowKeys`];
      if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) {
        const employeeReturnData = this.otherTableDel('employee', tableSelectedRowKeys);
        // const processReturnData = this.otherTableDel('process', tableSelectedRowKeys);
        const slaveReturnData = this.props.onDataRowDel(name, true, tableSelectedRowKeys);
        this.props.onSaveState({
          ...employeeReturnData,
          ...slaveReturnData,
        });
        return true;
      } else {
        return false;
      }
    } else {
      const { slaveData, employeeData } = this.props;
      const iIndex = employeeData.findIndex(item => item.sId === tableSelectedRowKeys.toString());
      let sSlaveId = '';
      if (iIndex > -1) {
        sSlaveId = employeeData[iIndex].sSlaveId;
      }
      const returnData = this.props.onDataRowDel(name, true, tableSelectedRowKeys);
      if (commonUtils.isNotEmptyArr(returnData.employeeData)) {
        const iSlaveIndex = slaveData.findIndex(item => item.sId === sSlaveId);
        let dProportionTotal = 0;
        const returnDataIndex = returnData.employeeData.findIndex(item => item.sSlaveId === sSlaveId);
        const returnFilterData = returnData.employeeData.filter(item => item.sSlaveId === sSlaveId);
        if (returnDataIndex > -1) {
          returnFilterData.forEach((item) => {
            if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
              dProportionTotal += commonUtils.convertFixNum(item.dProportion, 6);
              dProportionTotal = commonUtils.convertFixNum(dProportionTotal, 6);
            }
          });
        }
        if (returnDataIndex > -1) {
          returnFilterData.forEach((item) => {
            if (commonUtils.isNotEmptyNumber(item.dProportion)) {
              const index1 = returnData.employeeData.findIndex(item1 => item1.sId === item.sId);
              returnData.employeeData[index1] = {
                ...item,
                dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dWageMoney, 0), 6),
                dTimeMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dTimeMoney, 0), 6),
                dLossMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dLossMoney, 0), 6),
                dOtherMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dOtherMoney, 0), 6),
                dJobMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dJobMoney, 0), 6),
                handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
              };
            }
          });
        }
      }
      this.props.onSaveState({ ...returnData });
    }
  };

  /*  上一条、下一条、首条、末条 */
  handleSearchData = async (handleType) => {
    const {
      employeeConfig,
    } = this.props;
    const bReturn = await this.props.onSearchData(handleType);
    if (bReturn) {
      this.handleGetData(employeeConfig);
    }
  };
  handleEdit = () => {
    const { employeeConfig } = this.props;
    this.props.onEdit(() => {
      this.handleGetData(employeeConfig, { loading: false, enabled: true });
    });
  };
  /**   获取主表、从表、审核表、员工表数据   */
  handleGetTableData = (masterConfig, slaveConfig, checkConfig, employeeConfig) => {
    const { currentId } = this.props; /* 当前页签数据 */
    const sId = currentId || this.props.masterData?.sId || '';
    this.props.handleGetDataOne({
      name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
    });
    this.props.handleGetDataSet({
      name: 'slave', configData: slaveConfig, condition: { sSqlCondition: { sParentId: sId } },
    });
    this.props.handleGetDataSet({
      name: 'check', configData: checkConfig, condition: { sSqlCondition: { sParentId: sId } },
    });
    this.props.handleGetDataSet({
      name: 'employee', configData: employeeConfig, condition: { sSqlCondition: { sParentId: sId } },
    });
  };
  /*   取消操作  */
  handleCancel = (obj) => {
    /*   待用数据声明   */
    const {
      masterConfig, slaveConfig, checkConfig, employeeConfig,
    } = this.props;
    const onGetDataOk = this.handleGetTableData;
    const onSaveStateOk = this.props.onSaveState;
    confirm({
      title: obj.title,
      onOk() {
        onGetDataOk(masterConfig, slaveConfig, checkConfig, employeeConfig);
        onSaveStateOk({ enabled: false });
      },
      onCancel() {
      },
    });
  };
  /**  点击新增按钮   */
  handleAdd = async (config, copyTo) => {
    let configNew = {};
    if (commonUtils.isEmptyObject(config)) {
      const { masterConfig, slaveConfig } = this.props;
      configNew.masterConfig = masterConfig;
      configNew.slaveConfig = slaveConfig;
    } else {
      configNew = config;
    }
    const { token, sModelsId } = this.props;
    const state = await this.props.onAdd(configNew, copyTo, true);
    const { masterData, slaveData } = state;
    const employeeData = [];
    if (commonUtils.isNotEmptyObject(copyTo)) {
      const copyToControlConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.employee`.toLowerCase());
      const employeeAssignField = commonUtils.isNotEmptyArr(copyToControlConfig) ? copyToControlConfig[0].sAssignField : '';

      const newCopyTo = {};
      newCopyTo.masterData = copyTo.masterData;
      newCopyTo.slaveData = commonUtils.isEmptyArr(slaveData) ? {} : slaveData[0];
      if (commonUtils.isNotEmptyObject(copyTo.employeeData)) {
        copyTo.employeeData.forEach((employeeItem) => {
          newCopyTo.employeeData = employeeItem;
          let employeeRow = commonFunc.getDefaultData(config.employeeConfig, newCopyTo); // 取默认值
          employeeRow = { ...employeeRow, ...commonFunc.getAssignFieldValue(employeeAssignField, employeeItem, newCopyTo) }; // 取赋值字段
          employeeRow.handleType = 'add';
          employeeRow.sId = commonUtils.createSid();
          employeeRow.sParentId = masterData.sId;
          employeeData.push(employeeRow);
        });
      }

      if (commonUtils.isNotEmptyArr(slaveData)) {
        for (const tableDataRow of slaveData) {
          const sWageId = tableDataRow.sWageId;
          if (commonUtils.isNotEmptyObject(sWageId)) {
            tableDataRow.dWageMoney = await commonBusiness.getFormulaValue({
              token, sModelsId, masterData, tableDataRow, sComputeId: sWageId,
            });
          }
          /* 调用折算公式，算换算数量 */
          const sConversionFormulaId = tableDataRow.sConversionFormulaId;
          if (commonUtils.isNotEmptyObject(sConversionFormulaId)) {
            tableDataRow.dConversionQty = await commonBusiness.getFormulaValue({
              token, sModelsId, masterData, tableDataRow, sComputeId: sConversionFormulaId,
            });
          }

          /* 调用工时公式，算工时 */
          const sFactCapacityId = tableDataRow.sFactCapacityId;
          if (commonUtils.isNotEmptyObject(sFactCapacityId)) {
            tableDataRow.dHour = await commonBusiness.getFormulaValue({
              token, sModelsId, masterData, tableDataRow, sComputeId: sFactCapacityId,
            });
          }

          if (!commonUtils.isEmpty(tableDataRow.sTeamId) && commonUtils.isEmptyObject(copyTo.employeeData)) {
            const url = `${commonConfig.server_host}eleteamemployee/getEleteamemployee?sModelsId=${sModelsId}&sTeamId=${tableDataRow.sTeamId}&sSlaveId=${tableDataRow.sId}&sParentId=${tableDataRow.sParentId}`;
            const dataReturn = (await commonServices.getService(token, url)).data;
            if (dataReturn.code === 1) {
              const returnData = dataReturn.dataset.rows;
              returnData.forEach((child) => {
                employeeData.push({
                  sId: child.sId,
                  sParentId: child.sParentId,
                  sSlaveId: child.sSlaveId,
                  sEmployeeId: child.sEmployeeId,
                  sEmployeeName: child.sEmployeeName,
                  dProportion: child.dProportion !== 0 ? child.dProportion : commonUtils.convertFixNum(1 / returnData.length, 6),
                  handleType: 'add',
                });
              });
              /* 班组变化时，算每个工作人员计件工资 */
              const dWageMoneyTotal = tableDataRow.dWageMoney;
              if (commonUtils.isNotEmptyNumber(dWageMoneyTotal)) {
                let dProportionTotal = 0;
                employeeData.filter(item => item.sSlaveId === tableDataRow.sId).forEach((item) => {
                  if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
                    dProportionTotal += commonUtils.convertFixNum(item.dProportion, 6);
                    dProportionTotal = commonUtils.convertFixNum(dProportionTotal, 6);
                  }
                });
                employeeData.filter(item => item.sSlaveId === tableDataRow.sId).forEach((item) => {
                  if (commonUtils.isNotEmptyNumber(item.dProportion)) {
                    const index1 = employeeData.findIndex(item1 => item1.sId === item.sId);
                    employeeData[index1] = {
                      ...item,
                      dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * dWageMoneyTotal, 6),
                      handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
                    };
                  }
                });
              }
            } else { /*   失败   */
              this.props.getServiceError(dataReturn);
            }

            const dWageMoney = commonUtils.isNotEmptyNumber(tableDataRow.dWageMoney) ? commonUtils.convertFixNum(tableDataRow.dWageMoney, 6) : 0;
            const dTimeMoney = commonUtils.isNotEmptyNumber(tableDataRow.dTimeMoney) ? commonUtils.convertFixNum(tableDataRow.dTimeMoney, 6) : 0;
            const dLossMoney = commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney) ? commonUtils.convertFixNum(tableDataRow.dLossMoney, 6) : 0;
            tableDataRow.dAllMoney = commonUtils.convertFixNum((dWageMoney + dTimeMoney) - dLossMoney, 6);
          }
          /* 上报参数 如果没值则取默认值 */
          if (commonUtils.isNotEmptyObject(tableDataRow)) {
            const tableDataRowNew = JSON.parse(JSON.stringify(tableDataRow));
            /* 若sParamValue1为0或空时 将sParamDefault1值赋值给sParamValue1 */
            for (const key of Object.keys(tableDataRowNew)) {
              if (key.includes('sParamDefault')) {
                const sParamValueName = key.replace('Default', 'Value');
                if (commonUtils.isNotEmptyNumber(tableDataRowNew[key]) && tableDataRowNew[key] > 0) {
                  if (commonUtils.isEmptyNumber(tableDataRowNew[sParamValueName]) || tableDataRowNew[sParamValueName] === '0') {
                    tableDataRow[sParamValueName] = tableDataRowNew[key];
                  }
                }
              }
            }
          }
        }
      }
    }
    const stateNew = {
      ...state,
      employeeData,
      employeeSelectedRowKeys: [],
    };
    this.props.onSaveState(stateNew);
  };
  /** 表格数据更改 */
  handleTableChange = async (name, sFieldName, changeValue, sId, dropDownData) => {
    /*   从CommonBase获取默认参数   */
    if (name === 'slave') {
      const {
        sModelsId, masterData, [`${name}Data`]: tableData, token, employeeDelData: employeeDelDataOld,
      } = this.props;
      let {
        employeeData,
      } = this.props;
      const employeeDelData = commonUtils.isEmptyArr(employeeDelDataOld) ? [] : employeeDelDataOld;
      const tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
      if (tableDataRow === undefined) return;
      const iIndex = tableData.findIndex(item => item.sId === sId);
      tableData[iIndex] = tableDataRow;
      /* 改变上报数量时，调用折算公式，进行计算 */
      if (sFieldName === 'dProcessQty' || sFieldName === 'sConversionFormulaId' || sFieldName === 'sConversionFormulaName') {
        const sConversionFormulaId = tableDataRow.sConversionFormulaId;
        tableData[iIndex].dConversionQty = await commonBusiness.getFormulaValue({
          token, sModelsId, masterData, tableDataRow, sComputeId: sConversionFormulaId,
        });
      }
      if (sFieldName === 'sTeamName' || sFieldName === 'sTeamId') {
        const sTeamId = tableData[iIndex].sTeamId;
        const sSlaveId = tableData[iIndex].sId;
        const sParentId = tableData[iIndex].sParentId;
        // let handleType = tableData[iIndex].handleType;/* 获取操作类型 */
        // handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
        const url = `${commonConfig.server_host}eleteamemployee/getEleteamemployee?sModelsId=${sModelsId}&sTeamId=${sTeamId}&sSlaveId=${sSlaveId}&sParentId=${sParentId}`;
        const dataReturn = (await commonServices.getService(token, url)).data;
        if (dataReturn.code === 1) {
          employeeData.filter(item => item.sSlaveId === sId).forEach((item) => {
            item.handleType = 'del';
            employeeDelData.push(item);
          });
          const returnData = dataReturn.dataset.rows;
          const employeeDataNew = employeeData.filter(item => item.sSlaveId !== sId);
          const employeeSlaveData = [];
          returnData.forEach((child) => {
            employeeSlaveData.push({
              sId: child.sId,
              sParentId: child.sParentId,
              sSlaveId: child.sSlaveId,
              sEmployeeId: child.sEmployeeId,
              sEmployeeName: child.sEmployeeName,
              dProportion: child.dProportion !== 0 ? child.dProportion : commonUtils.convertFixNum(1 / returnData.length, 6),
              handleType: 'add',
            });
          });
          /* 班组变化时，算每个工作人员计件工资 */
          let dProportionTotal = 0;
          employeeSlaveData.forEach((item) => {
            if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
              dProportionTotal += commonUtils.convertFixNum(item.dProportion, 6);
              dProportionTotal = commonUtils.convertFixNum(dProportionTotal, 6);
            }
          });
          employeeSlaveData.forEach((item) => {
            if (commonUtils.isNotEmptyNumber(item.dProportion)) {
              const index1 = employeeSlaveData.findIndex(item1 => item1.sId === item.sId);
              employeeSlaveData[index1] = {
                ...item,
                dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dWageMoney, 0), 6),
                dTimeMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dTimeMoney, 0), 6),
                dLossMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dLossMoney, 0), 6),
                dOtherMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dOtherMoney, 0), 6),
                dJobMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableDataRow.dJobMoney, 0), 6),
                handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
              };
            }
          });
          employeeData = employeeDataNew.concat(employeeSlaveData);
        } else { /*   失败   */
          this.props.getServiceError(dataReturn);
        }
      } else if (sFieldName === 'dProcessQty' || sFieldName === 'sWageId' || sFieldName === 'sWageName') {
        const sFactCapacityId = tableDataRow.sFactCapacityId; /* 获取工时的公式id */
        if (commonUtils.isNotEmptyObject(sFactCapacityId)) { /* 调用工时公式,计算工时 */
          const dHour = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId: sFactCapacityId,
          });
          if (!commonUtils.isEmpty(dHour)) {
            tableData[iIndex].dHour = dHour;
          }
        }
        const sWageId = tableDataRow.sWageId;
        if (commonUtils.isNotEmptyObject(sWageId)) {
          tableData[iIndex].dWageMoney = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId: sWageId,
          });
        }
        const dWageMoneyTotal = tableData[iIndex].dWageMoney;
        let dProportionTotal = 0;
        const employeeSlaveData = employeeData.filter(item => item.sSlaveId === sId);
        employeeSlaveData.forEach((item) => {
          if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
            dProportionTotal += item.dProportion;
          }
        });
        employeeSlaveData.forEach((item) => {
          if (commonUtils.isNotEmptyNumber(item.dProportion)) {
            const index1 = employeeData.findIndex(item1 => item1.sId === item.sId);
            employeeData[index1] = {
              ...item,
              dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dWageMoney, 0), 6),
              dTimeMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dTimeMoney, 0), 6),
              dLossMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dLossMoney, 0), 6),
              dOtherMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dOtherMoney, 0), 6),
              dJobMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dJobMoney, 0), 6),
              handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
            };
          }
        });
        /* 选择计件方案后 算总金额 */
        const dWageMoney = commonUtils.isNotEmptyNumber(dWageMoneyTotal) ? commonUtils.convertFixNum(dWageMoneyTotal, 6) : 0;
        const dTimeMoney = commonUtils.isNotEmptyNumber(tableDataRow.dTimeMoney) ? commonUtils.convertFixNum(tableDataRow.dTimeMoney, 6) : 0;
        const dLossMoney = commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney) ? commonUtils.convertFixNum(tableDataRow.dLossMoney, 6) : 0;
        tableDataRow.dAllMoney = commonUtils.convertFixNum((dWageMoney + dTimeMoney) - dLossMoney, 6);
      } else if (sFieldName === 'dTimeMoney' || sFieldName === 'dLossMoney') {
        /* 总金额=计件工资+工时工资-损失金额 */
        let dProportionTotal = 0;
        const employeeSlaveData = employeeData.filter(item => item.sSlaveId === sId);
        employeeSlaveData.forEach((item) => {
          if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
            dProportionTotal += item.dProportion;
          }
        });
        employeeSlaveData.forEach((item) => {
          if (commonUtils.isNotEmptyNumber(item.dProportion)) {
            const index1 = employeeData.findIndex(item1 => item1.sId === item.sId);
            employeeData[index1] = {
              ...item,
              dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dWageMoney, 0), 6),
              dTimeMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dTimeMoney, 0), 6),
              dLossMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dLossMoney, 0), 6),
              dOtherMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dOtherMoney, 0), 6),
              dJobMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(tableData[iIndex].dJobMoney, 0), 6),
              handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
            };
          }
        });
        const dWageMoney = commonUtils.isNotEmptyNumber(tableDataRow.dWageMoney) ? commonUtils.convertFixNum(tableDataRow.dWageMoney, 6) : 0;
        const dTimeMoney = commonUtils.isNotEmptyNumber(tableDataRow.dTimeMoney) ? commonUtils.convertFixNum(tableDataRow.dTimeMoney, 6) : 0;
        const dLossMoney = commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney) ? commonUtils.convertFixNum(tableDataRow.dLossMoney, 6) : 0;
        tableDataRow.dAllMoney = commonUtils.convertFixNum((dWageMoney + dTimeMoney) - dLossMoney, 6);
      } else if (sFieldName === 'sProcessName') { /* 切换工序时 上报动态参数赋值 */
        if (commonUtils.isNotEmptyObject(tableDataRow.sReportParam)) {
          tableData[iIndex] = { ...tableDataRow, ...commonUtils.convertStrToObj(tableDataRow.sReportParam) };
          /* 上报参数 如果没值则取默认值 */
          if (commonUtils.isNotEmptyObject(tableData[iIndex])) {
            const tableDataRowNew = JSON.parse(JSON.stringify(tableData[iIndex]));
            /* 若sParamValue1为0或空时 将sParamDefault1值赋值给sParamValue1 */
            for (const key of Object.keys(tableDataRowNew)) {
              if (key.includes('sParamDefault')) {
                const sParamValueName = key.replace('Default', 'Value');
                if (commonUtils.isNotEmptyNumber(tableDataRowNew[key]) && tableDataRowNew[key] > 0) {
                  if (commonUtils.isEmptyNumber(tableDataRowNew[sParamValueName]) || tableDataRowNew[sParamValueName] === '0') {
                    tableDataRowNew[sParamValueName] = tableDataRowNew[key];
                  }
                }
              }
            }
            tableData[iIndex] = { ...tableData[iIndex], ...tableDataRowNew };
          }
        } else { /* 没有上报参数时 清除已有的上报参数下拉 */
          // eslint-disable-next-line no-plusplus
          for (let i = 1; i < 11; i++) {
            if (!commonUtils.isEmpty(tableData[iIndex][`sParamDropDown${i.toString()}`])) {
              tableData[iIndex][`sParamDropDown${i.toString()}`] = [];
            }
            if (!commonUtils.isEmpty(tableData[iIndex][`sParamValue${i.toString()}`]) && tableData[iIndex][`sParamValue${i.toString()}`] !== '0') {
              tableData[iIndex][`sParamValue${i.toString()}`] = '';
            }
            if (!commonUtils.isEmpty(tableData[iIndex][`sParam${i.toString()}`])) {
              tableData[iIndex][`sParam${i.toString()}`] = '';
            }
          }
        }
      } else if (sFieldName === 'sFactCapacityId' || sFieldName === 'sFactCapacityName' || sFieldName === 'sMachineName') {
        const sFactCapacityId = tableDataRow.sFactCapacityId;
        if (commonUtils.isNotEmptyObject(sFactCapacityId)) { /* 获取工时 */
          const dHour = await commonBusiness.getFormulaValue({
            token, sModelsId, masterData, tableDataRow, sComputeId: sFactCapacityId,
          });
          if (!commonUtils.isEmpty(dHour)) {
            tableData[iIndex].dHour = dHour;
          }
        }
      }

      this.props.onSaveState({
        [`${name}Data`]: tableData, employeeData, employeeDelData, enabled: true,
      });
    } else if (name === 'employee') {
      /* 班组变化时，算每个工作人员计件工资 */
      const {
        slaveData, [`${name}Data`]: tableData,
      } = this.props;
      const tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
      if (tableDataRow === undefined) return;
      const iIndex = tableData.findIndex(item => item.sId === sId);
      tableData[iIndex] = tableDataRow;

      const iSlaveIndex = slaveData.findIndex(item => item.sId === tableDataRow.sSlaveId);
      let dProportionTotal = 0;
      tableData.filter(item => item.sSlaveId === tableDataRow.sSlaveId).forEach((item) => {
        if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
          dProportionTotal += commonUtils.convertFixNum(item.dProportion, 6);
          dProportionTotal = commonUtils.convertFixNum(dProportionTotal, 6);
        }
      });
      tableData.filter(item => item.sSlaveId === tableDataRow.sSlaveId).forEach((item) => {
        if (commonUtils.isNotEmptyNumber(item.dProportion)) {
          const index1 = tableData.findIndex(item1 => item1.sId === item.sId);
          tableData[index1] = {
            ...item,
            dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dWageMoney, 0), 6),
            dTimeMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dTimeMoney, 0), 6),
            dLossMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dLossMoney, 0), 6),
            dOtherMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dOtherMoney, 0), 6),
            dJobMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveData[iSlaveIndex].dJobMoney, 0), 6),
            handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
          };
        }
      });

      this.props.onSaveState({ [`${name}Data`]: tableData, slaveData, enabled: true });
    } else {
      this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData);
    }
  };
  /* 非列表联动下拉 */
  handleMasterChange = async (name, sFieldName, changeValue, sId, dropDownData) => {
    /* 数据集类型，对象型为Map 数组型为List */
    const { masterConfig, sModelsId, app } = this.props;
    let { masterData } = this.props;
    const { token } = app;
    let { sBackProcessClassifyData } = this.props;

    let { sAllPartsName } = masterData;
    if (sFieldName === 'sProductId') {
      await this.handleBackProcessData();
      let allPartsName = [];
      if (sAllPartsName !== undefined) {
        allPartsName = sAllPartsName.split(',');
      }

      if (allPartsName.length > 0 && masterConfig.gdsconfigformslave.filter(item => item.sName === `sMaterialsName${allPartsName[0]}`).length > 0 &&
        (sBackProcessClassifyData !== undefined && sBackProcessClassifyData !== '' && sBackProcessClassifyData.length > 0 &&
          masterConfig.gdsconfigformslave.filter(item => item.sName === `${sBackProcessClassifyData[0].sId}${allPartsName[0]}`).length > 0)) {
        let iIndex;
        allPartsName.forEach((sPartsName) => {
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === `dSumPQty${sPartsName}`);
          if (iIndex > -1) {
            masterConfig.gdsconfigformslave.splice(iIndex, 1);
          }
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === `sMaterialsName${sPartsName}`);
          if (iIndex > -1) {
            masterConfig.gdsconfigformslave.splice(iIndex, 1);
          }
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === `iPrintModePo${sPartsName}`);
          if (iIndex > -1) {
            masterConfig.gdsconfigformslave.splice(iIndex, 1);
          }
          iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === `iPositiveColor${sPartsName}`);
          if (iIndex > -1) {
            masterConfig.gdsconfigformslave.splice(iIndex, 1);
          }

          if (sBackProcessClassifyData !== '') {
            sBackProcessClassifyData.filter(processClassify => processClassify.sType !== '3').forEach((processClassify) => {
              iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === processClassify.sId + sPartsName);
              if (iIndex > -1) {
                masterConfig.gdsconfigformslave.splice(iIndex, 1);
              }
            });
          }
        });
        if (sBackProcessClassifyData !== '') {
          sBackProcessClassifyData.filter(processClassify => processClassify.sType === '3').forEach((processClassify) => {
            iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === processClassify.sId);
            if (iIndex > -1) {
              masterConfig.gdsconfigformslave.splice(iIndex, 1);
            }
          });
        }
      }


      let sProductClassifyId;
      if (changeValue !== null && changeValue !== undefined) {
        sProductClassifyId = changeValue.sProductClassifyId;
        sAllPartsName = changeValue.sAllPartsName;
      } else {
        sProductClassifyId = masterData.sProductClassifyId;
      }
      if (commonUtils.isEmpty(sProductClassifyId)) {
        return;
      }
      const sBackProcessClassify = masterConfig.gdsconfigformslave.filter(item => (item.sName.toLowerCase() === 'sbackprocessclassify'))[0];

      const values = { sKeyUpFilterName: '', sSqlCondition: { sProductClassifyId } };
      const dataReturn = (await commonServices.postValueService(token, values, `${commonConfig.server_host}business/getSelectDataBysControlId/${sBackProcessClassify.sId}?sModelsId=${sModelsId}`)).data;
      /*   接收返回值   */
      /*   成功的话刷新页面(同步主表和从表数据),不成功就弹出错误提示   */
      if (dataReturn.code === 1) { /*   成功   */
        const { rows } = dataReturn.dataset;

        allPartsName = [];
        if (sAllPartsName !== undefined) {
          allPartsName = sAllPartsName.split(',');
        }

        sBackProcessClassifyData = rows;
        if (allPartsName.length > 0 && masterConfig.gdsconfigformslave.filter(item => item.sName === `sMaterialsName${allPartsName[0]}`).length <= 0 &&
          sBackProcessClassifyData !== undefined && sBackProcessClassifyData !== '' && sBackProcessClassifyData.length > 0 &&
          masterConfig.gdsconfigformslave.filter(item => item.sName === `${sBackProcessClassifyData[0].sId}${allPartsName[0]}`).length <= 0) {
          const sumPQtyConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'dSumPQty').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'dSumPQty')[0] : [];
          const materialsNameConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'sMaterialsName').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'sMaterialsName')[0] : [];
          const printModePoConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'iPrintModePo').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'iPrintModePo')[0] : [];
          const positiveColorConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'iPositiveColor').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'iPositiveColor')[0] : [];
          const processNameConfig = masterConfig.gdsconfigformslave.filter(item => item.sName === 'sProcessName').length > 0 ? masterConfig.gdsconfigformslave.filter(item => item.sName === 'sProcessName')[0] : [];

          let ConfigNew;
          allPartsName.forEach((item) => {
            ConfigNew = { ...sumPQtyConfig };
            ConfigNew.sName = `dSumPQty${item}`;
            ConfigNew.sAssignField = commonUtils.isEmpty(ConfigNew.sAssignField) ? '' : ConfigNew.sAssignField.replace(/:/g, `${item}:`);
            masterConfig.gdsconfigformslave.push(ConfigNew);

            ConfigNew = { ...materialsNameConfig };
            ConfigNew.sName = `sMaterialsName${item}`;
            ConfigNew.sAssignField = commonUtils.isEmpty(ConfigNew.sAssignField) ? '' : ConfigNew.sAssignField.replace(/:/g, `${item}:`);
            masterConfig.gdsconfigformslave.push(ConfigNew);

            ConfigNew = { ...printModePoConfig };
            ConfigNew.sName = `iPrintModePo${item}`;
            ConfigNew.sAssignField = commonUtils.isEmpty(ConfigNew.sAssignField) ? '' : ConfigNew.sAssignField.replace(/:/g, `${item}:`);
            masterConfig.gdsconfigformslave.push(ConfigNew);

            ConfigNew = { ...positiveColorConfig };
            ConfigNew.sName = `iPositiveColor${item}`;
            ConfigNew.sAssignField = commonUtils.isEmpty(ConfigNew.sAssignField) ? '' : ConfigNew.sAssignField.replace(/:/g, `${item}:`);
            masterConfig.gdsconfigformslave.push(ConfigNew);
            if (sBackProcessClassifyData !== '') {
              sBackProcessClassifyData.filter(processClassify => processClassify.sType !== '3').forEach((processClassify) => {
                ConfigNew = { ...processNameConfig };
                ConfigNew.sName = processClassify.sId + item;
                masterConfig.gdsconfigformslave.push(ConfigNew);
              });
            }
          });
          if (sBackProcessClassifyData !== '') {
            sBackProcessClassifyData.filter(processClassify => processClassify.sType === '3').forEach((processClassify) => {
              ConfigNew = { ...processNameConfig };
              ConfigNew.sName = processClassify.sId;
              masterConfig.gdsconfigformslave.push(ConfigNew);
            });
          }
        }
        const returnChange = this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, true);
        this.props.onSaveState({ ...returnChange, sBackProcessClassifyData, masterConfig });
      } else { /*   失败   */
        this.props.getServiceError(dataReturn);
      }
    } else if (sFieldName === 'sTeamName') { /* 主表选择的班组，循环复制到从表班组 */
      const { slaveData, slaveSelectedRowKeys, employeeDelData: employeeDelDataOld } = this.props;
      let { employeeData } = this.props;
      const employeeDelData = commonUtils.isEmptyArr(employeeDelDataOld) ? [] : employeeDelDataOld;
      const iIndex = dropDownData.findIndex(item => item.sId === changeValue.sTeamName);/* 拿到主表下拉选中的班组的名称 */
      const addStata = {};
      addStata.sTeamName = dropDownData[iIndex].sTeamName;
      addStata.sTeamId = dropDownData[iIndex].sId;
      masterData = { ...masterData, ...addStata };
      if (iIndex > -1) {
        if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
          const sTeamId = dropDownData[iIndex].sId;
          const sSlaveId = slaveData[0].sId;
          const sParentId = slaveData[0].sParentId;
          if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) { /* 第一个从表数据默认选中 */
            slaveSelectedRowKeys.push(sSlaveId);
          }
          const url = `${commonConfig.server_host}eleteamemployee/getEleteamemployee?sModelsId=${sModelsId}&sTeamId=${sTeamId}&sSlaveId=${sSlaveId}&sParentId=${sParentId}`;
          const dataReturn = (await commonServices.getService(token, url)).data;
          slaveData.forEach(async (slaveItem, index) => { /* 根据选中的班组 ，获取班组人员及比例 */
            let handleType = slaveItem.handleType;/* 获取操作类型 */
            handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
            addStata.handleType = handleType;
            slaveData[index] = { ...slaveItem, ...addStata };
            const employeeSlaveData = [];
            let employeeDataNew = [];
            if (dataReturn.code === 1) {
              const returnData = dataReturn.dataset.rows;
              if (commonUtils.isNotEmptyObject(returnData) && returnData.length > 0) {
                employeeDataNew = employeeData.filter(item => item.sSlaveId !== slaveItem.sId);

                const employeeDelDataNew = employeeData.filter(item => item.sSlaveId === slaveItem.sId);
                employeeDelDataNew.forEach((item) => {
                  item.handleType = 'del';
                  employeeDelData.push(item);
                });
                if (commonUtils.isEmptyArr(employeeSlaveData)) { /* 当班组人员无数据时 */
                  returnData.forEach((child) => {
                    employeeSlaveData.push({
                      sId: commonUtils.createSid(),
                      sParentId: slaveItem.sParentId,
                      sSlaveId: slaveItem.sId,
                      sEmployeeId: child.sEmployeeId,
                      sEmployeeName: child.sEmployeeName,
                      dProportion: child.dProportion !== 0 ? child.dProportion : commonUtils.convertFixNum(1 / returnData.length, 6),
                      handleType: 'add',
                    });
                  });
                }
              }
              const dWageMoneyTotal = commonUtils.isNotEmptyNumber(slaveItem.dWageMoney) ? slaveItem.dWageMoney : 0;
              if (commonUtils.isNotEmptyNumber(dWageMoneyTotal)) {
                let dProportionTotal = 0;
                employeeSlaveData.forEach((item) => {
                  if (commonUtils.isNotEmptyNumber(item.dProportion) && item.dProportion !== 0) {
                    dProportionTotal += commonUtils.convertFixNum(item.dProportion, 6);
                    dProportionTotal = commonUtils.convertFixNum(dProportionTotal, 6);
                  }
                });
                employeeSlaveData.forEach((item) => {
                  if (commonUtils.isNotEmptyNumber(item.dProportion)) {
                    const index1 = employeeSlaveData.findIndex(item1 => item1.sId === item.sId);
                    employeeSlaveData[index1] = {
                      ...item,
                      dWageMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveItem.dWageMoney, 0), 6),
                      dTimeMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveItem.dTimeMoney, 0), 6),
                      dLossMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveItem.dLossMoney, 0), 6),
                      dOtherMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveItem.dOtherMoney, 0), 6),
                      dJobMoney: commonUtils.convertFixNum((item.dProportion / dProportionTotal) * commonUtils.isNull(slaveItem.dJobMoney, 0), 6),
                      handleType: commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType,
                    };
                  }
                });
              }
              employeeData = employeeDataNew.concat(employeeSlaveData);
            }
          });
        }
      }
      this.props.onSaveState({
        masterData, slaveData, employeeData, employeeDelData,
      });
    } else {
      this.props.onChange(name, sFieldName, changeValue, sId, dropDownData);
    }
  };
  handleDel = (obj) => {
    const props = { ...this.props, ...this.state };
    const onOkDel = this.handleOkDel;
    confirm({
      title: obj.title,
      onOk() {
        onOkDel(props);
      },
      onCancel() {
      },
    });
  };
  handleOkDel = async (props) => {
    /*   数据参数   */
    const {
      token, sModelsId, masterConfig, masterData, slaveConfig, checkConfig, employeeConfig,
    } = props;
    const value = {
      sClientType: '1',
      data: {
        sMasterTable: masterConfig.sTbName,
        sId: [masterData.sId],
        sSlaveTable: [
          {
            tableName: slaveConfig.sTbName,
            relationName: 'sParentId',
          }, {
            tableName: checkConfig.sTbName,
            relationName: 'sBillId',
          }, {
            tableName: employeeConfig.sTbName,
            relationName: 'sParentId',
          }],
      },
    };
    const { sBillNo, sId } = masterData || {};
    const url = `${commonConfig.server_host}business/delMasSlaBusinessData?sModelsId=${sModelsId}&sBillNo=${sBillNo}&sSysLogSrcId=${sId}`;
    /*   接收返回值   */
    const { data } = await commonServices.postValueService(token, value, url);
    if (data.code === 1) {
      /*   数据删除成功   */
      if (this.props.app.currentPane.refresh !== undefined) {
        this.props.app.currentPane.refresh();
      }
      this.handleDelDataSuccess(props);
    } else { /*   失败   */
      this.props.getServiceError(data);
    }
  };
  /* 数据删除成功跳转到新路由即pane */
  handleDelDataSuccess = (props) => {
    const { app } = props;
    let { panes, currentPane } = app;
    /* 删除单据后退出当前路由后,标签panes变化后的集合 */
    panes = panes.filter(pane => pane.key !== currentPane.key);
    /* 跳转到panes集合的最后一个路由，因为panes集合一定含有主页路由所以panes的集合大于等于1 */
    currentPane = panes[panes.length - 1];
    this.props.onRemovePane(panes, currentPane);
  };

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

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

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

  render() {
    const {
      pageLoading, masterData, visible, checkConditions, checkPersonData, app, sModelsType,
    } = this.props;
    const checkCondition = commonFunc.showMessage(app.commonConst, 'checkCondition');/* 审核条件 */
    const checkSmemo = commonFunc.showMessage(app.commonConst, 'checkSmemo');/* 备注 */
    const columns = [{
      title: checkCondition,
      dataIndex: 'condition',
      key: 'condition',
    }, {
      title: checkSmemo,
      dataIndex: 'sMemo',
      key: 'sMemo',
    }];
    const imgSrc = commonBusiness.handleAddIcon(masterData, sModelsType, app);
    const btnSure = commonFunc.showMessage(app.commonConst, 'btnSure');/* 确认 */
    const check = commonFunc.showMessage(app.commonConst, 'check');/* 审核 */
    const BtnClose = commonFunc.showMessage(app.commonConst, 'BtnClose');/* 关闭 */
    const checkPerson = commonFunc.showMessage(app.commonConst, 'checkPerson');/* 审核人 */
    return (
      <Spin spinning={pageLoading}>
        <WorkOrderComponent
          {...this.props}
          {...this.state}
          onReturnForm={this.handleForm}
          onSubmit={this.handleSave}
          onFilterData={this.handleFilterData}
          onDataRowAdd={this.handleTableAdd}
          onDataRowDel={this.handleTableDel}
          onNext={this.handleSearchData.bind(this, 'next')}
          onBtnPrior={this.handleSearchData.bind(this, 'up')}
          onBtnFirst={this.handleSearchData.bind(this, 'first')}
          onBtnLast={this.handleSearchData.bind(this, 'end')}
          onEdit={this.handleEdit}
          onDel={this.handleDel}
          onCancel={this.handleCancel}
          onAdd={this.handleAdd}
          onMasterChange={this.handleMasterChange}
          onDataChange={this.handleTableChange}
          imgSrc={imgSrc}
          onTabChange={this.onTabChange}
        />
        {
          visible ?
            <AntdDraggableModal
              title={check}
              visible={visible}
              onCancel={this.handleCancelModal}
              footer={[
                <Button key="back" onClick={this.handleCancelModal}>{BtnClose}</Button>,
                <Button key="submit" type="primary" onClick={this.handleOk.bind(this, 1, 1, true)}>
                  {btnSure}
                </Button>,
              ]}
            >
              <Table columns={columns} dataSource={checkConditions} bordered pagination={false} className={styles.checkTable} />
              <div style={{ float: 'left', width: '15%' }}>{checkPerson}</div>
              <div style={{ float: 'left', width: '60%' }}>
                <Checkbox.Group style={{ width: '100%' }} onChange={this.onChange}>
                  <Row>
                    { commonUtils.isNotEmptyObject(checkPersonData) ?
                      checkPersonData.map((item) => {
                        return (
                          <Col span={8}>
                            <Checkbox value={item.sUserId}>{item.sUserName}</Checkbox>
                          </Col>
                        );
                      })
                      : ''
                    }
                  </Row>
                </Checkbox.Group>
              </div>
            </AntdDraggableModal>
            : ''
        }
      </Spin>
    );
  }
}

const WorkOrderComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form);
    return obj;
  },
})((props) => {
  const {
    form, onReturnForm, slavePagination, isSmall, sModelsType, app, checkConfig,
  } = props;
  if (commonUtils.isNotEmptyObject(slavePagination)) {
    if (isSmall) {
      slavePagination.showTotal = null;
    }
  }
  /*   回带表单   */
  onReturnForm(form);
  const pagination = {
    pageSize: commonConfig.pageSize,
    current: commonUtils.isEmptyObject(slavePagination) ? 1 : slavePagination.current,
    ...slavePagination,
    hideOnSinglePage: true,
    size: isSmall ? 'small' : 'large',
    pageSizeOptions: commonConfig.pageSizeOptions,
    showSizeChanger: !isSmall,
    showQuickJumper: !isSmall,
  };
  const propsType = {
    ...props,
    onChange: props.onMasterChange,
  };
  let topTableHeight = 0;
  if (document.getElementsByClassName('product_table' + props.sTabId)[0]) {
    topTableHeight = document.getElementsByClassName('product_table' + props.sTabId)[0].offsetHeight
  }
  const employeePropsType = {
    ...commonBusiness.getTableTypes('employee', props),
    filteredValue: props.slaveSelectedRowKeys,
    onFilterData: props.onFilterData,
    tableProps: {
      AutoTableHeight: (window.innerHeight - 178 - 89 - topTableHeight) > 250 ? (window.innerHeight - 178 - 89 - topTableHeight) : 250
    }
  };

  const slaveTableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    tableProps: {
      AutoTableHeight: 250,
      pagination,
      onChange: props.onTitleChange,
    },
  };

  const checkTableProps = {
    ...commonBusiness.getTableTypes('check', props),
    tableProps: {
      AutoTableHeight: 250,
    },
  };
  const sReportParams = commonUtils.isNotEmptyObject(commonFunc.showMessage(app.commonConst, 'sReportParams')) ?
    commonFunc.showMessage(app.commonConst, 'sReportParams') : '上报参数标准';
  /* 新方式的上报参数 */
  const sParamProps = {
    ...commonBusiness.getTableTypes('sParam', props),
    tableProps: {
      rowKey: 'sId',
      pagination,
      onChange: props.onTitleChange,
      sModelsType,
      AutoTableHeight: 350,
      rowSelection: null,
    },
    bRowClick: true,
    // enabled: true,
  };

  const slaveTablePropsList = {};
  if (commonUtils.isNotEmptyArr(props.slaveInfoList)) {
    props.slaveInfoList.forEach((item, index) => {
      // const slaveTablePagination = {
      //   pageSize: commonUtils.isNotEmptyNumber(props.iPageSize) && props.iPageSize !== 0 ? props.iPageSize : commonConfig.pageSize,
      //   ...slavePagination,
      //   size: isSmall ? 'small' : 'large',
      //   pageSizeOptions: commonConfig.pageSizeOptions,
      //   showSizeChanger: !isSmall,
      //   showQuickJumper: !isSmall,
      //   hideOnSinglePage: true,
      // };
      slaveTablePropsList[`slaveTable${index}Props`] = {
        ...commonBusiness.getTableTypes(`slave${index}`, props),
        // tableBelone: 'list',
        tableProps: {
          // pagination: slaveTablePagination, onChange: props.onTitleChange1.bind(this, `slave${index}`),
          AutoTableHeight: (window.innerHeight - 178 - 89 - topTableHeight) > 250 ? (window.innerHeight - 178 - 89 - topTableHeight) : 250
        },
      };
    });
  }
  return (
    <Form>
      <Layout>
        <Header className={styles.header}>
          <Toolbar {...props} />
        </Header>
        <Layout className={styles.clayout}>
          <Content className={styles.content} style={{ overflowY: 'unset' }}>
            <CommonView {...propsType} />
            <div id="slaveTabs" className={styles.bShow} >
              <div>
                <Avatar src={props.imgSrc} />
              </div>
              <Tabs className={styles.slaveTabs} style={{ overflowY: 'unset' }} tabBarStyle={{ margin: '0 10px' }}>
                <TabPane tab="主体内容" key={2} className={`xly-bill-list ${'product_table' + props.sTabId}`}>
                  <StaticEditTable {...slaveTableProps} setOpterationColumn="Y" noVlist />
                </TabPane>
                {
                  commonUtils.isNotEmptyObject(checkConfig) ?
                  <TabPane tab="审批信息" key={3}  className="xly-bill-list" >
                  <StaticEditTable {...checkTableProps} setOpterationColumn="Y" noVlist />
                  </TabPane> : ''
                }
              </Tabs>
            </div>
            <div style={{ marginTop: '5px', marginLeft: '10px', marginRight: '10px' }}>
              <Tabs onChange={props.onTabChange} className={styles.slaveTabs} tabBarStyle={{ margin: 0 }} >
                <TabPane tab="产量上报人员" className="xly-normal-list xly-normal-list1" key={99}>
                  <StaticEditTable {...employeePropsType} footer="hidden" setOpterationColumn="Y" />
                </TabPane>
                { props.slaveInfoList?.map((item, index) => {
                  const slaveTableProps = slaveTablePropsList[`slaveTable${index}Props`];
                  return (
                    <TabPane tab={item} className="xly-normal-list xly-normal-list1" key={index}>
                      <StaticEditTable {...slaveTableProps} footer="hidden" setOpterationColumn="Y" />
                    </TabPane>)
                }) }
              </Tabs>
            </div>
          </Content>
        </Layout>
      </Layout>
      {
        props.sParamsModalVisible ?
          <AntdDraggableModal
            width="800px"
            className="paramModal"
            title={sReportParams}
            visible={props.sParamsModalVisible}
            onOk={props.onReportParamsOk}
            onCancel={props.onCancelModal.bind(this, 'sParamsModalVisible')}
            // footer={null}
          >
            <div className="xly-bill-list" >
              <StaticEditTable {...sParamProps} footer="hidden" noVlist />
            </div>
          </AntdDraggableModal> : ''
      }
    </Form>
  );
});

export default CommonBase(CommonSales(ProductionReport));
