const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 0,
    pageNum: 24,
    volunteer: [],
    page_type: false
  },
  getdatalist() {
    wx.showLoading({
      title: '加载中', 
      mask: true
    })
    let that = this
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let url = 'index/index/volunteer';
    let params = {
      page: that.data.page,
      pageNum: that.data.pageNum
    }
    app.post(url, params, head).then((res) => {
      let volunteer = res.volunteer
      let datavolunteer = this.data.volunteer;
      let tem = [];
      let temvolunteer = [];
      if (volunteer.length > 0) {
        for (let i = 0; i < volunteer.length; i++) {
          tem.push(volunteer[i]);
          if ((i + 1) != volunteer.length) {
            if ((i + 1) % 4 == 0) {
              temvolunteer.push(tem);
              tem = [];
            }
          } else {
            temvolunteer.push(tem);
            tem = [];
          }
        }
        let setvolunteer = datavolunteer.concat(temvolunteer)
        if (that.data.page == 0) {
          wx.hideLoading()
          that.setData({
            volunteer: setvolunteer,
            page: res.page
          })
        } else {
          setTimeout(() => {
            wx.hideLoading()
            that.setData({
              volunteer: setvolunteer,
              page: res.page
            })
          }, 1000)
        }
      } else {
        wx.hideLoading()
        that.setData({
          page_type: true
        })

      }

    }).catch((err) => {

    })
  },
  //他人主页
  getother(e) {
    // console.log(e)
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/more_other/more_other?id=' + id,
    })

  },

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

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

  },

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


  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this
    if (that.data.page_type) {
      wx.showToast({
        title: '暂无更多数据',
        icon: 'none',
        duration: 1000
      })
      return
    }
    that.getdatalist()
  },

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

  }
})