<template>
  <div>
    <el-table v-loading="loading" :data="recordList">
      <el-table-column align="center" type="index" label="#"></el-table-column>
      <el-table-column align="center" label="时间" prop="createTime"></el-table-column>
      <el-table-column align="center" label="用户名称" prop="userName"></el-table-column>
    </el-table>

    <pagination
      :auto-scroll="false"
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getRecordList"
    />
  </div>
</template>

<script>
import {listBindRecord} from "@/api/system/bindRecord";

export default {
  name: 'bindRecord',
  props: {
    // 设备id
    deviceId: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      recordList: [], // 记录列表
      loading: false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        deviceId: null,
      }
    }
  },
  watch: {
    deviceId(nv, ov) {
      this.getRecordList(nv);
    }
  },
  created() {
    this.getRecordList(this.deviceId);
  },
  methods: {
    // 获取记录列表
    getRecordList(deviceId) {
      if(deviceId == null) {
        this.recordList = [];
        this.total = 0;
        return;
      }
      this.loading = true;
      this.queryParams.deviceId = deviceId | this.deviceId;
      listBindRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
      }).finally(() => {
        this.loading = false;
      });
    }
  }
}
</script>
