<template>
  <view class="page WoDeHuoDong">
    <ScrollY :IsRefreshing="IsRefreshing" @Refresh="Refresh" @ScrollBottom="ScrollBottom">
      <view class="Container">

        <!-- 标题 -->
        <view class="Title">
          <image mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/wodehuodong.png"></image>
        </view>

        <!-- 列表 -->
        <view class="List" v-if="UserActivityList.length">
          <navigator v-for="(item, index) in UserActivityList" :key="index" url="../../HuiShengHuo/ActivityList/ActivityDetail/index" hover-class="other-navigator-hover" class="Item flex-h">
            <view class="flex-item">
              <text>活动标题</text>
              <text>已报名123人</text>
              <text>已结束</text>
            </view>
            <view class="Img">
              <view>
                <image mode="aspectFill" class="centerLabel" :src="ToolClass.DemoImg()"></image>
              </view>
            </view>
          </navigator>
        </view>

      </view>
    </ScrollY>
  </view>
</template>

<script>
import ScrollY from '../../../components/ScrollY/index'
import { createNamespacedHelpers } from 'vuex'
const { mapState: mapIndexState, mapActions: mapIndexActions, mapMutations: mapIndexMutations } = createNamespacedHelpers('index')
export default {
  name: 'WoDeHuoDong',
  data () {
    return {
      PageData: {
        pageNum: 1,
        pageSize: 15
      },
      HasNextPage: true,
      IsRefreshing: false,
      DataLock: false
    }
  },
  computed: {
    ...mapIndexState({
      UserActivityList: x => x.UserActivityList // 我的活动列表
    })
  },
  components: {
    ScrollY
  },
  created () {
    this.Init() // 初始化
  },
  methods: {
    ...mapIndexActions([
      'GetUserActivityList' // 获取我的活动列表
    ]),
    ...mapIndexMutations([
      'EmptyUserActivityList' // 清空我的活动列表
    ]),
    Init () { // 初始化
      this.PageData.pageNum = 1
      this.HasNextPage = true
      this.EmptyUserActivityList() // 清空我的活动列表
      this.ToGetPageList() // 获取列表
    },
    ToGetPageList () { // 获取列表
      this.GetUserActivityList({ queryData: { accountId: 5, ...this.PageData } }).then((res) => { // 获取我的活动列表
        this.HasNextPage = res.data.data.current < res.data.data.pages
        this.DataLock = false
        this.IsRefreshing = false
      }).catch(() => {
        this.DataLock = false
        this.IsRefreshing = false
      })
    },
    ScrollBottom () { // 上拉加载
      if (this.DataLock || !this.HasNextPage) return
      this.DataLock = true
      this.PageData.pageNum += 1
      this.ToGetPageList() // 获取列表
    },
    Refresh (e) { // 页面下拉刷新
      if (this.DataLock) return
      this.DataLock = true
      this.IsRefreshing = true
      setTimeout(() => {
        this.Init() // 获取列表
      }, 1000)
    }
  }
}
</script>

<style lang="scss">
@import "page.scss";
</style>
