<template>
  <div>
    <el-table v-loading="loading" :data="tableData">
      <el-table-column align="center" type="index" label="#"></el-table-column>
      <el-table-column label="ID" align="center" prop="deviceId" width="100" />
      <el-table-column label="图片" align="center" prop="picture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.picture" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="设备Mac" align="center" prop="mac" />
      <el-table-column label="设备SN" align="center" prop="deviceNo" />
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="型号" align="center" prop="model" />
      <el-table-column label="所属用户" align="center" prop="userName" />
      <el-table-column label="在线状态" align="center" prop="onlineStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sm_device_online_status" :value="scope.row.onlineStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sm_device_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleSee(scope.row)"
            v-hasPermi="['system:device:detail']"
          >详细信息</el-button>
        </template>
      </el-table-column>
    </el-table>

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

<script>
import { listDevice } from '@/api/system/device'

export default {
  name: 'deviceList',
  dicts: ['sm_device_online_status', 'sm_device_status', 'sm_device_outage_way','sm_device_notice_way'],
  props: {
    // 店铺id
    storeId: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      tableData: [],
      loading: false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        storeId: null,
      }
    }
  },
  watch: {
    storeId(nv, ov) {
      this.getList(nv);
    }
  },
  created() {
    this.getList(this.storeId);
  },
  methods: {
    // 查看按钮操作
    handleSee(row) {
      this.$router.push({path: `/smDevice/device/${row.deviceId}`})
    },
    // 获取充值记录
    getList(storeId) {
      if (storeId == null) {
        this.recordList = [];
        this.total = 0;
        return;
      }
      this.loading = true;
      this.queryParams.storeId = storeId | this.storeId;
      listDevice(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
      }).finally(() => {
        this.loading = false;
      });
    }
  }
}
</script>
