/*
 * Create:      刘丹
 * CreateDate:  2023/10/19
 * Describe：   电子病历模板-新病历汇总打印中转
 * */
import React from 'react';
import EmrSummaryPrint from 'pages/newEmr/summaryPrinting/EmrSummaryPrint.jsx';
import SummaryPrinting from 'pages/workstation/SummaryPrinting.jsx';
import { Spin } from 'antd';
import { getEMRToken } from '../utils/index';

class EmrSummaryPrintMode extends React.Component {
  constructor(props) {
    super(props);
    const switchData = JSON.parse(sessionStorage.getItem('newemr-switchData'));
    let currentPatData = React.$getSessionData('titleData');

    this.state = {
      currentPatData,
      loading: true,
      switchData,
      useNewEmr: false, // 是否使用新病历
      token: '', //emr Token
    }
  }
  componentDidMount () {
    this.setState({
      loading: true,
    }, () => {
      getEMRToken(this.state.currentPatData?.admDateTime).then(({ newEmrToken, useNewEmr }) => {
        this.setState({
          token: newEmrToken,
          useNewEmr,
          loading: false,
        });
      }).catch(() => {
        this.setState({
          loading: false,
        });
      });
    });
  }
  render () {
    return (
      <>
        {this.state.loading
          ? <Spin tip="加载中...">
            <div style={{ height: '400px' }}></div>
          </Spin >
          : this.state.useNewEmr
            ? <EmrSummaryPrint {...this.props} />
            : <SummaryPrinting {...this.props} />
        }
      </>
    )
  }
};
export default EmrSummaryPrintMode;
