<!--白名单列表-->
<template>
  <div class="app-container whitelist">
    <div class="page-container whitelist-page" v-if="pageType == 1">
      <div class="page-form-title-box">
        <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>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <el-form-item style="float: right;">
            <el-button
              style="margin-left: 20px"
              type="primary"
              plain
              size="mini"
              @click="pageClick(2)"
              v-hasPermiRouter="['laboratory:white:add']"
            >新增</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList" >
          <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-hasPermiRouter="['laboratory:white:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="delButton(scope.row)"
                   v-hasPermiRouter="['laboratory:white:del']"
                >移除</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.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <add-page v-if="pageType == 2" :pageData="pageData"></add-page>
  </div>
</template>

<script>
  //                    V3
  import addPage from './addPage.vue'
  import { laboratoryWhiteList,laboratoryWhiteDelJoinSub } from "@/api/secureAccess/index";
  export default {
    components:{
      addPage
    },
    name: "whitelist",
    data() {
      return {
        tableButtonType:this.hasPermiDom(['laboratory:white:edit','laboratory:white:del']),
        pageType:1,
        // 遮罩层
        loading: false,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 实验室安全制度表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          page: 1,
          pageSize:20,
          searchValue: null,
        },
        pageData:{},
      };
    },
    created() {
      this.getList();
    },
    methods: {
      delButton(item){
        let self = this;
        this.$confirm('确定移除当前准入信息，移除后将无法进入实验室?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          self.laboratoryWhiteDelJoinSub(item);
        }).then(() => {}).catch(() => {});
      },
      laboratoryWhiteDelJoinSub(item){
        laboratoryWhiteDelJoinSub({whiteId:item.whiteId}).then(response => {
          this.msgSuccess("删除成功");
          this.getList();
        });
      },
      getList(){
        this.loading = true;
        laboratoryWhiteList(this.queryParams).then(response => {
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.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.page = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.searchValue='';
        this.handleQuery();
      },
      handleDelete(){

      },
    }
  };
</script>

<style scoped lang="scss">
  .whitelist {
    .whitelist-page{
    }
  }
</style>
