/* eslint-disable prefer-destructuring */
/**
 * Created by mar105 on 2019-03-27.
 */
import React, { Component } from 'react';
import { Toast, Modal, TextareaItem, List } from 'antd-mobile-v2';
import { history } from 'umi';
import * as commonUtils from '../../utils/utils'; /* 通用方法 */
import commonConfig from '../../utils/config';
import * as commonFunc from '../../components/Common/commonFunc';
import * as commonServices from '../../services/services';

const alert = Modal.alert;

export default (ChildComponent) => {
  return class extends Component {
    constructor(props) {
      super(props);
      this.state = {
        textAreaContent: '',
      };
    }

    async componentWillReceiveProps(nextProps) {
      const {
        formData, formRoute,
      } = nextProps;
      const {
        slaveConfig: slaveConfigOld, searchSolution, returnFilterCondition, returnFilterName, sModelsType,
      } = nextProps;
      if (commonUtils.isEmptyObject(slaveConfigOld) && formData.length > 0 && (searchSolution !== undefined || nextProps.bNotSearch
      )) {
        /* 数据Id */
        const slaveConfig = formData[0];
        let filterCondition = [];
        let iIndex = searchSolution?.findIndex(item => item.bDefault) || -1;
        iIndex = iIndex > -1 ? iIndex : commonUtils.isEmptyArr(searchSolution) ? -1 : 0;
        if (iIndex > -1 && !commonUtils.isEmpty(searchSolution[iIndex].sCondition)) {
          filterCondition = JSON.parse(searchSolution[iIndex].sCondition);
        }
        if (commonUtils.isNotEmptyArr(returnFilterCondition)) {
          filterCondition = returnFilterCondition;
        }
        let addState = await this.handleGetData(slaveConfig, filterCondition, 1, true);
        /* 如果是内部报工单据回刷过来的数据，则需要判断结果集是否有值；若没值 则清空搜索框的内容 查询全部数据  */
        if (commonUtils.isNotEmptyArr(returnFilterCondition) && sModelsType === 'mobile/productionReport') {
          if (commonUtils.isNotEmptyObject(addState)) {
            const slaveData = addState.slaveData;
            if (commonUtils.isEmptyArr(slaveData)) {
              const iRemoveIndex = filterCondition.findIndex(item => item.bFilterName === returnFilterName);
              if (iRemoveIndex > -1) {
                filterCondition[iRemoveIndex].bFilterValue = '';
                returnFilterCondition[iRemoveIndex].bFilterValue = '';
                addState = await this.handleGetData(slaveConfig, filterCondition, 1, true); /* 若结果集查出来没有数据 则查询全部数据 */
                addState.clearSearchValue = true; /* 清除搜索框数字 */
              }
            } else {
              addState.clearSearchValue = false; /* 清除搜索框数字 */
            }
          }
        }

        this.props.onSaveState({
          masterConfig: slaveConfig,
          slaveConfig,
          pageLoading: false,
          masterData: { bCheck: true },
          ...addState,
        });
      }
      if (formRoute === '/myself') {
        if (commonUtils.isEmptyObject(slaveConfigOld) && formData.length > 0) {
          const slaveConfig = formData[0];
          const isWait = true;
          const addState = (await this.props.handleGetDataSet({
            name: 'slave',
            configData: slaveConfig,
            condition: {},
            isWait,
          }));
          addState.slaveConfig = slaveConfig;
          this.props.onSaveState({ ...addState });
        }
      }
    }


    shouldComponentUpdate(nextProps) {
      const { slaveConfig } = nextProps;
      return commonUtils.isNotEmptyObject(slaveConfig);
    }

    /**   获取表数据   */
    handleGetData = async (slaveConfig, slaveFilterCondition, page, isWait) => {
      const { conditonValues } = this.props;
      const pageNum = commonUtils.isEmpty(page) ? 1 : page;
      const bFilter = [];
      if (commonUtils.isEmptyArr(slaveFilterCondition)) {
        const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.bFind);
        if (iIndex > -1) {
          bFilter.push({ bFilterName: slaveConfig.gdsconfigformslave[iIndex].sName, bFilterCondition: 'like', bFilterValue: '' });
        }
      } else {
        bFilter.push(...slaveFilterCondition);
      }
      if (this.props.sModelsId === '101251240115015881530120160' && !commonUtils.isEmpty(this.props.app.sMachineId)) { // 待产量上报
        bFilter.push({
          bFilterName: 'sMachineId_s_pro',
          bFilterCondition: '=',
          bFilterValue: this.props.app.sMachineId,
        });
      }
      const condition = { pageNum, pageSize: commonConfig.pageSize, bFilter };
      if (commonUtils.isNotEmptyObject(conditonValues)) {
        condition.sSqlCondition = conditonValues;
      }
      const addState = (await this.props.handleGetDataSet({
        name: 'slave',
        configData: slaveConfig,
        condition,
        isWait,
      }));
      return addState;
    };

    handleCopyToClick = async (name) => {
      const {
        slaveConfig, dispatch, slaveFilterCondition, slavePagination, slaveOrderBy, app, slaveData, slaveSelectedRowKeys, token, sModelsId, formRoute, sModelsType,
      } = this.props;
      const copyToConfig = slaveConfig.gdsconfigformslave.filter(item => (item.sControlName.includes(name)));
      const getData = this.handleGetData;

      let listFilterName = '';
      const showName = [];
      /* 找到搜索框呈现的字段 然后赋值在搜索框里  */
      if (commonUtils.isNotEmptyArr(slaveFilterCondition)) {
        slaveFilterCondition.forEach((item) => {
          const iIndex = slaveConfig.gdsconfigformslave.findIndex(i => i.sName === item.bFilterName);
          if (iIndex > -1) {
            showName.push(slaveConfig.gdsconfigformslave[iIndex].sName);
          }
        });
        if (commonUtils.isNotEmptyArr(showName)) {
          listFilterName = showName[0];
        }
      }
      const sendSocketMessage = this.props.handleSendSocketMessage;
      if (copyToConfig.length > 0) {
        const { sActiveId } = copyToConfig[0];
        const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}`;
        let copyTo = {};
        copyTo.name = copyToConfig[0].sControlName;
        copyTo.config = copyToConfig;
        copyTo.listFilterCondition = slaveFilterCondition; /* 列表的搜索条件 如搜索001 点击了复制到 则把001搜索条件同步传到单据 当回刷列表时 在带回来 */
        copyTo.listModelsId = sModelsId; /* 列表sModelsId */
        copyTo.listModelsType = sModelsType; /* 列表sModelsType */
        copyTo.listUrl = formRoute; /* 列表路由 */
        copyTo.listFilterName = listFilterName;
        const copyToData = [];
        if (!slaveConfig.bMutiSelect && false) { // 是否多选
          copyTo.masterData = name;
          copyTo.slaveData = [name];

          if (commonUtils.isNotEmptyObject(copyTo.name) && copyTo.name.toLowerCase().includes('tmpinfobysql')) { /* 根据配置下拉sql获取数据源 */
            copyTo = await this.props.onTmpInfoBySql(copyToConfig, copyTo.slaveData, copyTo);
          }
          dispatch({
            type: 'content/onRouterMobile',
            payload: {
              urlKey: sNameUrl,
              sModelsId: sActiveId,
              name,
              copyTo,
              refresh: getData.bind(this, slaveConfig, slaveFilterCondition, commonUtils.isEmpty(slavePagination) ? 0 : slavePagination.current, slaveOrderBy), /*   刷新方法   */
            },
          });
          sendSocketMessage('copy', 'execute', name.sSlaveId, app.userinfo.sId, null, null);
        } else if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
          slaveData.filter(item => slaveSelectedRowKeys.toString().includes(item.sSlaveId)).forEach((item) => {
            copyToData.push(item);
          });
          copyTo.masterData = copyToData[0];
          copyTo.slaveData = copyToData;

          if (commonUtils.isNotEmptyObject(copyTo.name) && copyTo.name.toLowerCase().includes('tmpinfobysql')) { /* 根据配置下拉sql获取数据源 */
            copyTo = await this.props.onTmpInfoBySql(copyToConfig, copyTo.slaveData, copyTo);
          }

          // 不重复字段处理 例如 复制到时只能同一客户复制到
          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 : '';
              Toast.fail(commonFunc.showMessage(app.commonConst, 'pleaseChooseSame') + sNotRepeatShowName); // 请选择相同
              return;
            }
          }
          this.props.app.webSocket.onmessageTmp = (msg) => {
            const rtmsg = JSON.parse(msg.data);
            if (rtmsg.action === 'execute') {
              if (rtmsg.msg === 'continue') {
                if (commonUtils.isNotEmptyArr(copyToData)) {
                  dispatch({
                    type: 'content/onRouterMobile',
                    payload: {
                      urlKey: sNameUrl,
                      sModelsId: sActiveId,
                      copyToData,
                      copyTo,
                      refresh: getData.bind(this, slaveConfig, slaveFilterCondition, commonUtils.isEmpty(slavePagination) ? 0 : slavePagination.current, slaveOrderBy), /*   刷新方法   */
                    },
                  });
                } else {
                  Toast.fail(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); // 请选择相同
                }
              } else {
                Toast.fail(rtmsg.handlers + commonFunc.showMessage(app.commonConst, 'InOperation')); /* 在操作,请稍后再操作! */
              }
            }
          };
          const tbSuffix = '';
          const dataUrl = `${commonConfig.server_host}bill/billCopyToCheck/?sModelsId=${sModelsId}&sActiveId=${sActiveId}&tbSuffix=${tbSuffix}`;
          const values = { sSlaveId: slaveSelectedRowKeys.toString() };
          const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
          if (dataReturn.code === 1) {
            if (dataReturn.dataset.rows.length > 0) {
              alert('Warn', commonFunc.showMessage(app.commonConst, 'beUsedToNew'), [
                {
                  text: 'Ok',
                  onPress: () => {
                    sendSocketMessage('copy', 'execute', slaveSelectedRowKeys.toString(), app.userinfo.sId, null, null);
                  },
                },
                { text: 'Cancel' },
              ]);
            } else {
              sendSocketMessage('copy', 'execute', slaveSelectedRowKeys.toString(), app.userinfo.sId, null, null);
            }
          }
        } else {
          Toast.fail(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); // 请选择数据
        }
      }
    };

    handleDoubleClick = async (record) => {
      const {
        slaveConfig,
        dispatch,
        slaveFilterCondition,
        slavePagination,
        slaveOrderBy,
        sModelsType,
        treeFilterCondition,
        app,
      } = 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' && sModelsType !== 'commonList/msg') {
          [{ sActiveId }] = picArr;
        } 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}`;
        dispatch({
          type: 'content/onRouterMobile',
          payload: {
            refresh: getData.bind(this, slaveConfig, slaveFilterCondition, commonUtils.isEmpty(slavePagination) ? 0 : slavePagination.current, slavePagination.pageSize, slaveOrderBy, undefined, undefined, undefined, treeFilterCondition), /*   刷新方法   */
            urlKey: sNameUrl,
            sModelsId: sActiveId,
            name: record,
            checkedId: record.sId,
          },
        });
      }
    };
    /**   表单回带   */
    handleForm = (form) => {
      this.form = form;
    };

    handleCheckboxChange = (e, selectedKey) => {
      const { slaveSelectedRowKeys: slaveSelectedRowKeysOld, slaveConfig } = this.props;
      let slaveSelectedRowKeys;
      if (commonUtils.isEmptyArr(slaveSelectedRowKeysOld)) {
        slaveSelectedRowKeys = [];
      } else {
        slaveSelectedRowKeys = [...slaveSelectedRowKeysOld];
      }
      if (slaveConfig.bMutiSelect) { /* 多选 */
        if (e.target.checked) {
          slaveSelectedRowKeys.push(selectedKey);
        } else {
          const iIndex = slaveSelectedRowKeys.findIndex(item => item === selectedKey);
          slaveSelectedRowKeys.splice(iIndex, 1);
        }
      } else { /* 单选:选择唯一 */
        // eslint-disable-next-line no-lonely-if
        if (e.target.checked) {
          slaveSelectedRowKeys = [];
          slaveSelectedRowKeys.push(selectedKey);
        } else {
          const iIndex = slaveSelectedRowKeys.findIndex(item => item === selectedKey);
          slaveSelectedRowKeys.splice(iIndex, 1);
        }
      }
      this.props.onSaveState({
        slaveSelectedRowKeys,
      });
    };
    /* 工单打印预览功能 */
    handlePrintView = (e, rowData, showConfig) => {
      const printPdf = showConfig.sControlName; /* 工单号配置调到打印界面，跳转打印页面 */
      const sActiveKey = showConfig.sActiveKey;/* 弹出界面对应数据主字段 */
      if (commonUtils.isNotEmptyObject(printPdf) && printPdf === 'printPdf' && commonUtils.isNotEmptyObject(sActiveKey)) {
        const token = this.props.app.token;
        const sActiveId = showConfig.sActiveId === '1' ? commonUtils.isEmpty(rowData.sFormId) ? rowData.sSrcFormId : rowData.sFormId : showConfig.sActiveId;
        const printsId = rowData[sActiveKey];
        const urlPrint = `${commonConfig.file_host_ebc}printReport/printPdfByFromDataId/${printsId}.pdf?sModelsId=${sActiveId}&sId=${printsId}&token=${encodeURIComponent(token)}`;
        const param = { urlPrint };
        // this.props.dispatch(history.push({ pathname: '/indexMobile/printPdf', state: { sParam: commonUtils.convertObjToStr(param) } }));
        this.props.dispatch(history.push('/indexMobile/printPdf', commonUtils.convertObjToStr(param)));
      }
    }
    /** 按钮操作事件 */
    handleButtonClick = (name) => {
      if (name.indexOf('BtnCopyTo') > -1) { /* 复制到 */ // && commonUtils.isNotEmptyStr(e.item.props.sActiveId)
        this.handleCopyToClick(name);
      } else if (name.includes('BtnForceComplete')) {
        this.handleForceComplete();
      } else if (name === 'BtnRefresh') {
        const {
          slaveConfig, slavePagination, slaveFilterCondition, sModelsType, slaveSelectedRowKeys, slaveSelectedData,
        } = this.props;
        /* 手机端工序报工，点开工之后，在再点完工，刷新不去除勾选 */
        if (sModelsType === 'mobile/productionReport') {
          this.props.onSaveState({
            slaveSelectedRowKeys, slaveSelectedData, loading: false,
          });
        } else {
          this.props.onSaveState({
            clearArray: [], searchText: '', slaveSelectedRowKeys: [], slaveSelectedData: [], slaveInfoSelectedRowKeys: [], slaveInfoSelectedData: [], treeSelectedKeys: [], treeFilterCondition: [], loading: false,
          });
        }
        if (slavePagination === undefined) return;
        this.handleGetData(slaveConfig, slaveFilterCondition); /*   刷新方法   */
        /* 判断是否要加载过滤树数据 */
        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 === 'BtnBatchExamine') {
        /* 批量审核 */
        this.handleBatchExamine();
      } else if (name === 'BtnBatchCancelExamine') {
        /* 批量销审 */
        this.handleBatchCancelExamine();
      } else if (name === 'BtnAdd') {
        this.handleAdd();
      } else if (name === 'BtnScanFace') {
        console.log(this.props, 'BtnScanFace');
        
      }
    };

     /**  点击新增按钮   */
    handleAdd = () => {
      const {
        slaveConfig, dispatch, slaveFilterCondition, slavePagination, slaveOrderBy, formRoute,
      } = 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}`;
        let copyTo = {};

        dispatch({
          type: 'content/onRouterMobile',
          payload: {
            urlKey: sNameUrl,
            sModelsId: sActiveId,
            copyToData: undefined,
            copyTo,
            refresh: getData.bind(this, slaveConfig, slaveFilterCondition, commonUtils.isEmpty(slavePagination) ? 0 : slavePagination.current, slaveOrderBy), /*   刷新方法   */
          },
        });
      }
    };

    handleForceComplete = () => {
      const { slaveSelectedRowKeys, app } = this.props;
      if (commonUtils.isEmptyObject(slaveSelectedRowKeys)) {
        Toast.info(commonFunc.showMessage(app.commonConst, 'pleaseChooseData')); // 请选择记录
      } else {
        const { getFieldProps } = this.form;
        alert(
          '详细',
          <List>
            <TextareaItem
              {...getFieldProps('note1')}
              rows={4}
              onChange={this.handleChangeTextarea.bind(this)}
              placeholder="请输入..."
            />
          </List>,
          [
            { text: '关闭', onPress: () => console.log('cancel') },
            { text: '确定', onPress: () => this.handleToForceComplete(this.state.textAreaContent) },
          ],
        );
      }
    }
    /* 批量审核 */
    handleBatchExamine = () => {
      this.handleAudit(1);
    };

    /* 批量消审 */
    handleBatchCancelExamine = () => {
      this.handleAudit(0);
    };
    handleChangeTextarea = (e) => {
      this.setState({
        textAreaContent: e,
      });
    }
    /**   toolbar批量审核(消审)   */
    handleAudit = async (flag) => {
      /*   待用数据声明   */
      const {
        slaveSelectedRowKeys, app, slaveConfig, slavePagination, slaveFilterCondition, slaveOrderBy, slaveData,
      } = this.props;
      /*   作废订单不能审核   */
      const slaveSelectedData = slaveData.filter(item => slaveSelectedRowKeys.includes(item.sSlaveId));
      const check = commonFunc.showMessage(app.commonConst, 'BtnExamine');/* 审核 */
      const checkChancel = commonFunc.showMessage(app.commonConst, 'BtnCancelExamine');/* 销审 */
      const msgShow = flag ? check : checkChancel;
      if (commonUtils.isNotEmptyArr(slaveSelectedData)) {
        // const slaveSelectedDataNew = this.deteleObject(slaveSelectedData); // 删除sid重复的数据
        let allMsg = '';
        let allErrorMsg = '';
        for (const child of slaveSelectedData) {
          if (child.bInvalid) {
            Toast.fail(`已作废的单据${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 += '';
          }
        }
        if (commonUtils.isNotEmptyStr(allMsg)) {
          Toast.fail(msgShow + allMsg);
        }
        if (allErrorMsg !== undefined && commonUtils.isNotEmptyStr(allErrorMsg)) {
          Toast.fail(allErrorMsg);
        }
        this.handleGetData(slaveConfig, slaveFilterCondition, slavePagination.current, slavePagination.pageSize, slaveOrderBy, true); /*   刷新方法   */
      } else {
        Toast.fail(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;
      }
    };
    handleToForceComplete = async (sValue) => {
      const {
        app, slaveSelectedRowKeys, slaveConfig, sModelsId, slaveInfoSelectedRowKeys, formRoute, slaveFilterCondition,
      } = this.props;

      const { token } = app;
      const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnForceComplete' || item.sControlName === 'BtnNoPurchase');
      const btnConfig = slaveConfig.gdsconfigformslave[iIndex];
      // debugger
      const sRelation = btnConfig.sRelation;

      let selectedRowKeys = '';
      if (formRoute === '/indexPage/materialRequirementsPlanning') {
        selectedRowKeys = slaveInfoSelectedRowKeys.toString();
      } else {
        selectedRowKeys = slaveSelectedRowKeys.toString();
      }
      const value = {};
      value.textareaValue = sValue;
      const url = `${commonConfig.server_host}bill/billForceComplete?sModelsId=${sModelsId}&sName=${formRoute}`;
      const values = { sqlParam: sRelation, sId: selectedRowKeys, sReason: value };

      const masterReturn = (await commonServices.postValueService(token, values, url)).data;
      if (masterReturn.code === 1) {
        Toast.success(masterReturn.msg);
        this.handleGetData(slaveConfig, slaveFilterCondition);
      } else {
        this.props.getServiceError(masterReturn);
      }
    }

    handleSelectAllClick = (e) => {
      const { slaveData } = this.props;
      const slaveSelectedRowKeys = [];
      if (e.target.checked) {
        slaveData.forEach((item) => {
          slaveSelectedRowKeys.push(item.sSlaveId);
        });
      }
      this.props.onSaveState({
        slaveSelectedRowKeys,
      });
    };
    render() {
      return (
        <ChildComponent
          {...this.props}
          {...this.state}
          onReturnForm={this.handleForm}
          onGetData={this.handleGetData}
          onCopyToClick={this.handleCopyToClick}
          onPrintView={this.handlePrintView}
          onCheckboxChange={this.handleCheckboxChange}
          onButtonClick={this.handleButtonClick}
          onDoubleClick={this.handleDoubleClick}
          onSelectAllClick={this.handleSelectAllClick}
        />
      );
    }
  };
};
