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

<script>
import Card from '@/components/Card'
import ActivityItem from '@/components/ActivityItem'
import * as api from '@/api'
export default {
  name: 'GroupActivity',
  components: { Card, ActivityItem },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      requestParams: { offset: 0, limit: 20 }
    }
  },
  computed: {
    pid() {
      return this.$route.params.id
    }
  },
  methods: {
    getList() {
      this.loading = true
      api
        .getActivitesByGroup(this.pid, this.requestParams)
        .then(response => {
          if (response.length) {
            this.list = this.list.concat(response)
          }
          this.loading = false
          this.finished = response.length < this.requestParams.limit
        })
        .catch(() => {
          this.loading = false
          this.finished = true
        })
    },
    onLoad() {
      this.requestParams.offset = this.requestParams.offset + this.requestParams.limit
      this.getList()
    },
    // 刷新
    refresh() {
      this.requestParams.offset = 0
      this.list = []
      this.getList()
    }
  },
  beforeMount() {
    this.getList()
  }
}
</script>

<style lang="scss" scoped></style>
