<!--白名单列表-->
<template>
  <div class="app-container whitelist">
    <div class="whitelist-page" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
        <el-form-item label="关键字" prop="userName">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="姓名/工号/联系方式"
            clearable
            maxLength="30"
            size="small"
          />
        </el-form-item>

        <el-form-item>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
        <el-form-item style="float: right;">
          <el-button
            style="margin-left: 20px"
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="pageClick(2)"
            v-hasPermi="['laboratory:whitelist:add']"
          >新增</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" border :data="safe_bookList" >
        <el-table-column label="姓名" align="left" prop="userName"/>
        <el-table-column label="工号" align="left" prop="userNumber"/>
        <el-table-column label="联系方式" align="left" prop="userTelephone"/>
        <el-table-column label="学院" align="left" prop="deptName"/>
        <el-table-column label="操作" align="center" width="160" v-if="tableButtonType">
          <template slot-scope="scope">
            <div class="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p"
                 @click="pageEditClick(2,scope.row)"
                 v-hasPermiAnd="['laboratory:whitelist:query','laboratory:whitelist:edit']"
              >编辑</p>
              <p class="table-button-p"
                 @click="delButton(scope.row)"
                 v-hasPermi="['laboratory:whitelist:remove']"
              >移除</p>
              <p class="table-button-null"></p>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <pagination :page-sizes="[20, 30, 40, 50]"
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <add-page v-if="pageType == 2" :pageData="pageData"></add-page>
  </div>
</template>

<script>
  import { whitelistList,whitelistDel } from "@/api/laboratory/whitelist";
  import addPage from './addPage.vue'
  export default {
    components:{
      addPage
    },
    name: "whitelist",
    data() {
      return {
        tableButtonType:this.hasPermiDom(['laboratory:whitelist:query','laboratory:whitelist:edit','laboratory:whitelist:remove']),
        pageType:1,
        // 遮罩层
        loading: false,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 实验室安全制度表格数据
        safe_bookList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize:20,
          searchValue: null,
        },
        pageData:{},
      };
    },
    created() {
      this.getList();
    },
    methods: {
      delButton(item){
        let self = this;
        this.$confirm('确定移除当前准入信息，移除后将无法进入实验室?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          self.whitelistDel(item);
        }).then(() => {}).catch(() => {});
      },
      whitelistDel(item){
        whitelistDel(item.id).then(response => {
          this.msgSuccess("删除成功");
          this.getList();
        });
      },
      getList(){
        this.loading = true;
        whitelistList(this.queryParams).then(response => {
          this.safe_bookList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      //新增
      pageClick(type){
        if(this.pageType != type){
          this.pageType = type;
          this.pageData= {};
          if(type == 1){
            this.getList();
          }
        }
      },
      //编辑
      pageEditClick(type,item){
        if(this.pageType != type){
          this.pageType = type;
          this.pageData=item;
          if(type == 1){
            this.getList();
          }
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.searchValue='';
        this.handleQuery();
      },
      handleDelete(){

      },
    }
  };
</script>

<style scoped lang="scss">
  .whitelist {
    flex:1;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    .whitelist-page{
      flex:1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      padding:11px 20px 20px!important;
      .button-box{
        margin:0 auto;
        width:190px;
        display: flex;
      }
    }
  }
</style>
