<template>
  <div class="app-container">
    <el-row :gutter="10">
      <el-col v-for="item in voteList" :key="item.id" :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
        <div class="voteitems">
          <div class="_title">考核主题：{{ item.voteTitle }}</div>
          <div class="_title">考核任务：{{ item.pingceName }}</div>
          <div class="_time">{{ item.sTime + ' - ' + item.eTime }}</div>
          <div>
            <el-tag
                type="success"
                v-if="(new Date(item.sTime) < (new Date())) && (new Date(item.eTime) > (new Date()))"
                @click="goVotepage(item)"
              >
              <i class="el-icon-thumb" v-hasPermi="['kaohe:vote_emp:edit']"></i> 去评分
            </el-tag>
            <el-tag type="info" v-if="new Date(item.sTime) > (new Date())">未开始</el-tag>
            <el-tag type="info" v-if="(new Date(item.sTime) < (new Date())) && (new Date(item.eTime) < (new Date()))">已结束</el-tag>
          </div>
        </div>
      </el-col>
    </el-row>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listByConditons, ListByVoteIds } from "@/api/kaohe/vote"
import { listVote_recard } from "@/api/kaohe/vote_recard"

export default {
  name: "Index",
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        voteIds: null
      },
      // 总条数
      total: 0,
      voteList: []
    }
  },
  created() {
    console.log(this.$store.state.user);
    // this.queryParams.itemIds = this.$store.state.user.itemIds;
    this.queryParams.voteIds= this.$store.state.user.voteIds
    if(this.$store.state.user.roles.length===1&&(this.$store.state.user.roles[0]==='employee'||this.$store.state.user.roles[0]==='deptRole')){

    }else {
      this.getList();
    }
  },
  methods: {
    getList(){
      /*listByConditons(this.queryParams).then(response => {
        this.voteList = response.rows;
        this.total = response.total
      })*/
      ListByVoteIds(this.queryParams).then(response => {
        this.voteList = response.rows;
        this.total = response.total
      });
    },
    goVotepage(row){
      if(this.$store.state.user.roles.indexOf('admin')>0 || this.$store.state.user.roles.indexOf('sysAdmin')>0){
        this.$router.push({ path: '/votepage', query: { id: row.id }});
      }else {
        listVote_recard({
          pageNum: 1,
          pageSize: 1000000000,
          voteId: row.id,
          userId: this.$store.state.user.id,
        }).then(response => {
          if(response.total>0){
            this.$alert(`已经评分完成，不能再次评分！`, `提示`, {
              type: 'Danger'
            })
          }else {
            this.$router.push({ path: '/votepage', query: { id: row.id }});
          }
        })
      }
    },
  }
}
</script>

<style scoped lang="scss">
.voteitems{
  font-size: 14px;
  color: #333;
  border: 1px solid #eeeeee;
  height: 115px;
  margin-bottom: 10px;
  padding: 10px;
  min-width: 300px;
  box-sizing: border-box;

  ._title{
    width: 100%;
    height: 24px;
    white-space: nowrap; /* 防止文本换行 */
    overflow: hidden; /* 隐藏溢出的内容 */
    text-overflow: ellipsis; /* 溢出内容显示为省略号 */
    color: #555555;
  }

  ._time{
    font-size: 12px;
    height: 20px;
    color: #af5e5e;
  }
}

.el-tag{
  cursor: pointer;
}

.pagination-container{
  margin-top: 30px;
  justify-content: flex-start;
}
</style>

