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({
                        bankAccount: bankAccount,
                        bankCardNumber: bankCardNumber
                    });
                } else {
                    message.warning(data.error[0].message);
                };
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getInitialState() {
        return {
            loading: false
        };
    },
    handleSubmit(e) {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
            if (!err) {
                this.setState({
                    loading: true
                });
                $.ajax({
                    method: "POST",
                    dataType: "json",
                    crossDomain: false,
                    url: globalConfig.context + "/api/user/userNextPro",
                    data: {
                        amountMoney:values.amountMoney,
                        process:5
                    }
                }).done(function (data) {
                    if (!data.error.length) {
                        message.success('保存成功！');
                        this.props.change(6);
                    } else {
                        if ( data.amountError.length ) {
                            message.warning(data.amountError[0].message);
                        } else if ( data.error.length) {
                            message.warning(data.error[0].message);
                        }; 
                    }
                }.bind(this)).always(function () {
                    this.setState({
                        loading: false
                    });
                }.bind(this));
            }
        });
    },
    componentWillMount() {
        this.getData();
    },
    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 wrapperCol={{ span: 18, offset: 4 }}>
                        <span>
                            请在下方输入银行卡{this.state.bankCardNumber}收到的认证打款，
                            务必在收到打款5日内完成，否则将无法完成
                        </span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="开户银行"
                    >
                        <span>{this.state.bankAccount}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="银行卡号"
                    >
                        <span>{this.state.bankCardNumber}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="打款金额"
                        extra={<span style={{ 'color': '#ea0862' }}><Icon type="exclamation-circle" /> 仅有3次输入机会，如3次输入有误，需更换银行卡重新认证</span>}
                    >
                        {getFieldDecorator('amountMoney', {
                            rules: [{ required: true, message: '请输入金额!' }]
                        })(
                            <Input />
                            )}
                            <span className="fromItem-postfix">元</span>
                    </FormItem>
                    <FormItem wrapperCol={{ span: 12, offset: 4 }}>
                        <Button className="set-submit" type="primary" htmlType="submit">确认</Button>
                    </FormItem>
                </Form >
            </Spin >
        );
    },
}));

export default Content;