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

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

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

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

  //获取数据列表
  get_detail = (type) => {
    console.log('***** get_agree_detail ******');
    this.setState({ loading: true });
    const { dispatch } = this.props;
    dispatch({
      type: 'common/get_agree_detail',
      payload: {
        agreementCode: (type == 1)?"seller_register_agreement":"seller_privacy_policy",
      },
      callback: (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={styles.agreementTitle}>
              <p className={styles.docText}>{info.title}</p>
            </div>
            <div className="doc-content" dangerouslySetInnerHTML={{ __html: quillEscapeToHtml(info.content) }}></div>
          </div>
        </div>
      </div>
    );
  }
}
