<template>
  <div>
    <el-table v-loading="loading" :data="tenantList">
      <el-table-column align="center" type="index" label="#"></el-table-column>
      <el-table-column align="center" label="头像" prop="avatar">
        <template slot-scope="d">
          <image-preview :src="d.row.avatar" :width="50" :height="50"/>
        </template>
      </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="getUserList"
    />
  </div>
</template>

<script>
import {listSmUser} from "@/api/system/smUser";

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