familyEvent.js 2.12 KB
// pages/familyEvent/familyEvent.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    familyEventList: [],
    page: 0,//当前页数
    pageCount: 0,//总页数
    //数据加载loading
    showLoading: false,
  },

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

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

  },

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

  },

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

  },

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

  },

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

  },

  // 社会实践列表
  familyEventList() {
    var that = this;
    that.setData({
      showLoading: true,
    });
    var config = wx.getStorageSync('config');
    wx.request({
      url: app.url + 'ajax_get_family_event_list.php',
      data: {
        unionId: config.unionId,
        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,
            familyEventList: res.data.result.familyEventList
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  //跳转到亲子活动详情页面
  familyEventDetail(e) {
    var eventId = e.currentTarget.dataset['index']
    wx.navigateTo({
      url: '../familyEventDetail/familyEventDetail?eventId=' + eventId,
    })
  },

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