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 CorrectionDesc = 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 + "/techservice/patent/replyConfirm",
            data: {
                pid: this.props.data.pid,
                patentState: this.props.data.patentState
            },
            success: function (data) {
                if (data.error.length) {
                    message.warning(data.error[0].message);
                    return;
                } else {
                    message.success('保存成功！');
                };
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false,
                visible: false,
            });
        }.bind(this));
        this.props.closeDesc(false);
    },
    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">
                            <div style={{ fontSize: '16px' }}>
                                <p><span>公司:</span>{this.props.data.companyName}</p>
                                <p><span>专利:</span>{this.props.data.patentName}</p>
                                <p><span>专利号:</span><a href="">{this.props.data.patentNumber}</a></p>
                                <p>{(() => {
                                    if (this.props.data.patentState == 4) { return <span>审查意见</span> }
                                    else if (this.props.data.patentState == 6) { return <span>补正通知</span> }
                                })()}
                                    <span>确认已经答复？</span></p>
                            </div>
                        </Modal>
                    </Spin>
                </div>
            );
        } else {
            return <div></div>
        }
    },
});
export default CorrectionDesc;