/*
 * Creater:     shizi
 * CreateDate:  2022/03/31
 * Describe：   必填库存项
 * */
import React, { Component } from 'react';
import { Util } from 'tools';
import '../style/new-drug.less';

import DynamicRenderingForm from 'pages/common/DynamicRenderingForm';
import UnitSetting from './UnitSetting'; // 单位设置
import UnitMaintenance from './UnitMaintenance'; // 子table列表维护

class RequiredInventoryItem extends Component {
  constructor(props) {
    super(props);
    var userData = JSON.parse(window.sessionStorage.userData);
    this.state = {
      userData,
      collapseKey: '1',
      activeKey: '',
      rowData: {},
      selectData: {},
      formData: [], // 基本信息
      basicUnitFormData: [], // 住院长期发药单位及系数
      valuationUnitFormData: [], // 门诊/住院
      basicPreview: '入库单位=系数+发药单位', // 住院长期预览
      valuationPreview: '入库单位=系数+发药单位', // 门诊/住院临时预览
      equivalentColumns: [], // 剂量单位表头数据
      doseUnitArr: [], // 剂量单位表格数据
      dispUomArr: [], // 发药单位表头数据
      dispensingColumns: [], // 发药单位表格数据
      baseUnitDesc: '', // 住院长期发药单位描述 - 对照单位
      equivalentPreview: '等效数量+剂量单位=对照单位', // 剂量单位预览
      dispensingPreview: '发药单位+系数=对照单位', // 更多发药单位预览
      billUnitSelectData: [], // 临时发药单位下拉数据
    };
    this.staticFieldsValue = {};
  }

  static getDerivedStateFromProps(nextProps, prevState) {
    //该方法内禁止访问this
    if (('selectData' in nextProps && (JSON.stringify(nextProps.selectData) !== JSON.stringify(prevState.selectData))) || ('rowData' in nextProps && (JSON.stringify(nextProps.rowData) !== JSON.stringify(prevState.rowData)))) {
      //通过对比nextProps和prevState，返回一个用于更新状态的对象
      return {
        baseUnitDesc: nextProps && 'rowData' in nextProps && 'stockObj' in nextProps.rowData && 'baseUnitDesc' in nextProps.rowData.stockObj ? nextProps.rowData.stockObj.baseUnitDesc : '',
        billUnitSelectData: nextProps && 'rowData' in nextProps && 'billUnitSelectData' in nextProps.rowData ? nextProps.rowData.billUnitSelectData : [], // 临时发药单位
        rowData: nextProps.rowData,
        activeKey: nextProps.activeKey,
        selectData: nextProps.selectData,
        doseUnitArr: nextProps && 'rowData' in nextProps && 'doseUnitArr' in nextProps.rowData ? nextProps.rowData.doseUnitArr : [], // 剂量单位/等效单位
        dispUomArr: nextProps && 'rowData' in nextProps && 'dispUomArr' in nextProps.rowData ? nextProps.rowData.dispUomArr : [], // 发药单位
      }
    }
    //不需要更新状态，返回null
    return null
  }

  componentDidMount() {
    this.getFormData();
    this.getBasicUnitFormData();
    this.getValuationUnitFormData();
    this.getEquivalentColumnsData();
    this.getDispensingColumns();
    this.props.onRef && this.props.onRef(this);
  }

  componentDidUpdate(prevProps, prevState) {
    if (this.state.activeKey === '2') return; // 防止无用加载
    if ('selectData' in prevProps && (JSON.stringify(prevProps.selectData) !== JSON.stringify(this.state.selectData))) {
      this.getEquivalentColumnsData();
      this.getDispensingColumns();
    }
    if (('selectData' in prevProps && (JSON.stringify(prevProps.selectData) !== JSON.stringify(this.state.selectData))) || ('rowData' in prevProps && (JSON.stringify(prevProps.rowData) !== JSON.stringify(this.state.rowData)))) {
      this.getFormData();
      this.getBasicUnitFormData();
      this.getValuationUnitFormData();
    }
    if ((prevProps.rowData.doseUnitArr !== undefined) && (JSON.stringify(prevProps.rowData.doseUnitArr) !== JSON.stringify(this.state.doseUnitArr))) {
      this.equivalentRef && this.equivalentRef.getTableData(this.state.doseUnitArr); // 计量单位/等效单位
    }
    if ((prevProps.rowData.dispUomArr !== undefined) && (JSON.stringify(prevProps.rowData.dispUomArr) !== JSON.stringify(this.state.dispUomArr))) {
      this.dispensingRef && this.dispensingRef.getTableData(this.state.dispUomArr); // 发药单位
    }
  }

  // 切换tabs进行表单赋值
  setTableData = () => {
    let { doseUnitArr, dispUomArr } = this.state;
    this.setState({ equivalentPreview: '等效数量+剂量单位=对照单位', dispensingPreview: '发药单位+系数=对照单位' }, () => {
      this.equivalentRef && this.equivalentRef.getTableData(doseUnitArr); // 计量单位/等效单位
      this.dispensingRef && this.dispensingRef.getTableData(dispUomArr); // 发药单位
    })
  }

  // 基本信息form数据
  getFormData = () => {
    let { selectData, rowData } = this.state;
    const stockObj = rowData && 'stockObj' in rowData ? rowData.stockObj : {};
    const moreHospFlag = 'moreHospFlag' in stockObj && stockObj.moreHospFlag ? stockObj.moreHospFlag : 'N';
    let formData = [{
      dataIndex: 'stkSubCatID',
      title: '库存分类',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'stkSubCat' in selectData ? selectData.stkSubCat : [],
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'stockSpec',
      title: '包装规格',
      typeCode: 'Input',
      required: 'Y',
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'itemPCID',
      title: '物价分类',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'PC' in selectData ? selectData.PC : [],
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'itemECID',
      title: '核算项目分类',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'EC' in selectData ? selectData.EC : [],
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'itemICID',
      title: '住院收据费用',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'IC' in selectData ? selectData.IC : [],
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'itemOCID',
      title: '门诊收据费用',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'OC' in selectData ? selectData.OC : [],
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'itemACID',
      title: '会计科目',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'AC' in selectData ? selectData.AC : [],
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'itemMCID',
      title: '病案分类',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'MC' in selectData ? selectData.MC : [],
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'itemTCID',
      title: '收费分类',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'TC' in selectData ? selectData.TC : [],
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'itemStDate',
      title: '生效日期',
      typeCode: 'Date',
      required: 'Y',
      default: 0,
      disabled: moreHospFlag,
      col: 8
    }, {
      dataIndex: 'itemEndDate',
      title: '失效日期',
      typeCode: 'Date',
      disabled: moreHospFlag,
      col: 8
    }];
    this.setState({ formData })
  }

  // 入库单位与基本单位转换系数form数据
  getBasicUnitFormData = () => {
    let { selectData, rowData } = this.state;
    const stockObj = rowData && 'stockObj' in rowData ? rowData.stockObj : {};
    const disabled = 'disabled' in stockObj && stockObj.disabled ? stockObj.disabled : 'N';
    const moreHospFlag = 'moreHospFlag' in stockObj && stockObj.moreHospFlag ? stockObj.moreHospFlag : 'N';
    let formData = [{
      dataIndex: 'purUnitID',
      title: '入库单位',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'unit' in selectData ? selectData.unit : [],
      changeCallBack: this.handlePurUnitChange,
      callBackResult: "Fn",
      disabled: disabled === 'Y' || moreHospFlag === 'Y' ? 'Y' : 'N',
      col: 8
    }, {
      dataIndex: 'baseFac',
      title: '转换系数',
      typeCode: 'Input',
      required: 'Y',
      changeCallBack: this.basicUnitConversionPreview,
      callBackResult: "Fn",
      disabled: disabled === 'Y' || moreHospFlag === 'Y' ? 'Y' : 'N',
      col: 8
    }, {
      dataIndex: 'baseUnitID',
      title: '住院长期发药单位',
      typeCode: 'Select',
      required: 'Y',
      detailItem: selectData && 'unit' in selectData ? selectData.unit : [],
      formItemCol: { labelCol: 12, wrapperCol: 12 },
      changeCallBack: this.handleBaseUnitChange,
      callBackResult: "Fn",
      disabled: disabled === 'Y' || moreHospFlag === 'Y' ? 'Y' : 'N',
      col: 8
    }];
    this.setState({ basicUnitFormData: formData })
  }

  // 单位换算预览
  basicUnitConversionPreview = (e, dataIndex, values) => {
    const { selectData } = this.state;
    let isFlag = Util.judgeValue(values);
    if (isFlag) {
      let purUnitItem = Util.returnDataCccordingToAttributes(selectData && 'unit' in selectData ? selectData.unit : [], values.purUnitID);
      let baseUnitItem = Util.returnDataCccordingToAttributes(selectData && 'unit' in selectData ? selectData.unit : [], values.baseUnitID);
      let basicPreview = '1' + purUnitItem?.unitDesc + '=' + values?.baseFac + baseUnitItem?.unitDesc;
      this.setState({ basicPreview })
    }
  }

  // 入库单位选择
  handlePurUnitChange = (e, dataIndex, values) => {
    let { selectData } = this.state;
    this.basicUnitConversionPreview(e, dataIndex, values);
    // 门诊/住院临时医嘱发药单位及系数
    this.valuationUnitRef && this.valuationUnitRef.setFieldsValue({
      purUnitID: e
    });
    let purUnitObj = Util.returnDataCccordingToAttributes(selectData && 'unit' in selectData ? selectData.unit : [], e);
    purUnitObj.dataIndex = 'purUnitID';
    this.getBillUnitSelectData(purUnitObj);
  }

  // 判断临时发药单位是否包含选择选择的数据，不包含则插入到临时发药单位下拉数据中
  getBillUnitSelectData = (currentData) => {
    let { billUnitSelectData } = this.state;
    let isFlag = false;
    for (var i = 0; i < billUnitSelectData.length; i++) {
      if (billUnitSelectData[i].dataIndex === currentData.dataIndex) {
        billUnitSelectData[i] = currentData;
        isFlag = true;
        break;
      }
    }
    if (!isFlag) {
      billUnitSelectData.push(currentData);
    }
    let billUnitFlag = false;
    let billUnitID = this.valuationUnitRef && this.valuationUnitRef.getFieldValue('billUnitID'); // 门诊/住院临时发药单位
    for (var i = 0; i < billUnitSelectData.length; i++) {
      if (billUnitSelectData[i].id === billUnitID) {
        billUnitFlag = true;
        break;
      }
    }
    this.setState({ billUnitSelectData }, () => {
      this.getValuationUnitFormData();
      if (!billUnitFlag) { // 判断临时发药单位在下拉数据中是否存在，不存在则情况清除选择的数据
        this.valuationUnitRef && this.valuationUnitRef.setFieldsValue({
          billUnitID: undefined
        });
      }
    })
  }

  // 住院长期发药单位change事件
  handleBaseUnitChange = (e, dataIndex, values) => {
    let { selectData } = this.state;
    this.basicUnitConversionPreview(e, dataIndex, values);
    this.modifyTableControlUnit(e, dataIndex, values);
    let baseUnitObj = Util.returnDataCccordingToAttributes(selectData && 'unit' in selectData ? selectData.unit : [], e);
    baseUnitObj.dataIndex = 'baseUnitID';
    this.getBillUnitSelectData(baseUnitObj);
  }

  // 修改table中的对照单位
  modifyTableControlUnit = (e, dataIndex, values) => {
    const { selectData } = this.state;
    let doseUnitData = this.equivalentRef && this.equivalentRef.handleSave(false); // 剂量单位
    let doseUnitArr = 'tableData' in doseUnitData && doseUnitData.tableData ? doseUnitData.tableData : [];
    let dispUomData = this.dispensingRef && this.dispensingRef.handleSave(false); // 更多发药单位
    let dispUomArr = 'tableData' in dispUomData && dispUomData.tableData ? dispUomData.tableData : [];
    let baseUnitDesc = Util.returnDataCccordingToAttributes(selectData && 'unit' in selectData ? selectData.unit : [], e)?.unitDesc;
    this.setState({ baseUnitDesc }, () => {
      if (doseUnitArr && doseUnitArr.length > 0) {
        for (var i = 0; i < doseUnitArr.length; i++) {
          doseUnitArr[i].baseUnitDesc = baseUnitDesc;
        }
        this.equivalentRef && this.equivalentRef.getTableData(doseUnitArr); // 计量单位/等效单位
      }
      if (dispUomArr && dispUomArr.length > 0) {
        for (var i = 0; i < dispUomArr.length; i++) {
          dispUomArr[i].baseUnitDesc = baseUnitDesc;
        }
        this.dispensingRef && this.dispensingRef.getTableData(dispUomArr); // 发药单位
      }
    });
  }

  // 入库单位与计价单位转换系数form数据
  getValuationUnitFormData = () => {
    let { selectData, billUnitSelectData, rowData } = this.state;
    const stockObj = rowData && 'stockObj' in rowData ? rowData.stockObj : {};
    const disabled = 'disabled' in stockObj && stockObj.disabled ? stockObj.disabled : 'N';
    const moreHospFlag = 'moreHospFlag' in stockObj && stockObj.moreHospFlag ? stockObj.moreHospFlag : 'N';
    let formData = [{
      dataIndex: 'purUnitID',
      title: '入库单位',
      typeCode: 'Select',
      required: 'Y',
      disabled: 'Y',
      detailItem: selectData && 'unit' in selectData ? selectData.unit : [],
      changeCallBack: this.valuationUnitConversionPreview,
      callBackResult: "Fn",
      col: 8
    }, {
      dataIndex: 'billFac',
      title: '转换系数', // 转换系数(计价)
      typeCode: 'Input',
      required: 'Y',
      changeCallBack: this.valuationUnitConversionPreview,
      callBackResult: "Fn",
      disabled: disabled === 'Y' || moreHospFlag === 'Y' ? 'Y' : 'N',
      col: 8
    }, {
      dataIndex: 'billUnitID',
      title: '门诊/住院临时发药单位', // 计价单位
      typeCode: 'Select',
      required: 'Y',
      detailItem: billUnitSelectData,
      formItemCol: { labelCol: 12, wrapperCol: 12 },
      changeCallBack: this.valuationUnitConversionPreview,
      callBackResult: "Fn",
      disabled: disabled === 'Y' || moreHospFlag === 'Y' ? 'Y' : 'N',
      col: 8
    }];
    this.setState({ valuationUnitFormData: formData })
  }

  // 单位换算预览
  valuationUnitConversionPreview = (e, dataIndex, values) => {
    const { selectData, billUnitSelectData } = this.state;
    let isFlag = Util.judgeValue(values);
    if (isFlag) {
      let purUnitItem = Util.returnDataCccordingToAttributes(selectData && 'unit' in selectData ? selectData.unit : [], values.purUnitID);
      let billUnitItem = Util.returnDataCccordingToAttributes(billUnitSelectData, values.billUnitID);
      let valuationPreview = '1' + purUnitItem?.unitDesc + '=' + values?.billFac + billUnitItem?.unitDesc;
      this.setState({ valuationPreview })
    }
  }

  // 获取剂量单位表头数据
  getEquivalentColumnsData = () => {
    let { selectData, rowData } = this.state;
    const stockObj = rowData && 'stockObj' in rowData ? rowData.stockObj : {};
    const moreHospFlag = 'moreHospFlag' in stockObj && stockObj.moreHospFlag ? stockObj.moreHospFlag : 'N';
    let columns = [{
      title: '剂量单位',
      dataIndex: 'doseUnitDesc',
      editable: true,
      width: '150px',
      align: 'center',
      inputType: 'Select',
      required: 'Y',
      disabled: moreHospFlag,
      detailitem: selectData && 'unit' in selectData ? selectData.unit : []
    }, {
      title: '等效数量',
      dataIndex: 'doseQty',
      editable: true,
      width: '150px',
      align: 'center',
      required: 'Y',
      disabled: moreHospFlag,
    }, {
      title: '默认数量',
      dataIndex: 'defaultQty',
      editable: true,
      width: '150px',
      align: 'center'
    }, {
      title: '对照单位',
      dataIndex: 'baseUnitDesc',
      editable: true,
      disabled: 'Y',
      width: '150px',
      align: 'center',
      inputType: 'Input',
    }];
    this.setState({ equivalentColumns: columns });
  }

  // 获取发药单位表格数据
  getDispensingColumns = () => {
    let { selectData, rowData } = this.state;
    const stockObj = rowData && 'stockObj' in rowData ? rowData.stockObj : {};
    const moreHospFlag = 'moreHospFlag' in stockObj && stockObj.moreHospFlag ? stockObj.moreHospFlag : 'N';
    let columns = [{
      title: '发药科室',
      dataIndex: 'dispLocDesc',
      editable: true,
      width: '150px',
      align: 'center',
      inputType: 'Select',
      required: 'Y',
      detailitem: selectData && 'loc' in selectData ? selectData.loc : [],
      disabled: moreHospFlag,
    }, {
      title: '发药单位',
      dataIndex: 'dispUnitDesc',
      editable: true,
      width: '150px',
      align: 'center',
      inputType: 'Select',
      required: 'Y',
      detailitem: selectData && 'unit' in selectData ? selectData.unit : [],
      disabled: moreHospFlag,
    }, {
      title: '转换系数',
      dataIndex: 'factor',
      editable: true,
      width: '150px',
      align: 'center',
      required: 'Y',
      disabled: moreHospFlag,
    }, {
      title: '对照单位',
      dataIndex: 'baseUnitDesc',
      editable: true,
      disabled: 'Y',
      width: '150px',
      align: 'center',
      inputType: 'Input'
    }];
    this.setState({ dispensingColumns: columns })
  }

  // 获取数据
  getFieldsValue = () => {
    let { billUnitSelectData } = this.state;
    let basicInfoData = this.basicInfoRef && this.basicInfoRef.getFieldsValue(); // 库存项基本信息
    let basicUnitData = this.basicUnitRef && this.basicUnitRef.getFieldsValue(); // 住院长期发药单位及系数
    let aluationUnitData = this.valuationUnitRef && this.valuationUnitRef.getFieldsValue(); // 门诊/住院临时医嘱发药单位及系数
    let doseUnitData = this.equivalentRef && this.equivalentRef.handleSave(); // 剂量单位
    let doseUnitArr = doseUnitData && 'tableData' in doseUnitData ? doseUnitData.tableData : [];
    let doseUnitEditingKey = doseUnitData && 'editingKey' in doseUnitData ? doseUnitData.editingKey : '';
    let dispUomData = this.dispensingRef && this.dispensingRef.handleSave(); // 更多发药单位
    let dispUomArr = dispUomData && 'tableData' in dispUomData ? dispUomData.tableData : [];
    let dispUomEditingKey = dispUomData && 'editingKey' in dispUomData ? dispUomData.editingKey : '';
    return {
      stockObj: {
        ...basicInfoData,
        ...basicUnitData,
        ...aluationUnitData
      },
      doseUnitArr,
      doseUnitEditingKey,
      dispUomArr,
      dispUomEditingKey,
      billUnitSelectData
    }
  }

  // 重置
  resetFields = () => {
    this.basicInfoRef && this.basicInfoRef.resetFields(); // 库存项基本信息
    this.basicUnitRef && this.basicUnitRef.resetFields(); // 住院长期发药单位及系数
    this.valuationUnitRef && this.valuationUnitRef.resetFields(); // 门诊/住院临时医嘱发药单位及系数
    this.equivalentRef && this.equivalentRef.resetFields(); // 剂量单位
    this.dispensingRef && this.dispensingRef.resetFields(); // 更多发药单位
  }

  // 保存
  handleSave = () => {
    let { selectData } = this.state;
    // 库存项基本信息
    this.basicInfoRef && this.basicInfoRef.handleSave().then(result => {
      const stockObj = this.staticFieldsValue && 'stockObj' in this.staticFieldsValue ? this.staticFieldsValue.stockObj : {};
      this.staticFieldsValue = {
        ...this.staticFieldsValue,
        stockObj: {
          ...stockObj,
          ...result,
          stockError: result?.error
        }
      }
    });
    // 住院长期发药单位及系数
    this.basicUnitRef && this.basicUnitRef.handleSave().then(result => {
      const stockObj = this.staticFieldsValue && 'stockObj' in this.staticFieldsValue ? this.staticFieldsValue.stockObj : {};
      this.staticFieldsValue = {
        ...this.staticFieldsValue,
        stockObj: {
          ...stockObj,
          ...result,
          basicError: result?.error
        }
      }
    });
    // 门诊/住院临时医嘱发药单位及系数
    this.valuationUnitRef && this.valuationUnitRef.handleSave().then(result => {
      const stockObj = this.staticFieldsValue && 'stockObj' in this.staticFieldsValue ? this.staticFieldsValue.stockObj : {};
      this.staticFieldsValue = {
        ...this.staticFieldsValue,
        stockObj: {
          ...stockObj,
          ...result,
          valuationError: result?.error
        }
      }
    });
    // 剂量单位
    let doseUnitData = this.equivalentRef && this.equivalentRef.handleSave();
    let doseUnitArr = doseUnitData && 'tableData' in doseUnitData ? doseUnitData.tableData : [];
    let doseUnitEditingKey = doseUnitData && 'editingKey' in doseUnitData ? doseUnitData.editingKey : '';
    // 更多发药单位
    let dispUomData = this.dispensingRef && this.dispensingRef.handleSave();
    let dispUomArr = dispUomData && 'tableData' in dispUomData ? dispUomData.tableData : [];
    let dispUomEditingKey = dispUomData && 'editingKey' in dispUomData ? dispUomData.editingKey : '';
    for (var i = 0; i < doseUnitArr.length; i++) {
      doseUnitArr[i].doseUnitID = Util.returnDataCccordingToAttributes(selectData && 'unit' in selectData ? selectData.unit : [], doseUnitArr[i].doseUnitDesc, 'descripts')?.id; // 剂量单位
    }
    for (var i = 0; i < dispUomArr.length; i++) {
      dispUomArr[i].dispLocID = Util.returnDataCccordingToAttributes(selectData && 'loc' in selectData ? selectData.loc : [], dispUomArr[i].dispLocDesc, 'descripts')?.id; // 发药科室
      dispUomArr[i].dispUnitID = Util.returnDataCccordingToAttributes(selectData && 'unit' in selectData ? selectData.unit : [], dispUomArr[i].dispUnitDesc, 'descripts')?.id; // 发药单位
    }
    this.staticFieldsValue = {
      ...this.staticFieldsValue,
      doseUnitArr,
      doseUnitEditingKey,
      dispUomArr,
      dispUomEditingKey,
    }
  }

  // 获取表单数据
  getStaticFieldsValue = () => {
    return this.staticFieldsValue;
  }

  // 剂量单位选中行操作
  handleEquivalentRowClick = record => {
    if ('doseQty' in record && 'doseUnitDesc' in record && 'baseUnitDesc' in record && record.doseUnitDesc && record.baseUnitDesc) {
      let equivalentPreview = (record.doseQty || 0) + record.doseUnitDesc + '=1' + record.baseUnitDesc;
      this.setState({ equivalentPreview })
    }
  }

  // 更多发药单位选中行操作
  handleDispensingRowClick = record => {
    if ('dispUnitDesc' in record && 'factor' in record && 'baseUnitDesc' in record && record.dispUnitDesc && record.baseUnitDesc) {
      let dispensingPreview = record.factor + record.dispUnitDesc + '=1' + record.baseUnitDesc;
      this.setState({ dispensingPreview })
    }
  }

  render() {
    let { rowData } = this.props;
    let { formData, basicUnitFormData, valuationUnitFormData, equivalentColumns, doseUnitArr, dispUomArr, dispensingColumns, basicPreview, valuationPreview, baseUnitDesc, equivalentPreview,
      dispensingPreview
    } = this.state;
    return (
      <div className='required-inventory-item'>
        {/* <div className="collapse-header">
          <div className="panel-left">
            <div onClick={() => this.handlecollapseClick('1')} className={collapseKey === '1' ? 'collapse-active' : ''}>库存项必要信息</div>
            <div onClick={() => this.handlecollapseClick('2')} className={collapseKey === '2' ? 'collapse-active' : ''}>库存项全部信息</div>
          </div>
          <Button type="primary" icon='plus'>新增库存项</Button>
        </div> */}
        <div className="card-title-left-icon rii-card-title"><div></div>库存项基本信息</div>
        <DynamicRenderingForm
          formItemCol={{ labelCol: 8, wrapperCol: 16 }}
          rowData={rowData && 'stockObj' in rowData ? rowData.stockObj : {}}
          formData={formData}
          onRef={ref => this.basicInfoRef = ref}
        />
        <div className="card-title-left-icon rii-card-title"><div></div>库存项单位维护</div>
        <UnitSetting
          key='basicUnit'
          title="1-住院长期发药单位及系数"
          desc=""
          result={basicPreview}
          formData={basicUnitFormData}
          rowData={rowData && 'stockObj' in rowData ? rowData.stockObj : {}}
          onRef={ref => this.basicUnitRef = ref}
        />
        <UnitSetting
          key='valuationUnit'
          title="2-门诊/住院临时医嘱发药单位及系数"
          desc=""
          result={valuationPreview}
          formData={valuationUnitFormData}
          rowData={rowData && 'stockObj' in rowData ? rowData.stockObj : {}}
          onRef={ref => this.valuationUnitRef = ref}
        />
        <UnitMaintenance
          dataSource={doseUnitArr}
          columns={equivalentColumns}
          baseUnitDesc={baseUnitDesc}
          title="3-剂量单位"
          desc="与基本单位转换"
          result={equivalentPreview}
          deleteCode="02020227"
          recordID="doseID"
          onRef={ref => this.equivalentRef = ref}
          setParentTableData={data => this.setState({ doseUnitArr: data })}
          handleRowClick={this.handleEquivalentRowClick}
        />
        <UnitMaintenance
          dataSource={dispUomArr}
          columns={dispensingColumns}
          baseUnitDesc={baseUnitDesc}
          title="4-更多发药单位"
          desc="用于增加门诊、住院发药单位"
          result={dispensingPreview}
          deleteCode="02020239"
          recordID="dispUomID"
          onRef={ref => this.dispensingRef = ref}
          setParentTableData={data => this.setState({ dispUomArr: data })}
          handleRowClick={this.handleDispensingRowClick}
        />
      </div>
    )
  }
};

export default RequiredInventoryItem;