import React from 'react';
import { Icon, Button, Input, Select, Spin, Table, DatePicker, message, Cascader } from 'antd';
import { techFieldList, provinceArr } from '../../../dataDic.js';
import { getTime, getPatentState } from '../../../tools.js';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import './highTechFoster.less';

const HighTechApply = React.createClass({
    loadData(pageNo) {
        this.state.data = [];
        this.setState({
            loading: true
        });
        $.ajax({
            method: "post",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/techservice/patent/managePatentList",
            data: {
                pageNo: pageNo || 1,
                pageSize: this.state.pagination.pageSize,
                locationProvince: this.state.province,
                unitName: this.state.unitName,
            },
            success: function (data) {
                if (data.error.length || !data.data || !data.data.list) {
                    message.warning(data.error[0].message);
                    return;
                }
                for (let i = 0; i < data.data.list.length; i++) {
                    let thisdata = data.data.list[i];
                    this.state.data.push({
                        key: i,

                    });
                };
                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));
    },
    getAuthorList() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/techservice/patent/getAdmin",
            success: function (data) {
                if (data.error.length || !data.data) {
                    return;
                };
                let _me = this;
                for (var item in data.data) {
                    _me.state.authorOption.push(
                        <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
                    )
                };
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getCompanyList() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/techservice/patent/getUnitNames",
            success: function (data) {
                if (data.error.length || !data.data) {
                    return;
                };
                let _me = this;
                for (var item in data.data) {
                    _me.state.companyOption.push(
                        <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
                    )
                };
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getInitialState() {
        return {
            provinceOption:[],
            companyOption:[],
            authorOption:[],
            province: '',
            unitName: '',
            data: [],
            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: 'patentNumber',
                    key: 'patentNumber',
                }, {
                    title: '事务所',
                    dataIndex: 'office',
                    key: 'office',
                }, {
                    title: '省份',
                    dataIndex: 'province',
                    key: 'province',
                }, {
                    title: '公司名称',
                    dataIndex: 'unitName',
                    key: 'unitName',
                }, {
                    title: '专利名称',
                    dataIndex: 'patentName',
                    key: 'patentName',
                }, {
                    title: '专利状态',
                    dataIndex: 'patentState',
                    key: 'patentState',
                    render: text => { return getPatentState(text) },
                }, {
                    title: '派单日',
                    dataIndex: 'createTime',
                    key: 'createTime',
                    render: text => { return getTime(text) },
                }, {
                    title: '申请日',
                    dataIndex: 'startTime',
                    key: 'startTime',
                    render: text => { return getTime(text) },
                }, {
                    title: '授权日',
                    dataIndex: 'endTime',
                    key: 'endTime',
                    render: text => { return getTime(text) },
                }, {
                    title: '资料撰写人',
                    dataIndex: 'author',
                    key: 'author',
                }
            ],
            dataSource: []
        };
    },
    componentWillMount() {
        let _me = this;
        provinceArr.map(function (item) {
            _me.state.provinceOption.push(
                <Select.Option value={item} key={item}>{item}</Select.Option>
            )
        });
        this.loadData();
        this.getAuthorList();
        this.getCompanyList();
    },
    tableRowClick(record, index) {
        this.state.RowData = record;
        this.setState({
            showDesc: true
        });
    },
    closeDesc(e) {
        this.state.showDesc = e;
        this.loadData();
    },
    search() {
        this.loadData();
    },
    reset() {
        this.state.province = undefined;
        this.state.unitName = undefined;
        this.loadData();
    },
    render() {
        const { MonthPicker, RangePicker } = DatePicker;
        return (
            <div className="foster-content" >
                <div className="content-title">
                    <span>高企认定申请</span>
                </div>
                <div className="foster-query">
                    <Select placeholder="选择省份" style={{ width: 200 }} onChange={(e) => { this.state.province = e }}>{this.state.provinceOption}</Select>
                    <Select placeholder="选择公司" style={{ width: 200 }} onChange={(e) => { this.state.unitName = e }}>{this.state.companyOption}</Select>
                    <Button type="primary" onClick={this.search}>搜索</Button>
                    <Button onClick={this.reset}>重置</Button>
                </div>
                <div className="foster-table">
                    <Spin spinning={this.state.loading}>
                        <Table columns={this.state.columns}
                            dataSource={this.state.dataSource}
                            pagination={this.state.pagination}
                            onRowClick={this.tableRowClick} />
                    </Spin>
                </div>
            </div >
        );
    }
});

export default HighTechApply;