/**
 * 公共组件弹框
 */
import React from 'react';
import { Modal } from 'antd';
// import { Util, } from 'tools/index';
// import asyncComponent from '../../../routers/AsyncComponent.js';
import CaseInformationPage from './CaseInformationPage';
import CaseInformationLogNew from 'pages/newEmr/CaseInformationLog';
import CaseInformationPageHospital from './CaseInformationPageHospital';
import { getEMRToken } from 'pages/newEmr/utils/index.js';
import '../style/index.less';

class ShowMedicalRecordModal extends React.Component {
  constructor(props) {
    super(props);
    var userData = JSON.parse(sessionStorage.getItem('userData'));
    this.state = {
      userData: userData,
      useNewEmr: false, // 是否使用显示新的自研emr预览
      token: '', // emr访问token
    }
  }
  //   componentWillReceiveProps(nextProp) {
  //     if (nextProp.isShow === true) {
  //       this.setState({
  //         component: nextProp.dataSource.component
  //       })
  //     } else if (this.props.isShow === false) {

  //     }
  //   }
  componentDidMount () {
    this.initData(this.props);
  }
  componentWillReceiveProps (nextProp) {
    this.initData(nextProp);
  }
  initData = (nextProp) => {
    if (nextProp.isShow) {
      const { admDate, admDateTime } = this.props.rowData || {};
      getEMRToken(admDate || admDateTime).then(({ newEmrToken, useNewEmr }) => {
        this.setState({
          token: newEmrToken,
          useNewEmr,
        });
      });
    }
  }
  closeModal (name) {
    let { onHide } = this.props;
    onHide && onHide();
  }

  render () {
    const { modalTitle } = this.props;
    // const Component = asyncComponent(() => import('../../../' + this.state.component));
    // modal 是否弹框标记
    return <div>
      <Modal className='medical-component-modal'
        title={modalTitle || (this.props.admTypeCode == 'O' ? '门诊病历' : '住院病历')}
        maskClosable={false}
        visible={this.props.isShow}
        onCancel={this.closeModal.bind(this)}
        footer={null}
      >
        {/* <Component modal="1" /> */}
        {/* admTypeCode  0 门诊 1住院 */}
        {
          this.props.admTypeCode == 'O' ?
            (this.state.useNewEmr
              ? <CaseInformationLogNew
                token={this.state.token}
                admID={this.props && this.props.historyAdmID ? this.props.historyAdmID : ""}
              />
              : <CaseInformationPage
                fGroupTempByInfo="previewEMRRec"
                fGroup="previewEMRRec"
                isDidUpdate="Y"
                editorID="SMRWriterControl"
                caseInformationPageTabs="N"
                clpHeader="80vh"
                viewEMRFlag={this.props && 'viewEMRFlag' in this.props ? this.props.viewEMRFlag : 'N'}
                initTemplate={this.props && 'initTemplate' in this.props ? this.props.initTemplate : 'N'}
                isBasicOperation={this.props && 'isBasicOperation' in this.props ? this.props.isBasicOperation : true}
                historyAdmID={this.props && this.props.historyAdmID ? this.props.historyAdmID : ""}
                isOperable={this.props && 'isOperable' in this.props ? this.props.isOperable : 'Y'}
                prCont={this.props && 'prCont' in this.props ? this.props.prCont : 'N'}
              />)
            : <CaseInformationPageHospital
              isDidUpdate="Y"
              clpHeader="80vh"
              fGroup="previewEMRRec"
              caseInformationPageTabs="N"
              editorID="SMRWriterControlHospital"
              viewEMRFlag={this.props && 'viewEMRFlag' in this.props ? this.props.viewEMRFlag : 'N'}
              initTemplate={this.props && 'initTemplate' in this.props ? this.props.initTemplate : 'N'}
              isBasicOperation={this.props && 'isBasicOperation' in this.props ? this.props.isBasicOperation : true}
              historyAdmID={this.props && this.props.historyAdmID ? this.props.historyAdmID : ""}
              isOperable={this.props && 'isOperable' in this.props ? this.props.isOperable : 'Y'}
              prCont={this.props && 'prCont' in this.props ? this.props.prCont : 'N'}
            />
        }
      </Modal>
    </div>
  }
}

export default ShowMedicalRecordModal;