小程序上拉加载 分页功能

js代码

Page({    
  data: {
    toastMessage: "",
    toastStatus: "",
    list: [],
    nowPage: 0,
    forbid: false
  },
  onShow: function () {
    this.setData({ nowPage: 0, list: [] });
    this.nextPage();
  },
  nextPage: function () {//下一页
    if (!this.data.forbid) {
      this.setData({ forbid: true });
      request.get("XXXXXXX.do", { nowPage: this.data.nowPage }).then(res => {
        if (res.flag == 0) {

          let data = res.results;
          let nowPage = this.data.nowPage;
          let list = this.data.list;
          if (data.length > 0) {
            nowPage++;
          } else {
            if (list.length != 0)//不是第一次
              wx.showToast({ title: "已经后一页了", icon: 'none' });
            setTimeout(() => {
              this.setData({ forbid: false });
            }, 3000);
            return;
          }
         
          this.setData({ list: list, nowPage: nowPage, forbid: false });
        } else if (res.flag == 100) {
          wx.redirectTo({ url: 'XXXXX' });
        } else {
          toast.danger(this, res.message);
          this.setData({ forbid: false });
        }
      }).catch(e => {
        this.setData({ forbid: false });
      });
    }
  }
})


wxml代码

<view class="container">
  <scroll-view scroll-y enable-back-to-top lower-threshold="10" bindscrolltolower="nextPage" class="list">
    <button wx:for="{{list}}" wx:key="item"  data-orderisn="{{item.orderIsn}}">
      <view class="row row1">    
        <text>{{item.createDateStr}}</text>
        <text>
          <block wx:if="{{item.orderStatus == 0}}">进行中</block>
          <block wx:elif="{{item.orderStatus == 1}}">等待支付</block> 
          <block wx:else>已完成</block>
        </text>
      </view>
      <view class="row row2">
        <text>骑行时间:{{item.totalMinute}}分钟</text>
        <text>{{item.realPay}}元</text>
      </view>
      <view class="row row3">
        <text>订单号:{{item.orderIsn}}</text>
      </view>
    </button>
    <view wx:if="{{list.length == 0}}" class="empty">
      <image src="/image/order-empty.svg" mode="aspectFit"  />
    </view>
  </scroll-view>
</view>
<view class="toast {{toastStatus}}">
  <text>{{toastMessage}}</text>
</view>

css代码

.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
  box-sizing: border-box;
  background-color: #F2F2F2;
}
.empty{
  width: 100%;
  text-align: center;
}
.empty image{
  width: 45%;
}
button{
  border-radius: 0;
}
button::after{
  border: 0;
}
button.button-hover{
  background-color: #E4E4E4 !important;
}
.list{
  height: 100%;
  padding-top: 4rpx;
}
.list button{
  width: 100%;
  height: 250rpx;
  background-color: #fff;
  margin-top: 16rpx;
  padding: 30rpx;
  font-size: 95%;
  display: flex;
  flex-direction: column;
}
.list button .row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-grow: 1;
}
.list button .row2{
  font-size: 90%;
  color: #757575;
}
.list button .row3{
  font-size: 90%;
  color: #757575;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值