<template>
  <div>
    <div class="app-container" v-if="isList">
      <div style="float:right">
        <el-button type="primary" size="mini" @click="btnCurrentMonth">本月绩效</el-button>
        <el-button type="primary" size="mini" @click="btnNextMonth">下月绩效</el-button>
      </div>
      <el-table size="mini" height="500px" v-loading="loading" :data="listData" @row-dblclick="btnDetails">
        <el-table-column label="绩效编号" align="center" prop="id" />
        <el-table-column label="员工姓名" align="center" prop="staffName" />
        <el-table-column show-overflow-tooltip label="评估周期" align="center" prop="name" />
        <el-table-column label="月度" align="center" prop="month" />
        <el-table-column label="自评分" align="center" prop="saMark" />
        <el-table-column label="上级评分" align="center" prop="ldMark" />
        <el-table-column label="综合得分" align="center" prop="mark" />
        <el-table-column label="等级" align="center" prop="grade" />
        <el-table-column label="绩效系数" align="center" prop="coefficient" />
        <el-table-column label="状态" align="center" prop="status" >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.ehr_pm_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-search"
              @click="btnDetails(scope.row)"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="paginationClass">
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
    <detail v-model="isList" v-if="!isList" :pageStu="page" :rowId="rowId" :ids="ids" @refresh="refresh" />
  </div>
</template>

<script>
import detail from './detail.vue'
import { listPerformance,getCurrentMonthId,getNextMonthId} from "@/api/business/ehr/pm/performance";

export default {
  name: "assess",
  dicts: ['ehr_pm_status'],
  components: {detail},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      listData: [],
      // id集合
      ids: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        params:{
          oneself: true,
        },
      },
      //页面显示
      isList: true,
      //页面状态
      page: '',
      //详情id
      rowId: '',
    };
  },
  async created() {
    //如果是跳转过来的页面带了参数flowId则直接进入填写页面
    if(this.$route['query'] !== undefined && this.$route.query['flowId'] !== undefined){
      this.rowId = this.$route.query.performanceId;
      this.page = 'add';
      this.ids = [this.$route.query.performanceId];
      this.isList = false;
    }
    this.getList();
  },
  methods: {
    /** 查询绩效列表 */
    getList() {
      this.loading = true;
      listPerformance(this.queryParams).then(response => {
        this.listData = response.rows;
        this.ids = response.rows.map(item => item.id);
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 刷新 */
    refresh(){
      this.resetForm("queryForm");
      this.dateRange = [];
      this.treeValue = [];
      this.getList();
    },
    /** 进入详情 */
    btnDetails(row){
      this.rowId = row.id;
      this.page = 'add';
      this.isList = false;
    },
    //查看当月绩效
    async btnCurrentMonth(){
      let res = await getCurrentMonthId();
      if(!res.id){
        this.$modal.msgSuccess("未查询到本月绩效！");
      }else{
        this.rowId = res.id;
        this.page = 'add';
        this.ids = [res.id];
        this.isList = false;
      }
    },
    //查看下月绩效
    async btnNextMonth(){
      let res = await getNextMonthId();
      if(!res.id){
        this.$modal.msgSuccess("未查询到下月绩效！");
      }else{
        this.rowId = res.id;
        this.page = 'add';
        this.ids = [res.id];
        this.isList = false;
      }
    },
  }
};
</script>

<style lang="scss" scoped>
.btn_grooup {
  margin-bottom: 10px;
  display: flex;
  justify-content: flex-end;
}
.paginationClass {
  z-index: 500;
  position: fixed;
  bottom: 10px;
  right: 10px;
  width: 100%;
  line-height: var(--footer-height);
  color: #fff;
}
</style>
