<template>
    <d2-container>
        <div class="d2-table-view-full" style="overflow: hidden;">
            <div class="d2-table-view-header">
                <el-form label-width="100px" labelPosition="right" size="small" :inline="true" :model="filter"
                         @keyup.enter.native="handleList" class="demo-form-inline">
                    <el-form-item label="工号/学号">
                        <el-input style="width: 192px" v-model.trim="filter.userNo" placeholder="工号/学号" clearable/>
                    </el-form-item>
                    <el-form-item label="部门/班级" prop="depId">
                        <department-tree @clearInput="clearDepartment1" v-model="filter.depId" :isClear="isClear1"/>
                    </el-form-item>
                    <el-form-item label="门" prop="eqpId" label-width="50px">
                        <equi-tree @clearInput="clearDepartment" v-model="filter.eqpId" :isClear="isClear"/>
                    </el-form-item>
                    <el-form-item label="通行时间">
                        <el-date-picker
                                v-model="creTm"
                                type="datetimerange"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                @change="dateChange"
                                range-separator="至"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="handleList('1')">查询</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <div class="d2-table-view-content">
                <div class="d2-table-view-handle">
                    <el-button size="small">导出</el-button>
                </div>
                <d2-crud
                        title="通行记录"
                        ref="d2Crud"
                        :options="tableOptions"
                        :loading="loading"
                        :columns="columns"
                        :data="data"
                >
                </d2-crud>
            </div>
            <div class="d2-table-view-footer">
                <el-pagination
                        @current-change="handleCurrentChange"
                        @size-change="handleSizeChange"
                        :page-size="tableOptions.pageList[0]"
                        :page-sizes="tableOptions.pageList"
                        :current-page.sync="currentPage"
                        layout="total,sizes, prev, pager, next,jumper"
                        :total="pagination.total"
                ></el-pagination>
            </div>
        </div>
    </d2-container>
</template>
<script>
  import { tableOptions } from '@/assets/options'
  import {getThroughRecordList} from '@/api/accessControl/throughRecord'

  export default {
    name: 'cateUser',
    components: {},
    data () {
      return {
        creTm:"",
        // options1:[],
        flag:true,
        dateList:[],
        isChangeDate:false,
        veIds:[],
        schannelIds: [],
        schannelIdss: '',
        equipmentOptions: [],
        workStationOptions: [],
        time: '',
        options: [],
        stationId: [],
        stationIds: '',
        isCreate: false,
        userId: '',
        checkList: [],
        // classVisible:false,
        staLoading: false,
        multipleSelection: [],
        tableOptions,
        loading: false,
        isClear:'123',
        isClear1:'123',
        filter: {
          pageSize: 10,
          pageNum: 1,
          depId:"",
          userNo:"",
          eqpId:"",
          startTime:"",
          endTime:"",
        },
        pagination: {
          total: 0
        },
        currentPage: 1,
        treeData: [],
        columns: [
          {
            title: '序号',
            key: 'index',
            minWidth: '50',
            formatter (row, column, cellValue, index) {
              return index+1
            }
          },
          {
            title: '卡号',
            key: 'cardCode',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '工号/学号',
            key: 'userNo',
            minWidth: '140',
            showOverflowTooltip: true
          },
          {
            title: '姓名',
            key: 'userNm',
            minWidth: '90',
            showOverflowTooltip: true
          },
          {
            title: '部门/班级',
            key: 'depNm',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '通行时间',
            key: 'creTm',
            minWidth: '180',
            showOverflowTooltip: true
          },
          {
            title: '机号',
            key: 'eqpNo',
            minWidth: '90',
            showOverflowTooltip: true
          },
          {
            title: '门名称',
            key: 'doorNm',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '门号',
            key: 'doorCode',
            minWidth: '180',
            showOverflowTooltip: true
          },
          {
            title: '事件类型',
            key: 'paramData',
            minWidth: '180',
            showOverflowTooltip: true
          },
        ],
        data: [],
      }
    },

    methods: {
      clearDepartment1(){
        this.filter.depId=''
      },
      clearDepartment(){
        this.filter.eqpId=''
      },
      dateChange (val) {
        if (val == null) {
          this.filter.startTime = ''
          this.filter.endTime = ''
        } else {
          this.filter.startTime = val[0]
          this.filter.endTime = val[1]
        }
      },
      handleTreeNode () {
        this.handleList()
      },
      handleList (val) {
        if (val) {
          this.filter.pageNum = 1
          this.currentPage = 1
        }
        this.loading = true
        getThroughRecordList(this.filter)
          .then(res => {
            // console.log(res)
            this.loading = false
            this.data = res.page.list
            this.pagination.total = res.page.total
          })
          .catch(err => {
            this.loading = false
          })
      },
      handleCurrentChange (val) {
        this.filter.pageNum = val
        this.handleList()
      },
      handleSizeChange (val) {
        this.filter.pageNum = 1
        this.filter.pageSize = val
        this.handleList()
      },
    },
    mounted () {
      this.filter.pageSize = this.tableOptions.pageList[0]
      this.tableOptions = this.$calcTableHeight(tableOptions, 90)
      this.handleTreeNode()
    }
  }
</script>
<style>
    /*.d2-table-view-header .el-radio {*/
        /*margin-right: 15px;*/
    /*}*/

    /*.d2-table-view-full {*/
        /*height: 100%;*/
    /*}*/

    /*.timeBox {*/
        /*margin-top: 10px;*/
    /*}*/

    /*.timePay {*/
        /*margin-left: 8px;*/
    /*}*/

    /*.avatar-uploader .el-upload {*/
        /*border: 1px dashed #d9d9d9;*/
        /*border-radius: 6px;*/
        /*cursor: pointer;*/
        /*position: relative;*/
        /*overflow: hidden;*/
    /*}*/

    /*.avatar-uploader .el-upload:hover {*/
        /*border-color: #409eff;*/
    /*}*/

    /*.avatar-uploader-icon {*/
        /*font-size: 28px;*/
        /*color: #8c939d;*/
        /*width: 178px;*/
        /*height: 178px;*/
        /*line-height: 178px;*/
        /*text-align: center;*/
    /*}*/

    /*.avatar {*/
        /*width: 178px;*/
        /*height: 178px;*/
        /*display: block;*/
    /*}*/

    /*.timeLabel label {*/
        /*width: 110px !important;*/
    /*}*/

    /*.bankLabel label {*/
        /*font-size: 13px;*/
    /*}*/

    /*.el-form-item__label {*/
        /*text-align: left !important;*/
    /*}*/

    /*.d2-table-view {*/
        /*overflow: hidden;*/
    /*}*/
    /*.d2-table-view-content{*/
        /*height: 100%;*/
    /*}*/
    /*.el-table{*/
        /*height: 450px !important;*/
    /*}*/
</style>