<template>
  <mescroll-vue
    ref="mescrollRef"
    @init="mescrollInit"
    :down="downOptions"
    :up="upOptions"
  >
    <div class="list-wrap">
      <div class="list-item" v-for="item of ListData" :key="item.id">
        <div class="item-top flex-default">
          <div class="number" :class="{ reduce: item.type === 18 }">
            {{ AssetsRecordTypeObj[item.type].symbol }}{{ item.amount }}
          </div>
          <div class="status" :class="{ fail: item.status === 1 }">
            {{ item.status === 1 ? "失败" : "成功" }}
          </div>
        </div>
        <div class="item-footer flex-default">
          <div class="address">
            {{ AssetsRecordTypeObj[item.type].label }}
          </div>
          <div class="time">
            {{ item.createTime | getTime }}
          </div>
        </div>
      </div>
    </div>
    <m-no-data v-if="ListData.length == 0" />
  </mescroll-vue>
</template>

<script>
import { MescrollMixin, MescrollMoreItemMixin } from "@/mixins";
import { formatTime } from "@/utils/common";
import { AssetsRecordType, AssetsRecordTypeObj } from "@/enums";
export default {
  mixins: [MescrollMixin, MescrollMoreItemMixin],
  props: {
    coin: String,
    tab: Object,
    index: Number,
    skuId: String
  },
  data() {
    return {
      AssetsRecordType,
      AssetsRecordTypeObj,
      downOptions: {
        autoShowLoading: false,
        auto: false,
        callback: this.downCallback,
      },
      upOptions: {
        auto: false,
        textNoMore: "没有更多啦",
        callback: this.upCallback,
      },
      ListData: [],
    };
  },
  filters: {
    getTime(val) {
      if (val) {
        return formatTime(new Date(val), "yyyy-MM-dd hh:mm:ss");
      }
      return "";
    },
  },
  methods: {
    initData() {
      this.requestData({ num: 1, size: 10 });
      this.ListData = [];
      this.mescroll.setPageNum(2);
    },
    requestData(page) {
      this.$api({
        apiName: "postAssetRecord",
        postData: {
          coin: this.coin,
          payment: this.tab.payment,
          page: page.num,
          size: page.size,
          skuId: this.skuId
        },
        success: (res) => {
          if (page.num == 1) {
            this.ListData = res.data;
          } else {
            this.ListData = this.ListData.concat(res.data);
          }
          this.mescroll.endBySize(res.data.length, res.totalSize);
        },
        fail: (err) => {
          this.mescroll.endErr();
        },
        complete: () => {
          this.mescroll.endDownScroll();
        },
      });
    },
    downCallback() {
      this.mescroll.resetUpScroll();
    },
    upCallback(page) {
      this.requestData(page);
    },
  },
};
</script>
<style lang="less">
</style>
