import React from 'react';
import { Icon, Modal, message, Spin, Steps, Input, Select, Upload, DatePicker, Button, Table } from 'antd';
import './comprehensive.less';
import ajax from 'jquery/src/ajax/xhr.js';
import moment from 'moment';
import $ from 'jquery/src/ajax';
import { patentTypeList, patentFieldList, patentStateList } from '../../../dataDic.js';
import { getBase64, beforeUpload, getPatentState, getTime, newDownloadFile } from '../../../tools.js';
class Avatar extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            imageUrl: ''
        }
    }
    handleChange(info) {
        if (info.file.status !== 'uploading') {
            console.log(info.file, info.fileList);
        }
        if (info.file.status === 'done') {
            if (!info.file.response.error.length) {
                message.success(`${info.file.name} 文件上传成功!`);
            } else {
                message.warning(info.file.response.error[0].message);
                return;
            };
            this.props.urlData(info.file.response.data);
        } else if (info.file.status === 'error') {
            message.error(`${info.file.name} 文件上传失败。`);
        };
    }
    render() {
        return (
            
                
            
        );
    }
};
const PatentDesc = React.createClass({
    getInitialState() {
        return {
            visible: false,
            loading: false,
            patentTypeOption: [],
            patentFieldOption: [],
            patentStateOption: [],
            adminOption: [],
            stateTable: [],
            stateColumns: [{
                title: '申请状态',
                dataIndex: 'state',
                key: 'state',
                render: (text) => { return getPatentState(text) }
            }, {
                title: '处理时间',
                dataIndex: 'recordTimeFormattedDate',
                key: 'recordTimeFormattedDate',
            }, {
                title: '负责人',
                dataIndex: 'principal',
                key: 'principal',
            }, {
                title: '操作人',
                dataIndex: 'operator',
                key: 'operator',
            }, {
                title: '备注',
                dataIndex: 'comment',
                key: 'comment',
            }]
        };
    },
    loadData() {
        this.setState({
            loading: true
        });
        $.when($.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/patent/detail?pid=" + this.state.xid,
        }), $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/patent/logs?pid=" + this.state.xid,
        }), $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/techservice/patent/getAdmin"
        }), $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/patent/patentStatus"
        })).done((data1, data2, data3, data4) => {
            let _me = this;
            if (data1[0].error.length || !data1[0].data) {
                message.warning(data1[0].error[0].message);
                return;
            };
            this.state.data = data1[0].data;
            if (data2[0].error.length) {
                message.warning(data2[0].error[0].message);
                return;
            };
            _me.state.stateTable = [];
            data2[0].data.map(function (item) {
                _me.state.stateTable.push({
                    comment: item.comment,
                    id: item.id,
                    operator: item.operator,
                    pid: item.pid,
                    principal: item.principal,
                    recordTime: item.recordTime,
                    recordTimeFormattedDate: item.recordTimeFormattedDate,
                    state: item.state,
                });
            });
            if (data3[0].error.length) {
                message.warning(data3[0].error[0].message);
                return;
            };
            for (var item in data3[0].data) {
                _me.state.adminOption.push(
                    {data3[0].data[item]}
                )
            };
            if (!data4[0].data) {
                if (data4[0].error && data4[0].error.length) {
                    message.warning(data4[0].error[0].message);
                    return;
                };
            };
            _me.state.patentStateOption = [];
            for (var item in data4[0].data) {
                _me.state.patentStateOption.push(
                    {data4[0].data[item]}
                )
            };
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getOption() {
        let _me = this;
        _me.state.patentTypeOption = [];
        _me.state.patentFieldOption = [];
        patentTypeList.map(function (item) {
            _me.state.patentTypeOption.push(
                {item.key}
            )
        });
        patentFieldList.map(function (item) {
            _me.state.patentFieldOption.push(
                {item.key}
            )
        });
    },
    showModal() {
        this.setState({
            visible: true,
        });
    },
    handleOk() {
        this.setState({
            visible: true,
        });
        $.ajax({
            method: "POST",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/patent/update",
            data: {
                "id": this.state.xid,
                "patentNumber": this.state.patentNumber,
                "patentName": this.state.patentName,
                "patentCatagory": this.state.data.patentCatagory,
                "patentField": this.state.patentField,
                "patentDes": this.state.patentDes,
                "patentWritingUrl": this.state.patentWritingUrl,
                "authorizationNoticeUrl": this.state.authorizationNoticeUrl,
                "patentCertificateUrl": this.state.patentCertificateUrl,
                "pState": this.props.data.patentState,
                "state": this.state.patentStateAdd,
                "recordTimeFormattedDate": this.state.recordTime,
                "principal": this.state.adminName,
                "comment": this.state.comment
            }
        }).done(function (data) {
            if (!data.error.length) {
                message.success('保存成功!');
            } else {
                message.warning(data.error[0].message);
            }
        }.bind(this)).always(function () {
            this.setState({
                visible: false,
            });
            this.props.closeDesc(false, true);
        }.bind(this));
    },
    checkPatentProcess() {
        if (this.state.patentStateAdd || this.state.adminName || this.state.recordTime) {
            if (this.state.patentStateAdd && this.state.adminName && this.state.recordTime)
            { this.handleOk() } else {
                message.warning("请填写完整的状态流转信息!");
                return;
            }
        } else {
            this.handleOk()
        };
    },
    componentWillMount() {
        this.getOption();
    },
    componentWillReceiveProps(nextProps) {
        this.state.patentStateAdd = undefined;
        this.state.adminName = undefined;
        this.state.recordTime = undefined;
        this.state.comment = undefined;
        this.state.adminOption = [];
        if (nextProps.data && !this.state.visible && nextProps.showDesc) {
            this.state.xid = nextProps.data.pid;
            this.state.patentDes = nextProps.data.patentDes;
            this.state.patentName = nextProps.data.patentName;
            this.state.patentNumber = nextProps.data.patentNumber;
            this.state.patentCatagory = String(nextProps.data.patentCatagory);
            this.state.patentState = String(nextProps.data.patentState);
            this.state.patentField = String(nextProps.data.patentField);
            this.loadData();
        };
        this.state.visible = nextProps.showDesc;
    },
    handleCancel(e) {
        this.setState({
            visible: false,
        });
        this.props.closeDesc(false);
    },
    getPatentWritingUrl(e) {
        this.state.patentWritingUrl = e;
    },
    getAuthorizationNoticeUrl(e) {
        this.state.authorizationNoticeUrl = e;
    },
    getPatentCertificateUrl(e) {
        this.state.patentCertificateUrl = e;
    },
    render() {
        const Step = Steps.Step;
        const theData = this.state.data;
        if (this.state.data) {
            let companyAddress = theData.locationProvince || theData.locationCity || theData.locationArea ? theData.locationProvince + '/' + theData.locationCity + '/' + theData.locationArea : '';
            return (
                
                    
                        保存,
                                ,
                            ]}
                            className="patent-desc-content">
                            
                                公司名称:{theData.unitName}
                                公司组织机构代码:{theData.orgCode}
                             
                            
                                公司地址:{companyAddress}
                                联系人:{theData.companyContacts}
                             
                            
                            
                            
                                专利状态:{getPatentState(theData.patentState)}
                                专利领域:
                                    
                                
                             
                            
                                专利简介:
                                 { this.setState({ patentDes: e.target.value }); } }
                                    rows={6} />
                            
                            
                                第一发明人:
                                姓名:{theData.firstInventorName}
                                身份证:{theData.firstInventorIdNumber}
                                国籍:中国
                             
                            
                                第二发明人:
                                姓名:{theData.secondInventorName}
                                国籍:中国
                             
                            
                                第三发明人:
                                姓名:{theData.thirdInventorName}
                                国籍:中国
                             
                            
                                材料管理:
                                    {theData.patentWritingUrl !== null && theData.patentWritingUrl !== undefined && theData.patentWritingUrl !== '' ?
                                    
                                        授权通知书
                                        {theData.confirmState == '0' ?
                                             : 
                                        }
                                    
 :
                                    
专利稿件未上传
                                    }
                                    {theData.authorizationNoticeUrl !== null && theData.authorizationNoticeUrl !== undefined && theData.authorizationNoticeUrl !== '' ?
                                        
                                            授权通知书
                                        
 :
                                        
授权通知书未上传
                                    }
                                    {theData.patentCertificateUrl !== null && theData.patentCertificateUrl !== undefined && theData.patentCertificateUrl !== '' ?
                                        
                                            专利证书
                                        
 :
                                        
专利证书未上传
                                    }
                                    {theData.patentProryStatementUrl !== null && theData.patentProryStatementUrl !== undefined && theData.patentProryStatementUrl !== '' ?
                                        
                                            {theData.patentProryStatementDownloadFileName}
                                        
 :
                                        
专利代理委托书未上传
                                    }
                                    {theData.lastYearTaxReportUrl !== null && theData.lastYearTaxReportUrl !== undefined && theData.lastYearTaxReportUrl !== '' ?
                                        
                                            {theData.lastYearTaxReportDownloadFileName}
                                        
 :
                                        
上年度纳税报表
                                    }
                                
 
                            专利稿件上传授权通知书上传专利证书上传
                            
                                专利状态流转记录:
                                
                                
                                    状态流转:
                                    
                                
                                
                                    处理时间:
                                    {this.setState({recordTime : dataString});}}/>
                                
                                
                                    负责人:
                                    
                                
                             
                            
                                备注:
                                {this.setState({comment : e.target.value});}}/>
                            
                        
                    
                 
            );
        } else {
            return 
        }
    },
});
export default PatentDesc;