<template>
  <view class="page ZhengNengLiangShiJi">
    <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/zhengnengliangshiji.png"></image>
        </view>

        <!-- 列表 -->
        <view class="List" v-if="PageList.length">
          <navigator v-for="(item, index) in PageList" :key="index" :url="`../../HuiShengHuo/ActivityList/ActivityDetail/index?id=${item.activityId}`" hover-class="other-navigator-hover" class="Item flex-h">
            <view class="flex-item">
              <text>{{item.name}}</text>
              <text>副标题</text>
              <text>来源</text>
            </view>
            <view class="Img">
              <view>
                <image mode="aspectFill" class="centerLabel" :src="item.thumb"></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')
const { mapActions: mapUserActions, mapMutations: mapUserMutations } = createNamespacedHelpers('user')
export default {
  name: 'ZhengNengLiangShiJi',
  data () {
    return {
      PageList: [],
      PageData: {
        pageNum: 1,
        pageSize: 15
      },
      HasNextPage: true,
      IsRefreshing: false,
      DataLock: false
    }
  },
  computed: {
    ...mapIndexState({
      ZhengNengLiangShiJiList: x => x.ZhengNengLiangShiJiList // 正能量事迹列表
    })
  },
  components: {
    ScrollY
  },
  created () {
    this.$authed(() => {
      this.Init()
    })
  },
  methods: {
    ...mapUserActions([
      'MainSignIn' // 获取用户信息
    ]),
    ...mapUserMutations([
      'EditUserInfo' // 编辑用户信息
    ]),
    ...mapIndexActions([
      'GetZhengNengLiangShiJiList' // 获取正能量事迹列表
    ]),
    ...mapIndexMutations([
      'EmptyZhengNengLiangShiJiList' // 清空正能量事迹列表
    ]),
    Init () { // 初始化
      this.PageData.pageNum = 1
      this.HasNextPage = true
      this.EmptyZhengNengLiangShiJiList() // 清空正能量事迹列表
      this.PageList = []
      this.ToGetPageList() // 获取列表
    },
    ToGetPageList () { // 获取列表
      this.GetZhengNengLiangShiJiList({ queryData: { ...this.PageData, typeId: 6 } }).then((res) => { // 获取正能量事迹列表
        this.PageList = [...this.ZhengNengLiangShiJiList]
        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>
