<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="mchName"></el-table-column>
      <el-table-column align="center" label="归零前剩余时长" prop="surplusTime">
        <template slot-scope="d">{{d.row.surplusTime | 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="getRecordList"
    />
  </div>
</template>

<script>
import {listResetRecord} from "@/api/system/resetRecord";

export default {
  name: 'resetRecord',
  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;
      listResetRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
      }).finally(() => {
        this.loading = false;
      });
    }
  }
}
</script>
