scroll-view实现上拉加载(tab切换多页数据加载)

原文链接:http://www.xiaoshu168.com/wxapplet/121.html

var app = getApp();
const _JulijiaUrl = require('../../utils/baseurl');
const requestUtil = require('../../utils/httpHelper');
var GetList = function (that) {
  var page = that.data.page;
  var p = page[that.data.currentTab];
  var typeid = that.data.typedata[that.data.currentTab].id;
  requestUtil.httpGet(_JulijiaUrl.julijia_newslistpage, { page: p, typeid: typeid }, function (res) {
    var pagelist = that.data.listdatat;
    for (var i = 0; i < res.length; i++) 
    {
      pagelist[that.data.currentTab].data.push(res[i]);
    }  
    p++;
    page[that.data.currentTab] = p;
    that.setData({
      listdatat: pagelist,
      page: page
    });
  });
}  


Page({
  data: {
    /** 
        * 页面配置 
        */
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0,
    typedata:'',
    listdatat:'',
    page:[],
    typeid:'',
  },
  onLoad: function () {
    var that = this;


    /** 
     * 获取系统信息 
     */
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
    
    /**
     * 请求回调
     */
    requestUtil.httpGet(_JulijiaUrl.julijia_newslist, {}, function (res) {
      /** 
       * 设置分页参数
       */
      var page = that.data.page;
      for (var p = 0; p < res.typeData.length; p++) {
        page.push(2);
      }
      that.setData({
        typedata: res.typeData,
        listdatat: res.listDta,
        typeid: res.typeData[0].id
      });
    });
    
  },
  /** 
     * 滑动切换tab 
     */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current,
      typeid: e.target.id
    });
  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {


    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current,
      });
    }
    that.setData({
      typeid: e.target.dataset.id
    });
  },
  /** 
   * 绑定下拉加载 
   */
  bindDownLoad:function(e) {
    var that = this;
    GetList(that);
  },
});

你可能感兴趣的:(api)