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({
    getData() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            url: globalConfig.context + "/api/user/userPro",
            success: function (data) {
                if (data.data) {
                    this.setState({
                        username: data.data.username,
                        idNumber: data.data.idNumber,
                        contactMobile: data.data.contactMobile,
                        bankName: data.data.bankName,
                        bankAccount: data.data.bankAccount,
                        bankCardNumber: data.data.bankCardNumber,
                        positiveIdUrl: data.data.positiveIdUrl,
                        oppositeIdUrl: data.data.oppositeIdUrl
                    });
                };
            }.bind(this),
        }).done(function (data) {
            if (data.error.length) {
                message.warning(data.error[0].message);
            }
        }.bind(this)).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getInitialState() {
        return {
            loading: false
        };
    },
    handleSubmit() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "POST",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/user/userNextPro",
            data: {
                process: 3
            }
        }).done(function (data) {
            if (!data.error.length) {
                message.success('保存成功！');
                this.props.changeStep(4);
            } else {
                message.warning(data.error[0].message);
            }
        }.bind(this));
    },
    componentWillMount() {
        this.getData();
    },
    changeStep() {
        this.props.changeStep(1);
    },
    render() {
        const FormItem = Form.Item;
        const { getFieldDecorator } = this.props.form;
        const formItemLayout = {
            labelCol: { span: 4 },
            wrapperCol: { span: 12 },
        };
        const _me = this;
        return (
            <Spin spinning={this.state.loading} className="certify-spin">
                <Form horizontal onSubmit={this.handleSubmit} className="certify-form">
                    <FormItem wrapperCol={{ span: 12, offset: 4 }}>
                        <p className="certify-title">请确认个人信息</p>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="真实姓名"
                    >
                        <span>{this.state.username}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="身份证号码"
                    >
                        <span>{this.state.idNumber}</span>
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 4 }}
                        wrapperCol={{ span: 18 }}
                        label="身份证图片"
                    >
                        <div className="idcard-img clearfix">
                            <div>
                                <div className="idcard-imgbox">
                                    <img src={globalConfig.context + '/open/writeImage?path=' + this.state.positiveIdUrl} alt="点击查看大图"
                                        onClick={(e) => { window.open(e.target.src) }} />
                                </div>
                            </div>
                            <div>
                                <div className="idcard-imgbox">
                                    <img src={globalConfig.context + '/open/writeImage?path=' + this.state.oppositeIdUrl} alt="点击查看大图"
                                        onClick={(e) => { window.open(e.target.src) }} />
                                </div>
                            </div>
                        </div>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="联系方式"
                    >
                        <span>{this.state.contactMobile}</span>
                    </FormItem>
                    <FormItem wrapperCol={{ span: 12, offset: 4 }}>
                        <p className="certify-title">请确认银行卡信息</p>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="银行开户名"
                    >
                        <span>{this.state.bankName}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="开户银行"
                    >
                        <span>{this.state.bankAccount}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="银行卡号"
                    >
                        <span>{this.state.bankCardNumber}</span>
                    </FormItem>
                    <FormItem wrapperCol={{ span: 18, offset: 4 }}>
                        <span style={{ 'color': '#ea0862' }}>
                            <Icon type="exclamation-circle" />
                            提醒：银行卡号、身份证号码，认证成功之前，最多只能申请认证3次，
                            认证成功后，不能再申请认证。
                        </span>
                    </FormItem>
                    <FormItem wrapperCol={{ span: 12, offset: 4 }}>
                        <Button className="set-submit" type="primary" htmlType="submit">下一步</Button>
                        <Button className="exit" type="ghost" onClick={_me.changeStep}>返回修改</Button>
                    </FormItem>
                </Form >
            </Spin >
        );
    },
}));

export default Content;