/*
 * Creater:     shizi
 * CreateDate:  2022/05/24
 * Describe：   新增医嘱项
 * */
import React, { Component } from 'react';
import { Spin, Card, Button, Row, Col, Icon, message, Popconfirm, Modal, Checkbox, Tooltip } from 'antd';
import { Util, dayFormat } from 'tools';
import { $http } from 'containers/config/https';
import moment from 'moment';
import BasicInformation from './BasicInformation';
import ChargeItemModal from './ChargeItemModal';
import ChargeItemInformation from './ChargeItemInformation';
import UnitMaintenance from '../newDrugComponent/UnitMaintenance'; // 表格行内操作
import ListOfChargeItems from './ListOfChargeItems'; // 收费项列表
import InspectionItemList from './InspectionItemList'; // 检验项列表
import '../style/order-item.less';

const { confirm } = Modal;

class AddOrderItem extends Component {
  constructor(props) {
    super(props);
    var userData = JSON.parse(sessionStorage.getItem('userData'));
    this.state = {
      userData,
      loading: false,
      subCatType: '', // 医嘱类别
      rowData: {},
      selectData: {},
      chargeList: [],
      chargeModalData: {}, // 新增收费弹窗回显数据
      chargeItemActiveData: {},
      positionColumns: [], // 部位表头数据
      positionTableData: [], // 部位列表数据
      positionChargeColumns: [], // 部位关联收费项表头数据
      inspectTableData: [], // 检验项目列表数据
      inspectColumns: [], // 检验项目表头数据
      specimenTableData: [], // 项目标本列表数据
      specimenColumns: [], // 项目标本表头数据
      executiveDepartmentColumns: [], // 执行科室设置表头数据
      executiveDepartmentTableData: [], // 执行科室列表数据
      mutexColumns: [], // 互斥医嘱项目表头数据
      mutexTableData: [], // 互斥医嘱项目列表数据
      aliasColumns: [], // 别名表头数据
      aliasTableData: [], // 别名列表数据
      addType: '', // 新增收费项列表数据
      positionChargeTableData: [], // 部位关联收费项列表数据
      positionRowData: {}, // 部位列表选中行数据
      inspectRowData: {}, // 检查项目选中行数据
      medItemSelectData: [], // 互斥医嘱下拉数据
      isValidate: false,
      chargeChecked: true, // 仅显示生效
    };
    this.timeout = null;
  }

  static getDerivedStateFromProps(nextProps, prevState) {
    // 该方法内禁止访问this
    if (('selectData' in nextProps && (JSON.stringify(nextProps.selectData) !== JSON.stringify(prevState.selectData)))) {
      // 通过对比nextProps和prevState，返回一个用于更新状态的对象
      return {
        selectData: nextProps.selectData
      }
    }
    // 不需要更新状态，返回null
    return null
  }

  componentDidMount() {
    this.props.onRef && this.props.onRef(this);
    this.getPositionColumns();
    this.getPositionChargeColumns();
    this.getInspectColumns();
    this.getSpecimenColumns();
    this.getExecutiveDepartmentColumns();
    this.getMutexColumns();
    this.getAliasColumns();
  }

  componentDidUpdate(prevProps, prevState) {
    if ('selectData' in prevProps && (JSON.stringify(prevProps.selectData) !== JSON.stringify(this.state.selectData))) {
      this.getPositionColumns();
      this.getSpecimenColumns();
      this.getExecutiveDepartmentColumns();
    }
  }

  // 查询医嘱维护的详细信息
  queryRowDataByID = async (id, isCopy) => {
    try {
      let oldRowData = this.state.rowData ? JSON.parse(JSON.stringify(this.state.rowData)) : {};
      let data = {
        params: [{
          medID: id
        }]
      }
      let res = await React.$asyncPost(this, '02020385', data);
      let rowData = { ...res.result };
      let medObj = res.result && res.result.medObj ? res.result.medObj : {};
      rowData.medObj = {
        ...medObj, // 医嘱项信息
        medID: isCopy ? '' : ('medID' in medObj && medObj.medID ? medObj.medID : ''),
        medCode: isCopy ? undefined : ('medCode' in medObj && medObj.medCode ? medObj.medCode : undefined), // 另存为代码置空
      };
      // 关联收费项
      let chargeList = 'chargeLinkMedArr' in rowData && Array.isArray(rowData.chargeLinkMedArr) && rowData.chargeLinkMedArr.length > 0 ? JSON.parse(JSON.stringify(rowData.chargeLinkMedArr)) : [];
      chargeList = isCopy ? chargeList.filter(item => item.statusFlag === 'A') : chargeList; // 另存时过滤失效和将启用收费项数据
      for (var i = 0; i < chargeList.length; i++) {
        chargeList[i].index = i;
        chargeList[i].key = 'medLinkChargeID' in chargeList[i] && chargeList[i].medLinkChargeID ? chargeList[i].medLinkChargeID : i + 1;
        chargeList[i].medLinkChargeID = isCopy ? '' : (chargeList[i]?.medLinkChargeID || ''); // 医嘱项关联收费项
        // chargeList[i].chargeItemHospID = isCopy ? '' : (chargeList[i]?.chargeItemHospID || '');
        // chargeList[i].chargeCode = isCopy ? undefined : (chargeList[i]?.chargeCode || ''); // 另存置空收费项代码
      }
      rowData.chargeLinkMedArr = chargeList;
      rowData.partArr = 'partArr' in rowData && rowData.partArr ? this.handleModifyRowID(isCopy, rowData.partArr, 'medItemPartID') : []; // 检查部位
      rowData.lisArr = 'lisArr' in rowData && rowData.lisArr ? this.handleModifyRowID(isCopy, rowData.lisArr, 'lisItemID', 'medItemLinkLisID') : []; // 检验项目
      rowData.recLocArr = 'recLocArr' in rowData && rowData.recLocArr ? this.handleModifyRowID(isCopy, rowData.recLocArr, 'medItemRecID') : []; // 执行科室
      rowData.exclusiveMedItemArr = 'exclusiveMedItemArr' in rowData && rowData.exclusiveMedItemArr ? this.handleModifyRowID(isCopy, rowData.exclusiveMedItemArr, 'exclusiveMedItemID') : []; // 互斥医嘱
      rowData.aliasArr = isCopy && 'aliasArr' in rowData && Array.isArray(rowData.aliasArr) ? this.handleModifyRowID(isCopy, rowData.aliasArr.filter(item => item.autoFlag !== 'Y'), 'orderAliasID') : (rowData?.aliasArr || []); // 别名
      let isClear = this.isClearChargeItemActiveData(id, oldRowData);
      this.setState({
        rowData
      }, () => {
        this.setValuesForSubcomponents(isClear);
        // this.getPositionChargeColumns();
        if (medObj && medObj.medSubCatID)
          this.getOrderCategory(medObj.medSubCatID);
      });
    } catch (error) {
      this.props.resetFields && this.props.resetFields();
    }
  }

  // 保存后是否清空选择的收费项信息数据
  isClearChargeItemActiveData = (id, rowData) => {
    let isClear = false;
    if (!(rowData && rowData.medID === id)) { // 清空收费项信息选中数据
      isClear = true;
    }
    return isClear;
  }

  // 另存则修改表格行id
  handleModifyRowID = (isModify, data, dataIndex, dataIndex2, dataIndex3) => {
    let dataSource = data && data.length > 0 ? JSON.parse(JSON.stringify(data)) : [];
    if (isModify) {
      for (var i = 0; i < dataSource.length; i++) {
        dataSource[i][dataIndex] = '';
        dataIndex2 ? dataSource[i][dataIndex2] = '' : '';
        dataIndex3 ? dataSource[i][dataIndex3] = '' : ''
      }
    }
    return dataSource;
  }

  // 获取当前医嘱子类所属类别
  getOrderCategory = (subCatID) => {
    let { selectData } = this.state;
    if (subCatID) {
      let ordSubCatSelectData = selectData && 'ordSubCat' in selectData ? selectData.ordSubCat : []
      let subCatType = Util.returnDataCccordingToAttributes(ordSubCatSelectData, subCatID)?.type;
      this.setState({ subCatType })
    }
  }

  // 设置子组件的值 - isClear是否清除选中数据
  setValuesForSubcomponents = (isClear) => {
    let { rowData, isValidate, chargeItemActiveData } = this.state;

    this.setState({
      chargeList: 'chargeLinkMedArr' in rowData && rowData.chargeLinkMedArr ? JSON.parse(JSON.stringify(rowData.chargeLinkMedArr)) : [], // 关联收费项
      positionTableData: rowData?.partArr || [], // 检查部位
      inspectTableData: rowData?.lisArr || [], // 检验项目
      executiveDepartmentTableData: rowData?.recLocArr || [], // 执行科室
      mutexTableData: rowData?.exclusiveMedItemArr || [], // 互斥医嘱
      aliasTableData: rowData?.aliasArr || [], // 医嘱别名
      // specimenTableData: [],
      // positionChargeTableData: []
    }, () => {
      this.positionRef && this.positionRef.getTableData && this.positionRef.getTableData(this.state.positionTableData, isClear ? 'Y' : 'N');
      this.inspectRef && this.inspectRef.getTableData && this.inspectRef.getTableData(this.state.inspectTableData, isClear ? 'Y' : 'N');
      // this.positionRef && this.positionRef.getTableData && this.positionRef.getTableData(this.state.positionTableData);
      // this.inspectRef && this.inspectRef.getTableData && this.inspectRef.getTableData(this.state.inspectTableData);
      this.executiveDepartmentRef && this.executiveDepartmentRef.getTableData && this.executiveDepartmentRef.getTableData(this.state.executiveDepartmentTableData);
      this.mutexRef && this.mutexRef.getTableData && this.mutexRef.getTableData(this.state.mutexTableData);
      this.aliasRef && this.aliasRef.getTableData && this.aliasRef.getTableData(this.state.aliasTableData);
      // this.positionChargeRef && this.positionChargeRef.resetFields && this.positionChargeRef.resetFields(); // 清空部位关联收费项
      // this.specimenRef && this.specimenRef.resetFields && this.specimenRef.resetFields(); // 清空项目标本
    })
    if (isClear) { // 清除选中及关联数据
      this.setState({
        chargeItemActiveData: {},
        chargeChecked: true,
        specimenTableData: [],
        positionChargeTableData: []
      }, () => {
        this.chargeItemInfoRef && this.chargeItemInfoRef.resetFields(); // 重置界面收费项信息
        this.positionChargeRef && this.positionChargeRef.resetFields && this.positionChargeRef.resetFields(); // 清空部位关联收费项
        this.specimenRef && this.specimenRef.resetFields && this.specimenRef.resetFields(); // 清空项目标本
      })
    } else {
      if (isValidate && !(chargeItemActiveData && chargeItemActiveData.key)) {
        this.setState({ chargeItemActiveData: this.state.chargeList && this.state.chargeList.length > 0 ? this.state.chargeList[0] : {} })
      }
    }
  }

  // 添加收费项
  handleAddChargeItem = (type) => {
    this.setState({ addType: type }, () => {
      this.chargeItemRef && this.chargeItemRef.modifyVisible(true);
      this.chargeItemInfoRef && this.chargeItemInfoRef.resetFields();
    })
  }

  // 判断界面是否录入收费项信息
  handleEnterChargeItem = (callback) => {
    let { chargeList, chargeItemActiveData } = this.state;
    let values = this.chargeItemInfoRef && this.chargeItemInfoRef.getFieldsValue && this.chargeItemInfoRef.getFieldsValue(); // 收费项表单信息 
    let isEnter = false;
    for (var key in values) {
      if (key !== 'chargeCode' && key !== 'startDate' && values[key]) {
        isEnter = true;
        break;
      }
    }
    if (isEnter && !(chargeItemActiveData && chargeItemActiveData.key)) {
      confirm({
        title: '保存提醒',
        content: '当前界面已录入收费项信息，是否需要保存?',
        onOk: () => {
          this.chargeItemInfoRef && this.chargeItemInfoRef.handleSave && this.chargeItemInfoRef.handleSave();

          setTimeout(() => {
            let chargeItemInfoValues = this.chargeItemInfoRef && this.chargeItemInfoRef.getStaticFieldsValue && this.chargeItemInfoRef.getStaticFieldsValue();
            // 收费项验证
            if (chargeItemInfoValues && (chargeItemInfoValues.error || chargeItemInfoValues.priceError)) {
              message.error("请先完善收费项必填信息。")
              return;
            } else {
              chargeList.push({
                ...chargeItemInfoValues,
                key: chargeList && chargeList.length ? chargeList.length + 1 : 1
              })
              this.setState({ chargeList }, () => {
                this.chargeItemInfoRef && this.chargeItemInfoRef.resetFields();
              })
            }
          }, 300);
        },
        onCancel: () => {
          callback && callback()
        },
      });
    } else {
      callback && callback()
    }
  }

  handleChargeItemClick = record => {
    let { chargeList, chargeItemActiveData } = this.state;
    let values = this.chargeItemInfoRef && this.chargeItemInfoRef.getFieldsValue && this.chargeItemInfoRef.getFieldsValue(); // 收费项表单信息
    // 切换前保存表单数据
    if (chargeItemActiveData && 'index' in chargeItemActiveData) {
      chargeList[chargeItemActiveData.index] = {
        ...chargeList[chargeItemActiveData.index],
        ...values
      }
    }
    this.setState({ chargeList, chargeItemActiveData: chargeItemActiveData.key !== record.key ? record : {} }, () => {
      this.chargeItemInfoRef && this.chargeItemInfoRef.resetFields();
    })
  }

  // 设置收费项表单数据
  setChargeItemValues = (values) => {
    let { chargeItemActiveData } = this.state;
    if (!(chargeItemActiveData && chargeItemActiveData.key)) {
      this.chargeItemInfoRef && this.chargeItemInfoRef.setFieldsValue(values); // 设置表单的值
      this.setState({
        chargeModalData: { ...this.state.chargeModalData, ...values }
      })
    }
  }

  // 获取部位表头数据
  getPositionColumns = () => {
    let { selectData } = this.state;
    let columns = [{
      title: '部位名称',
      dataIndex: 'partDesc',
      align: 'center',
      inputType: 'Select',
      detailitem: selectData && 'bodyPart' in selectData ? selectData.bodyPart : [],
      editable: true,
      required: 'Y',
      width: 150
    }, {
      title: '互斥',
      dataIndex: 'mutexFlag',
      align: 'center',
      inputType: 'Switch',
      editable: true,
      width: 100
    }, {
      title: '默认',
      dataIndex: 'isDefault',
      align: 'center',
      inputType: 'Switch',
      editable: true,
      width: 100
    }];
    this.setState({ positionColumns: columns })
  }

  // 获取部位关联收费项表头数据
  getPositionChargeColumns = () => {
    let columns = [{
      title: '项目名称',
      dataIndex: 'chargeDesc',
      align: 'center',
      inputType: 'Input',
      // editable: true,
      required: 'Y',
      disabled: 'Y',
      width: 150,
      fixed: 'left',
      render: (text, record) => {
        return (
          <Tooltip title={text}>
            <span className='ellipsis' style={{ width: '100%', display: 'inline-block' }}>{text}</span>
          </Tooltip>
        );
      },
    }, {
      title: '项目代码',
      dataIndex: 'chargeCode',
      align: 'center',
      inputType: 'Input',
      // editable: true,
      required: 'Y',
      disabled: 'Y',
      width: 150
    }, {
      title: '数量',
      dataIndex: 'partLinkChargeNum',
      align: 'center',
      inputType: 'InputNumber',
      editable: true,
      required: 'Y',
      width: 100
    }, {
      title: '单价',
      dataIndex: 'chargePrice',
      align: 'center',
      inputType: 'Input',
      editable: true,
      required: 'Y',
      disabled: 'Y',
      width: 100
    }, {
      title: '金额',
      dataIndex: 'totalMoney',
      align: 'center',
      editable: true,
      inputType: 'InputNumber',
      disabled: 'Y',
      width: 100
    }, {
      title: '生效日期',
      dataIndex: 'startDate',
      align: 'center',
      inputType: 'Date',
      required: 'Y',
      editable: true,
      defaultValue: moment().add(1, 'days').format(dayFormat),
      disabled: 'N',
      width: 150
    }, {
      title: '失效日期',
      dataIndex: 'endDate',
      align: 'center',
      inputType: 'Date',
      editable: true,
      disableddate: 'disabledEndDate',
      width: 150
    }];
    this.setState({ positionChargeColumns: columns })
  }

  // 获取检验项目表头数据
  getInspectColumns = () => {
    let columns = [{
      title: '项目代码',
      dataIndex: 'lisItemCode',
      align: 'center',
      inputType: 'Input',
      editable: true,
    }, {
      title: '项目描述',
      dataIndex: 'lisItemDesc',
      align: 'center',
      inputType: 'Input',
      editable: true,
    }];
    this.setState({ inspectColumns: columns })
  }

  // 获取项目标本表头数据
  getSpecimenColumns = () => {
    let { selectData } = this.state;
    let columns = [{
      title: '标本',
      dataIndex: 'specimenDesc',
      align: 'center',
      inputType: 'Select',
      detailitem: selectData && 'specimen' in selectData ? selectData.specimen : [],
      editable: true,
      width: 150
    }, {
      title: '容器',
      dataIndex: 'containerDesc',
      align: 'center',
      inputType: 'Select',
      detailitem: selectData && 'container' in selectData ? selectData.container : [],
      editable: true,
      width: 150
    }, {
      title: '默认',
      dataIndex: 'isDefault',
      align: 'center',
      inputType: 'Switch',
      editable: true,
      width: 100
    }];
    this.setState({ specimenColumns: columns })
  }

  // 获取执行科室设置表头数据
  getExecutiveDepartmentColumns = () => {
    let { selectData } = this.state;
    let columns = [{
      title: '执行科室',
      dataIndex: 'recLocDesc',
      align: 'center',
      inputType: 'Select',
      detailitem: selectData && 'loc' in selectData ? selectData.loc : [],
      editable: true,
      required: 'Y',
      width: 150
    }, {
      title: '科室类型',
      dataIndex: 'locTypeDesc',
      align: 'center',
      inputType: 'Select',
      detailitem: selectData && 'locType' in selectData ? selectData.locType : [],
      editable: true,
      required: 'Y',
      width: 150
    }, {
      title: '开单科室',
      dataIndex: 'locDesc',
      align: 'center',
      inputType: 'Select',
      detailitem: selectData && 'loc' in selectData ? selectData.loc : [],
      editable: true,
      width: 150
    }, {
      title: '默认标志',
      dataIndex: 'defaultFlag',
      align: 'center',
      inputType: 'Switch',
      editable: true,
      width: 100
    }];
    this.setState({ executiveDepartmentColumns: columns })
  }

  // 获取互斥医嘱项目表头数据
  getMutexColumns = () => {
    let { medItemSelectData } = this.state;
    let columns = [{
      title: '互斥医嘱',
      dataIndex: 'exclMedItemDesc',
      align: 'center',
      inputType: 'SearchSelect',
      editable: true,
      search: this.handleSearch,
      detailitem: medItemSelectData,
      width: '300px',
      valueindex: 'medDesc',
      descindex: 'medDesc',
      desccodeindex: 'medCode',
      loading: 'N',
    }, {
      title: '备注',
      dataIndex: 'note',
      align: 'center',
      inputType: 'Input',
      editable: true,
      width: '300px',
    }];
    this.setState({ mutexColumns: columns })
  }

  // 互斥医嘱搜索事件
  handleSearch = (value) => {
    this.state.mutexColumns[0].loading = 'Y';
    this.setState({});
    this.fetchCharge(value, medItemSelectData => this.setState({ medItemSelectData }, () => {
      this.getMutexColumns();
    }));
  }

  fetchCharge = (value, callback) => {
    value = value.replace(/^\s+/, "").replace(/\s+$/, "");
    if (value === "") {
      callback([]);
      return;
    }
    if (this.timeout) {
      clearTimeout(this.timeout);
      this.timeout = null;
    }
    function fakeCharge() {
      let data = {
        params: [{
          inputValue: value
        }],
        pagination: [{
          pageSize: 100,
          currentPage: 1
        }]
      }
      $http.post('urlS', this, {
        code: "02020389",
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            callback(res.result?.rows || []);
          }
        }
      });
    }
    this.timeout = setTimeout(fakeCharge, 500);
  }

  // 获取别名表头数据
  getAliasColumns = () => {
    let columns = [{
      title: '别名',
      dataIndex: 'aliasDesc',
      align: 'center',
      inputType: 'Input',
      editable: true,
    }, {
      title: '自动生成标志',
      dataIndex: 'autoFlag',
      align: 'center',
      inputType: 'Switch',
      editable: true,
    }];
    this.setState({ aliasColumns: columns })
  }

  // 重置数据
  resetFields = () => {
    this.setState({
      rowData: {}, chargeList: [], chargeItemActiveData: {}, positionTableData: [], positionChargeTableData: [], inspectTableData: [], specimenTableData: [], executiveDepartmentTableData: [],
      mutexTableData: [], aliasTableData: []
    }, () => {
      this.chargeItemInfoRef && this.chargeItemInfoRef.resetFields();
      this.basicInfoRef && this.basicInfoRef.handleSave && this.basicInfoRef.resetFields();
      this.positionRef && this.positionRef.resetFields && this.positionRef.resetFields(); // 清空关联部位列表数据
      this.positionChargeRef && this.positionChargeRef.resetFields && this.positionChargeRef.resetFields(); // 清空部位关联收费项
      this.inspectRef && this.inspectRef.resetFields && this.inspectRef.resetFields(); // 清空关联检验项目
      this.specimenRef && this.specimenRef.resetFields && this.specimenRef.resetFields(); // 清空项目标本
      this.executiveDepartmentRef && this.executiveDepartmentRef.resetFields && this.executiveDepartmentRef.resetFields(); // 清空执行科室数据
      this.mutexRef && this.mutexRef.resetFields && this.mutexRef.resetFields(); // 清空互斥医嘱数据
      this.aliasRef && this.aliasRef.resetFields && this.aliasRef.resetFields(); // 清空别名数据
    });
  }

  // 打开收费项列表弹窗
  handleOpenChargeList = (type) => {
    let { positionRowData } = this.state;
    if (type === 'positionChargeTableData') {
      if (!(positionRowData && positionRowData.key)) {
        message.error("请先从部位列表选择一条数据进行关联。");
        return;
      }
    }
    this.setState({ addType: type }, () => {
      this.listChargeRef && this.listChargeRef.modifyVisible && this.listChargeRef.modifyVisible(true);
    })
  }

  // 打开检验项列表弹窗
  handleOpenInspectionItem = () => {
    this.inspectionItemRef && this.inspectionItemRef.modifyVisible && this.inspectionItemRef.modifyVisible(true);
  }

  // 本地删除数据
  deleteRow = (dataIndex, key) => {
    if (this.state[dataIndex] && this.state[dataIndex].length > 0) {
      this.state[dataIndex] = this.state[dataIndex].filter(item => item.key !== key);
      this.setState({})
    }
  }

  // 删除医嘱关联的收费项
  handleDeleteChargeItem = (record, e) => {
    e?.stopPropagation();
    try {
      let { chargeItemActiveData } = this.state;
      if (record && record.medLinkChargeID) {
        // let data = {
        //   params: [{
        //     medLinkItmID: record?.medLinkChargeID, // 医嘱关联收费项表ID（medLinkChargeID）
        //     endDate: moment().subtract(1, 'days').format('YYYY-MM-DD'), // 失效日期，取前一天
        //     updateUserID: userData?.userID, // 用户ID
        //   }]
        // }
        // let res = await React.$asyncPost(this, '05100172', data);
        // message.success(res.errorMessage ? res.errorMessage : "删除成功");
        message.error(`收费项（${record?.chargeDesc || ''}）已关联医嘱项，不能直接删除！请单击该数据去修改失效日期。`);
      } else {
        this.deleteRow('chargeList', record?.key);
        // 当删除为选中的数据则清空
        if (chargeItemActiveData && (chargeItemActiveData.key === record.key)) {
          this.setState({ chargeItemActiveData: {} }, () => {
            this.chargeItemInfoRef && this.chargeItemInfoRef.resetFields();
          })
        }
      }
    } catch (error) {
      console.log("error");
    }
  }

  // 阻止事件冒泡
  handleStopPropagation = (e) => {
    e.stopPropagation();
  }

  // 添加收费项信息
  handleAddChargeList = (data, isClear) => {
    let { addType, chargeItemActiveData } = this.state;
    let chargeList = [...JSON.parse(JSON.stringify(data)), ...this.state[addType]];
    for (var i = 0; i < chargeList.length; i++) {
      chargeList[i].index = i;
      chargeList[i].key = 'medLinkChargeID' in chargeList[i] && chargeList[i].medLinkChargeID ? chargeList[i].medLinkChargeID : i + 1;
    }
    this.state[addType] = [...chargeList];
    if (isClear === 'clear' || addType === 'chargeList') { // 清空收费项弹窗数据
      this.state.chargeModalData = {};
      if (!(chargeItemActiveData && chargeItemActiveData.key)) {
        this.chargeItemInfoRef && this.chargeItemInfoRef.resetFields();
      }
    }
    this.setState({}, () => {
      if (addType === 'positionChargeTableData') {
        this.positionChargeRef && this.positionChargeRef.getTableData && this.positionChargeRef.getTableData(this.state[addType]);
        this.handlePositionChargeSave(this.state[addType]);
      }
    })
  }

  // 选中行操作
  handlePositionRowClick = record => {
    let positionChargeTableData = record && 'partLinkChargeArr' in record && Array.isArray(record.partLinkChargeArr) && record.partLinkChargeArr.length > 0 ? record.partLinkChargeArr : [];
    for (var i = 0; i < positionChargeTableData.length; i++) {
      if ('partLinkChargeNum' in positionChargeTableData[i] && positionChargeTableData[i].partLinkChargeNum && 'chargePrice' in positionChargeTableData[i] && positionChargeTableData[i].chargePrice) {
        positionChargeTableData[i].totalMoney = (positionChargeTableData[i].partLinkChargeNum * 100) * (positionChargeTableData[i].chargePrice * 100) / 10000;
      }
    }
    this.setState({
      positionRowData: record,
      positionChargeTableData
    }, () => {
      this.positionChargeRef && this.positionChargeRef.getTableData && this.positionChargeRef.getTableData(this.state.positionChargeTableData);
    })
  }

  // 保存关联部位列表
  handlePositionSave = data => {
    this.setState({ positionTableData: [...data] }, () => {
      this.positionChargeRef && this.positionChargeRef.resetFields && this.positionChargeRef.resetFields(); // 清空部位关联收费项
      this.handleSaveTableData();
    })
  }

  // 删除关联部位列表
  handlePositionDelete = async (record, callback) => {
    try {
      let { userData } = this.state;
      let data = {
        params: [{
          id: record?.medItemPartID,
          userID: userData?.userID,
          hospID: userData?.hospID,
          logonHospID: userData?.hospID,
          groupID: userData?.groupID,
        }]
      }
      let res = await React.$asyncPost(this, '03010035', data);
      message.success(res && res.errorMessage ? res.errorMessage : '删除成功');
      callback && callback();
    } catch (error) {
      console.log(error)
    }
  }

  // 部位关联收费项保存
  handlePositionChargeSave = data => {
    let { positionRowData, positionTableData } = this.state;
    if (positionRowData && positionRowData.key && positionTableData && positionTableData.length > 0) {
      positionTableData[positionRowData?.key - 1]['partLinkChargeArr'] = [...data];
      this.setState({}, () => {
        this.positionRef && this.positionRef.getTableData && this.positionRef.getTableData(this.state.positionTableData, 'N');
        this.handleSaveTableData();
      })
    }
  }

  // 编辑行操作
  handlepositionEditCurrentLine = (record) => {
    let { positionChargeColumns } = this.state;
    if (record && 'partLinkChargeID' in record && record.partLinkChargeID) {
      positionChargeColumns[5].disabled = 'Y'
    } else {
      positionChargeColumns[5].disabled = 'N'
    }
    this.setState({ positionChargeColumns })
  }

  // 删除关联收费项
  handlePositionChargeDelete = async (record, callback) => {
    try {
      let { userData } = this.state;
      let data = {
        params: [{
          medPartLinkItmID: record?.partLinkChargeID,
          endDate: moment().subtract(1, 'days').format('YYYY-MM-DD'), // 失效日期，取前一天
          updateUserID: userData?.userID
        }]
      }
      let res = await React.$asyncPost(this, '05100176', data);
      message.success(res && res.errorMessage ? res.errorMessage : '删除成功');
      callback && callback();
      // let oldMedObj = rowData && 'medObj' in rowData && rowData.medObj ? rowData.medObj : {};
      // oldMedObj && 'medID' in oldMedObj && oldMedObj.medID ? this.props.getTableData && this.props.getTableData(res.result) : '';
    } catch (error) {
      console.log(error)
    }
  }

  // 新增前确认
  handleConfirmBeforeAdd = () => {
    let { inspectRowData } = this.state;
    if (!(inspectRowData && inspectRowData.key)) {
      message.error("请先从检查项目列表选择选择一条数据进行关联。");
      return 'N';
    }
    return 'Y';
  }

  // 检验项目选中操作
  handleInspectRowClick = record => {
    this.setState({ inspectRowData: record, specimenTableData: record && 'specArr' in record && Array.isArray(record.specArr) && record.specArr.length > 0 ? record.specArr : [] }, () => {
      this.specimenRef && this.specimenRef.getTableData && this.specimenRef.getTableData(this.state.specimenTableData);
    })
  }

  // 保存医嘱关联检验项
  handleInspectTableSave = data => {
    this.setState({ inspectTableData: [...data] }, () => {
      this.specimenRef && this.specimenRef.resetFields && this.specimenRef.resetFields(); // 清空项目标本
      this.handleSaveTableData();
    })
  }

  // 删除医嘱关联检验项
  handleInspectDelete = async (record, callback) => {
    try {
      let { userData } = this.state;
      let data = {
        params: [{
          id: record?.medItemLinkLisID,
          userID: userData?.userID
        }]
      }
      let res = await React.$asyncPost(this, '01040234', data);
      message.success(res && res.errorMessage ? res.errorMessage : '删除成功');
      callback && callback();
    } catch (error) {
      console.log(error)
    }
  }

  // 项目标本保存
  handleSpecimenSave = data => {
    let { inspectRowData, inspectTableData } = this.state;
    if (inspectRowData && inspectRowData.key && inspectTableData && inspectTableData.length > 0) {
      inspectTableData[inspectRowData?.key - 1]['specArr'] = [...data]
      this.setState({}, () => {
        this.inspectRef.getTableData && this.inspectRef.getTableData(this.state.inspectTableData, 'N');
        this.handleSaveTableData();
      })
    }
  }

  // 删除项目标本
  handleSpecimenDelete = async (record, callback) => {
    try {
      let { userData } = this.state;
      let data = {
        params: [{
          id: record?.medItemLisLinkSpecID,
          userID: userData?.userID
        }]
      }
      let res = await React.$asyncPost(this, '01040239', data);
      message.success(res && res.errorMessage ? res.errorMessage : '删除成功');
      callback && callback();
    } catch (error) {
      console.log(error)
    }
  }

  // 添加检验项目
  handleAddInspectionItem = (data) => {
    this.setState({ inspectTableData: Util.addKeyValueToDataSource([...this.state.inspectTableData, ...data]) }, () => {
      this.inspectRef.getTableData && this.inspectRef.getTableData(this.state.inspectTableData, 'N');
    })
  }

  // 删除执行科室
  handleExecutiveDepartmentDelete = async (record, callback) => {
    try {
      let { userData } = this.state;
      let data = {
        params: [{
          id: record?.medItemRecID,
          userID: userData?.userID,
          hospID: userData?.hospID,
          logonHospID: userData?.hospID,
          groupID: userData?.groupID,
        }]
      }
      let res = await React.$asyncPost(this, '03010029', data);
      message.success(res && res.errorMessage ? res.errorMessage : '删除成功');
      callback && callback();
    } catch (error) {
      console.log(error)
    }
  }

  // 删除互斥医嘱
  handleMutexDelete = async (record, collback) => {
    try {
      let { userData } = this.state;
      let data = {
        params: [{
          ID: record?.exclusiveMedItemID,
          updateUserID: userData?.userID
        }]
      }
      let res = await React.$asyncPost(this, '03050190', data);
      message.success(res && res.errorMessage ? res.errorMessage : '删除成功');
      collback && collback();
    } catch (error) {
      console.log(error)
    }
  }

  // 数据校验 - isTable - 是否行内编辑table上的保存
  handleSave = (isTable) => {
    let { chargeList, chargeItemActiveData, subCatType, rowData } = this.state;
    let staticChargeList = chargeList ? JSON.parse(JSON.stringify(chargeList)) : [];
    this.basicInfoRef && this.basicInfoRef.handleSave && this.basicInfoRef.handleSave();
    let chargeValues = this.chargeItemInfoRef && this.chargeItemInfoRef.getFieldsValue && this.chargeItemInfoRef.getFieldsValue(); // 收费项表单信息
    let isValidate = false; // 是否需要验证
    if ((chargeValues && chargeValues.chargeTCID && chargeValues.chargeCode && staticChargeList && staticChargeList.length === 0) || (chargeItemActiveData && chargeItemActiveData.key)) { // 当收费项数组没有数据或者只有一条或者选中修改的时候需要验证表单数据
      this.chargeItemInfoRef && this.chargeItemInfoRef.handleSave && this.chargeItemInfoRef.handleSave();
      isValidate = true;
    }

    setTimeout(() => {
      let basicInfoValues = this.basicInfoRef && this.basicInfoRef.getStaticFieldsValue && this.basicInfoRef.getStaticFieldsValue(); // 医嘱项基本信息

      // 医嘱项基本信息验证
      if (basicInfoValues && basicInfoValues.error) {
        message.error("请先完善必填信息再保存。")
        return;
      }

      let chargeItemInfoValues;
      if (isValidate) {
        chargeItemInfoValues = this.chargeItemInfoRef && this.chargeItemInfoRef.getStaticFieldsValue && this.chargeItemInfoRef.getStaticFieldsValue(); // 收费项表单信息
      }

      // 收费项验证
      if (isValidate && chargeItemInfoValues && (chargeItemInfoValues.error || chargeItemInfoValues.priceError)) {
        message.error("请先完善收费项必填信息再保存。")
        return;
      }

      chargeItemInfoValues = chargeValues;
      if (chargeItemActiveData && chargeItemActiveData.key) {
        for (var i = 0; i < staticChargeList.length; i++) {
          if (staticChargeList[i].key === chargeItemActiveData.key) {
            staticChargeList[i] = {
              ...staticChargeList[i],
              ...chargeItemInfoValues
            }
          }
        }
      } else if (chargeValues && chargeValues.chargeTCID && chargeValues.chargeCode && staticChargeList && staticChargeList.length < 1) {
        staticChargeList.push({
          ...chargeItemInfoValues,
          key: 1
        })
      }

      // 检查部位
      let positionData = this.positionRef && this.positionRef.handleSave();
      let positionEditingKey = positionData && 'editingKey' in positionData ? positionData.editingKey : '';
      if (subCatType === 'E' && positionEditingKey) {
        message.error("关联部位列表处于编辑状态，请先保存或取消该操作再做保存。");
        return;
      }

      // 部位关联收费项
      let positionChargeData = this.positionChargeRef && this.positionChargeRef.handleSave();
      let positionChargeEditingKey = positionChargeData && 'editingKey' in positionChargeData ? positionChargeData.editingKey : '';
      if (subCatType === 'E' && positionChargeEditingKey) {
        message.error("部位关联收费项列表处于编辑状态，请先保存或取消该操作再做保存。");
        return;
      }

      // 检验项目
      let inspectData = this.inspectRef && this.inspectRef.handleSave();
      let inspectEditingKey = inspectData && 'editingKey' in inspectData ? inspectData.editingKey : '';
      if (subCatType === 'L' && inspectEditingKey) {
        message.error("关联检验列表处于编辑状态，请先保存或取消该操作再做保存。");
        return;
      }

      // 项目标本
      let specimenRefData = this.specimenRefRef && this.specimenRefRef.handleSave();
      let specimenRefEditingKey = specimenRefData && 'editingKey' in specimenRefData ? specimenRefData.editingKey : '';
      if (subCatType === 'L' && specimenRefEditingKey) {
        message.error("项目标本列表处于编辑状态，请先保存或取消该操作再做保存。");
        return;
      }

      // 执行科室
      let executiveDepartmentData = this.executiveDepartmentRef && this.executiveDepartmentRef.handleSave();
      let executiveDepartmentEditingKey = executiveDepartmentData && 'editingKey' in executiveDepartmentData ? executiveDepartmentData.editingKey : '';
      if (executiveDepartmentEditingKey) {
        message.error("执行科室列表处于编辑状态，请先保存或取消该操作再做保存。");
        return;
      }

      // 互斥医嘱
      let mutexData = this.mutexRef && this.mutexRef.handleSave();
      let mutexEditingKey = mutexData && 'editingKey' in mutexData ? mutexData.editingKey : '';
      if (mutexEditingKey) {
        message.error("执行科室列表处于编辑状态，请先保存或取消该操作再做保存。");
        return;
      }

      // 医嘱别名
      let aliasData = this.aliasRef && this.aliasRef.handleSave();
      let aliasEditingKey = aliasData && 'editingKey' in aliasData ? aliasData.editingKey : '';
      if (aliasEditingKey) {
        message.error("医嘱别名列表处于编辑状态，请先保存或取消该操作再做保存。");
        return;
      }

      let oldMedObj = rowData && 'medObj' in rowData && rowData.medObj ? rowData.medObj : {};
      if (oldMedObj && 'medID' in oldMedObj && oldMedObj.medID && isTable !== 'table') {
        this.handleDifferenceComparison(staticChargeList, basicInfoValues, isValidate); // 走数据校验
      } else {
        this.handleHttpSave(staticChargeList, basicInfoValues, isValidate);
      }
    }, 300)
  }

  // 调用接口保存
  handleHttpSave = async (staticChargeList, basicInfoValues, isValidate) => {
    try {
      // 保存触发loading
      this.setState({ loading: true });
      let { rowData, selectData, subCatType, positionTableData, inspectTableData, executiveDepartmentTableData, mutexTableData, aliasTableData } = this.state;

      // 检查部位
      for (var i = 0; i < positionTableData.length; i++) {
        positionTableData[i].partID = Util.returnDataCccordingToAttributes(selectData && 'bodyPart' in selectData ? selectData.bodyPart : [], positionTableData[i].partDesc, 'descripts')?.id; // 部位ID
        positionTableData[i].partLinkChargeArr = 'partLinkChargeArr' in positionTableData[i] && positionTableData[i].partLinkChargeArr ? positionTableData[i].partLinkChargeArr : [];
      }

      // 检验项目 - 标本ID和容器ID
      for (var i = 0; i < inspectTableData.length; i++) {
        if (inspectTableData[i] && 'specArr' in inspectTableData[i] && inspectTableData[i].specArr) {
          for (var j = 0; j < inspectTableData[i].specArr.length; j++) {
            inspectTableData[i].specArr[j].specimenID = Util.returnDataCccordingToAttributes(selectData && 'specimen' in selectData ? selectData.specimen : [], inspectTableData[i].specArr[j].specimenDesc, 'descripts')?.id; // 标本
            inspectTableData[i].specArr[j].containerID = Util.returnDataCccordingToAttributes(selectData && 'container' in selectData ? selectData.container : [], inspectTableData[i].specArr[j].containerDesc, 'descripts')?.id; // 容器
          }
        } else {
          inspectTableData[i].specArr = [];
        }
      }

      // 执行科室
      for (var i = 0; i < executiveDepartmentTableData.length; i++) {
        executiveDepartmentTableData[i].recLocID = Util.returnDataCccordingToAttributes(selectData && 'loc' in selectData ? selectData.loc : [], executiveDepartmentTableData[i].recLocDesc, 'descripts')?.id; // 执行科室
        executiveDepartmentTableData[i].locTypeID = Util.returnDataCccordingToAttributes(selectData && 'locType' in selectData ? selectData.locType : [], executiveDepartmentTableData[i].locTypeDesc, 'descripts')?.id; // 科室类型
        executiveDepartmentTableData[i].locID = Util.returnDataCccordingToAttributes(selectData && 'loc' in selectData ? selectData.loc : [], executiveDepartmentTableData[i].locDesc, 'descripts')?.id; // 开单科室
      }

      // 互斥医嘱
      for (var i = 0; i < mutexTableData.length; i++) {
        let detailitem = 'detailitem' in mutexTableData[i] && mutexTableData[i].detailitem ? mutexTableData[i].detailitem : [];
        if (detailitem && Array.isArray(detailitem) && detailitem.length > 0) {
          let medRecord = Util.returnDataCccordingToAttributes(detailitem, mutexTableData[i].exclMedItemDesc, 'medDesc'); // 医嘱
          mutexTableData[i] = {
            ...mutexTableData[i],
            exclMedItemCode: medRecord?.medCode,
            exclMedItemID: medRecord?.medID,
            detailitem: undefined, // 清空数据，防止出参过多影响保存接口效率
          }
        }
      }

      let oldMedObj = rowData && 'medObj' in rowData && rowData.medObj ? rowData.medObj : {};
      let data = {
        params: [{
          medObj: { ...oldMedObj, ...basicInfoValues },
          chargeLinkMedArr: staticChargeList, // 关联收费项
          partArr: subCatType === 'E' ? positionTableData : [], // 检查部位
          lisArr: subCatType === 'L' ? inspectTableData : [], // 检验项目
          recLocArr: executiveDepartmentTableData, // 执行科室
          exclusiveMedItemArr: mutexTableData, // 互斥医嘱
          aliasArr: aliasTableData, // 医嘱别名
        }]
      }
      // 调用接口保存
      let res = await React.$asyncPost(this, '02020386', data);
      message.success(res && res.errorMessage ? res.errorMessage : '保存成功');
      let rowID = res && res.result ? String(res.result) : '';
      this.setState({ loading: false, rowData: { ...this.state.rowData, medID: rowID }, isValidate });
      this.props.getTableData && this.props.getTableData(res.result);
    } catch (error) {
      console.log(error)
      this.setState({ loading: false });
    }
  }

  // 保存时展示修改前和修改后的
  handleDifferenceComparison = (staticChargeList, basicInfoValues, isValidate) => {
    const { rowData } = this.state;
    let baseInfoDiffData = this.basicInfoRef && this.basicInfoRef.getDiffData && this.basicInfoRef.getDiffData(); // 医嘱项基本信息变更的数据
    let isModifyCharge = this.isModify(rowData?.chargeLinkMedArr, staticChargeList); // 收费信息
    // console.log("isModifyCharge", isModifyCharge)
    if ((baseInfoDiffData && baseInfoDiffData.length > 0) || isModifyCharge) {
      confirm({
        title: '修改提醒',
        content: `医嘱项${basicInfoValues?.medDesc}(${basicInfoValues?.medCode})中存在内容被修改，是否确认保存?`,
        onOk: () => {
          this.handleHttpSave(staticChargeList, basicInfoValues, isValidate);
        },
        onCancel: () => {
          console.log("取消了")
        },
      });
    } else {
      message.error("没有修改的数据需要保存。")
    }
  }

  // 修改table信息时调用接口保存
  handleSaveTableData = () => {
    let { rowData } = this.state;
    let oldMedObj = rowData && 'medObj' in rowData && rowData.medObj ? rowData.medObj : {};
    if (oldMedObj && 'medID' in oldMedObj && oldMedObj.medID) {
      this.handleSave('table');
    }
  }

  // 判断是否修改
  isModify = (oldArr, newArr) => {
    // console.log("oldArr", oldArr, newArr)
    if (JSON.stringify(oldArr) !== JSON.stringify(newArr)) {
      return true;
    }
    return false;
  }

  // 记录收费项表单的值
  recordFormInput = record => {
    this.setState({
      chargeModalData: { ...record }
    })
  }

  // 仅显示生效
  handleChargeChecked = e => {
    this.setState({ chargeChecked: e.target.checked })
  }

  // 获取界面显示的收费项信息
  filterChargeList = () => {
    // statusFlag: A - 正在用  B - 已停用  C - 将启用
    let { chargeChecked, chargeList } = this.state;
    let newChargeList = chargeList && Array.isArray(chargeList) ? JSON.parse(JSON.stringify(chargeList)) : [];
    if (chargeChecked) {
      return newChargeList && newChargeList.length > 0 ? newChargeList.filter(item => item.statusFlag === 'A' || item.statusFlag === 'C') : [];
    } else {
      return newChargeList;
    }
  }

  render() {
    let { height } = this.props;
    let { loading, subCatType, selectData, rowData, chargeItemActiveData, positionTableData, positionColumns, positionChargeColumns, inspectTableData, inspectColumns, specimenTableData, specimenColumns,
      executiveDepartmentTableData, executiveDepartmentColumns, mutexTableData, mutexColumns, aliasTableData, aliasColumns, positionChargeTableData, chargeModalData, chargeChecked
    } = this.state;
    let newChargeList = this.filterChargeList();
    let rowID = rowData && 'medObj' in rowData && rowData.medObj && 'medID' in rowData.medObj && rowData.medObj.medID ? rowData.medObj.medID : '';
    return (
      <Spin spinning={loading} tip="数据保存中...">
        <div style={{ height: height + 'px' }} className='add-order-item scroll-bar-style'>
          <Card
            type="inner"
            title={<div>基本信息</div>}
            size="small"
          >
            <BasicInformation
              selectData={selectData}
              rowData={rowData?.medObj}
              setChargeItemValues={this.setChargeItemValues} // 选择医嘱子类设置收费项代码
              onRef={ref => this.basicInfoRef = ref}
              getOrderCategory={this.getOrderCategory}
            />
          </Card>

          {/* 收费项信息 */}
          <Card
            type="inner"
            style={{ marginTop: '16px' }}
            title={<div className="flex-between-center">
              <div>
                收费项信息
                <span style={{ fontSize: '12px', color: '#999' }}>（一条收费项直接在界面填写，或选择修改，底下按钮保存。）注：背景黄色的为将生效，背景红色为失效。</span>
              </div>
              <div>
                <Checkbox checked={chargeChecked} onChange={this.handleChargeChecked}>仅显示生效</Checkbox>
                <Button
                  style={{ marginLeft: '12px' }}
                  type="primary"
                  ghost
                  onClick={() => this.handleEnterChargeItem(() => this.handleOpenChargeList('chargeList'))}
                >
                  收费项列表
                </Button>
                <Button
                  style={{ marginLeft: '12px' }}
                  className="add-btn add-btn-nohover"
                  icon="plus"
                  onClick={() => this.handleEnterChargeItem(() => this.handleAddChargeItem('chargeList'))}
                >
                  新增收费项
                </Button>
              </div>
            </div>}
            size="small"
          >
            <div className="charge-list" style={{ display: newChargeList && newChargeList.length > 0 ? 'flex' : 'none' }}>
              {newChargeList && newChargeList.map((item, index) => {
                return (
                  <div
                    key={index}
                    className={(chargeItemActiveData?.key === item.key ? 'charge-list-item-active' : '') + (item.statusFlag === 'C' ? ' charge-list-item-bg' : (item.statusFlag === 'B' ? ' charge-list-item-bg2' : '')) + ' charge-list-item flex-column-between'}
                    onClick={() => this.handleChargeItemClick(item, index)}
                  >
                    <Popconfirm
                      title="删除不可恢复，确定要删除吗？"
                      onClick={this.handleStopPropagation}
                      onCancel={this.handleStopPropagation}
                      onConfirm={(e) => this.handleDeleteChargeItem(item, e)}
                    >
                      <Icon type="close-circle" className="charge-list-item-close" />
                    </Popconfirm>
                    <div className="charge-list-item-title ellipsis" title={item.chargeDesc}>{item.chargeDesc}</div>
                    <div className="charge-list-item-price" style={{ marginTop: '4px' }}>
                      {('chargeNum' in item && item.chargeNum ? String(item.chargeNum) : '') + ('chargeUnitDesc' in item && item.chargeUnitDesc ? item.chargeUnitDesc : '')}
                      <span>￥{item?.chargePrice || item?.effectivePrice || '无数据'}</span>
                    </div>
                  </div>
                )
              })}
            </div>
            <div style={{ display: (rowID && chargeItemActiveData && chargeItemActiveData.key) || (!rowID) ? 'block' : 'none' }}>
              <ChargeItemInformation
                rowData={chargeItemActiveData}
                selectData={selectData}
                onRef={ref => this.chargeItemInfoRef = ref}
              />
            </div>
          </Card>

          {/* 关联检查部位 */}
          <Card
            type="inner"
            style={{ marginTop: '16px', display: subCatType === 'E' ? 'block' : 'none' }}
            title={<div>关联检查部位</div>}
            size="small"
          >
            <Row>
              <Col span={10}>
                <UnitMaintenance
                  dataSource={positionTableData}
                  columns={positionColumns}
                  title="关联部位列表"
                  desc=""
                  result=""
                  recordID="medItemPartID" // 删除传给后台的字段
                  onRef={ref => this.positionRef = ref}
                  handleRowClick={this.handlePositionRowClick}
                  handleDelete={this.handlePositionDelete}
                  handleSave={this.handlePositionSave}
                />
              </Col>
              <Col span={14}>
                <div style={{ paddingLeft: '12px', position: 'relative' }}>
                  <UnitMaintenance
                    dataSource={positionChargeTableData}
                    columns={positionChargeColumns}
                    title="部位关联收费项（选择一条部位进行关联）"
                    desc=""
                    result=""
                    recordID="partLinkChargeID" // 删除传给后台的字段
                    addBtnName="收费项列表"
                    tableFixed="right"
                    totalWidth={850}
                    operationSymbol="*"
                    saveoperation="totalMoney=partLinkChargeNum^chargePrice"
                    isDelete="N"
                    btnClick={() => this.handleOpenChargeList('positionChargeTableData')}
                    onRef={ref => this.positionChargeRef = ref}
                    // handleDelete={this.handlePositionChargeDelete}
                    handleSave={this.handlePositionChargeSave}
                    editCurrentLine={this.handlepositionEditCurrentLine}
                  />
                  <div style={{ width: '12px', position: 'absolute', top: 0, left: 0, height: '100%' }}></div>
                </div>
              </Col>
            </Row>
          </Card>

          {/* 关联检验项目 */}
          <Card
            type="inner"
            size="small"
            style={{ marginTop: '16px', display: subCatType === 'L' ? 'block' : 'none' }}
            title={<div>关联检验项目</div>}
            extra={(
              <Button type="primary" ghost onClick={this.handleOpenInspectionItem}>检验项列表</Button>
            )}
          >
            <Row>
              <Col span={10}>
                <UnitMaintenance
                  dataSource={inspectTableData}
                  columns={inspectColumns}
                  title="关联检验项目"
                  desc=""
                  result=""
                  recordID="medItemLinkLisID" // 删除传给后台的字段
                  onRef={ref => this.inspectRef = ref}
                  handleRowClick={this.handleInspectRowClick}
                  handleSave={this.handleInspectTableSave}
                  handleDelete={this.handleInspectDelete}
                />
              </Col>
              <Col span={14}>
                <div style={{ paddingLeft: '12px', position: 'relative' }}>
                  <UnitMaintenance
                    dataSource={specimenTableData}
                    columns={specimenColumns}
                    title="项目标本（选择一条检验项目进行关联）"
                    desc=""
                    result=""
                    recordID="medItemLisLinkSpecID" // 删除传给后台的字段
                    onRef={ref => this.specimenRef = ref}
                    confirmBeforeAdd={this.handleConfirmBeforeAdd}
                    handleSave={this.handleSpecimenSave}
                    handleDelete={this.handleSpecimenDelete}
                  />
                  <div style={{ width: '12px', position: 'absolute', top: 0, left: 0, height: '100%' }}></div>
                </div>
              </Col>
            </Row>
          </Card>

          {/* 其他 */}
          <Card
            type="inner"
            style={{ marginTop: '16px' }}
            title={<div>其他信息</div>}
            size="small"
          >
            <UnitMaintenance
              dataSource={executiveDepartmentTableData}
              columns={executiveDepartmentColumns}
              title="执行科室设置"
              desc=""
              result=""
              recordID="medItemRecID" // 删除传给后台的字段
              isShowIcon="Y"
              onRef={ref => this.executiveDepartmentRef = ref}
              handleSave={data => this.setState({ executiveDepartmentTableData: [...data] }, () => { this.handleSaveTableData(); })}
              handleDelete={this.handleExecutiveDepartmentDelete}
            />

            <UnitMaintenance
              dataSource={mutexTableData}
              columns={mutexColumns}
              title="互斥医嘱项目"
              desc=""
              result=""
              recordID="exclusiveMedItemID" // 删除传给后台的字段
              isShowIcon="Y"
              onRef={ref => this.mutexRef = ref}
              handleSave={data => this.setState({ mutexTableData: [...data] }, () => { this.handleSaveTableData(); })}
              handleDelete={this.handleMutexDelete}
            />

            <UnitMaintenance
              dataSource={aliasTableData}
              columns={aliasColumns}
              title="别名"
              desc=""
              result=""
              deleteCode="02020228"
              recordID="medAliasID" // 删除传给后台的字段
              rowIDName="orderAliasID" // 对应的数据ID
              isShowIcon="Y"
              onRef={ref => this.aliasRef = ref}
              handleSave={data => this.setState({ aliasTableData: [...data] }, () => { this.handleSaveTableData(); })}
            />
          </Card>

          {/* 新增收费项弹窗 */}
          <ChargeItemModal
            onRef={ref => this.chargeItemRef = ref}
            rowData={chargeModalData}
            selectData={selectData}
            handleAdd={this.handleAddChargeList}
            recordFormInput={this.recordFormInput}
          />

          {/* 收费项列表 */}
          <ListOfChargeItems
            onRef={ref => this.listChargeRef = ref}
            handleAdd={this.handleAddChargeList}
          />

          {/* 检验项列表 */}
          <InspectionItemList
            onRef={ref => this.inspectionItemRef = ref}
            handleAdd={this.handleAddInspectionItem}
          />
        </div >
      </Spin>
    )
  }
};

export default AddOrderItem;