circleEvents.js 2.55 KB
// pages/circleEvents/circleEvents.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    circleId: 0,

    isOwner: false,
    page: 0,//当前页数
    pageCount: 0,//总页数
    volunteerEventList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      circleId: options.circleId
    })
    this.getEventList();

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if ((this.data.page+1) < this.data.pageCount) {
      var pageIndex = this.data.page + 1
      this.setData({
        page: pageIndex
      })
      this.getEventList()
    } else {
      wx.showToast({
        title: '没有更多内容啦。',
        icon: 'success',
        duration: 2000
      });
    }
    
  },

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

  },

  //获取活动列表
  getEventList() {
    var that = this;
    var config = wx.getStorageSync('config');
    wx.request({
      url: app.url + 'ajax_get_circle_event_list.php',
      data: {
        unionId: config.unionId,
        circleId: that.data.circleId,
        page:that.data.page
      },
      header: { 'content-type': 'application/json' },
      method: 'GET',
      dataType: 'json',
      success: function (res) {
        console.log(res)
        if (res.statusCode == 200) {
          that.setData({
            pageCount: res.data.result.pageCount,
            volunteerEventList: that.data.volunteerEventList.concat(res.data.result.volunteerEventList),
            isOwner: res.data.result.isOwner
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  //发布活动
  newCircleEvent() {
    wx.navigateTo({
      url: '../newCircleEvent/newCircleEvent?circleId=' + this.data.circleId,
    })
  },

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