import React from 'react';
import { Spin, Button, Tabs } 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 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 {
            per: '24',
            loading: false,
            userlvl: '0',
            userid: '1234567',
            follow: '0',
            chengguo: '0',
            kaifa: '0',
            fuwu: '0',
            xuqiu: '0',
            activityArr: [{ type: '成果对接会', title: '龙岗区在线科技成果对接会——智能制造业专场', time: '2017-01-10', link: '' },
            { type: '成果对接会', title: '钛白粉行业技术在线对接会', time: '2017-01-11', link: '' }]
        };
    },
    getData() {
        this.setState({
            loading: false
        });
        $.ajax({
            method: "get",
            dataType: "json",
            url: globalConfig.context + "/api/user/homePage",
            success: function (data) {
                if (data.data && data.data.personPortraitUrl && data.data.nickname) {
                    this.setState({
                        personPortraitUrl: data.data.personPortraitUrl,
                        logoUrl:data.data.logoUrl,
                        type:data.data.type,
                        nickname: data.data.nickname,
                        lvl: data.data.lvl,
                        number: data.data.number
                    })
                };
            }.bind(this),
        }).done(function (data) {
            if (data.error && data.error.length) {
                message.warning(data.error[0].message);
            }
        }.bind(this)).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    componentDidMount() {
        this.getData();
    },
    handlekey(key) {
        this.setState({
            leftKey: key,
        });
    },
    tabChange(key) {

    },
    render() {
        return (
                <div className="acc-content">
                    <LeftTab handlekey={this.handlekey} />
                    <div className="content-right">
                        <Spin spinning={this.state.loading} className='spin-box'>
                            <div className="index-content">
                                <div className="index-userdata clearfix">
                                    <p className="acc-title">{this.state.number}</p>
                                    <div className="userdata-img">
                                        {this.state.type == 0 ?
                                        <img src={globalConfig.avatarHost + "/upload" + this.state.personPortraitUrl} alt="" /> : 
                                        <img src={globalConfig.avatarHost + "/upload" + this.state.logoUrl} alt="" />}
                                    </div>
                                    <div className="userdata-content">
                                        {(() => {
                                            switch (userData.lvl || this.state.userlvl) {
                                                case '0':
                                                    return <p className="userdata-lvl">等级：<span>LV1</span> 普通用户</p>;
                                                case '1':
                                                    return <p className="userdata-lvl">等级：<span>LV2</span> 已认证用户</p>;
                                            };
                                        })()}
                                        <p>完善资料 {this.state.per}% ，<a href="./set.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 className="userdata-follow">已有<a href="">{this.state.follow}</a>人关注你</div>
                                    </div>
                                </div>
                                <div className="index-record">
                                    <p className="acc-title">我的轨迹</p>
                                    <ul className="record-list clearfix">
                                        <li>技术成果：<a href="">{this.state.chengguo}</a>项</li>
                                        <li>技术开发：<a href="">{this.state.kaifa}</a>项</li>
                                        <li>科技服务：<a href="">{this.state.fuwu}</a>项</li>
                                        <li>发布需求：<a href="">{this.state.xuqiu}</a>项</li>
                                    </ul>
                                </div>
                                <div className="index-activity">
                                    <Tabs defaultActiveKey="1" onChange={this.tabChange}>
                                        <TabPane tab="活动" key="1">
                                            <p className="acc-title">即将举办的活动</p>
                                            <ul className="activity-list">
                                                {
                                                    this.state.activityArr.map(function (item, i) {
                                                        return <li key={i}>
                                                            <span className="list-type">[{item.type}]</span>
                                                            <span className="list-title">{item.title}</span>
                                                            <a href={item.link}>报名</a>
                                                            <span className="list-time">{item.time}</span>
                                                        </li>;
                                                    })
                                                }
                                            </ul>
                                        </TabPane>
                                        <TabPane tab="其他" key="2">Content of Tab Pane 2</TabPane>
                                    </Tabs>
                                </div>
                            </div>
                        </Spin>
                    </div>
                </div>
            )
    }
});

export default Content;