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/orgProcess",
            success: function (data) {
                if (data.data) {
                    this.setState({
                        unitName: data.data.unitName,
                        licenceNumber: data.data.licenceNumber,
                        licenceScanningUrl: data.data.licenceScanningUrl,
                        orgCode: data.data.orgCode,
                        orgCodeUrl: data.data.orgCodeUrl,
                        lastYearTaxReportUrl: data.data.lastYearTaxReportUrl,
                        contactMobile: data.data.contactMobile,
                        bankAccount: data.data.bankAccount,
                        banks: data.data.banks,
                        bankBranch: data.data.bankBranch,
                        bankCardNumber: data.data.bankCardNumber,
                        legalPerson: data.data.legalPerson,
                        legalPersonIdCard: data.data.legalPersonIdCard,
                    });
                };
            }.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/orgNextPro",
            data: {
                process: 3
            }
        }).done(function (data) {
            if (!data.error.length) {
                message.success('保存成功！');
                this.props.changeStep(4);
            } else {
                message.warning(data.error[0].message);
                this.setState({
                    loading: false
                });
            }
        }.bind(this));
    },
    componentWillMount() {
        this.getData();
    },
    changeStep() {
        this.props.changeStep(1);
    },
    render() {
        const FormItem = Form.Item;
        const { getFieldDecorator } = this.props.form;
        const formItemLayout = {
            labelCol: { span: 6 },
            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: 6 }}>
                        <p className="certify-title">请确认提交的企业信息</p>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="企业名称"
                    >
                        <span>{this.state.unitName}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="营业执照注册号"
                    >
                        <span>{this.state.licenceNumber}</span>
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 18 }}
                        label="营业执照副本扫描件"
                    >
                        <div className="idcard-img clearfix">
                            <div className="idcard-imgbox">
                                <img src={globalConfig.context + '/open/writeImage?path=' + this.state.licenceScanningUrl} alt="点击查看大图"
                                    onClick={(e) => { window.open(e.target.src) }} />
                            </div>
                        </div>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="组织机构代码"
                    >
                        <span>{this.state.orgCode}</span>
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 18 }}
                        label="组织机构代码证"
                    >
                        <div className="idcard-img clearfix">
                            <div className="idcard-imgbox">
                                <img src={globalConfig.context + '/open/writeImage?path=' + this.state.orgCodeUrl} alt="点击查看大图"
                                    onClick={(e) => { window.open(e.target.src) }} />
                            </div>
                        </div>
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 18 }}
                        label="上年度纳税报表"
                    >
                        <div className="idcard-img clearfix">
                            <div className="idcard-imgbox">
                                <img src={globalConfig.context + '/open/writeImage?path=' + this.state.lastYearTaxReportUrl} alt="点击查看大图"
                                    onClick={(e) => { window.open(e.target.src) }} />
                            </div>
                        </div>
                    </FormItem>
                    <FormItem wrapperCol={{ span: 12, offset: 6 }}>
                        <p className="certify-title">请确认银行卡信息</p>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="银行开户名"
                    >
                        <span>{this.state.bankAccount}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="开户银行"
                    >
                        <span>{this.state.banks}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="开户行支行名称"
                    >
                        <span>{this.state.bankBranch}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="银行卡号"
                    >
                        <span>{this.state.bankCardNumber}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="联系方式"
                    >
                        <span>{this.state.contactMobile}</span>
                    </FormItem>
                    <FormItem wrapperCol={{ span: 12, offset: 6 }}>
                        <p className="certify-title">请确认法人信息</p>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="法人真实姓名"
                    >
                        <span>{this.state.legalPerson}</span>
                    </FormItem>
                    <FormItem
                        {...formItemLayout}
                        label="法人身份证号"
                    >
                        <span>{this.state.legalPersonIdCard}</span>
                    </FormItem>
                    <FormItem wrapperCol={{ span: 18, offset: 6 }}>
                        <span style={{ 'color': '#ea0862' }}>
                            <Icon type="exclamation-circle" />
                            提醒：银行卡号、营业执照号码、组织机构代码证号码，认证成功之前，
                            最多只能申请认证3次；认证成功后，不能再申请认证。
                        </span>
                    </FormItem>
                    <FormItem wrapperCol={{ span: 12, offset: 6 }}>
                        <Button className="set-submit" type="primary" htmlType="submit">下一步</Button>
                        <Button className="exit" type="ghost" onClick={_me.changeStep}>返回修改</Button>
                    </FormItem>
                </Form >
            </Spin >
        );
    },
}));

export default Content;