import React from 'react';
import { Icon, Button, Input, Select, Spin, message, Col, Row, Table } from 'antd';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import './userList.less';
import BatchImport from './batchImport';
import { provinceList, getProvince } from '../../NewDicProvinceList';
import { companySearch } from '../../tools';
const HighTechSearch = React.createClass({
    loadData(pageNo) {
        if (!this.state.searchName && !this.state.province && !this.state.city && !this.state.searchYear) {
            message.warning('请选择至少一个搜索条件!');
            return;
        };
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/cognizanceRecord/search",
            data: {
                "pageNo": pageNo || 1,
                "pageSize": this.state.pagination.pageSize,
                "district": this.state.city || this.state.province,
                "unitName": this.state.searchName,
                "year": this.state.searchYear
            },
            success: function (data) {
                let theArr = [];
                if (data.error && data.error.length) {
                    message.warning(data.error[0].message);
                } else {
                    for (let i = 0; i < data.data.list.length; i++) {
                        let thisdata = data.data.list[i];
                        theArr.push({
                            key: i + 1,
                            id: thisdata.id,
                            district: thisdata.district,
                            unitName: thisdata.unitName,
                            year: thisdata.year
                        });
                    };
                    this.state.pagination.current = data.data.pageNo;
                    this.state.pagination.total = data.data.totalCount;
                };
                this.setState({
                    dataSource: theArr,
                    pagination: this.state.pagination
                });
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getInitialState() {
        return {
            loading: false,
            yearOption: [],
            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: 'key',
                    key: 'key',
                }, {
                    title: '地区',
                    dataIndex: 'district',
                    key: 'district',
                    render: (text) => { return getProvince(text) }
                }, {
                    title: '公司名称',
                    dataIndex: 'unitName',
                    key: 'unitName',
                }, {
                    title: '申报年份',
                    dataIndex: 'year',
                    key: 'year',
                }
            ],
            dataSource: []
        };
    },
    componentWillMount() {
        let theProvinceArr = [];
        let d = new Date();
        let thisYear = d.getFullYear();
        for (let i = thisYear; i >= 2000; i--) {
            this.state.yearOption.push(