import React from 'react';
import { Icon, Modal, Button, Form, Upload, message, Input, Spin, Select } from 'antd';
import { beforeUploadFile, downloadFile, setUserContactsList } from '../../tools.js';
import './patent.less';
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';
const PatentAddFrom = Form.create()(React.createClass({
    getInitialState() {
        return {
            loading: false
        };
    },
    componentWillMount() {
        let theOption = [];
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + '/api/user/getContacts',
            success: function (data) {
                if (!data.data) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    };
                } else {
                    for (let item in data.data) {
                        let theData = data.data[item];
                        theOption.push(
                            {theData}
                        );
                    };
                };
            }
        });
        this.setState({ contactsOption: theOption });
    },
    handleSubmit(e) {
        e.preventDefault();
        if (!this.state.patentProryStatementUrl) {
            message.warning('未上传代理委托书!');
            return;
        };
        this.props.form.validateFields((err, values) => {
            if (!err) {
                this.props.spinState(true);
                $.ajax({
                    method: "POST",
                    dataType: "json",
                    crossDomain: false,
                    url: globalConfig.context + "/api/user/patent/clientApplyPatent",
                    data: {
                        'firstInventorIdNumber': values.firstInventorID,
                        'firstInventorName': values.firstInventorName,
                        'patentDes': values.intro,
                        'patentName': values.patentName,
                        'contacts': values.contacts,
                        'secondInventorName': values.secondInventorName,
                        'thirdInventorName': values.thirdInventorName,
                        'patentProryStatementUrl': this.state.patentProryStatementUrl
                    }
                }).done(function (data) {
                    if (!data.error.length) {
                        message.success('保存成功!');
                    } else {
                        message.warning(data.error[0].message);
                    }
                }.bind(this)).always(function () {
                    this.props.spinState(false);
                    this.props.clickOk();
                    this.props.form.resetFields();
                }.bind(this));
            }
        });
    },
    avatarUrl(e) {
        this.state.avatarUrl = e;
    },
    checkIdcardnum(rule, value, callback) {
        if (!/(^\d{15}$)|(^\d{17}(\d|X)$)/.test(value)) {
            callback('请输入正确的身份证号!');
        } else {
            callback();
        }
    },
    render() {
        const FormItem = Form.Item;
        const { getFieldDecorator } = this.props.form;
        const formItemLayout = {
            labelCol: { span: 3 },
            wrapperCol: { span: 16 },
        };
        const _me = this;
        return (
            
        );
    },
}));
const PatentAdd = React.createClass({
    getInitialState() {
        return {
            visible: false,
            loading: false
        };
    },
    showModal() {
        this.setState({
            visible: true,
        });
    },
    handleOk() {
        this.setState({
            visible: false,
        });
        this.props.closeDesc(false, true);
    },
    handleCancel(e) {
        this.setState({
            visible: false,
        });
        this.props.closeDesc(false);
    },
    spinChange(e) {
        this.setState({
            loading: e
        });
    },
    render() {
        return (
            
        );
    },
});
export default PatentAdd;