import { connect } from 'dva/index';
import React, { Component, Fragment } from 'react';
import styles from './doc.less';
import { Form, List } from 'antd';
import {
  sldComLanguage, failTip,
} from '@/utils/utils';
import global from '@/global.less';

@connect(({ common }) => ({
  common,
}))

@Form.create()
export default class DocDetail extends Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      query: props.location.query,
      info: {},
    };
  }

  componentDidMount() {
    let id = this.state.query.id;
    if (id != undefined && id != null && id != '') {
      this.get_detail(id);
    } else {
      failTip(`${sldComLanguage('文章详情获取失败')}`);
    }
  }

  //获取数据列表
  get_detail = (id) => {
    console.log('***** get_detail ******');
    this.setState({ loading: true });
    const { dispatch } = this.props;
    dispatch({
      type: 'common/get_help_article_detail',
      payload: {
        id: id,
      },
      callback: (res) => {
        console.log('res:{}', res);
        this.setState({ loading: false });
        if (res.state == 200) {
          this.setState({
            info: res.data,
          });
        } else {
          failTip(`${sldComLanguage('文章详情获取失败')}`);
        }
      },
    });
  };

  render() {
    const { info } = this.state;
    return (
      <div className={global.common_page}>
        <div className={styles.docContentWrapper}>
          <div className="doc-body">

            <div className="doc-title">
              <p className={styles.docText}>{info.title}</p>

              <p className={styles.docTime}>{info.createTime}</p>
            </div>

            <div className="doc-content" dangerouslySetInnerHTML={{ __html: info.content }}></div>
          </div>
        </div>
      </div>
    );
  }
}
