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

const PatentDesc = React.createClass({
    getInitialState() {
        return {
            visible: false,
            loading: false,
        };
    },
    showModal() {
        this.setState({
            visible: true,
        });
    },
    handleOk() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "post",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/patent/confirmPayment",
            data: {
                cid: this.props.data.cid,
                uid: this.props.data.uid
            },
            success: function (data) {
                if (data.error && data.error.length) {
                    message.warning(data.error[0].message);
                    return;
                } else {
                    message.success('保存成功！');
                    this.props.closeDesc(false, true);
                };
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false,
                visible: false,
            });
        }.bind(this));
    },
    handleCancel(e) {
        this.setState({
            visible: false,
        });
        this.props.closeDesc(false);
    },
    componentWillReceiveProps(nextProps) {
        this.state.visible = nextProps.showDesc
    },
    render() {
        if (this.props.data) {
            return (
                <div className="payment-desc">
                    <Spin spinning={this.state.loading} className='spin-box'>
                        <Modal title="缴费确认" visible={this.state.visible}
                            onOk={this.handleOk} onCancel={this.handleCancel}
                            width='500px'
                            footer={[
                                <Button key="submit" type="primary" size="large" onClick={this.handleOk}>确认缴费</Button>,
                                <Button key="back" type="ghost" size="large" onClick={this.handleCancel}>取消</Button>,
                            ]}
                            className="patent-desc-content">
                            <p style={{ fontSize: '16px' }}>
                                <span>确认已经缴纳 </span> {this.props.data.unitName}
                                <span> 公司专利 </span> {this.props.data.patentName}
                                <span> 的年登印费用？</span>
                            </p>
                        </Modal>
                    </Spin>
                </div>
            );
        } else {
            return <div></div>
        }
    },
});
export default PatentDesc;