小程序翻頁加載數據


加載第一頁留店商品數據
  firstGetGiftData: function () {
    this.setData({
      page: 1
    })
    this.getGiftData("正在加載數據");
  },
  // 下拉加載留店數據
  onReachBottom: function () {
    console.log("下拉加載");
    if (this.data.hasMoreData) {
      this.getGiftData("加載更多數據")
    }
  },
  // 獲取留店商品數據
  getGiftData: function (message) {
    var that = this;
    this.setData({
      ifstore: 1
    })
    var shop = wx.getStorageSync('shop');
    var purchaseStorage = wx.getStorageSync('purchaseStorage');
    console.log("留店商品");
    util.reqAsync('shopOrder/storeRetentionList', {
      page: that.data.page,
      shopId: shop.id,
      userId: wx.getStorageSync('scSysUser').id,
      merchantId: that.data.merchantId,
      rows: that.data.rows
    }).then((res) => {
      console.log("留店商品列表")
      console.log(res);
      // 數據增加加購數量,重置加購數量
      for (let i = 0; i < res.data.data.length; i++) {
        if (!res.data.data[i]["shopNum"]) {
          res.data.data[i]["shopNum"] = 1;
          res.data.data[i]["pitch"] = 0;
        }
      }
      var purchaselistTem = that.data.purchase;
      if (that.data.page == 1) {
        purchaselistTem = [];
      }
      // debugger
      if (res.data.data.length < that.data.rows) {
        that.setData({
          purchase: purchaselistTem.concat(res.data.data),
          hasMoreData: false
        })
      }
      else {
        that.setData({
          purchase: purchaselistTem.concat(res.data.data),
          hasMoreData: true,
          page: that.data.page + 1
        })
      }
    }).catch((err) => {
      console.log(err)
    })
  },

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM