<template>
  <div>
    <el-table v-loading="loading" :data="tableData">
      <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="totalElectriQuantity">
        <template slot-scope="d">{{d.row.totalElectriQuantity | money}} 度</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="getChargeList"
    />
  </div>
</template>

<script>

import {listRecord} from "@/api/system/record";

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