
<template>
  <el-dialog :visible.sync="dialogFormVisible" title="分组详情" append-to-body @close="cancel">
    <el-form label-width="100px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="门禁组别名称">
            <el-input v-model.trim="row.groupName" disabled type="text" placeholder="人员组别名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="描述">
            <el-input v-model.trim="row.description" disabled type="text" placeholder="描述"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!--查询结果Table显示-->
    <div class="tablediv">
      <el-row class="table-title">
        <el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>门禁列表({{ list.length }})</div></el-col>
      </el-row>
      <el-table v-loading="listLoading" :data="list" size="small" max-height="200" class="table" border @selection-change="handleSelectionChange">
        <el-table-column align="center" type="index" />
        <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :width="column.width" :align="column.align">
          <template slot-scope="scope">
            <span v-if="column.value === 'idCard'">{{ encrypIdCardNo(scope.row[column.value]) }}</span>
            <span v-else :class="column.class">{{ scope.row[column.value] }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </el-dialog>
</template>

<script>
import { groupList } from '@/api/door'
import DeptSelect from '../../components/DeptSelect/index'

export default {
  name: 'DetailGroup',
  components: { DeptSelect },
  data() {
    return {
      textMap: {
        update: '编辑',
        create: '新增',
        detail: '详情'
      }, // 表头显示标题
      dialogStatus: '',
      dialogFormVisible: false, // 对话框是否显示
      listQuery: {
        groupId: ''
      }, // 员工查询条件
      list: [], // 搜索结果
      columns: [
        {
          text: '门禁编号',
          value: 'doorCode',
          align: 'center'
        },
        {
          text: '门禁名称',
          value: 'doorName',
          align: 'center'
        },
        {
          text: '描述',
          value: 'description',
          align: 'center'
        },
        {
          text: '设备编号',
          value: 'devCode',
          align: 'center'
        },
        {
          text: '区域',
          value: 'areaName',
          align: 'center'
        }
      ],
      multipleSelection: [], // 多选选中项
      strategyList: [], // 策略列表
      listLoading: true,
      canEdit: true,
      row: ''
    }
  },
  mounted() {
  },
  methods: {
    // 初始化对话框
    initDialog: function(dialogStatus, dialogFormVisible, row = null) {
      this.dialogStatus = dialogStatus
      this.dialogFormVisible = true
      this.listQuery.groupId = row.id
      this.row = row
      this.canEdit = true
      this.fetchData()
    },
    // 验证表单
    validateForm(permissionForm) {
      if (this.multipleSelection.length <= 0) {
        this.$message.warning('请选中人员再进行授权')
        return false
      }
      // if (permissionForm.strategyId === '') {
      //   this.$message.warning('门禁策略必选')
      //   return false
      // }
      return true
    },
    // 获取查询数据
    fetchData() {
      this.listLoading = true
      groupList(this.listQuery).then(response => {
        this.listLoading = false
        this.list = response.data
      })
    },
    // 多选触发方法
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 取消
    cancel: function() {
      console.log('cancel')
      this.dialogFormVisible = false
      this.$emit('watchChild')
    },
    // 身份证号加密
    encrypIdCardNo(idCardNo) {
      if (idCardNo) {
        return idCardNo.substr(0, 6) + '********' + idCardNo.substr(14, 18)
      } else {
        return ''
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  $tableTitleHeight:42px;
  .tablediv{
    margin-bottom: 10px;
  }
  .table-title{
    background-color:rgba(243, 243, 243, 1);
    .title-header{
      line-height:$tableTitleHeight;
      color: #606266;
      font-size: 14px;
      i{
        margin-left: 5px;
        margin-right: 5px;
      }
    }
    .edit_btns{
      .edit_btn{
        float:right;
        margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
      }
    }
  }
  .el-select{
    width: 100%;
  }
  .el-date-editor{
    width: 100%;
  }
  .strategy-title{
    line-height: 30px;
  }
  .strategy-body{
    line-height:30px !important;
  }
</style>
