<!-- 全局白名单配置 -->
<template>
  <div class="app-container globalWhitelistConfiguration">
    <div class="page-container globalWhitelistConfigurationPage">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="姓名/工号/联系方式"
              style="width: 200px"
            />
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-submit-common-style-button"
             style="float: right;"
             @click="dialogOpen"
             v-hasPermiRouter="['lab:allWhite:add']"
          >新增</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="序号" type="index" width="60"/>
          <el-table-column label="名称" prop="userName"  show-overflow-tooltip/>
          <el-table-column label="工号" prop="account" width="200" show-overflow-tooltip/>
          <el-table-column label="联系方式" prop="mobile" width="200" show-overflow-tooltip/>
          <el-table-column label="部门" prop="deptName" width="200" show-overflow-tooltip/>
          <el-table-column label="创建人" prop="createName" width="200" show-overflow-tooltip/>
          <el-table-column label="创建时间" prop="createTime" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="delRow(scope.row)"
                   v-hasPermiRouter="['lab:allWhite: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>
    <!--新增弹窗-->
    <el-dialog class="globalWhitelistConfiguration-dialog" title='新增' width="800px" append-to-body
               :visible.sync="dialogType" v-if="dialogType" @close="dialogOff()"
               :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="dialogForm" ref="dialogForm" class="dialog-top-box" :inline="true" label-width="80px">
        <el-form-item label="" prop="searchValue">
          <el-input v-model="dialogForm.searchValue" placeholder="请输入姓名/工号检索人员" style="width:300px;"></el-input>
        </el-form-item>
        <p class="page-inquire-common-style-button" @click="dialogHandleQuery">查询</p>
        <p class="page-reset-common-style-button" @click="dialogResetQuery">重置</p>
      </el-form>
      <div class="page-content-box dialog-center-box">
        <el-table class="table-box table-null-img-20" highlight-current-row v-loading="loading" border :data="dialogDataList"
                  @current-change="handleCurrentChange">
          <el-table-column label="名称" prop="userName"  show-overflow-tooltip/>
          <el-table-column label="工号" prop="account" width="200" show-overflow-tooltip/>
          <el-table-column label="部门" prop="deptName" width="200" show-overflow-tooltip/>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="dialogTotal>0"
                    :total="dialogTotal"
                    :page.sync="dialogForm.page"
                    :limit.sync="dialogForm.pageSize"
                    @pagination="dialogGetList"
        />
      </div>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="dialogOff()">取消</p>
        <p class="dialog-footer-button-primary" @click="dialogSubmit">提交</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {
    labAllWhiteList,
    laboratoryLabAllWhiteAdd,
    laboratoryLabAllWhiteDelete,
    laboratoryLabAllWhiteSelectUserNotAllWhite,
  } from "@/api/secureAccess/index";
  export default {
    name: 'index',
    data () {
      return {
        tableButtonType:this.hasPermiDom(['lab:allWhite:del',]),
        //页面遮罩
        loading:false,
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          searchValue:"",
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //弹窗相关
        dialogDataList:[],
        dialogTotal:0,
        dialogType:false,
        dialogForm:{
          searchValue:'',
          page:1,
          pageSize:20,
        },
        currentRow:null,
      }
    },
    created () {

    },
    mounted () {
      this.getList();
    },
    methods: {
      //选中
      handleCurrentChange(val) {
        this.$set(this,'currentRow',val);
      },
      //弹窗查询按钮
      dialogHandleQuery(){
        this.$set(this.dialogForm,'page',1);
        this.$set(this,'currentRow',null);
        this.dialogGetList();
      },
      //弹窗重置按钮
      dialogResetQuery(){
        this.$set(this,'dialogForm',{
          page:1,
          pageSize:20,
          searchValue:"",
        });
        this.$set(this,'currentRow',null);
        this.dialogGetList();
      },
      //弹层关闭
      dialogOff(){
        this.$set(this,'dialogType',false);
      },
      //弹层开启
      dialogOpen(){
        this.$set(this,'dialogForm',{
          page:1,
          pageSize:20,
          searchValue:"",
        });
        this.dialogGetList();
        this.$set(this,'currentRow',null);
        this.$set(this,'dialogDataList',[]);
        this.$set(this,'dialogTotal',0);
        this.$set(this,'dialogType',true);
      },
      //弹层确定
      dialogSubmit(){
        if(!this.currentRow){
          this.msgError('请选择人员')
          return
        }
        let obj ={
          userId: this.currentRow.userId,
          userName: this.currentRow.userName,
          deptId: this.currentRow.deptId,
          deptName: this.currentRow.deptName,
          mobile: this.currentRow.mobile,
          account: this.currentRow.account,
          userType: this.currentRow.userType,
        };
        laboratoryLabAllWhiteAdd(obj).then(response => {
          this.msgSuccess(response.message)
          this.resetQuery();
          this.$set(this,'dialogType',false);
        });
      },
      //弹层数据拉取
      dialogGetList(){
        laboratoryLabAllWhiteSelectUserNotAllWhite(this.dialogForm).then(response => {
          this.$set(this,'dialogDataList',response.data.records);
          this.$set(this,'dialogTotal',response.data.total);
        });
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          searchValue:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        labAllWhiteList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      delRow(row){
        let self = this;
        //删除
        this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
        }).then(() => {
          laboratoryLabAllWhiteDelete({id:row.id}).then(response => {
            self.msgSuccess(response.message)
            self.getList();
          });
        }).catch(() => {});
      },
    },
  }
</script>
<style scoped lang="scss">
  .globalWhitelistConfiguration{
    .globalWhitelistConfigurationPage{

    }
  }
</style>
<style lang="scss">
  .globalWhitelistConfiguration-dialog{
    .el-dialog__body{
      padding:20px;
      .dialog-top-box{
        padding:0 ;
      }
      .dialog-center-box{
        height:400px;
        padding:0 ;
      }
    }
  }
</style>
