<template>
  <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">
        <el-button type="primary" size="mini" @click="btnGetRelation">同步EHR评估关系</el-button>
      </div>
      <el-table size="mini" height="500px" v-loading="loading" :data="listData" @row-dblclick="btnDetails">
        <el-table-column label="员工编号" align="center" prop="staff" />
        <el-table-column label="员工姓名" align="center" prop="staffName" />
        <el-table-column label="创建时间" align="center" prop="createTime" />
        <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" :enterState="page" :rowId="rowId" :ids="ids" @refresh="refresh" />
  </div>
</template>

<script>
import detail from './detail.vue'
import { listPsnrelation,sync} from "@/api/business/ehr/pm/psnrelation";
export default {
  name: "psnrelation",
  components: {detail},
  data() {
    return {
      // 总条数
      total: 0,
      // 表格数据
      listData: [],
      // id集合
      ids: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        staffName: null,
      },
      //页面显示
      isList: true,
      //页面状态
      page: '',
      //详情id
      rowId: '',
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询绩效列表 */
    getList() {
      this.loading = true;
      listPsnrelation(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.dateRange = [];
      this.btnSearch();
    },
    /** 刷新 */
    refresh(){
      this.resetForm("queryForm");
      this.dateRange = [];
      this.getList();
    },
    /** 进入详情 */
    btnDetails(row){
      this.rowId = row.id;
      this.page = 'see';
      this.isList = false;
    },
    //获取EHR评估关系按钮
    btnGetRelation(){
      sync().then(response => {
        if(response.code == 200){
          this.$modal.msgSuccess(response.rows.length > 0 ? "同步成功" + "新增下列人员" + response.rows : "同步成功");
          this.getList();
        }
      });
    }
  }
};
</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>
