<template>
  <div class="all boxMinHeight">
    <header class="flex-box flex-d-center">
      <div class="flex-box">
        <el-select v-model="amhlvalue"  style="width:100px;" placeholder="请选择">
          <el-option v-for="item in amhlList" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <div style="margin-left:10px;width:250px;"><JxSearch :screen="2"  title="搜索考核名称" @confirm="searchList"></JxSearch></div>
      </div>
      <div>
        <el-button icon="el-icon-s-promotion" v-if="$getRole(1)&&$isAuthoritys($7)"  type="primary" @click="amhrsponsor">发起考核</el-button>
        <!-- <el-button  @click="amhrImport">导入历史绩效</el-button> -->
      </div>
    </header>

    <footer v-loading="tableDataLoad">
	  <template v-if="tableData.length==0&&!assessData.keywords">
		  <noData isSolt>
			  <div v-if="$getRole(1)&&$isAuthoritys($7)" style="text-align: center;">暂无考核记录，去 <span @click="amhrsponsor" class="blue">【发起考核】</span></div>
		  </noData>
	  </template>
	  <template v-else>
		  <el-table stripe :data="tableData" @row-click="amfTabLckick"  style="width: 100%">
		    <el-table-column prop="name" label="考核表"></el-table-column>
		    <el-table-column prop="date" label="考核周期"></el-table-column>
		    <el-table-column prop="employee_num_all" label="参与人数(人)">
		      <template slot-scope="scope">
		        <div style="width:55px;text-align:center;">{{ scope.row.employee_num_all }}</div>
		      </template>
		    </el-table-column>
		  		<el-table-column prop="employee_num" label="我的团队(人)">
		  			<template slot-scope="scope">
		  			  <div style="width:55px;text-align:center;">{{ scope.row.employee_num }}</div>
		  			</template>
		  		</el-table-column>
		    <el-table-column prop="peoplenum">
		      <template slot-scope="scope">
		        <el-button type="text" size="medium" @click="amfTabLckick(scope.row)">查看</el-button>
		      </template>
		    </el-table-column>
		  </el-table>
		  <Pagination :page="assessData.page" :page_size="assessData.page_size" :total="total" @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange"></Pagination>
	  </template>
    </footer>
  </div>
</template>

<script>
import JxSearch from '@/components/public/JxSearch';
export default {
  name:'assessManagement',
  data() {
    return {
      tableDataLoad: false, //列表load
      amhlvalue: 0, //当前删选的时间
      amhlList: [
        { value: 0, label: '全部' },
        { value: 2, label: '月度' },
        { value: 3, label: '季度' },
        { value: 4, label: '半年度' },
        { value: 5, label: '年度' },
        { value: 1, label: '日' },
        { value: 6, label: '自定义' }
      ],
      total: 10,
      assessData: {
        cycle_type: 0, //周期类型
        keywords: '', //搜索字
        page: 1, //当期页
        page_size: 10 ,//一页多少数据
        is_manage_scope:1,
      },

      tableData: []
    };
  },
  components: { JxSearch },
  watch: {
    amhlvalue(val) {
      this.assessData.cycle_type = val;
      this.assessData.page = 1;
      this.assessBagList();
    }
  },
  created() {
    this.assessBagList();
  },
  activated() {
    this.assessBagList();
  },
  methods: {
    assessBagList() {
      this.tableDataLoad = true;
      this.$axios('get', '/api/per/package/list', this.assessData)
        .then(res => {
          if (res.data.code == 1) {
            this.tableData = res.data.data.list;
            this.total = res.data.data.total;
          }
        })
        .finally(() => {
          this.tableDataLoad = false;
        });
    },
    searchList(data) {
      //搜索
      this.assessData.keywords = data;
      this.assessBagList();
    },
    //发起考核
    amhrsponsor() {
	  this.getList((data)=>{
		  if(data.length>0){
			 this.$router.push({ name: 'sponsorAssess' }); 
		  }else{
			  this.$confirm('暂无考核表，请到【考核设置】中【新建考核表】', '提示', {
			    confirmButtonText: '知道了',
			    cancelButtonText: '取消',
			    type: 'warning'
			  }).then(() => {
				  

			  }).catch(() => {});
		  }
	  })	
    },
	// 获取考核表
	getList(fun) {
	  this.$axios('get', '/api/per/evaluation/all_group', { page:1, page_size:5 }).then(res => {
	      let data = res.data.data.list || [];
			fun(data)
	    })
	},
    //导入历史绩效
    amhrImport() {},

    //点击表格某一行
    amfTabLckick(row) {
      this.$router.push({ path: '/assessDetails', query: { amfTabLckick: JSON.stringify(row) } });
    },

    // 页面变更
    handleCurrentChange(val) {
      this.assessData.page = val;
      this.assessBagList();
    },
    // 页面跳转
    handleSizeChange(val) {
      this.assessData.page_size = val;
      this.assessBagList();
    }
  }
};
</script>

<style scoped="scoped" lang="scss">
.all {
  position: relative;
  background-color: #fff;
  padding: 20px;
}
header {
 margin-bottom: 20px;
}
footer {
  ::v-deep .el-table__row {
    height: 60px;
  }
  ::v-deep .el-table__row .cell {
    font-size: 13px;
  }
  ::v-deep .has-gutter tr {
    background-color: rgb(240, 240, 240);
  }
  ::v-deep .el-table tr:hover {
    cursor: pointer;
  }
}
.color_blue {
  color: #1299f9;
}
</style>
