Newer
Older
iris_temperature_front_gz / src / views / accessPermission / listStaffPermission.vue
StephanieGitHub on 12 Mar 2020 8 KB first commit
<!--员工授权列表-->
<template>
  <div class="app-container">
    <!--筛选条件-->
    <div class="search-div">
      <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container">
        <el-row>
          <el-form-item class="selectForm-container-item" prop="keyword">
            <el-input v-model.trim="listQuery.keyword" placeholder="姓名/身份证号" clearable/>
          </el-form-item>
          <el-form-item class="selectForm-container-item">
            <dept-select v-model="listQuery.deptId" :need-top="deptShowTop" placeholder="选择单位/部门"/>
          </el-form-item>
          <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        </el-row>
      </el-form>
    </div>
    <!--查询结果Table显示-->
    <div>
      <el-row class="table-title">
        <el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>{{ doorName }}门禁员工授权列表</div></el-col>
        <el-col :span="12" :offset="6" class="edit_btns">
          <el-button v-if="hasPerm('/acsPermission/exportStaffPerm')" class="edit_btn" size="small" @click="batchExport">导出授权记录</el-button>
          <el-button v-if="hasPerm('/acsPermission/add')" class="edit_btn" size="small" @click="addPermission">新增员工授权</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="listLoading" :data="list" class="table" border>
        <el-table-column :index="indexMethod" align="center" type="index" />
        <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :width="column.width" :align="column.align" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="column.type!='Button'" :class="column.class">{{ scope.row[column.value] }}</span>
            <el-button v-if="column.type=='Button'" type="text" @click="showStrategyDetail(scope.row)">{{ scope.row[column.value] }}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="120">
          <template slot-scope="scope">
            <el-button v-if="hasPerm('/acsPermission/delete')" type="text" @click="cancelPermission(scope.row)">取消授权</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <div class="pagination-container">
        <el-pagination
          v-show="total>listQuery.limit"
          :current-page="listQuery.offset"
          :page-sizes="[20,30,50]"
          :page-size="listQuery.limit"
          :total="total"
          align="center"
          layout="total, sizes, prev, pager, next"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </div>
    <add-staff-perm ref="staffperm" @watchChild="fetchData"/>
    <edit-strategy ref="editstrategy"/>
  </div>
</template>

<script>
import { getStaffPermissionByDoor, delPermission, exportStaffPermission } from '@/api/access'
import DeptSelect from '../../components/DeptSelect/index'
import AddStaffPerm from './addStaffPerm'
import EditStrategy from '../accessStrategy/editStrategy'
export default {
  name: 'ListStaffPermission',
  components: { EditStrategy, AddStaffPerm, DeptSelect },
  data() {
    return {
      doorName: '', // 门禁名称
      listQuery: {
        doorCode: '', // 门禁编号
        keyword: '', // 关键字
        deptId: '', // 部门
        offset: 1,
        limit: 20,
        sort: 'createTime',
        order: 'desc'
      }, // 筛选条件
      total: 0, // 数据总数
      deptShowTop: false,
      columns: [
        {
          text: '员工编号',
          value: 'personCode',
          align: 'center'
        },
        {
          text: '姓名',
          value: 'personName',
          align: 'center'
        },
        {
          text: '身份证号',
          value: 'idCard',
          align: 'center',
          width: 170
        },
        {
          text: '部门',
          value: 'deptName',
          align: 'center'
        },
        {
          text: '门禁',
          value: 'doorName',
          align: 'center'
        },
        {
          text: '门禁策略',
          value: 'strategyName',
          align: 'center',
          type: 'Button'
        },
        {
          text: '操作人姓名',
          value: 'createUserName',
          align: 'center'
        },
        {
          text: '更新时间',
          value: 'createTime',
          align: 'center',
          width: 170
        }
      ], // 显示列
      list: [], // 列表数据
      listLoading: true // 加载动画
    }
  },
  mounted() {
    if (this.$route.query && this.$route.query.doorCode) {
      this.listQuery.doorCode = this.$route.query.doorCode
      this.doorName = this.$route.query.doorName
      this.fetchData()
    }
  },
  activated() {
    if (this.$route.query && this.$route.query.doorCode) {
      this.listQuery.doorCode = this.$route.query.doorCode
      this.doorName = this.$route.query.doorName
      this.fetchData()
    }
  },
  methods: {
    // 取消授权
    cancelPermission(row) {
      this.$confirm(
        '确认取消该员工的门禁授权吗?',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        delPermission(row.permissionId).then(response => {
          if (response.code === 200) {
            this.$message.success('取消授权成功')
            this.fetchData()
          }
        })
      })
    },
    // 新增授权
    addPermission() {
      this.$refs.staffperm.initDialog(this.listQuery.doorCode)
    },
    // 查询数据
    search() {
      this.fetchData(false)
    },
    // 获取门禁授权数据
    fetchData(isNowPage = true) {
      this.listLoading = true
      getStaffPermissionByDoor(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = parseInt(response.data.total)
        this.listLoading = false
      })
    },
    // 批量导出
    batchExport() {
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '下载中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      exportStaffPermission(this.listQuery).then(res => {
        loading.close() // 关闭加载动画
        const blob = new Blob([res.data])
        const downloadElement = document.createElement('a')
        const href = window.URL.createObjectURL(blob) // 创建下载的链接
        downloadElement.href = href
        downloadElement.download = this.doorName + '门禁员工授权列表.xlsx' // 下载后文件名
        document.body.appendChild(downloadElement)
        downloadElement.click() // 点击下载
        document.body.removeChild(downloadElement) // 下载完成移除元素
        window.URL.revokeObjectURL(href) // 释放blob对象
      }).catch((res) => {
        loading.close()
      })
    },
    // 显示策略详情
    showStrategyDetail(row) {
      this.$refs.editstrategy.initDialog('detail', row)
    },
    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.fetchData()
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.listQuery.offset = val
      this.fetchData()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  $tableTitleHeight:46px;
  .table{
    margin-bottom: 20px;
  }
  .pagination-container{
    margin-bottom: 50px;
  }
  .table-title{
    background-color:rgba(243, 243, 243, 1);
    height: $tableTitleHeight;
    .title-header{
      line-height:$tableTitleHeight;
      color: #606266;
      font-size: 15px;
      i{
        margin-left: 5px;
        margin-right: 5px;
      }
    }
  }
  .edit_btns{
    .edit_btn{
      float:right;
      margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
</style>