<template>
  <div>
    <el-table v-loading="loading" :data="orderList">
      <el-table-column align="center" type="index" label="#"></el-table-column>
      <el-table-column align="center" label="订单编号" width="200"  prop="orderNo"></el-table-column>
      <el-table-column align="center" label="使用用户" prop="userName"></el-table-column>
      <el-table-column align="center" label="手机号" prop="phonenumber"></el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.et_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="支付费用(元)" prop="totalFee">
        <template slot-scope="d">{{d.row.totalFee}} 元</template>
      </el-table-column>
      <el-table-column align="center" label="下单时间" prop="createTime"></el-table-column>
    </el-table>

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

<script>
import {listOrder} from "@/api/system/order";

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