<template>
  <div>
    <div slot="header" class="clearfix">
      <span style="font-weight:bold">等级调整</span>
      <div style="float: right; padding: 3px 0" type="text">
        <el-button size="mini" plain @click="btnBack">返回</el-button>
      </div>
    </div>
    <div class="app-container" v-if="isList">
      <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true">
        <el-form-item label="员工" prop="staffName">
          <el-input
            v-model="queryParams.staffName"
            clearable
            @keyup.enter.native="btnSearch"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="btnSearch">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="btnResetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <div style="float:right">
      </div>
      <el-table size="mini" height="500px" v-loading="loading" :data="listData">
        <el-table-column label="编号" align="center" prop="id" />
        <el-table-column label="员工姓名" align="center" prop="staffName" />
        <el-table-column label="评估周期" align="center" prop="name" />
        <el-table-column label="月度" align="center" prop="month" />
        <el-table-column label="权重" align="center" prop="weight" />
        <el-table-column label="自评分" align="center" prop="saMark" />
        <el-table-column label="上级评分" align="center" prop="ldMark" />
        <el-table-column label="调整分" align="center" prop="ajMark" />
        <el-table-column label="调整分等级" align="center" prop="ajGrade" />
        <el-table-column label="最终等级" align="center" prop="grade" />
        <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="btnAdjustMark(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>

    <el-dialog title="分数调整" :visible.sync="formOpen" width="1000px" :close-on-click-modal="false" :show-close="false">
      <el-descriptions :column="1">
        <el-descriptions-item label="员工编号">{{form.staff}}</el-descriptions-item>
        <el-descriptions-item label="员工姓名">{{form.staffName}}</el-descriptions-item>
        <el-descriptions-item label="自评分">{{form.saMark}}</el-descriptions-item>
        <el-descriptions-item label="上级评分">{{form.ldMark}}</el-descriptions-item>
        <el-descriptions-item label="调整分">{{form.ajMark}}</el-descriptions-item>
        <el-descriptions-item label="调整分等级">{{form.grade}}</el-descriptions-item>
        <el-descriptions-item label="调整分原因">{{form.ajCause}}</el-descriptions-item>
      </el-descriptions>
      <el-form size="mini" label-position="right" ref="form" :model="form" :rules="formRules" label-width="80px">
        <el-form-item label="最终等级" prop="grade">
          <el-select v-model="form.grade" >
            <el-option
              v-for="dict in ehr_pm_gradeconfig"
              :key="dict.name"
              :label="dict.name"
              :value="dict.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="调整原因" prop="cause">
          <el-input v-model="form.cause"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="btnClose">取 消</el-button>
        <el-button size="mini" type="primary" @click="btnConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listPerformance,getPerformance,gradeAdjust} from "@/api/business/ehr/pm/gradeadjust";
import { getGradeconfig} from "@/api/business/ehr/pm/gradeconfig";

export default {
  name: "AdjustGrade",
  dicts: ['ehr_pm_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      listData: [],
      //表单数据
      form:{},
      //是否显示行明细弹出层
      formOpen:false,
      //当行明细校验规则
      formRules:{
        grade: [
          { required: true, message: "调整等级不能为空", trigger: "blur" },
        ],
        cause: [
          { required: true, message: "调整原因不能为空", trigger: "blur" },
        ],
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sourceId: null,
        staffName: null,
      },
      //页面显示
      isList: true,
      //页面状态
      page: '',
      //详情id
      rowId: '',
      //等级配置数据
      ehr_pm_gradeconfig:[],
    };
  },
  created() {
    this.queryParams.sourceId = this.$route.params.id;
    getGradeconfig(this.$route.params.gradeconfigId).then(response => {
      this.ehr_pm_gradeconfig = response.data.gradeconfigItem;
    });
    this.getList();
  },
  methods: {
    /** 查询绩效列表 */
    getList() {
      this.loading = true;
      listPerformance(this.queryParams).then(response => {
        this.listData = response.rows;
        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();
    },
    //调整分数
    async btnAdjustMark(row){
      await getPerformance(row.id).then(res => {
        if (res.code === 200) {
          this.form = res.data
          this.formOpen = true;
         }
      })
    },
    //取消
    btnClose(){
      this.formOpen = false;
    },
    //确定
    btnConfirm(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          gradeAdjust(this.form).then(response => {
            this.$modal.msgSuccess("保存成功");
            this.formOpen = false;
            this.getList();
          });
        }
      });
    },
    //返回
    btnBack(){
      this.$router.back();
    },
  }
};
</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>
