/*
 * Create:      柿子
 * CreateDate:  2023/01/12
 * Describe：   订单审核公共配置组件(支持父子表上下结构查询|单表选择列操作等|主列表导出，查询条件可单独出来或者包裹在主列表中) - 医院退货审核（VisualReturnReview） / 集团退货审核
 * */
import React, { Component } from 'react';
import { Card, Button, message, Row, Col, Spin, Input, Select, Modal, Progress, Tag } from 'antd';
import { Util } from 'tools';
import { handleExcel } from 'tools/handleExcel';
import store from 'store';
import PubilcTablePagination from 'pages/common/PubilcTablePagination.jsx';
import DynamicRenderingForm from 'pages/common/DynamicRenderingForm';
import OrderDetailsQuery from 'pages/optometry/component/OrderDetailsQuery';
import MatchingDetails from 'pages/optometry/glassesManagement/component/MatchingDetails';
import iconInquire from 'assets/images/icon_Inquire.png';
import iconListvisits from 'assets/images/icon_listvisits.png';
import './style/index.less';

class OrderReviewComponent extends Component {
  constructor(props) {
    super(props);
    let userData = React.$getSessionData();
    this.state = {
      userData,
      categoryData: {},
      selectData: {},
      queryFormData: [],
      queryHeight: 64,
      page: 1,
      pageSize: 10,
      total: 0,
      loading: false,
      tableData: [],
      totalWidth: 0,
      columns: [],
      selectedRowKeys: [],
      selectedRows: [],
      detailPage: 1,
      detailPageSize: 10,
      detailTotal: 0,
      detailLoading: false,
      detailTableData: [],
      detailTotalWidth: 0,
      detailColumns: [],
      rowID: '',
      rowData: {},
      spinLoading: true,
      detailRowID: '',
      exportLoading: false,
      recordSaveLoading: false,
      successCount: 0,
      errorCount: 0,
      fullLoading: false,
      percentCount: 0,
      busTypeSelectData: [], // 业务类型下拉数据
      ERPExportFlag: 'N', // ERP导出按钮控制
      ERPExportLoading: false,
      columnsObj: {}, // 暂存表头数据
      currentMainComponentName: '', // 当前主表组件名
    };
    this.queryRef = React.createRef();
    this.percentTimer = null;
  }

  componentDidMount() {
    let newCategory;
    if ('paras' in this.props && this.props.paras && this.props.paras.params) { // 侧菜单获取类别参数
      newCategory = this.props.paras.params;
    } else {
      if ('location' in this.props && this.props.location.state && this.props.location.state.params) { // 头菜单获取类别参数
        newCategory = this.props.location.state.params;
        React.$setSessionData('OrderReviewComponent', newCategory, false);
      } else { // 头菜单刷新界面时获取类别
        newCategory = React.$getSessionData('OrderReviewComponent', false);
      }
    }
    let categoryData = Util.getObjByUrlStr(newCategory);
    console.log('OrderReviewComponent', categoryData)
    let defaultPageSize = categoryData?.paginationSize === 'large' ? (categoryData?.defaultPageSize || 50) : (categoryData?.defaultPageSize || 10); // 默认条数
    let defaultDetailPageSize = categoryData?.detailPaginationSize === 'large' ? (categoryData?.defaultDetailPageSize || 50) : (categoryData?.defaultDetailPageSize || 10); // 明细列表默认条数
    this.setState({ categoryData, pageSize: defaultPageSize, detailPageSize: defaultDetailPageSize }, () => {
      this.getSelectData();
      this.getDetailTableColumns();
    });
  }

  // 组件销毁前将静止让setState修改state的状态
  componentWillUnmount() {
    this.percentTimer && clearInterval(this.percentTimer);
    this.setState = (state, callback) => { return; }
  }

  // 获取下拉框数据
  getSelectData = async () => {
    try {
      let { userData, categoryData } = this.state;
      if (!(categoryData && categoryData.selectCode)) {
        this.getTableColumns('Y');
        return
      };
      let data = {
        params: [{
          hospID: userData?.hospID || '',
          groupType: categoryData?.groupType || undefined, //  H 医院   G集团
          componentName: categoryData?.componentName || undefined, // 组件名
        }]
      }
      let res = await React.$asyncPost(this, categoryData.selectCode, data);
      this.setState({ selectData: res.result }, () => {
        this.getTableColumns('Y');
      });
    } catch (error) {
      this.getTableColumns('Y');
    }
  }

  // 获取表头数据
  getTableColumns = async (isQuery) => {
    try {
      const { categoryData } = this.state;
      if (!(categoryData && categoryData.componentName)) {
        message.error('主列表数据还未配置呢，快去配置先！');
        this.setState({ spinLoading: false });
        return;
      }
      this.postTableColumns(categoryData?.componentName || '', isQuery, 'Y');
    } catch (error) {
      console.log(error)
    }
  };

  postTableColumns = async (componentName, isQuery, isInit) => {
    try {
      const { selectData } = this.state;
      let data = {
        params: [{
          compontName: componentName,
          type: 'C',
        }]
      }
      let res = await React.$asyncPost(this, '01040073', data);
      let columns = res.result?.C || [];
      if (columns && columns.length > 0) {
        let colSpanCount = 1, colSpanLinkValue = ''; // 合并单元格操作(栗子参照物品销售统计)
        for (let i = 0; i < columns.length; i++) {
          if (columns[i]?.linkMethod === 'colSpanVal') {
            colSpanLinkValue = columns[i]?.linkService || '';
          }
          if (columns[i]?.linkMethod === 'colSpan_child' || (columns[i] && columns[i]?.linkMethod === 'colSpanVal_child' && 'linkService' in columns[i] && columns[i].linkService)) {
            colSpanCount += 1;
          }
        }
        columns = columns.map(item => {
          let dataIndex = item?.dataIndex || '';
          let linkService = item?.linkService || '';
          return {
            ...item,
            render: (text, record, index) => {
              if (item?.linkMethod === 'Input') {
                return (
                  <Input
                    allowClear
                    placeholder="请输入"
                    style={{ width: '96%' }}
                    value={record && dataIndex in record ? record[dataIndex] : undefined}
                    onChange={(e) => this.handleInputChange(index, e.target.value, item, record, e)}
                    onBlur={() => this.handleLogisticsSave(record)}
                    onClick={(e) => React.$stopPropagation(e)}
                  />
                )
              } else if (item?.linkMethod === 'Select') {
                let selectAttr = { // 下拉框属性
                  allowClear: true,
                  showSearch: true,
                  style: { width: '96%' },
                  optionFilterProp: "seachprop",
                  placeholder: '请选择',
                  value: record && dataIndex in record ? record[dataIndex] : undefined,
                  onChange: (e) => this.handleInputChange(index, e, item, record, e),
                  onClick: (e) => React.$stopPropagation(e)
                };
                let selectOption = linkService && selectData[linkService] && Array.isArray(selectData[linkService]) ? React.$SelectOptions(selectData[linkService]) : '';
                return (
                  <Select {...selectAttr}>
                    {selectOption}
                  </Select>
                )
              } else if (item?.linkMethod === 'colSpan' || (item?.linkMethod === 'colSpanVal' && text && typeof (text) === 'string' && linkService && typeof (linkService) === 'string' && linkService.split('&').indexOf(text) > -1)) { // 现仅供物品销售统计
                return {
                  children: <span style={{ textAlign: text && typeof (text) === 'string' && (text.indexOf('合计') > -1 || text.indexOf('小计') > -1) ? 'right' : '', display: 'inline-block', width: '100%' }}>{text}</span>,
                  props: {
                    colSpan: colSpanCount || 1,
                  },
                };
              } else if (item?.linkMethod === 'colSpan_child' || (item?.linkMethod === 'colSpanVal_child' && linkService && record[linkService] && typeof (record[linkService]) === 'string' && colSpanLinkValue.split('&').indexOf(record[linkService]) > -1)) {
                return {
                  props: {
                    colSpan: 0,
                  },
                };
              } else if (item?.linkMethod.indexOf('rowSpan') > -1) {
                const currentIndex = this.state.tableData.findIndex(item => item.key === record.key);
                // 如果当前记录不是该名字的第一条，则设定 rowSpan 为 0（即隐藏此单元格）
                if (text && currentIndex > 0 && this.state.tableData[currentIndex - 1][dataIndex] === text) {
                  return {
                    props: {
                      rowSpan: 0,
                    },
                  };
                }
                let rowCount = 1;
                // 计算该名字有多少条记录，并设置 rowSpan 的值
                while (this.state.tableData[currentIndex + rowCount] && text && this.state.tableData[currentIndex + rowCount][dataIndex] === text) {
                  rowCount++;
                }
                return {
                  children: <span style={{ textAlign: text && typeof (text) === 'string' && (text.indexOf('合计') > -1 || text.indexOf('小计') > -1) ? 'right' : '', display: 'inline-block', width: '100%' }}>{text}</span>,
                  props: {
                    rowSpan: rowCount,
                  },
                };
              } else if (item?.linkMethod === 'viewOrderList') {
                return <span className="span" onClick={() => this.handleViewOrderList(record, dataIndex)}>{text}</span>
              } else {
                return <span style={{ textAlign: text && typeof (text) === 'string' && (text.indexOf('合计') > -1 || text.indexOf('小计') > -1) ? 'right' : '', display: 'inline-block', width: '100%' }}>{text}</span>;
              }
            },
          }
        });
        let totalWidth = res.totalWidth;
        this.state.columnsObj[componentName] = columns;
        this.state.columnsObj[componentName + 'TotalWidth'] = totalWidth;
        this.setState({
          columns,
          totalWidth,
          currentMainComponentName: componentName, // 当前操作的主表组件名称
        })
      }
      if (isInit === 'Y') { // 初始化加载
        let nFormData = res.result?.formData || [];
        let busTypeSelectData = [];
        for (var i = 0; i < nFormData.length; i++) {
          let methodName = nFormData[i]?.methodName || '';
          if (nFormData[i].className === 'auditStatus' || nFormData[i].className === 'aduitStatus') { // 医院退货审核/集团退货审核 -> 审核状态
            nFormData[i].detailItem = [{
              id: methodName || 'N',
              descripts: '未审核',
            }, {
              id: methodName ? String((parseInt(methodName) + 10)) : 'Y',
              descripts: '已审核',
            }];
          }
          if (nFormData[i].className === 'receiveStatus') { // 转移接收(护理液等) -> 接收状态
            nFormData[i].detailItem = [{
              id: methodName || 'N',
              descripts: '未接收',
            }, {
              id: methodName ? String((parseInt(methodName) + 10)) : 'Y',
              descripts: '已接收',
            }];
          }
          if (methodName === 'ERPExportFlag') {
            nFormData[i].callBackResult = 'Fn';
            nFormData[i].changeCallBack = this.handleBusTypeChange; // 切换业务类型控制ERP导出按钮是否展示
            busTypeSelectData = selectData[nFormData[i]?.className || 'busType'] || [];
          }
          if (methodName === 'columnChange') { // 表头数据切换切换
            nFormData[i].callBackResult = 'Fn';
            nFormData[i].changeCallBack = this.handleColumnChange;
          }
        }
        this.setState({ queryFormData: nFormData, busTypeSelectData }, () => {
          if (this.state.queryFormData && this.state.queryFormData.length > 0) {
            this.setState({ queryHeight: this.queryRef?.current?.clientHeight || 64 });
          }
          if (busTypeSelectData && Array.isArray(busTypeSelectData) && busTypeSelectData.length > 0) { // 存在默认数据自动执行一次
            let busTypeDefaultVal = Util.returnDataCccordingToAttributes(busTypeSelectData, 'Y', 'default')?.id || ''; // 获取默认业务类型ID
            busTypeDefaultVal && this.handleBusTypeChange(busTypeDefaultVal)
          }
        });
      }
    } catch (error) {
      console.log(error);
    }
    if (isQuery === 'Y') { // 自动查询标志
      this.setState({ spinLoading: false }, () => {
        setTimeout(() => {
          this.getTableData();
        }, 300)
      });
    };
  }

  // 业务类型切换
  handleBusTypeChange = (e) => {
    const { busTypeSelectData } = this.state;
    if (busTypeSelectData && Array.isArray(busTypeSelectData) && busTypeSelectData.length > 0) {
      let ERPExportFlag = Util.returnDataCccordingToAttributes(busTypeSelectData, e, 'id')?.ERPExportFlag || 'N';
      this.setState({ ERPExportFlag });
    }
  }

  // 查看订单列表
  handleViewOrderList = (record, dataIndex) => {
    const { categoryData } = this.state;
    let values = this.queryFormRef && this.queryFormRef.getFieldsValue();
    let queryCode = categoryData?.orderQueryModalCode || '';
    if (!queryCode) {
      message.error('未维护弹窗订单查询接口代码');
      return;
    };
    this.orderQueryRef && this.orderQueryRef.modifyVisible(true, { ...values, record, dataIndex, queryCode });
  }

  // 修改入参
  handleInputChange = (index, val, item, record) => {
    let dataIndex = item?.dataIndex || '';
    let inputType = item?.linkMethod || 'Input';
    if (inputType === 'DatePicker' || item.inputType === 'Date') { // 日期
      record.autoOpenFlag = 'Y'; // 新增时不自动打开日期选择框，选择过一次之后左右键切回来自动打开
      val = val ? moment(val).format(item?.format || dayFormat) : undefined;
    } else if (inputType === 'TimePicker' || inputType === 'Time') { // 时间
      val = val ? moment(val).format(item?.format || timeFormat) : undefined;
    }
    record[dataIndex] = val;
    this.setState({}, () => {
      inputType === 'Select' && this.handleLogisticsSave(record);
    });
  }

  // 保存行数据
  handleLogisticsSave = async record => {
    try {
      const { categoryData } = this.state;
      if (!(categoryData && categoryData.recordSaveCode)) {
        message.error('行数据保存接口还未配置呢，快去配置先！');
        return;
      };
      this.setState({ recordSaveLoading: true });
      let data = {
        params: [{
          ...record
        }]
      }
      let res = await React.$asyncPost(this, categoryData.recordSaveCode, data);
      message.success(res?.errorMessage || '保存成功');
      this.setState({ recordSaveLoading: false }, () => {
        this.getTableData();
      });
    } catch (error) {
      console.log('error', error);
      this.setState({ recordSaveLoading: false });
    }
  }

  // 查询
  handleQuery = () => {
    this.setState({ page: 1 }, () => {
      this.getTableData();
    })
  }

  // 获取列表数据
  getTableData = async (isClear) => {
    try {
      let { pageSize, page, categoryData } = this.state;
      if (!(categoryData && categoryData.queryCode)) {
        message.error('查询接口未配置，快去配置先！');
        return
      };
      let values = await this.queryFormRef.handleSave();
      if (values.error) {
        message.error('请完善必填信息');
        return;
      }
      this.setState({ loading: true });
      let data = {
        params: [{
          ...values,
          groupType: categoryData?.groupType || undefined, //  H 医院   G集团
          componentName: categoryData?.componentName || undefined, // 组件名
        }],
      }
      if (categoryData?.hideMainPaginationFlag !== 'Y') {
        data.pagination = [{
          pageSize,
          currentPage: page
        }]
      }
      let res = await React.$asyncPost(this, categoryData.queryCode, data);
      if (categoryData?.queryDllFlag === 'Y') {
        this.handleCallDllQuery(res, isClear);
      } else {
        let idIndex = categoryData?.idIndex || 'id';
        let tableData = Util.addKeyValueToDataSource(res?.result?.rows || res?.result?.Data || res?.result?.data || res?.result?.Rows || (Array.isArray(res.result) ? res.result : []), idIndex);
        this.setState({ tableData, total: res.result?.total || res.result?.TotalCount || tableData.length, loading: false }, () => {
          isClear !== 'N' ? this.handleClearSelectData() : ''; // 清除操作数据
        });
      }
    } catch (error) {
      console.log('错误', error);
      this.setState({ loading: false });
    }
  }

  // 查询调用动态库
  handleCallDllQuery = async (queryResult, isClear) => {
    try {
      let { pageSize, page, categoryData } = this.state;
      let dllinput = queryResult.result;
      let dllres = await React.$dllPost(categoryData?.dllFuncName || 'PlatformDirectConnect', dllinput, categoryData?.dllPath || 'INSUNew/PTMedInsuInterface.dll', categoryData?.dllClassName || 'PTMedInsuInterface.InsuBusiness');
      if (+dllres.errorCode === 0) {
        let values = this.queryFormRef && this.queryFormRef.getFieldsValue();
        let data = {
          params: [{
            dllres,
            dllinput,
            queryValues: values
          }],
          pagination: [{
            pageSize,
            currentPage: page
          }]
        };
        let res = await React.$asyncPost(this, categoryData.dllQueryCode, data);
        let idIndex = categoryData?.idIndex || 'id';
        let tableData = Util.addKeyValueToDataSource(res.result && 'rows' in res.result ? res.result.rows : (Array.isArray(res.result) ? res.result : []), idIndex);
        this.setState({ tableData, total: res.result?.total || tableData.length, loading: false }, () => {
          isClear !== 'N' ? this.handleClearSelectData() : ''; // 清除操作数据
        });
      }
    } catch (error) {
      console.log('error', error);
      this.setState({ loading: false });
    }
  }

  // 清除操作数据
  handleClearSelectData = () => {
    this.setState({ rowID: '', rowData: {}, detailTableData: [], selectedRowKeys: [], selectedRows: [], detailTotal: 0 });
  }

  // 分页操作
  compilePage = (page, pageSize) => {
    this.setState({ page, pageSize }, () => {
      this.getTableData();
    })
  }

  // 操作行
  onClickRowPublic = (record) => {
    const { categoryData } = this.state;
    let idIndex = categoryData?.idIndex || 'id';
    return {
      // 单击行选中
      onClick: () => {
        if (this.state.rowID === '' || (this.state.rowID && (this.state.rowID !== (record && idIndex in record ? record[idIndex] : record.key)))) {
          this.setState({ rowID: (record && idIndex in record ? record[idIndex] : record.key), rowData: record }, () => {
            this.getDetailTableData();
          });
        } else {
          this.handleClearSelectData();
        }
      }
    }
  }

  // 选中行操作
  setRowClassNamePublic = (record) => {
    const { categoryData } = this.state;
    let idIndex = categoryData?.idIndex || 'id';
    let rowDataColorArr = categoryData && categoryData.rowDataColor ? categoryData.rowDataColor.split(',') : [];
    let colorExpression = '';
    for (let i = 0; i < rowDataColorArr.length; i++) {
      let currentItem = rowDataColorArr[i] && rowDataColorArr[i].indexOf('^') > -1 ? rowDataColorArr[i].split('^') : [];
      if (currentItem && currentItem.length > 2) {
        colorExpression += record[currentItem[0]] === currentItem[1] ? currentItem[2] : ''
      }
    }
    return (record && idIndex in record ? record[idIndex] : record.key) === this.state.rowID ? 'clickRowStyle' : colorExpression;
  }

  // 获取明细列表表头数据
  getDetailTableColumns = async () => {
    try {
      const { categoryData } = this.state;
      if (categoryData?.isShowDetailTable !== 'Y') return;
      let compontName = categoryData?.componentName || '';
      let detailComponentName = categoryData?.detailComponentName || (compontName ? (compontName + 'Detail') : '');
      if (!detailComponentName) {
        message.error('明细列表数据还未配置呢，快去配置先！');
        return;
      }
      let data = {
        params: [{
          compontName: detailComponentName,
          type: 'C',
        }]
      }
      let res = await React.$asyncPost(this, '01040073', data);
      let detailColumns = res.result?.C || [];
      if (detailColumns && detailColumns.length > 0) {
        for (var i = 0; i < detailColumns.length; i++) {
          if (detailColumns[i].dataIndex === 'exchangeDesc') { // 需换货红色字体显示
            detailColumns[i].render = (text, record) => {
              return (
                <span style={{ color: 'red' }}>{text}</span>
              )
            }
          } else if (detailColumns[i].dataIndex === 'urgentSign') { // 加急标志
            detailColumns[i].render = (text, record) => {
              if ((text === '一级加急' || text === '二级加急')) {
                return (
                  <Tag style={{ fontWeight: 'normal' }} color={text === '一级加急' ? '#FF3D00' : (text === '二级加急' ? '#FA8C17' : '')}>{text}</Tag>
                );
              } else {
                return text;
              }
            }
          }
        }
        this.setState({
          detailColumns,
          detailTotalWidth: res.totalWidth
        });
      }
    } catch (error) {
      console.log(error)
    }
  }

  // 查询明细数据
  getDetailTableData = async () => {
    try {
      const { categoryData, rowID, detailPageSize, detailPage } = this.state;
      if (categoryData?.isShowDetailTable !== 'Y') return;
      this.setState({ detailLoading: true });
      let idIndex = categoryData?.idIndex || 'id';
      let queryDetailCode = categoryData?.queryDetailCode || '';
      let detailPaginationFlag = categoryData?.detailPaginationFlag || 'N';
      if (!queryDetailCode) {
        message.error('明细列表查询接口未配置，快去配置先！');
        return;
      };
      let data = {
        params: [{
          [idIndex]: rowID,
          groupType: categoryData?.groupType || undefined, //  H 医院   G集团
          componentName: categoryData?.componentName || undefined, // 组件名
        }]
      }
      if (detailPaginationFlag === 'Y') { // 明细分页
        data.pagination = [{
          pageSize: detailPageSize,
          currentPage: detailPage
        }]
      }
      let res = await React.$asyncPost(this, queryDetailCode, data);
      let detailIDIndex = categoryData?.detailIDIndex || 'key';
      let detailTableData = Util.addKeyValueToDataSource(res.result?.rows || res.result?.detailInfo || res.result?.data || res.result?.Data || res?.result || [], detailIDIndex);
      this.setState({
        detailTableData,
        detailLoading: false,
        detailTotal: res.result?.total || 0
      });
    } catch (error) {
      console.log(error)
      this.setState({ detailLoading: false });
    }
  }

  // 行操作审核
  handleExamine = async (record, e) => {
    React.$stopPropagation(e);
    const { categoryData } = this.state;
    if (!(categoryData && categoryData.examineCode)) {
      message.error('审核接口未配置，快去配置先！');
      return
    };
    if (categoryData?.auditDllFlag === 'Y') { // 调用动态库
      this.handleCallDll(record, categoryData.examineCode);
    } else {
      let idIndex = categoryData?.idIndex || 'id';
      this.handleBatchApproval([record[idIndex]]);
    }
  }

  // 批量审核/接收
  handleBatchApproval = async (batchData) => {
    const { categoryData } = this.state;
    if (!(categoryData && categoryData.examineCode)) {
      message.error('审核接口未配置，快去配置先！');
      return
    };
    if (categoryData?.auditDllFlag === 'Y') { // 调用动态库
      this.handleBatchCallDll(categoryData.examineCode);
      return;
    }
    this.handleBulkOperation(batchData, categoryData.examineCode);
  }

  // 明细列表分页
  handleDetailPageChange = (page, pageSize) => {
    this.setState({ detailPage: page, detailPageSize: pageSize }, () => {
      this.getDetailTableData();
    })
  }

  // 明细行操作
  handleDetailRowClick = (record) => {
    const { categoryData } = this.state;
    let detailIDIndex = categoryData?.detailIDIndex || 'key';
    return {
      // 单击行选中
      onClick: () => {
        if (categoryData?.detailRowClickFlag === 'Y') {
          if (this.state.detailRowID === '' || (this.state.detailRowID && (this.state.detailRowID !== record[detailIDIndex]))) {
            this.setState({ detailRowID: record[detailIDIndex] });
          } else {
            this.setState({ detailRowID: '' })
          }
        }
      },
      onDoubleClick: () => {
        this.handleViewDetails(record)
      }
    }
  }

  handleDetailRowClassName = (record) => {
    const { categoryData } = this.state;
    let detailIDIndex = categoryData?.detailIDIndex || 'key';
    let rowDataColorArr = categoryData && categoryData.detailRowDataColor ? categoryData.detailRowDataColor.split(',') : [];
    let colorExpression = '';
    for (let i = 0; i < rowDataColorArr.length; i++) {
      let currentItem = rowDataColorArr[i] && rowDataColorArr[i].indexOf('^') > -1 ? rowDataColorArr[i].split('^') : [];
      if (currentItem && currentItem.length > 2) {
        colorExpression += record[currentItem[0]] === currentItem[1] ? currentItem[2] : ''
      }
    }
    return record[detailIDIndex] === this.state.detailRowID ? 'clickRowStyle' : colorExpression;
  }

  // 批量修改申请单状态
  modifyApplicationFormStatus = async (statusCode, requestIDArr, compnentSource, remark) => {
    try {
      const { returnFlag, selectedRowKeys } = this.state;
      if (returnFlag === 'orderReturn') { // 集团退回，走保存接口传入40
        this.handleSave(statusCode, remark);
        return;
      }
      let cRequestIDArr = this.getDetailTableRequestID();
      let data = {
        params: [{
          requestIDArr: selectedRowKeys && selectedRowKeys.length > 0 ? selectedRowKeys : cRequestIDArr,
          statusCode,
          remark, // 退回时填写，退回原因
          componentName: categoryData?.componentName || undefined, // 组件名
        }]
      }
      let res = await React.$asyncPost(this, '17030026', data);
      if (returnFlag === 'detailReturn') { // 明细列退回，医院退回
        this.returnOrderRef.modifyVisible && this.returnOrderRef.modifyVisible(false);
      }
      message.success(res.errorMessage || '操作成功');
      this.queryRowDataByID();
    } catch (error) {
      console.log(error)
    }
  }

  // 获取明细列表申请单ID
  getDetailTableRequestID = () => {
    let { detailTableData } = this.state;
    let requestIDArr = [];
    for (var i = 0; i < detailTableData.length; i++) {
      requestIDArr.push(detailTableData[i].glassesRequestID);
    }
    return requestIDArr;
  }

  // 查看详情
  handleViewDetails = (record, e) => {
    React.$stopPropagation(e);
    const { categoryData, rowData } = this.state;
    if (!!(record?.glassesRequestID || record?.requestID)) { // 正常流程可以查看订单详情
      this.matchingDetailsRef && this.matchingDetailsRef.modifyVisible(true, { ...record, suppFlag: categoryData?.componentName || '', statusCode: rowData?.statusCode || '' });
    }
  }

  // 导出 
  handleExport = async () => {
    try {
      let { categoryData, pageSize, page } = this.state;
      if (!(categoryData && categoryData.exportCode)) {
        message.error('导出接口未配置，快去配置先！');
        return
      };
      let values = await this.queryFormRef.handleSave();
      if (values.error) {
        message.error('请完善必填信息');
        return;
      }
      this.setState({ exportLoading: true });
      let data = {
        params: [{
          ...values,
          groupType: categoryData?.groupType || undefined, //  H 医院   G集团
          componentName: categoryData?.componentName || undefined, // 组件名
        }],
        pagination: [{
          pageSize,
          currentPage: page
        }]
      }
      let res = await React.$asyncPost(this, categoryData.exportCode, data);
      if (categoryData?.reactExportERPFlag === 'Y') { // 前端导出ERP标志
        this.handleReactExportData(res);
      } else {
        handleExcel.downloadExcel(res.result);
      }
      this.setState({ exportLoading: false });
    } catch (error) {
      this.setState({ exportLoading: false });
    }
  }

  // 前端导出ERP - 数据量多的情况每次调用固定的条数，分页请求，最后拿到全部数据再导出
  handleReactExportData = async (res) => {
    let tableData = res.result?.rows || [];
    if (tableData && tableData.length > 0) {
      handleExcel.exportExcel(res.result?.columns || [], res.result?.rows || [], res.result?.fileName || '订单审核', '', res.result?.type || 'xlsx', res.result?.sheetName || 'mySheet');
    } else {
      message.error('前端导出异常，请检查返回数据！')
    }
  }

  // 上传
  handleUpload = (record, e) => {
    React.$stopPropagation(e);
    let { categoryData } = this.state;
    if (categoryData?.uploadDllFlag === 'Y') { // 调用动态库
      this.handleCallDll(record, categoryData.uploadCode);
    } else {
      let idIndex = categoryData?.idIndex || 'id';
      this.handleBatchUpload([record[idIndex]]);
    }
  }

  // 批量上传
  handleBatchUpload = async (batchData) => {
    const { categoryData } = this.state;
    if (!(categoryData && categoryData.uploadCode)) {
      message.error('上传接口未配置，快去配置先！');
      return
    };
    if (categoryData?.uploadDllFlag === 'Y') { // 调用动态库
      this.handleBatchCallDll(categoryData.uploadCode);
      return;
    }
    this.handleBulkOperation(batchData, categoryData.uploadCode);
  }

  // 签名
  handleSignature = (record, e) => {
    React.$stopPropagation(e);
    let { categoryData } = this.state;
    if (!(categoryData && categoryData.signatureCode)) {
      message.error('签名接口未配置，快去配置先！');
      return
    };
    if (categoryData?.signatureDllFlag === 'Y') { // 调用动态库
      this.handleCallDll(record, categoryData.signatureCode);
    } else {
      let idIndex = categoryData?.idIndex || 'id';
      this.handleBatchSignature([record[idIndex]]);
    }
  }

  // 批量签名
  handleBatchSignature = (batchData) => {
    const { categoryData } = this.state;
    if (!(categoryData && categoryData.signatureCode)) {
      message.error('签名接口未配置，快去配置先！');
      return
    };
    if (categoryData?.signatureDllFlag === 'Y') { // 调用动态库
      this.handleBatchCallDll(categoryData.signatureCode);
      return;
    }
    this.handleBulkOperation(batchData, categoryData.signatureCode);
  }

  // 取消
  handleCancel = (record, e) => {
    React.$stopPropagation(e);
    let { categoryData } = this.state;
    if (!(categoryData && categoryData.cancelCode)) {
      message.error('取消接口未配置，快去配置先！');
      return
    };
    if (categoryData?.cancelDllFlag === 'Y') { // 调用动态库
      this.handleCallDll(record, categoryData.cancelCode);
    } else {
      let idIndex = categoryData?.idIndex || 'id';
      this.handleBatchCancel([record[idIndex]]);
    }
  }

  // 批量取消
  handleBatchCancel = (batchData) => {
    const { categoryData } = this.state;
    if (!(categoryData && categoryData.cancelCode)) {
      message.error('取消接口未配置，快去配置先！');
      return
    };
    if (categoryData?.cancelDllFlag === 'Y') { // 调用动态库
      this.handleBatchCallDll(categoryData.cancelCode);
      return;
    }
    this.handleBulkOperation(batchData, categoryData.cancelCode);
  }

  // 批量操作
  handleBulkOperation = async (batchData, httpCode) => {
    try {
      const { categoryData, selectedRowKeys, tableData } = this.state;
      let idIndex = categoryData?.idIndex || 'id';
      let idIndexArr = idIndex + 'Arr';
      let currentCheckArr = [];
      if (!(categoryData?.batchAuditBtnFlag === 'Y' || categoryData?.batchIsChecked === 'Y')) { // 如果不是勾选则取当前页数据
        currentCheckArr = tableData && tableData.map(item => item[idIndex]);
      } else {
        currentCheckArr = selectedRowKeys;
      }
      let paramsObj = {
        [idIndexArr]: batchData && batchData.length > 0 ? batchData : currentCheckArr,
        groupType: categoryData?.groupType || undefined, //  H 医院   G集团
        componentName: categoryData?.componentName || undefined, // 组件名
      };
      if (batchData && batchData.length > 0) { // 行内单个操作
        paramsObj[idIndex] = batchData[0];
      }
      let data = {
        params: [{ ...paramsObj }]
      };
      let res = await React.$asyncPost(this, httpCode, data);
      message.success(res?.errorMessage || '操作成功');
      this.setState({ selectedRowKeys: [], selectedRows: [] });
      this.getTableData();
    } catch (error) {
      console.log(error);
    }
  }

  // 调用dll
  handleCallDll = async (record, httpCode, type, index, resolve, reject) => {
    try {
      const { categoryData } = this.state;
      let data = {};
      if (httpCode && httpCode.indexOf('recordData') > -1) { // 上传取行数据
        let dllInputDataIndex = httpCode && httpCode.indexOf('^') > -1 ? httpCode.split('^')[1] : 'dllInput';
        data = record && dllInputDataIndex in record ? record[dllInputDataIndex] : {};
      } else {
        let queryRes = await React.$asyncPost(this, httpCode, {
          params: [{
            ...record
          }]
        })
        if (queryRes.errorCode === '0') {
          data = {
            params: [queryRes?.result?.inputParams],
            businessType: queryRes?.result?.businessType,
            funNO: queryRes?.result?.funNO,
            interfaceinfo: queryRes?.result?.interfaceinfo
          }
        }
      }
      let res = await React.$dllPost(categoryData?.dllFuncName || 'PlatformDirectConnect', data, categoryData?.dllPath || 'INSUNew/PTMedInsuInterface.dll', categoryData?.dllClassName || 'PTMedInsuInterface.InsuBusiness');
      if (res.errorCode === '0') {
        message.success(res.errorMessage || '成功');
        this.handleSaveUploadRecord(res, record, type, index, resolve, reject);
      } else {
        message.error(res.errorMessage || '失败');
        this.handleRecordUploadStatus(index, 'error', resolve, reject);
      }
    } catch (error) {
      console.log(error);
      this.handleRecordUploadStatus(index, 'error', resolve, reject);
    }
  }

  // 批量调用dll
  handleBatchCallDll = (httpCode) => {
    let _this = this;
    const { categoryData, tableData, selectedRows } = this.state;
    let dataList = categoryData?.batchIsChecked === 'Y' ? selectedRows : tableData;
    if (!(dataList && dataList.length > 0)) {
      message.error('请勾选需要操作的数据');
      return;
    }
    this.setState({ fullLoading: true, percentCount: 0 }, () => {
      this.percentTimer = setInterval(() => {
        this.setState({ percentCount: this.state.percentCount + 1 > 99 ? 99 : this.state.percentCount + 1 })
      }, 300);
      async function run() {
        for (let i = 0; i < dataList.length; i++) {
          await _this.httpBatchUpload(dataList[i], httpCode, i);
        }
      }
      run().then((res) => {
        console.log(res, '执行完成');
      })
    })
  }

  httpBatchUpload = async (record, httpCode, index) => {
    let _this = this;
    await Promise.resolve(record, index);
    return await new Promise((resolve, reject) => {
      setTimeout(async () => {
        _this.handleCallDll(record, httpCode, 'all', index, resolve, reject)
      }, 300)
    });
  }

  // 保存上传记录
  handleSaveUploadRecord = async (dllRes, record, type, index, resolve, reject) => {
    try {
      let { categoryData } = this.state;
      if (!(categoryData && categoryData.uploadRecordCode)) {
        this.handleRecordUploadStatus(index, 'success', resolve, reject);
        return;
      };
      let res = await React.$asyncPost(this, categoryData.uploadRecordCode, {
        params: [{
          dllRes,
          recordData: record
        }]
      });
      type === 'all' && this.handleRecordUploadStatus(index, 'success', resolve, reject);
    } catch (error) {
      console.log(error);
      type === 'all' && this.handleRecordUploadStatus(index, 'success', resolve, reject)
    }
  }

  handleRecordUploadStatus = (index, type, resolve, reject) => {
    const { categoryData, tableData, selectedRows } = this.state;
    let dataList = categoryData?.batchIsChecked === 'Y' ? selectedRows : tableData;
    if (type === 'success') {
      this.state.successCount = this.state.successCount + 1;
      resolve && resolve();
    } else {
      this.state.errorCount = this.state.errorCount + 1;
      resolve && resolve();
    }
    this.setState({ percentCount: ((index + 1) / dataList.length) * 100 }, () => {
      const { successCount, errorCount } = this.state;
      if (dataList.length - 1 === index) {
        clearInterval(this.percentTimer);
        Modal.success({
          title: '批量上传完成',
          content: '成功了：' + successCount + '个；失败了：' + errorCount + '个。'
        });
        // 清除操作数据
        this.setState({ successCount: 0, errorCount: 0, fullLoading: false, percentCount: 100 })
      }
    });
  }

  // 获取form表单连带的操作按钮
  getFormBtn = () => {
    const { categoryData, exportLoading, ERPExportLoading, ERPExportFlag } = this.state;
    let btnArr = [{
      col: 1,
      title: '查询',
      typeCode: 'Button',
      type: 'primary',
      marginBottom: 12,
      onClick: this.handleQuery,
    }];
    if (categoryData.exportCode && categoryData?.exportFollowQueryFlag === 'Y') {
      // 正常导出
      if (categoryData.exportCode) {
        btnArr.push({
          col: 1,
          ghost: true,
          loading: exportLoading,
          title: categoryData?.exportBtnTitle || '导出',
          typeCode: 'Button',
          type: 'primary',
          marginLeft: 10,
          marginBottom: 12,
          onClick: this.handleExport,
        })
      }
      // ERP导出
      if (ERPExportFlag === 'Y') {
        btnArr.push({
          col: 2,
          ghost: true,
          loading: ERPExportLoading,
          title: categoryData?.mainListEMRExportBtnTitle || '导出ERP明细',
          typeCode: 'Button',
          type: 'primary',
          marginLeft: 20,
          marginBottom: 12,
          onClick: this.handleERPExport,
        })
      }
    }
    return btnArr;
  }

  // 其他导出 - ERP导出
  handleERPExport = async () => {
    try {
      let { categoryData, queryParams } = this.state;
      if (!(categoryData && categoryData.mainListERPExportCode)) {
        message.error('ERP导出接口未配置，快去配置先！');
        return
      };
      this.setState({ ERPExportLoading: true });
      let patientInfo = this.patientRef && this.patientRef.getPatientInfo();
      let data = {
        params: [{
          ...queryParams,
          ...patientInfo,
          status: categoryData?.groupType || undefined, // 界面标识
          groupType: categoryData?.groupType || undefined,
          compontName: categoryData?.componentName || undefined,
        }]
      }
      let res = await React.$asyncPost(this, categoryData.mainListERPExportCode, data);
      if (categoryData?.ReactExportERPFlag === 'Y') { // 前端导出ERP标志
        let columns = res.result?.columns || [];
        let tableData = res.result?.rows || [];
        if (columns && columns.length > 0 && tableData && tableData.length > 0) {
          handleExcel.exportExcel(columns, tableData, res.result?.fileName || '订单审核', '', res.result?.type || 'xlsx', res.result?.sheetName || 'mySheet');
        } else {
          message.error('前端导出异常，请检查返回数据！');
        }
      } else {
        handleExcel.downloadExcel(res.result);
      }
      this.setState({ ERPExportLoading: false });
    } catch (error) {
      this.setState({ ERPExportLoading: false });
    }
  };

  getRowDataTitleDom = (rowDataTitle) => {
    return (
      <div className="flex-align-items">
        {rowDataTitle && rowDataTitle.split(',').map(((item, index) => {
          let childData = item && item.indexOf('^') > -1 ? item.split('^') : [];
          return (
            <div className="flex-align-items" key={index} style={{ marginRight: '12px', color: '#999', fontWeight: 'normal' }}>
              <span style={{ display: 'inline-block', width: '16px', height: '16px', marginRight: '6px', background: childData && childData.length > 1 ? childData[1] : '#b9eddf', borderRadius: '2px' }}></span>
              {childData && childData.length > 0 ? childData[0] : ''}
            </div>
          )
        }))}
      </div>
    )
  };

  // 表头数据切换change
  handleColumnChange = (e, index, record) => {
    let { columnsObj } = this.state;
    let optionList = record?.detailItem || []; // 当前才做下拉框数据
    let mainComponentName = Util.returnDataCccordingToAttributes(optionList, e,)?.componentName || '';
    if (!mainComponentName) return;
    if (columnsObj && mainComponentName in columnsObj && columnsObj[mainComponentName] && Array.isArray(columnsObj[mainComponentName]) && columnsObj[mainComponentName].length > 0) {
      this.setState({ columns: columnsObj[mainComponentName], totalWidth: columnsObj[mainComponentName + 'TotalWidth'] });
    } else {
      this.postTableColumns(mainComponentName);
    }
  }

  render() {
    let { categoryData, queryFormData, queryHeight, selectData, page, total, loading, tableData, totalWidth, columns, selectedRowKeys, detailLoading, detailTableData, detailTotalWidth, detailColumns, detailPage,
      detailTotal, spinLoading, exportLoading, recordSaveLoading, percentCount, fullLoading, ERPExportFlag, ERPExportLoading, currentMainComponentName
    } = this.state;
    let rowSelection = {
      selectedRowKeys,
      onChange: (selectedRowKeys, selectedRows) => {
        this.setState({
          selectedRowKeys,
          selectedRows
        })
      },
      getCheckboxProps: record => ({
        disabled: categoryData?.currentAuditStatus === 'none' ? false : !((String(record.statusCode) === (categoryData?.currentAuditStatus || '30') || String(record?.statusCode) === (categoryData?.currentCancelStatus || '40'))),
      }),
    };
    let nQueryFormData = queryFormData && queryFormData.length > 0 ? [...queryFormData, ...this.getFormBtn()] : [];
    let detailComponentName = categoryData?.detailComponentName || (categoryData.componentName ? (categoryData.componentName + 'Detail') : '');
    let hideMainPaginationFlag = categoryData?.hideMainPaginationFlag || 'N';
    let detailPaginationFlag = categoryData?.detailPaginationFlag || 'N';

    let operationCount = (categoryData?.auditBtnFlag === 'Y' ? 1 : 0) + (categoryData?.uploadBtnFlag === 'Y' ? 1 : 0) + (categoryData?.signatureBtnFlag === 'Y' ? 1 : 0) + (categoryData?.cancelBtnFlag === 'Y' ? 1 : 0) + (categoryData?.operationViewDetailsFlag === 'Y' ? 1 : 0);
    // 列表操作
    const operationObj = {
      width: parseInt(categoryData?.operationFixedWidth || (operationCount * 80 + 20)),
      title: '操作',
      align: 'center',
      fixed: categoryData?.operationFixedFlag === 'Y' ? 'right' : null,
      key: 'operation',
      render: (text, record) => {
        return (
          <>
            {categoryData?.auditBtnFlag === 'Y' ? <Button
              type="link"
              style={{ padding: '0 8px' }}
              disabled={categoryData?.currentAuditStatus === 'none' ? false : String(record.statusCode) !== (categoryData?.currentAuditStatus || '30')}
              onClick={(e) => this.handleExamine(record, e)}
            >
              {categoryData?.auditBtnTitle || '审核'}
            </Button> : ''}
            {categoryData?.uploadBtnFlag === 'Y' ? <Button
              type="link"
              style={{ padding: '0 8px' }}
              disabled={!categoryData?.currentUploadStatus || categoryData?.currentUploadStatus === 'none' ? false : (String(record.statusCode) !== categoryData?.currentUploadStatus)}
              onClick={(e) => this.handleUpload(record, e)}
            >
              {categoryData?.uploadBtnTitle || '上传'}
            </Button> : ''}
            {categoryData?.signatureBtnFlag === 'Y' ? <Button
              type="link"
              style={{ padding: '0 8px' }}
              disabled={!categoryData?.currentSignatureStatus || categoryData?.currentSignatureStatus === 'none' ? false : (String(record.statusCode) !== categoryData?.currentSignatureStatus)}
              onClick={(e) => this.handleSignature(record, e)}
            >
              {categoryData?.signatureBtnTitle || '签名'}
            </Button> : ''}
            {categoryData?.cancelBtnFlag === 'Y' ? <Button
              type="link"
              style={{ color: !(!categoryData?.currentCancelStatus || categoryData?.currentCancelStatus === 'none' ? false : (String(record.statusCode) !== categoryData?.currentCancelStatus)) ? '#f04134' : '', padding: '0 8px' }}
              disabled={!categoryData?.currentCancelStatus || categoryData?.currentCancelStatus === 'none' ? false : (String(record.statusCode) !== categoryData?.currentCancelStatus)}
              onClick={(e) => this.handleCancel(record, e)}
            >
              {categoryData?.cancelBtnTitle || '取消'}
            </Button> : ''}
            {categoryData?.operationViewDetailsFlag === 'Y' ? <Button
              type="link"
              style={{ padding: '0 8px' }}
              disabled={!(record?.glassesRequestID || record?.requestID)}
              onClick={(e) => this.handleViewDetails(record, e)}
            >
              {categoryData?.viewDetailsBtnTitle || '查看详情'}
            </Button> : ''}
          </>
        )
      },
    };

    let queryOperationCount = (categoryData?.batchAuditBtnFlag === 'Y' ? 1 : 0) + (ERPExportFlag === 'Y' && categoryData?.exportFollowQueryFlag !== 'Y' ? 1 : 0) + (categoryData.exportCode && categoryData?.exportFollowQueryFlag !== 'Y' ? 1 : 0) + (categoryData?.batchUploadBtnFlag === 'Y' ? 1 : 0) + (categoryData?.batchSignatureBtnFlag === 'Y' ? 1 : 0) + (categoryData?.batchCancelBtnFlag === 'Y' ? 1 : 0);
    let queryOperationCol = queryOperationCount ? (queryOperationCount * 2 + (queryOperationCount > 2 ? -2 : 1)) : 0;
    // 查询条件栏
    let queryCard = (
      <div ref={this.queryRef}>
        <Row
          style={{
            paddingRight: !(categoryData?.cardTitle) || categoryData?.independentQueryConditions === 'Y' ? '24px' : 'initial',
            paddingTop: !(categoryData?.cardTitle) || categoryData?.independentQueryConditions === 'Y' ? '16px' : '2px',
            paddingBottom: !(categoryData?.cardTitle) || categoryData?.independentQueryConditions === 'Y' ? '2px' : 'initial'
          }}
        >
          <Col span={24 - queryOperationCol}>
            <DynamicRenderingForm
              className="dynamic-component-form"
              onRef={ref => this.queryFormRef = ref}
              rowData={{}}
              selectData={selectData}
              formData={nQueryFormData && nQueryFormData.map((item => {
                return {
                  ...item,
                  onPressEnter: this.handleQuery
                }
              }))}
            />
          </Col>
          <Col span={queryOperationCol} style={{ textAlign: 'right' }}>
            {categoryData?.batchAuditBtnFlag === 'Y' ? (
              <Button
                ghost
                type="primary"
                disabled={!(selectedRowKeys && selectedRowKeys.length > 0)}
                onClick={() => this.handleBatchApproval('')}
              >
                {categoryData?.batchAuditBtnTitle || '批量审核'}
              </Button>
            ) : ''}
            {categoryData?.batchUploadBtnFlag === 'Y' ? (
              <Button
                ghost
                type="primary"
                style={{ marginLeft: '12px' }}
                disabled={categoryData?.batchIsChecked === 'Y' ? !(selectedRowKeys && selectedRowKeys.length > 0) : !(tableData && tableData.length > 0)}
                onClick={this.handleBatchUpload}
              >
                {categoryData?.batchUploadBtnTitle || '批量上传'}
              </Button>
            ) : ''}
            {categoryData?.batchSignatureBtnFlag === 'Y' ? (
              <Button
                ghost
                type="primary"
                style={{ marginLeft: '12px' }}
                disabled={categoryData?.batchIsChecked === 'Y' ? !(selectedRowKeys && selectedRowKeys.length > 0) : !(tableData && tableData.length > 0)}
                onClick={this.handleBatchSignature}
              >
                {categoryData?.batchSignatureBtnTitle || '批量签名'}
              </Button>
            ) : ''}
            {categoryData?.batchCancelBtnFlag === 'Y' ? (
              <Button
                ghost
                type="danger"
                style={{ marginLeft: '12px' }}
                disabled={categoryData?.batchIsChecked === 'Y' ? !(selectedRowKeys && selectedRowKeys.length > 0) : !(tableData && tableData.length > 0)}
                onClick={this.handleBatchCancel}
              >
                {categoryData?.batchCancelBtnTitle || '批量取消'}
              </Button>
            ) : ''}
            {ERPExportFlag === 'Y' && categoryData?.exportFollowQueryFlag !== 'Y' ? (
              <Button
                ghost
                type="primary"
                loading={ERPExportLoading}
                style={{ marginRight: '12px' }}
                onClick={this.handleERPExport}
              >
                {categoryData?.mainListEMRExportBtnTitle || '导出ERP明细'}
              </Button>
            ) : ''}
            {categoryData.exportCode && categoryData?.exportFollowQueryFlag !== 'Y' ? (
              <Button
                ghost
                type="primary"
                loading={exportLoading}
                style={{ marginLeft: '12px' }}
                onClick={this.handleExport}
              >
                {categoryData?.exportBtnTitle || '导出'}
              </Button>
            ) : ''}
          </Col>
        </Row>
        {!(categoryData?.cardTitle) || categoryData?.independentQueryConditions === 'Y' ? <div className="common-query-split-line" style={{ height: 8 }}></div> : ''}
      </div>
    )

    return (
      <Spin
        indicator={null}
        spinning={spinLoading || recordSaveLoading || fullLoading}
        tip={(
          spinLoading ? '正在初始界面数据……' : (recordSaveLoading ? '数据保存中…' : (
            <div style={{ textAlign: 'center' }}>
              <Progress style={{ width: '240px' }} percent={percentCount} />
              <div>
                {percentCount === 100 ? '批量上传完成' : '批量上传中，请耐心等待…'}
              </div>
            </div>
          ))
        )}
      >
        <div className="dynamic-component table-body-height">
          {!(categoryData?.cardTitle) || categoryData?.independentQueryConditions === 'Y' ? queryCard : ''}
          <div style={{ position: 'relative' }}>
            {categoryData && categoryData.cardTitle ? (
              <Card
                size="small"
                bordered={false}
                title={(
                  <div className="card-title-left-img">
                    <img src={iconInquire} alt="" />
                    {categoryData?.cardTitle || '主列表'}
                  </div>
                )}
                extra={(
                  categoryData && categoryData?.rowDataTitle && categoryData?.cardTitle ? this.getRowDataTitleDom(categoryData.rowDataTitle) : ''
                )}
              >
                {categoryData?.independentQueryConditions !== 'Y' ? queryCard : ''}
                <PubilcTablePagination
                  param={{
                    page: hideMainPaginationFlag === 'Y' ? undefined : page,
                    total: hideMainPaginationFlag === 'Y' ? undefined : total,
                    loading,
                    pageSize: categoryData?.defaultPageSize || '',
                    size: categoryData?.paginationSize || 'small',
                    componentName: currentMainComponentName || categoryData?.componentName || '',
                    data: tableData, // 表格数据
                    x: totalWidth, // 表格的宽度
                    y: categoryData?.isShowDetailTable === 'Y' ? (store.getState().tableHeight.y / 2 - (queryHeight / 2) - (hideMainPaginationFlag === 'Y' ? 0 : 28)) : store.getState().tableHeight.y + (hideMainPaginationFlag === 'Y' ? 128 : 90) - queryHeight,
                    height: categoryData?.isShowDetailTable === 'Y' ? (store.getState().tableHeight.y / 2 - (queryHeight / 2) + (hideMainPaginationFlag === 'Y' ? 45 : 18) + 'px') : store.getState().tableHeight.y + (hideMainPaginationFlag === 'Y' ? 173 : 140) - queryHeight + 'px',
                    columns: columns && columns.length > 0 ? (operationCount > 0 ? [...columns, operationObj] : columns) : [], // 表头配置
                  }}
                  rowSelectionPublic={categoryData?.batchAuditBtnFlag === 'Y' || categoryData?.batchIsChecked === 'Y' ? rowSelection : null}
                  compilePage={this.compilePage}
                  getColumns={() => this.getTableColumns(currentMainComponentName)}
                  onClickRowPublic={this.onClickRowPublic}
                  setRowClassNamePublic={this.setRowClassNamePublic}
                />
              </Card>
            ) : (
              <div style={{ padding: '24px' }}>
                <PubilcTablePagination
                  param={{
                    page: hideMainPaginationFlag === 'Y' ? undefined : page,
                    total: hideMainPaginationFlag === 'Y' ? undefined : total,
                    loading,
                    pageSize: categoryData?.defaultPageSize || '',
                    size: categoryData?.paginationSize || 'small',
                    componentName: currentMainComponentName || categoryData?.componentName || '',
                    data: tableData, // 表格数据
                    x: totalWidth, // 表格的宽度
                    y: categoryData?.isShowDetailTable === 'Y' ? (store.getState().tableHeight.y / 2 - (queryHeight / 2) - (hideMainPaginationFlag === 'Y' ? '-10' : 28)) : store.getState().tableHeight.y + (hideMainPaginationFlag === 'Y' ? 144 : 106) - queryHeight,
                    height: categoryData?.isShowDetailTable === 'Y' ? (store.getState().tableHeight.y / 2 - (queryHeight / 2) + (hideMainPaginationFlag === 'Y' ? 55 : 18) + 'px') : store.getState().tableHeight.y + (hideMainPaginationFlag === 'Y' ? 189 : 156) - queryHeight + 'px',
                    columns: columns && columns.length > 0 ? (operationCount > 0 ? [...columns, operationObj] : columns) : [], // 表头配置
                  }}
                  // batchIsChecked - 批量处理是否走勾选
                  rowSelectionPublic={categoryData?.batchAuditBtnFlag === 'Y' || categoryData?.batchIsChecked === 'Y' ? rowSelection : null}
                  compilePage={hideMainPaginationFlag === 'Y' ? null : this.compilePage}
                  getColumns={() => this.getTableColumns(currentMainComponentName)}
                  onClickRowPublic={this.onClickRowPublic}
                  setRowClassNamePublic={this.setRowClassNamePublic}
                />
              </div>
            )}
            {!!(categoryData?.cardTitle) ? '' : (
              <div style={{ position: 'absolute', bottom: '36px', left: '36px' }}>
                {categoryData && categoryData?.rowDataTitle ? this.getRowDataTitleDom(categoryData.rowDataTitle) : ''}
              </div>
            )}
          </div>
          <div style={{ position: 'relative' }}>
            {categoryData?.isShowDetailTable === 'Y' ? (
              <>
                <div className="common-query-split-line" style={{ height: 8 }}></div>
                <Card
                  size="small"
                  bordered={false}
                  title={(
                    <div className="card-title-left-img">
                      <img src={iconListvisits} alt="" />
                      {categoryData?.detailCardTitle || ((categoryData && 'cardTitle' in categoryData && categoryData.cardTitle ? categoryData.cardTitle.replace('列表', '') : '') + '明细')}
                    </div>
                  )}
                  extra={(
                    categoryData && categoryData?.detailRowDataTitle && categoryData?.detailCardTitle ? this.getRowDataTitleDom(categoryData?.detailRowDataTitle) : ''
                  )}
                >
                  <PubilcTablePagination
                    param={{
                      page: detailPaginationFlag === 'Y' ? detailPage : undefined,
                      total: detailPaginationFlag === 'Y' ? detailTotal : undefined,
                      loading: detailLoading,
                      data: detailTableData, // 表格数据
                      x: detailTotalWidth, // 表格的宽度
                      pageSize: categoryData?.defaultDetailPageSize || '',
                      size: categoryData?.detailPaginationSize || 'small',
                      y: store.getState().tableHeight.y / 2 - (queryHeight / 2) - (detailPaginationFlag === 'Y' ? 28 : 0),
                      componentName: detailComponentName,
                      height: store.getState().tableHeight.y / 2 - (queryHeight / 2) + (detailPaginationFlag === 'Y' ? 18 : 45) + 'px',
                      columns: detailColumns && detailColumns.length > 0 ? detailColumns : [], // 表头配置
                    }}
                    compilePage={detailPaginationFlag === 'Y' ? this.handleDetailPageChange : null}
                    getColumns={this.getDetailTableColumns}
                    onClickRowPublic={this.handleDetailRowClick}
                    setRowClassNamePublic={this.handleDetailRowClassName}
                  />
                </Card>
              </>
            ) : ''}
            {!!(categoryData?.detailCardTitle) ? '' : (
              <div style={{ position: 'absolute', bottom: '36px', left: '36px' }}>
                {categoryData && categoryData?.detailRowDataTitle ? this.getRowDataTitleDom(categoryData?.detailRowDataTitle) : ''}
              </div>
            )}
          </div>
        </div>

        {/* 查看详情 */}
        <MatchingDetails interfaceFlag="OrderReviewComponent" modifyApplicationFormStatus={this.modifyApplicationFormStatus} onRef={ref => this.matchingDetailsRef = ref} />

        {/* 订单查询 */}
        <OrderDetailsQuery onRef={ref => this.orderQueryRef = ref} />
      </Spin>
    )
  }
};

export default OrderReviewComponent;
/*
 * 菜单参数配置
 * interfaceType - 动态组件类型
 * componentName - 组件名
 * selectCode - 初始化接口对应的code
 * queryCode - 查询接口
 * idIndex - 主列表行ID字段名
 * queryDetailCode - 明细列表对应code
 * detailIDIndex - 明细列表行ID字段名
 * 医院退货审核: params=interfaceType:orderReview&selectCode:17060064&componentName:HospitalReturnReview&detailComponentName:VisualReturnReviewDetail&queryCode:17060071&queryDetailCode:17060072&idIndex:returnHandleID&detailIDIndex:returnHandleDetailID&cardTitle:退货单列表&examineCode:17060073&groupType:H&isShowDetailTable:Y&operationFixedFlag:N&detailPaginationFlag:Y&interfaceTypeDesc:订单审核样式
 * 集团退货审核: params=interfaceType:orderReview&selectCode:17060064&componentName:VisualReturnReview&queryCode:17060071&queryDetailCode:17060072&idIndex:returnHandleID&detailIDIndex:returnHandleDetailID&cardTitle:退货单列表&examineCode:17060073&currentAuditStatus:40&groupType:G&isShowDetailTable:Y&operationFixedFlag:N&detailPaginationFlag:Y&interfaceTypeDesc:订单审核样式
 * */
