<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="billId" width="100" />
      <el-table-column label="充值用户" align="center" prop="userName" />
      <el-table-column label="设备" align="center" prop="deviceName" />
      <el-table-column label="到账用户" align="center" prop="mchName" />
      <el-table-column label="充值金额" align="center">
        <template slot-scope="d">
          {{d.row.money | money}}
        </template>
      </el-table-column>
      <el-table-column label="收入金额" align="center">
        <template slot-scope="d">
          {{d.row.arrivalAmount | money}}
        </template>
      </el-table-column>
      <el-table-column label="手续费" align="center">
        <template slot-scope="d">
          {{d.row.serviceCharge | money}}
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center">
        <template slot-scope="d">
          <dict-tag :value="d.row.channelId" :options="dict.type.channel_type"/>
        </template>
      </el-table-column>
      <el-table-column label="交易状态" align="center">
        <template slot-scope="d">
          <dict-tag :value="d.row.status" :options="dict.type.sm_transaction_bill_status"/>
        </template>
      </el-table-column>
      <el-table-column label="时间" align="center" prop="createTime" width="180"/>
    </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 { listBill } from '@/api/system/recharge'

export default {
  name: 'rechargeList',
  dicts: ['channel_type','sm_transaction_bill_status', 'sm_transaction_bill_device_recharge_status'],
  props: {
    // 店铺id
    storeId: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      tableData: [],
      loading: false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        status: '2',
        storeId: null,
      }
    }
  },
  watch: {
    storeId(nv, ov) {
      this.getList(nv);
    }
  },
  created() {
    this.getList(this.storeId);
  },
  methods: {
    // 获取充值记录
    getList(storeId) {
      if (storeId == null) {
        this.recordList = [];
        this.total = 0;
        return;
      }
      this.loading = true;
      this.queryParams.storeId = storeId | this.storeId;
      listBill(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
      }).finally(() => {
        this.loading = false;
      });
    }
  }
}
</script>
