<template>
  <div class="mine-container">
    <div class="mine-top-wrapper">
      <el-row :gutter="0" style="height:100%">
        <el-col :span="16">
          <div class="advertise-imgs">
            <img
              src="http://sinastorage.com/storage.miaosha.sina.com.cn/products/201903/e496d11b3d74cf660c286fbd5ab8d0bb.png"
            >
          </div>
        </el-col>
        <el-col :span="8">
          <div class="user-banner">
            <p class="head">
              <a href="javascript:;" class="login-link">
                <img src="http://www.mooctest.net/assets/img/mooctest.png" class="user-img">
                <span class="vertify hide"></span>
              </a>
            </p>
            <div class="username_box">
              <div class="username_icon username_"></div>
              <span class="username">{{user.name}}</span>
            </div>
            <!--<p class="name">-->
            <!--<a href="javascript:;" class="login-btn btn btn-medium btn-info">登录</a>-->
            <!--<a-->
            <!--href="https://login.sina.com.cn/signup/signup?entry=tech"-->
            <!--class="register-btn btn btn-medium btn-info"-->
            <!--target="_blank"-->
            <!--&gt;注册</a>-->
            <!--</p>-->
            <p class="scores">
              <a href="/rule/merit" target="_blank">
                积分
                <em class="num1">{{user.score}}</em>
              </a>
              <span class="line">|</span>
              <a href="/rule/merit" target="_blank">
                威望
                <em class="num2">{{user.prestige}}</em>
              </a>
            </p>
            <p>
              <router-link :to="{ name: 'ProjectCreate'}">
                <div class="btn btn-medium">申请项目</div>
              </router-link>
            </p>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="mine-body">
      <el-tabs tabPosition="top" type="card">
        <el-tab-pane label="未完成任务">
          <span v-if="unFinishedTaskList == null || unFinishedTaskList.length == 0"> 暂无任务 </span>
          <task-item v-if="unFinishedTaskList != null || unFinishedTaskList.length > 0"
                     v-for="(item,index) in unFinishedTaskList" :key="index" :task="item"/>
        </el-tab-pane>
        <el-tab-pane label="已完成任务">
          <span v-if="finishedTaskList == null || finishedTaskList.length == 0"> 暂无任务 </span>
          <task-item v-if="finishedTaskList != null || finishedTaskList.length > 0"
                     v-for="(item,index) in finishedTaskList" :key="index" :task="item"/>
        </el-tab-pane>
        <el-tab-pane label="已申请项目">
          <span v-if="appliedProjectList == null || appliedProjectList.length == 0"> 暂无项目 </span>
          <project-item v-if="appliedProjectList != null || appliedProjectList.length > 0"
                        v-for="(item,index) in appliedProjectList" :key="index" :projectItem="item"/>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
import TaskItem from '@/components/commons/TaskItem'
import ProjectItem from '@/components/commons/ProjectItem'
import Http from '@/js/http.js'
import Apis from '@/js/api.js'
import {notify} from '@/constants/index'
export default {
  name: 'Mine',
  components: {TaskItem, ProjectItem},
  data () {
    return {
      unFinishedTaskList: [],
      finishedTaskList: [],
      appliedProjectList: [],
      user: {}
    }
  },
  methods: {
    loadData () {
      Http.get(Apis.PAGE.MY_CROWD_TEST_PAGE.replace('{userId}', 3), {}).then((res) => {
        if (res.unfinishedTasks != null && res.unfinishedTasks.length > 0) {
          this.unFinishedTaskList = res.unfinishedTasks
        }
        if (res.finishedTasks != null && res.finishedTasks.length > 0) {
          this.finishedTaskList = res.finishedTasks
        }
        if (res.crowdProjectVOList != null && res.crowdProjectVOList.length > 0) {
          this.appliedProjectList = res.crowdProjectVOList
        }
        if (res.userVO != null && res.userVO.length > 0) {
          this.user = res.userVO
        }
      })
    }
  },
  created: function () {
    this.loadData()
  }
}
</script>

<style lang="less" scoped>
  .mine-container {
    padding: 0 80px 40px 80px;
  }

  .mine-top-wrapper {
    height: 350px;
    background-color: #fff;
  }

  [class*="el-col-"] {
    height: 100%;
  }

  .advertise-imgs {
    height: 100%;
  }

  .advertise-imgs img {
    width: 100%;
    height: 100%;
  }

  .user-banner {
    text-align: center;
    display: inline-table;
    height: 100%;
    width: 100%;
    margin-top: 40px;
  }

  .mine-body {
    margin-top: 30px;
  }
</style>

