import React, { Component } from 'react';
import { connect } from 'react-redux';
import DocumentTitle from 'react-document-title';
import 'antd-mobile/dist/antd-mobile.less';
import Xt from './xt';
import ZaXt from './zaXt';
import ZaJd from './zaJd';
import Jd from './jd';
import DnaXt from './dnaXt';
import DnaYsfyXt from './dnaYsfyXt';
import Dg from './dg';
import Mq from './mq';
import GeneReport from './geneReport';
import Country from './country';
import Normal from './normal';
import DnaAppRaisal from './dnaAppRaisal';

@connect(({ ckuCertificate }) => ({ ckuCertificate }))
class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  componentWillMount = () => { };

  componentDidMount = () => {
    const { id, token, type, club } = this.props.location.query;
    if (token) {
      window.sessionStorage.setItem('token', token);
      window.sessionStorage.setItem('club', club)
    }
    if (type === 'gene') {
      //基因报告
      if (id) {
        this.props.dispatch({
          type: 'ckuCertificate/geneReport',
          payload: {
            id,
          },
        });
      }
    } else {
      //cku证书
      if (id) {
        this.props.dispatch({
          type: 'ckuCertificate/certificateInfo',
          payload: {
            id,
          },
        });
      }
    }

  };

  componentWillUnmount = () => {
    this.props.dispatch({
      type: 'ckuCertificate/clean',
    });
  };

  render() {
    const data = this.props.ckuCertificate;
    const { type } = this.props.location.query;
    return (
      <div>
        {type === 'gene'
          ? (
            data ? <GeneReport ckuCertificate={data} /> :  <Normal />
          )
          : (
            <DocumentTitle title="电子证书">
              {data.certificateType === 'XT' ? (
                <Xt ckuCertificate={data} />
              ) : data.certificateType === 'ZA_XT' ? (
                <ZaXt ckuCertificate={data} />
              ) : data.certificateType === 'ZA_JD' ? (
                <ZaJd ckuCertificate={data} />
              ) : data.certificateType === 'JD' ? (
                <Jd ckuCertificate={data} />
              ) : data.certificateType === 'DNA_XT' ? (
                <DnaXt ckuCertificate={data} />
              ) : data.certificateType === 'DNA_YSFY_XT' ? (
                <DnaYsfyXt ckuCertificate={data} />
              ) : data.certificateType === 'DG' ? (
                <Dg ckuCertificate={data} />
              ) : data.certificateType === 'MQ' ? (
                <Mq ckuCertificate={data} />
              ) : data.certificateType === 'COUNTRY' ? (
                <Country ckuCertificate={data} />
              ) : data.certificateType === 'DNA_APPRAISAL' ? (
                <DnaAppRaisal ckuCertificate={data} />
              ) : null
              }
            </DocumentTitle>
          )}
      </div>


    );
  }
}

export default Index;
