<template>
  <div class="createPm">
    <el-button size="mini" icon="el-icon-plus" @click="click">生成绩效</el-button>
    <el-dialog title="生成绩效" :visible.sync="open" width="1000px" :close-on-click-modal="false">
      <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" @submit.native.prevent>
        <el-form-item label="员工" prop="staffCodeOrName">
          <el-input
            v-model="queryParams.staffCodeOrName"
            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>
      <el-table size="mini" height="500px" v-loading="loading" :data="listData">
        <el-table-column label="员工名称" align="center" prop="staffName" />
        <el-table-column label="员工编号" align="center" prop="staffNo" />
        <el-table-column label="入职日期" align="center" prop="dateJoin" />
        <el-table-column label="部门" align="left" prop="deptName" />
        <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-plus"
                @click="btnCreate(scope.row)"
              >生成</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStaff} from "@/api/business/ehr/ehr/staff";
import { createPm} from "@/api/business/ehr/pm/stage";
export default {
  name: "CreatePmDialog",
  props: ["stageId"],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        staffCodeOrName: null,
      },
      // 总条数
      total: 0,
      // 表格数据
      listData: [],
      // 遮罩层
      loading: true,
      // 是否显示弹出层
      open: false,
    };
  },
  methods: {
    /** 查询绩效列表 */
    getList() {
      this.loading = true;
      listStaff(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();
    },
    //点击了当前按钮
    click() {
      this.open = true;
      this.getList();
    },
    //生成
    async btnCreate(row){
      let data = {
        stageId: this.stageId,
        staff: row.staffNo
      }
      this.$confirm('确认要生成【' + row.staffName + '】的绩效吗？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'success'
      }).then(() => {
        createPm(data).then(response => {
          if(response.code == 200){
            this.$modal.msgSuccess("生成成功");
            this.open = false;
          }
        });
      }).catch(() => {      
      });
    },
  },
  created() {
  },
};
</script>
<style>
.createPm{
  display: flex;
  align-items: center;
  justify-content: end;
}
</style>

