import React from 'react';
import { Icon, Button, Input, Select, Spin, Table, message } from 'antd';
import { patentTypeList, patentStateList } from '../../dataDic.js';
import { getPatentType, getPatentState, getTime, setUserContactsList } from '../../tools.js';
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';
import './patent.less';
import PatentAdd from './patentAdd.jsx';
import PatentDesc from './patentDesc.jsx';
const Patent = React.createClass({
    loadData(pageNo) {
        this.state.data = [];
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/user/patent/clientApplyList",
            data: {
                pageNo: pageNo || 1,
                pageSize: this.state.pagination.pageSize,
                patentNumber: this.state.searchNum,
                patentName: this.state.searchName,
                patentCatagory: this.state.searchType,
                patentState: this.state.searchState
            },
            success: function (data) {
                if (!data.data) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                        this.state.ButtonDisabled = true;
                    }
                    return;
                };
                for (let i = 0; i < data.data.list.length; i++) {
                    let thisdata = data.data.list[i];
                    this.state.data.push({
                        key: i,
                        pid: thisdata.id,
                        number: thisdata.serialNumber,
                        patentNum: thisdata.patentNumber,
                        patentName: thisdata.patentName,
                        patentCatagory: thisdata.patentCatagory ? getPatentType(thisdata.patentCatagory) : '',
                        patentState: getPatentState(thisdata.patentState),
                        patentField: thisdata.patentField,
                        patentDes: thisdata.patentDes,
                        patentProryStatementUrl: thisdata.patentProryStatementUrl, //专利代理委托书
                        patentWritingUrl: thisdata.patentWritingUrl, //专利稿件
                        authorizationNoticeUrl: thisdata.authorizationNoticeUrl, //授权通知书
                        patentCertificateUrl: thisdata.patentCertificateUrl, //专利证书
                        confirmState: thisdata.confirmState, //稿件确认状态
                        authorizedTime: getTime(thisdata.authorizedDate),
                        startTime: getTime(thisdata.patentApplicationDate),
                        endTime: getTime(thisdata.patentApplicationDate, 12),
                        firstInventorName: thisdata.firstInventorName,
                        firstInventorNationality: thisdata.firstInventorNationality, //国籍
                        firstInventorIdNumber: thisdata.firstInventorIdNumber,   //id
                        firstInventorIsPublish: thisdata.firstInventorIsPublish, //是否公布
                        secondInventorName: thisdata.secondInventorName,
                        secondInventorNationality: thisdata.secondInventorNationality,
                        secondInventorIsPublish: thisdata.secondInventorIsPublish,
                        thirdInventorName: thisdata.thirdInventorName,
                        thirdInventorNationality: thisdata.thirdInventorNationality,
                        thirdInventorIsPublish: thisdata.thirdInventorIsPublish,
                        createTime: thisdata.createTime,   //派单日
                        author: thisdata.author, //撰写人
                        office: thisdata.office, //事务所
                        principal: thisdata.principal //负责人
                    });
                };
                this.state.pagination.current = data.data.pageNo;
                this.state.pagination.total = data.data.totalCount;
                this.setState({
                    dataSource: this.state.data,
                    pagination: this.state.pagination
                });
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getInitialState() {
        return {
            patentTypeOption: [],
            patentStateOption: [],
            data: [],
            //dataSource: [],
            loading: false,
            pagination: {
                defaultCurrent: 1,
                defaultPageSize: 10,
                showQuickJumper: true,
                pageSize: 10,
                onChange: function (page) {
                    this.loadData(page);
                }.bind(this),
                showTotal: function (total) {
                    return '共' + total + '条数据';
                }
            },
            columns: [
                {
                    title: '编号',
                    dataIndex: 'number',
                    key: 'number',
                }, {
                    title: '申请号/专利号',
                    dataIndex: 'patentNum',
                    key: 'patentNum',
                }, {
                    title: '专利类型',
                    dataIndex: 'patentCatagory',
                    key: 'patentCatagory',
                }, {
                    title: '专利名称',
                    dataIndex: 'patentName',
                    key: 'patentName',
                }, {
                    title: '专利状态',
                    dataIndex: 'patentState',
                    key: 'patentState',
                }, {
                    title: '申请日',
                    dataIndex: 'startTime',
                    key: 'startTime',
                }, {
                    title: '授权缴费截止日',
                    dataIndex: 'endTime',
                    key: 'endTime',
                }
            ],
            dataSource: []
        };
    },
    componentWillMount() {
        let _me = this;
        patentTypeList.map(function (item) {
            _me.state.patentTypeOption.push(