
<template>
  <el-dialog :visible.sync="dialogFormVisible" title="刷卡记录" append-to-body @close="cancel">
    <!--查询结果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 { getCardRecords } from '@/api/card'

export default {
  name: 'CardRecord',
  data() {
    return {
      dialogFormVisible: false, // 对话框是否显示
      listQuery: {
        cardCode: '',
        offset: 1,
        limit: 20,
      }, // 员工查询条件
      list: [], // 搜索结果
      columns: [
        {
          text: '员工编号',
          value: 'personCode',
          align: 'center'
        },
        {
          text: '姓名',
          value: 'NAME',
          align: 'center'
        },
        {
          text: '卡编号',
          value: 'cardCode',
          align: 'center'
        },
        {
          text: '身份证号',
          value: 'idCard',
          align: 'center'
        },
        {
          text: '单位/部门',
          value: 'deptName',
          align: 'center'
        }
      ],
      listLoading: true,
      canEdit: true
    }
  },
  mounted() {
    this.fetchStrategyList()
  },
  methods: {
    // 初始化对话框
    initDialog: function(cardCode) {
      this.dialogFormVisible = true
      this.listQuery.cardCode = cardCode
      this.fetchData()
    },
    // 获取查询数据
    fetchData() {
      this.listLoading = true
      getCardRecords(this.listQuery).then(response => {
        this.listLoading = false
        this.list = response.data
      })
    },
    // 取消
    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>
