小程序分页


data: {
orderlist: [],
totalDataCount: 0,
currentPage: 0,
}
 
 /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadInitData();
  },
 
 /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
       this.loadMoreData();
 },
 
 
loadInitData: function () {
    var that = this
    var currentPage = 0; // 因为数组下标是从0开始的,所以这里用了0
    var tips = "加载第" + (currentPage+1) + "页";
    console.log("load page " + (currentPage + 1));
    wx.showLoading({
      title: tips,
      duration: 2000
    })
    // 刷新时,清空dataArray,防止新数据与原数据冲突
    that.setData({
      orderlist: []
    })

    //var url = App.globalData.URL + ‘rubbish_order‘
    var url =‘http://box/mpapi/web/oampapi/rubbish_order‘;
    App.wxRequest(
      ‘POST‘,
      url,
      {
        // admin_id: wx.getStorageSync(‘admin_id‘),
        item: 0
      },
      (res) => {
        var articles = res.data; // 接口中的data对应了一个数组,这里取名为 articles
        var totalDataCount = articles.length;
        console.log("totalDataCount:"+totalDataCount);

        that.setData({
                ["orderlist["+currentPage+"]"]: articles,
                currentPage: currentPage,
                totalDataCount: totalDataCount
              })

        console.log(that.data.orderlist);    
        wx.hideLoading();
      }
    )
  },

/**
   * 加载下一页数据
   */
  loadMoreData: function() {
    var that = this
    var currentPage = that.data.currentPage; // 获取当前页码
    currentPage += 1; // 加载当前页面的下一页数据
    var tips = "加载第" + (currentPage + 1) + "页";
    console.log("load page " + (currentPage + 1));
    wx.showLoading({
      title: tips,
      duration: 2000
    })

    //var url = App.globalData.URL + ‘rubbish_order‘
    var url =‘http://box/mpapi/web/oampapi/rubbish_order‘;
    App.wxRequest(
      ‘POST‘,
      url,
      {
        page: currentPage,
        admin_id: wx.getStorageSync(‘admin_id‘),
        item: that.data.datenum
      },
      (res) => {
        //wx.hideLoading();

        var articles = res.data; // 接口中的data对应了一个数组,这里取名为 articles

        // 计算当前共加载了多少条数据,来证明这种方式可以加载更多数据
        var totalDataCount = that.data.totalDataCount;
        totalDataCount = totalDataCount + articles.length;
        console.log("totalDataCount:" + totalDataCount);
        
        // 直接将新一页的数据添加到数组里
        that.setData({
          ["orderlist[" + currentPage + "]"]: articles,
          currentPage: currentPage,
          totalDataCount: totalDataCount
        })

        console.log(that.data.orderlist);    
        wx.hideLoading();
      }
    )
 
 
 
<view class="window" wx:if="{{orderlist.length > 0}}">
 
    <view wx:for="{{orderlist}}" wx:for-item="articles" wx:for-index="dataArrayIndex"  wx:key="dataArrayIndex">
      <view class="list"  wx:for="{{articles}}" wx:for-item="item" wx:key="index" wx:for-index="index">

        <view class="dateinfo">
        <text class="date">{{item.create_at}}</text>
        <text class="ascription">{{item.order_sn}}</text>
        </view>

        <view class="listinfo">
        <image class="img" src="{{item.goods_img}}" mode="aspectFit"></image>
        <view class="info">
          <text>{{item.goods_name}}</text>
          <text>+{{item.weight}} g</text>
        </view>
        <text class="state">{{item.status}}</text>
        </view>

        <!-- <template is = "articles" data=‘{{item:item,index:index,dataArrayIndex:dataArrayIndex}}‘/>  -->
        <!--将item和index都传到模版里去,不然模版中获取不到index-->
      </view>
    </view>
 
    <view class="bottom">没有更多了哦~</view>
 
</view>
 
 
 
 
 
$query = new Query();
$qeery->select(["aaa","bbb"])->from(‘m_rubbish‘)->where();

$page = isset($data[‘page‘]) ? $data[‘page‘] : 1;
$page = intval($page) - 1;
$offset = $page*10;

$rubbish_list = $query->offset($offset)->limit(10)->all();

return [‘code‘ => 1, ‘msg‘ => ‘查询成功!‘, ‘data‘=>$rubbish_list];

 

小程序分页

上一篇:Maven创建Spring项目


下一篇:微信小程序 判断页面是否滚动到底部