<template>
  <mescroll-vue
    class="after-sale-list-scroll-con"
    :ref="`mescrollRef${i}`"
    @init="mescrollInit"
    :down="downOptions"
    :up="upOptions"
    :fixed="false"
  >
    <component
      :is="comType"
      v-for="(item, index) of list"
      :key="`list-item-${index}`"
      :data="item"
    />
  </mescroll-vue>
</template>

<script>
import OrderListItem from "./order-list-item";
import DeliveryListItem from "./delivery-list-item";
import { MescrollMixin, MescrollMoreItemMixin } from "@/mixins";
import { OrderType, OrderTypeObj } from "@/enums";
export default {
  mixins: [MescrollMixin, MescrollMoreItemMixin],
  components: { OrderListItem, DeliveryListItem },
  props: {
    index: Number,
    tab: Object,
  },
  data() {
    return {
      list: [],
      downOptions: {
        autoShowLoading: false,
        auto: false,
        callback: this.downCallback,
      },
      upOptions: {
        auto: false,
        callback: this.upCallback,
      },
    };
  },
  computed: {
    comType() {
      return this.tab.val == OrderType.ORDER ? OrderListItem : DeliveryListItem;
    },
  },
  methods: {
    initData() {
      this.requestData({ num: 1, size: 10 });
      this.list = [];
      this.mescroll.setPageNum(2);
    },
    requestData({ num, size }) {
      let apiName = OrderTypeObj[this.tab.val].refundListApi;
      num == 1 && this.$showLoading();

      this.$api({
        apiName,
        postData: {
          orderState: "afterSale",
          page: num,
          size,
        },
        success: (res) => {
          if (num == 1) {
            this.list = [];
          }
          this.mescroll.endBySize(res.data.length, res.totalSize);
          this.list = this.list.concat(res.data);
        },
        complete: () => {
          this.$hideLoading();
        },
      });
    },
    downCallback() {
      this.mescroll.resetUpScroll();
    },
    upCallback(page) {
      this.requestData(page);
    },
  },
};
</script>

<style lang="less">
.after-sale-list-scroll-con {
}
</style>

