下拉加载 刷新 模板

//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    pageNumber: 1,
    limit: 5,
    pages: 1,
 
    list:[],
  },

  onLoad() {
    var that = this;
    that.setData({
      pageNumber: 1,
      limit: 5,
      list: []
    });
    var pageNumber = that.data.pageNumber;
    var limit = that.data.limit;
    that.getMessageInform(1);
   },
  onShow() {

  },
  //重置
  reset() {

  },


  getMessageInform: function (pageNumber) {
    var that = this;
    //显示加载动画
    if (pageNumber == 1) {
      that.setData({
        list: []
      });
    }
    var data = {};
    data.pageNumber = pageNumber;
    data.limit = that.data.limit;
    wx.showLoading({
      title: '加载中',
    })
    app.my_request("/messageInfo/getMessageInform.html", data, function (res) {
      var status = res.data.status;
      if (status === "success") {

        let list =res.data.list

        let pageNumber = res.data.pageNumber
        let pages = res.data.pages
  
        if (pageNumber == 1) {//查询第一页的不进行数据累加
          that.setData({
            list: list,
            pageNumber: pageNumber,
            pages: pages,

          });
        } else {
          var list = that.data.list.concat(list);
          that.setData({
            list: list,
            pageNumber: pageNumber,
            pages: pages,
    
          });
        }
      }
    }, function (e) {
      console.log(e);
    }, function () {
      wx.hideLoading();
      wx.stopPullDownRefresh();
    })
  },

  // 上拉加载
  onReachBottom: function () {
    var that = this;
    var pageNumber = that.data.pageNumber;
    var pageNumber2 = pageNumber + 1;
    var pages = that.data.pages;
    if (pageNumber2 <= pages) {
      that.getMessageInform(pageNumber2);
    }
  },

  //下拉刷新
  onPullDownRefresh: function () {
    var that = this;
 
    that.getMessageInform(1);
    wx.stopPullDownRefresh();
  },



  //详情页
  adviceMessageDetail(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/my/messageInformDetail/messageInformDetail?id=' + id,

    })
  },


})

 

你可能感兴趣的:(小程序)