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

      <!-- 活动照片墙 -->
      <view class="PhotoList">
        <view class="flex-h">
          <view class="flex-item">
            <image mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/huodongzhaopianqiang.png"></image>
          </view>
        </view>
        <view class="List">
          <view v-for="(item, index) in List" :key="index">
            <text>{{item.Month}}</text>
            <view>
              <view v-for="(subItem, subIndex) in item.List" :key="subIndex">
                <navigator url="./PhotoDetail/index" hover-class="other-navigator-hover" class="Img"></navigator>
              </view>
            </view>
          </view>
        </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: 'HuoDongZhaoPianQiang',
  data () {
    return {
      PageData: {
        pageNum: 1,
        pageSize: 15
      },
      HasNextPage: true,
      IsRefreshing: false,
      DataLock: false,
      List: [
        { Month: '8月份', List: ['', '', '', '', '', '', '', '', '', ''] },
        { Month: '7月份', List: ['', '', '', '', '', '', '', '', '', ''] },
        { Month: '6月份', List: ['', '', '', '', '', '', '', '', '', ''] },
        { Month: '5月份', List: ['', '', '', '', '', '', '', '', '', ''] }
      ]
    }
  },
  computed: {
    ...mapIndexState({
      PhotoList: x => x.PhotoList // 照片墙列表
    })
  },
  components: {
    ScrollY
  },
  created () {
    this.Init() // 初始化
  },
  methods: {
    ...mapIndexActions([
      'GetPhotoList' // 获取照片墙列表
    ]),
    ...mapIndexMutations([
      'EmptyPhotoList' // 清空照片墙列表
    ]),
    Init () { // 初始化
      this.PageData.pageNum = 1
      this.HasNextPage = true
      this.EmptyPhotoList() // 清空照片墙列表
      this.ToGetPageList() // 获取列表
    },
    ToGetPageList () { // 获取列表
      this.GetPhotoList({ queryData: { accountId: 5, ...this.PageData } }).then((res) => { // 获取照片墙列表
        this.HasNextPage = res.data.data.hasNextPage
        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>
