import React from 'react';
import { Spin, Button, Tabs, message } from 'antd';
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';

import '../content.less';
import './content.less';
import LeftTab from './leftTab.jsx';
import Collection from './collection';

import weixin from '../../../../image/weixin-w.png';
import qq from '../../../../image/qq-w.png';
import weibo from '../../../../image/weibo-w.png';

const TabPane = Tabs.TabPane;

const Content = React.createClass({
    getInitialState() {
        return {
            loading: false
        };
    },
    getData() {
        this.setState({
            loading: false
        });
        $.ajax({
            method: "get",
            dataType: "json",
            url: globalConfig.context + "/api/user/homePage"
        }).done(function (data) {
            if (data.error && data.error.length) {
                message.warning(data.error[0].message);
            } else {
                this.setState({
                    achievementNum: data.data.achievementNum,
                    copyrightNum: data.data.copyrightNum,
                    demandNum: data.data.demandNum,
                    email: data.data.email,
                    intellectualPropertyNum: data.data.intellectualPropertyNum,
                    logoUrl: data.data.logoUrl,
                    level: data.data.lvl,
                    nickname: data.data.nickname,
                    number: data.data.number,
                    patentNum: data.data.patentNum,
                    personPortraitUrl: data.data.personPortraitUrl,
                    techProjectNum: data.data.techProjectNum,
                    type: data.data.type,
                    uid: data.data.uid
                })
            }
        }.bind(this)).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    componentWillMount() {
        this.getData();
    },
    tabChange(key) {

    },
    render() {
        return (
            <Spin spinning={this.state.loading} className='spin-box'>
                <div className="index-content">
                    <div className="index-userdata clearfix">
                        <p className="acc-title">欢迎, <span>{this.state.nickname || ('No.' + this.state.number)}</span>     </p>
                        <div className="userdata-img">
                            {this.state.personPortraitUrl || this.state.logoUrl ?
                                <img src={globalConfig.avatarHost + "/upload" + (this.state.type == 0 ? this.state.personPortraitUrl : this.state.logoUrl)} alt="" />
                                : <img src="" alt="" />}
                        </div>
                        <div className="userdata-content">
                            {(() => {
                                if (this.state.level > 0) {
                                    return <p className="userdata-lvl"><span>Lv.{this.state.level}</span> 用户</p>;
                                } else {
                                    return <p className="userdata-lvl"><span>用户未认证</span><a style={{ marginLeft: '20px' }} href={userData.type == 1 ? globalConfig.context + "/user/groupCertify.html" : globalConfig.context + "/user/certify.html"}>进行实名认证</a></p>;
                                };
                            })()}
                            <p><a href={globalConfig.context + "/user/account/set.html"}>填写完整资料</a>，有助于提高您的资信</p>
                            <p><a href={globalConfig.context + "/portal/search/achievement.html"}>成果搜索</a></p>
                            <p><a href={globalConfig.context + "/portal/search/demand.html"}>需求搜索</a></p>
                            <p className="userdata-relate" style={{ 'display': 'none' }}>
                                <Button className="relateqq"><img src={qq} alt="" /> QQ账号登录</Button>
                                <Button className="relateweibo"><img src={weibo} alt="" />微博账号登录</Button>
                                <Button className="relateweixin"><img src={weixin} alt="" />微信账号登录</Button>
                            </p>
                        </div>
                    </div>
                    <div className="index-record">
                        <p className="acc-title">我的轨迹</p>
                        <ul className="record-list clearfix">
                            <li>专利：<a href={globalConfig.context + "/user/account/services.html#patent"}>{this.state.patentNum || 0}</a> 项</li>
                            <li>软著：<a href={globalConfig.context + "/user/account/services.html#copyright"}>{this.state.copyrightNum || 0}</a> 项</li>
                            <li>知识产权：<a href={globalConfig.context + "/user/account/services.html#intellectual"}>{this.state.intellectualPropertyNum || 0}</a> 项</li>
                            <li>科技项目：<a href={globalConfig.context + "/user/account/services.html#technology"}>{this.state.techProjectNum || 0}</a> 项</li>
                            <li>技术成果：<a href={globalConfig.context + "/user/account/achievement.html#techAchievement"}>{this.state.achievementNum || 0}</a> 项</li>
                            <li>发布需求：<a href={globalConfig.context + "/user/account/demand.html#techDemand"}>{this.state.demandNum || 0}</a> 项</li>
                        </ul>
                    </div>
                    <div className="index-activity">
                        <Collection />
                    </div>
                </div>
            </Spin>
        )
    }
});

export default Content;