import React from 'react';
import { Input, Button, Form, Icon, Spin, message, } from 'antd';
import './certify.less';
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';


const Content = Form.create()(React.createClass({
    getInitialState() {
        return {
            loading: false,
        };
    },
    handleSubmit() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/user/identFailed",
            data: {
            }
        }).done(function (data) {
            if (!data.error.length) {
                message.success('已提交重新审核！');
                this.props.changeStep(1);
            } else {
                message.warning(data.error[0].message);
            }
        }.bind(this)).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    componentWillMount() {
        $.ajax({
            method: "get",
            dataType: "json",
            url: globalConfig.context + "/api/user/orgProcess",
            success: function (data) {
                if (data.data) {
                    this.setState({
                        auditStatus: data.data.auditStatus
                    });
                };
            }.bind(this),
        }).done(function (data) {
            if (data.error.length) {
                message.warning(data.error[0].message);
            };
            this.setState({
                loading:false
            });
        }.bind(this));
    },
    render() {
        const _me = this;
        return (
            <Spin spinning={this.state.loading} className="certify-spin">
                {(() => {
                    switch (this.state.auditStatus) {
                        case '5':
                            return <div className="certify-result-box">
                                <p className="certify-title"
                                    style={{ 'textAlign': 'center' }}
                                >审核通过，认证申请成功</p>
                                <div className="certify-result-state">
                                    <Icon type="check-circle-o" />
                                    <p>您已通过了实名认证</p>
                                </div>
                            </div>;
                        case '4':
                            return <div className="certify-result-box">
                                <p className="certify-title"
                                    style={{ 'textAlign': 'center' }}
                                >实名认证未通过。您可以可重新申请实名认证。</p>
                                <div className="certify-result-state">
                                    <Icon type="close-circle-o" />
                                    <p>您未能通过实名认证审核</p>
                                    <p>可能的原因是：</p>
                                    <p>您提交的认证资料不符合要求，未能通过实名认证；</p>
                                    <p>您输入的银行账户信息有误，未能通过实名认证；</p>
                                    <Button className="set-submit" type="primary" onClick={this.handleSubmit}>重新申请实名认证</Button>
                                </div>
                            </div>;
                    };
                })()}
            </Spin >
        );
    },
}));

export default Content;