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

  /**
   * 页面的初始数据
   */
  data: {
    volunteerEventList:[],
    place:'',
    page: 0,//当前页数
    pageCount: 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: 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({
            volunteerEventList: res.data.result.volunteerEventList,
            page: res.data.result.page
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

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

  },

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

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

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

  },

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

  },
  paiming(){
    wx.navigateTo({
      url: '../volunteersRank3/volunteersRank3',
    });
    wx.setNavigationBarTitle({
      title: '志愿者排名'
    })
  },
  activeXiangxi(e){
    let id = e.currentTarget.dataset['id'];
    wx.navigateTo({
      url: '../volunteersEventDetail/volunteersEventDetail?id='+id,
    })
  },
  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
      });
    }
  },
})