<template>
  <div>
    <div class="app-container">
      <div style="float:right">
        <el-badge :value="adjustCount" class="item" style="margin: 0 10px"  v-if="adjustCount> 0">
          <el-button type="primary" size="mini" @click="btnGradeAdjust">待分数调整</el-button>
        </el-badge>
      </div>
      <el-table size="mini" v-loading="loading" :data="listData" show-summary :summary-method="getSummaries">
        <el-table-column label="周期编号" align="center" prop="id" />
        <el-table-column label="名称" align="center" prop="name" />
        <el-table-column label="月份" align="center" prop="month" />
        <el-table-column label="阶段" align="center" prop="stage" >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.ehr_pm_status" :value="scope.row.stage"/>
          </template>
        </el-table-column>
        <el-table-column label="待确认" align="center" prop="unVerify">
          <template scope="scope">
            <div v-if="scope.row.unVerify > 0" style="color:red" @click="btnEntryUnVerify(scope.row)">{{ scope.row.unVerify}}</div>
            <div v-if="scope.row.unVerify == 0" @click="btnEntryUnVerify(scope.row)">{{ scope.row.unVerify}}</div>
          </template>
        </el-table-column>
        <el-table-column label="已确认" align="center" prop="verify">
          <template scope="scope">
            <div v-if="scope.row.verify > 0" style="color:blue" @click="btnEntryVerify(scope.row)">{{ scope.row.verify}}</div>
            <div v-if="scope.row.verify == 0" @click="btnEntryVerify(scope.row)">{{ scope.row.verify}}</div>
          </template>
        </el-table-column>
        <el-table-column label="待评分" align="center" prop="unMark">
          <template scope="scope">
            <div v-if="scope.row.unMark > 0" style="color:red" @click="btnEntryUnMark(scope.row)">{{ scope.row.unMark}}</div>
            <div v-if="scope.row.unMark == 0" @click="btnEntryUnMark(scope.row)">{{ scope.row.unMark}}</div>
          </template>
        </el-table-column>
        <el-table-column label="已评分" align="center" prop="mark">
          <template scope="scope">
            <div v-if="scope.row.mark > 0" style="color:blue" @click="btnEntryMark(scope.row)">{{ scope.row.mark}}</div>
            <div v-if="scope.row.mark == 0" @click="btnEntryMark(scope.row)">{{ scope.row.mark}}</div>
          </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>
    <el-dialog title="分数调整" :visible.sync="stageListOpen" width="1000px" :close-on-click-modal="false">
      <el-table size="mini" height="500px" v-loading="stageListLoading" :data="stageList">
        <el-table-column label="名称" align="center" prop="name" />
        <el-table-column label="月份" align="center" prop="month" />
        <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="btnEntryAdjust(scope.row)"
            >进入调整</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listEvaluate} from "@/api/business/ehr/pm/evaluate";
import { getGradeAdjustConut,toDoList} from "@/api/business/ehr/pm/gradeadjust";

export default {
  name: "EvaluatePm",
  dicts: ['ehr_pm_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      listData: [],
      // id集合
      ids: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
      },
      //等级调整周期列表
      stageList:[],
      //等级调整周期列表弹出层
      stageListOpen:false,
      //等级调整数量
      adjustCount: null,
      //等级调整周期列表遮罩层
      stageListLoading: true,
    };
  },
  async created() {
    //查询等级调整数量
    let res = await getGradeAdjustConut();
    this.adjustCount = res.row;
    this.getList();
  },
  methods: {
    /** 查询行动列表 */
    getList() {
      this.loading = true;
      listEvaluate(this.queryParams).then(response => {
        this.listData = response.rows;
        this.ids = response.rows.map(item => item.id);
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    btnSearch() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    btnResetQuery() {
      this.resetForm("queryForm");
      this.btnSearch();
    },
    /** 刷新 */
    refresh(){
      this.resetForm("queryForm");
      this.getList();
    },
    //等级调整
    btnGradeAdjust(){
      this.stageListOpen = true;
      this.getlistStage();
    },
    //查询周期列表
    getlistStage() {
      this.stageListLoading = true;
      toDoList().then(response => {
        this.stageList = response.rows;
        this.stageListLoading = false;
      });
    },
    //进入调整
    btnEntryAdjust(row){
      this.$router.push({ name: 'AdjustGrade', query: { id: row.id,flowId: row.flowId } });
    },
    //进入待确认
    btnEntryUnVerify(val) {
      if(val.unVerify > 0){
        this.$router.push({name:'AwaitVerifyPm',query: { id: val.id}});
      }
    },
    //进入已确认
    btnEntryVerify(val) {
      if(val.verify > 0){
        this.$router.push({name:'FinishVerifyPm',params: { id: val.id}});
      }
    },
    //进入待评分
    btnEntryUnMark(val) {
      if(val.unMark > 0){
        this.$router.push({name:'AwaitMarkPm',query: { id: val.id}});
      }
    },
    //进入已评分
    btnEntryMark(val) {
      if(val.mark > 0){
        this.$router.push({name:'FinishMarkPm',params: { id: val.id}});
      }
    },
    //合计
    getSummaries(param){
      return ['','','','','处理待确认','查看已确认','处理待评分','查看已评分'];
    },
  }
};
</script>

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