import React from 'react';
import { Row, Col } from 'antd';
import './topTab.less';
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';

const TopTab = React.createClass({
    getInitialState() {
        return {
            username: '管理员',
        };
    },
    logOut() {
        $.ajax({
            method: "get",
            dataType: "json",
            url: globalConfig.context + "/login",
        }).done(function (data) {
            window.location.href = globalConfig.context + "/admin/login.html"
        });
    },
    componentWillMount () {
        this.loadData();
    },
    loadData() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/notice/unreadCount",
            success: function (data) {
                if (!data.data) {
                    if (data.error[0] && data.error[0]) {
                        message.warning(data.error[0].message);
                        return;
                    };
                };
                this.setState({
                    badge: data.data,
                });
            }.bind(this),
        }).always(function (data) {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    render() {
        return (
            <div className="account-top" >
                <div className="acc-top-user">
                    <span className="acc-top-user-name">欢迎您, {this.state.username||adminData.name || adminData.mobile } <a onClick={this.logOut}>[ 退出 ]</a></span>
                    <span className="acc-top-user-toindex"><a href={globalConfig.context + "/portal/index.html"}>返回首页</a></span>    
                </div >
            </div >
        )
    }
});

export default TopTab;