<template>
  <div class="list">
    <van-list
      v-model="loading"
      :finished="finished"
      @load="onLoad"
      v-if="list.length"
    >
      <my-activity-item
        v-for="item in list"
        :data="item"
        :key="item.id"
      ></my-activity-item>
    </van-list>
    <template v-else>
      <slot name="empty">
        <div class="empty">暂时没有内容哦，去别处看看吧～</div>
      </slot>
    </template>
  </div>
</template>

<script>
import * as api from '@/api/index'
import MyActivityItem from '@/components/MyActivityItem'
export default {
  components: { MyActivityItem },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: { offset: 0, limit: 10 }
    }
  },
  methods: {
    getList() {
      this.loading = true
      api
        .getJoinedActivities(this.page)
        .then(response => {
          if (response.length) {
            this.list = this.list.concat(response)
          }
          this.loading = false
          this.finished = response.length < this.page.limit
        })
        .catch(() => {
          this.loading = false
          this.finished = true
        })
    },
    onLoad() {
      this.page.offset = this.page.offset + this.page.limit
      this.getList()
    }
  },
  beforeMount() {
    this.getList()
  }
}
</script>
