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';

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

  componentDidMount = () => {
    const { id, token } = this.props.location.query;
    if (token) {
      window.sessionStorage.setItem('token', token);
    }
    if (id) {
      this.props.dispatch({
        type: 'ckuCertificate/newdogchipView',
        payload: {
          id,
        },
      });
    }
  };

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

  render() {
    const data = this.props.ckuCertificate;
    return (
      <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} />
        ) : null}
      </DocumentTitle>
    );
  }
}

export default Index;
