<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="user == null || user.userVO.photoUrl == null?defaultValue.image:user.userVO.photoUrl" class="user-img">
                <span class="vertify hide"></span>
              </a>
            </p>
            <div class="username_box">
              <div class="username_icon username_"></div>
              <span class="username">{{user == null?'...':user.userVO.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: 'AuthenticationIndex'}">
                <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 v-if="rolesPermissions.isAgency" 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 v-if="rolesPermissions.isAgency" 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="myProjects == null || myProjects.length == 0"> 暂无项目 </span>
          <project-item v-if="myProjects != null || myProjects.length > 0"
                        v-for="(item,index) in myProjects" :key="index" :projectItem="item"/>
        </el-tab-pane>
        <el-tab-pane v-if="rolesPermissions.isRegionManager" label="处理中项目">

          <span v-if="handlingProjects == null || handlingProjects.length == 0"> 暂无项目 </span>
          <project-item v-if="handlingProjects != null || handlingProjects.length > 0"
                        v-for="(item,index) in handlingProjects" :key="index" :projectItem="item"/>
        </el-tab-pane>
        <el-tab-pane v-if="rolesPermissions.isRegionManager" label="可接收项目">

          <span v-if="acceptableProjects == null || acceptableProjects.length == 0"> 暂无项目 </span>
          <project-item v-if="acceptableProjects != null || acceptableProjects.length > 0"
                        v-for="(item,index) in acceptableProjects" :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'
import {defaultValue, getRolesPermissions, storageGet} from '@/js/index'

export default {
  name: 'Mine',
  components: {TaskItem, ProjectItem},
  watch: {
    user (val) {
      this.user = val
    },
    rolesPermissions (val) {
      this.rolesPermissions = val
    },
    deep: true
  },
  data () {
    return {
      unFinishedTaskList: [],
      finishedTaskList: [],
      appliedProjectList: [],
      myProjects: [],
      handlingProjects: [],
      acceptableProjects: [],
      defaultValue: defaultValue,
      rolesPermissions: {
        isRegionManager: false,
        isIndividualUser: false,
        isEnterpriseUser: false,
        isAgency: false,
        isSystemAdministrator: false
      },
      user: {
        userVO: {
          id: '',
          name: '',
          photo: '',
          roleList: []
        }
      }
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    init () {
      this.setUserInfo()
      this.setRolesPermissions()
      this.loadData()
      // storageGet('user').then((res)=>{
      //   this.user = res;
      //   this.setRolesPermissions()
      //   this.loadData()
      // })

    },
    loadData () {
      Http.get(Apis.PAGE.MY_CROWD_TEST_PAGE.replace('{userId}', this.user.userVO.id)).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.myProjects != null && res.myProjects.length > 0) {
          this.myProjects = res.myProjects
        }
        if (res.handlingProjects != null && res.handlingProjects.length > 0) {
          this.handlingProjects = res.handlingProjects
        }
        if (res.acceptableProjects != null && res.acceptableProjects.length > 0) {
          this.acceptableProjects = res.acceptableProjects
        }
        // if (res.userVO != null && res.userVO.length > 0) {
        //   this.user = res.userVO
        // }
      })
    },
    setUserInfo () {
      this.user = storageGet('user')
    },
    setRolesPermissions () {
      this.rolesPermissions = storageGet('rolesPermissions')
    }

  },
  created: function () {

  }
}
</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>

