// pages/volunteers/volunteers.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    volunteerEventList:[],
    place:'',
    page: 0,//当前页数
    pageCount: 0,//总页数
    abilityPoint: 0,//能力分汇总

    //数据加载loading
    showLoading: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    var config = wx.getStorageSync('config');
    var location = wx.getStorageSync('location');
    var place = location.province + location.city + location.district;
    this.setData({
      place:place,
      showLoading: true,
    })

    //检索志愿者活动列表
    wx.request({
      url: app.url + 'ajax_get_volunteer_event_list.php',
      data: {
        unionId: config.unionId,
        province: location.province,
        city: location.city,
        district: location.district
      },
      header: { 'content-type': 'application/json' },
      method: 'GET',
      dataType: 'json',
      success: function (res) {
        if (res.statusCode == 200) {
          console.log(res)
          that.setData({
            page: res.data.result.page,
            pageCount: res.data.result.pageCount,
            volunteerEventList: res.data.result.volunteerEventList,
            abilityPoint: res.data.result.abilityPoint
            
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //志愿者排名1
  rank1(){
    wx.navigateTo({
      url: '../volunteersRank1/volunteersRank1',
    });
  },

  //志愿者活动详情页面
  volunteersEventDetail(e){
    let eventId = e.currentTarget.dataset['id'];
    wx.navigateTo({
      url: '../volunteersEventDetail/volunteersEventDetail?eventId=' + eventId,
    })
  },

  //加载更多
  loadMore() {
    if (this.data.page < this.data.pageCount) {
      var pageIndex = this.data.page + 1
      this.setData({
        page: pageIndex
      })
    } else {
      wx.showToast({
        title: '没有更多内容啦。',
        icon: 'success',
        duration: 2000
      });
    }
  },
})