Browse Source

fix:上拉刷新

sunshine1130 4 years ago
parent
commit
e60f75b877

+ 40 - 61
pages/index/index.js

@@ -19,40 +19,10 @@ Page({
     tabs: [],
     activeTab: 0,
     productHeight: 0,
-    productList: [{
-        id: "1",
-        title: "葛优躺(北京躺)电影足疗",
-        price: "299",
-        desc: "全店通用",
-        open: true,
-        imgurl: "../../images/product01.jpg"
-      },
-      {
-        id: "2",
-        title: "中式古法推拿",
-        price: "299",
-        desc: "暂未开放",
-        open: false,
-        imgurl: "../../images/product02.jpg"
-      },
-      {
-        id: "3",
-        title: "中式古法推拿",
-        price: "299",
-        desc: "暂未开放",
-        open: false,
-        imgurl: "../../images/product02.jpg"
-      },
-      {
-        id: "4",
-        title: "葛优躺(北京躺)电影足疗",
-        price: "299",
-        desc: "暂未开放",
-        open: false,
-        imgurl: "../../images/product01.jpg"
-      }
-    ],
-    isLocation:false
+    productList: [],
+    isLocation: false,
+    pageNo: 1,
+    pageSum: 0
 
   },
 
@@ -60,10 +30,10 @@ Page({
   onLoad: async function () {
     const self = this
     const tokenData = await commonApi.getToken();
-      if(tokenData.token){
-        wx.setStorageSync('token', tokenData.token)
-        requestApi.HEAD.token = tokenData.token
-      }
+    if (tokenData.token) {
+      wx.setStorageSync('token', tokenData.token)
+      requestApi.HEAD.token = tokenData.token
+    }
     wx.getSetting({
       success: (res) => {
         let authSetting = res.authSetting
@@ -76,45 +46,44 @@ Page({
           console.log('未授权地理位置');
           wx.getLocation({
             type: 'wgs84',
-            async success (res) {
+            async success(res) {
               console.log(res)
               const latitude = res.latitude
               const longitude = res.longitude
-              const rs = await storeApi.getNearStore(latitude,longitude)
+              const rs = await storeApi.getNearStore(latitude, longitude)
               console.log(rs.info);
               self.setData({
                 locationFlag: true,
                 storeInfo: rs.info
               })
             }
-           })
+          })
         }
       }
     })
+
+    // this.getProductHeight()
+  },
+  onShow: async function () {
     var tabs = await this.getProductList();
     this.setData({
       tabs
     });
-    this.getProductHeight()
   },
 
 
-  //动态生成产品的父盒子高度
-  getProductHeight: function () {
-    var h = wx.getSystemInfoSync().windowHeight * (750 / wx.getSystemInfoSync().windowWidth);
-    var productHeight = h - 430;
-    this.setData({
-      productHeight
-    })
-  },
-
   getProductList: async function () {
     const self = this
-    const productList = await productApi.getProductList(1, 4)
+    let pageNo = this.data.pageNo;
+    let productList = this.data.productList;
+    const proList = await productApi.getProductList(pageNo, 4)
+    let list = proList.list;
+    list.forEach((item)=>{
+      productList.push(item)
+    })
     self.setData({
-      productList: productList,
-      page: 1,
-      pageSize: 10
+      productList,
+      pageSum: proList.pageCount
     })
   },
   requestAll(url, data, header = {}, method) {
@@ -188,23 +157,33 @@ Page({
         const longitude = res.longitude
         const speed = res.speed
         const accuracy = res.accuracy
-        const rs = await storeApi.getNearStore(latitude,longitude)
+        const rs = await storeApi.getNearStore(latitude, longitude)
         console.log(rs.info);
         self.setData({
           locationFlag: true,
           storeInfo: rs.info
         })
-      },fail(err){
+      },
+      fail(err) {
         console.log(err)
 
       }
-     })
+    })
   },
   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-    console.log('2222')
+    console.log(1213131)
+    let pageNo = this.data.pageNo;
+    let pageSum = this.data.pageSum;
+    pageNo++;
+    this.setData({
+      pageNo
+    })
+    if (this.data.pageNo <= pageSum) {
+      this.getProductList()
+    }
   },
   /**
    * 页面相关事件处理函数--监听用户下拉动作
@@ -212,7 +191,7 @@ Page({
   onPullDownRefresh: function () {
     console.log(111)
   },
-  showProduct:async function (e) {
+  showProduct: async function (e) {
     const self = this
     console.log(e.currentTarget.dataset.productid)
     var productId = e.currentTarget.dataset.productid;
@@ -245,4 +224,4 @@ Page({
     })
 
   },
-})
+})

+ 1 - 1
pages/index/index.wxml

@@ -91,7 +91,7 @@
       </mp-tabs>
  -->
 
- <block wx:for="{{productList.list}}" wx:key="id" >
+ <block wx:for="{{productList}}" wx:key="id" >
   <view class="productinfo">
     <view class="product-item" data-productid="{{item.id}}" bindtap = "showProduct" style="background-image: url({{item.productImg}});">
       <view class="product-desc" >

+ 169 - 75
pages/personorder/personorder.js

@@ -8,10 +8,10 @@ Page({
    */
   data: {
     activeTab: 0,
-    orderHeight: 0,
     tabs: [],
     orderList: [],
-    pageNo: 1,
+    pageNo: [1, 1, 1, 1],
+    pageSum: [],
     loadingEnd: false,
     tabs: [{
         title: '全部'
@@ -41,86 +41,96 @@ Page({
     }
 
 
-    this.getOrderHeight();
 
   },
-  //动态生成产品的父盒子高度
-  getOrderHeight: function () {
-    var h = wx.getSystemInfoSync().windowHeight * (750 / wx.getSystemInfoSync().windowWidth);
-    var orderHeight = h - 95;
-    this.setData({
-      orderHeight
-    })
-  },
-  getOrderList: async function (params) {
-    var pageNo = this.data.pageNo;
-    var orderList = await orderApi.getAllOrderList(pageNo, 3);
-    var list = orderList.list;
-    console.log(list)
-    //代消费订单
-    var writeOffOrderList = [];
-    //待评价订单
-    var commentOffOrderList = [];
-    //已完成订单
-    var finishOrderList = [];
-    list.forEach(function (item, u, array) {
-      if (item.status == 2 && item.writeOffStatus == 1) {
-        writeOffOrderList.push(item)
-      }
-      if (item.status == 2 && item.writeOffStatus == 2 && item.discussId != '') {
-        finishOrderList.push(item)
-      }
-      if (item.status == 2 && item.writeOffStatus == 2 && item.discussId == '') {
-        commentOffOrderList.push(item)
-      }
-    })
-    var tabs = this.data.tabs;
-    tabs[0].list = list;
-    tabs[1].list = writeOffOrderList;
-    tabs[2].list = commentOffOrderList;
-    tabs[3].list = finishOrderList;
-    this.setData({
-      tabs
-    })
-
-  },
-
+  
   // 获取全部列表
   getAllOrderList: async function () {
     const self = this
-    var pageNo = this.data.pageNo;
+    let pageNo = this.data.pageNo;
+    let tabs = this.data.tabs;
+    let pageSum = this.data.pageSum;
     // 获取全部订单
-    var orderList = await orderApi.getAllOrderList(pageNo, 4);
-    var tabs = this.data.tabs;
-    tabs[0].list = orderList.list;
+    var orderList = await orderApi.getAllOrderList(pageNo[0], 4);
+    var list = orderList.list;
+    if (!tabs[0].list) {
+      tabs[0].list = []
+    }
+    if (pageNo[0] == 1) {
+      tabs[0].list = list;
+    } else {
+      list.forEach((item, i, array) => {
+        tabs[0].list.push(item)
+      })
+    }
+
+    pageSum[0] = orderList.pageCount;
     this.setData({
-      tabs
+      tabs,
+      pageSum
     })
     // return list;
   },
   // 获取代消费列表
   getwriteOffOrderList: async function () {
     const self = this
-    var pageNo = this.data.pageNo;
+    let pageNo = this.data.pageNo;
+    let tabs = this.data.tabs;
+    let pageSum = this.data.pageSum;
     // 获取代消费订单
-    var orderList = await orderApi.getOrderList(pageNo, 4, 2, 1);
-    var tabs = this.data.tabs;
-    tabs[1].list = orderList.list;
+    var orderList = await orderApi.getOrderList(pageNo[1], 4, 2, 1);
+    var list = orderList.list;
+    if (!tabs[1].list) {
+      tabs[1].list = []
+    }
+    if (pageNo[1] == 1) {
+      tabs[1].list = list;
+    } else {
+      list.forEach((item, i, array) => {
+        tabs[1].list.push(item)
+      })
+    }
+
+    pageSum[1] = orderList.pageCount;
     this.setData({
-      tabs
+      tabs,
+      pageSum
     })
     // return list;
   },
   // 获取待评价列表
   getcommentOffOrderList: async function () {
     const self = this
-    var pageNo = this.data.pageNo;
+    let pageNo = this.data.pageNo;
+    let tabs = this.data.tabs;
+    let pageSum = this.data.pageSum;
     // 获取代消费订单
-    var orderList = await orderApi.getOrderList(pageNo, 4, 2, 1);
-    var tabs = this.data.tabs;
-    tabs[2].list = orderList.list;
+    var orderList = await orderApi.getOrderList(pageNo[2], 4, 2, 2);
+    var list = orderList.list;
+    if (!tabs[2].list) {
+      tabs[2].list = []
+    }
+
+    if (pageNo[2] == 1) {
+      let tabList = [];
+      list.forEach((item, i, array) => {
+        if (item.discussId == '') {
+          tabList.push(item)
+        }
+      })
+      tabs[2].list = tabList;
+    } else {
+      list.forEach((item, i, array) => {
+        if (item.discussId == '') {
+          tabs[2].list.push(item)
+        }
+      })
+    }
+
+    pageSum[2] = orderList.pageSum
     this.setData({
-      tabs
+      tabs,
+      pageSum
     })
     // return list;
   },
@@ -128,13 +138,29 @@ Page({
   // 获取已经完成的列表
   getfinishOrderList: async function () {
     const self = this
-    var pageNo = this.data.pageNo;
+    let pageNo = this.data.pageNo;
+    let tabs = this.data.tabs;
+    let pageSum = this.data.pageSum;
     // 获取代消费订单
-    var orderList = await orderApi.getOrderList(pageNo, 4, 2, 1);
-    var tabs = this.data.tabs;
-    tabs[3].list = orderList.list;
+    var orderList = await orderApi.getOrderList(pageNo[3], 4, 2, 2);
+    var list = orderList.list;
+    if (!tabs[3].list) {
+      tabs[3].list = []
+    }
+    if (pageNo[3] == 1) {
+      tabs[3].list = list;
+    } else {
+      list.forEach((item, i, array) => {
+        if (item.discussId != '') {
+          tabs[3].list.push(item)
+        }
+      })
+    }
+
+    pageSum[3] = orderList.pageCount;
     this.setData({
-      tabs
+      tabs,
+      pageSum
     })
     // return list;
   },
@@ -149,25 +175,41 @@ Page({
   onChange(e) {
     const index = e.detail.index
     this.setData({
-      activeTab: index
+      activeTab: index,
+      pageNo: [1, 1, 1, 1]
     })
+    if(index==0){
+      this.getAllOrderList()
+      return
+    }
+    if (index == 1) {
+      this.getwriteOffOrderList()
+      return
+    }
+    if (index == 2) {
+      this.getcommentOffOrderList()
+      return
+    }
+    if (index == 3) {
+      this.getfinishOrderList()
+    }
+
   },
   handleClick(e) {
 
   },
 
   showOrderInfo: async function (e) {
-    console.log(e.currentTarget)
     var orderId = e.currentTarget.dataset.orderid;
     var status = e.currentTarget.dataset.status;
     var writeStatus = e.currentTarget.dataset.writestatus;
-   
-     if(status==2&&writeStatus==1){
-       wx.navigateTo({
-         url: '../order/order?orderId='+orderId,
-       })
-       return
-     }
+
+    if (status == 2 && writeStatus == 1) {
+      wx.navigateTo({
+        url: '../order/order?orderId=' + orderId,
+      })
+      return
+    }
 
   },
   /**
@@ -181,7 +223,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: async function () {
-    await this.getOrderList()
+    await this.getAllOrderList()
   },
 
   /**
@@ -208,7 +250,59 @@ Page({
   /**
    * 页面上拉触底事件的处理函数
    */
-  onReachBottom: function () {
+  onReachBottom: async function () {
+    console.log("到底啦")
+    var self = this;
+    let activeTab = this.data.activeTab;
+    if (activeTab == 0) {
+      console.log("all")
+      let pageNo = this.data.pageNo;
+      pageNo[0]++;
+      self.setData({
+        pageNo
+      })
+      if (self.data.pageNo[0] <= self.data.pageSum[0]) {
+        await this.getAllOrderList()
+        return
+      }
+
+    }
+    if (activeTab == 1) {
+      console.log("xiaofei")
+      let pageNo = this.data.pageNo;
+      pageNo[1]++;
+      self.setData({
+        pageNo
+      })
+      if (self.data.pageNo[1] <= self.data.pageNo[1]) {
+        await this.getwriteOffOrderList()
+        return
+      }
+    }
+    if (activeTab == 2) {
+      console.log("pingjia")
+      let pageNo = this.data.pageNo;
+      pageNo[2]++;
+      self.setData({
+        pageNo
+      })
+      if (self.data.pageNo[2] <= self.data.pageSum[2]) {
+        await this.getcommentOffOrderList()
+        return
+      }
+    }
+    if (activeTab == 4) {
+      let pageNo = this.data.pageNo;
+      pageNo[3]++;
+      self.setData({
+        pageNo
+      })
+      if (self.data.pageNo[3] <= self.data.pageSum[3]) {
+        await this.getfinishOrderList()
+        return
+      }
+    }
+
 
   },
 

+ 1 - 0
pages/personorder/personorder.json

@@ -1,4 +1,5 @@
 {
+  
   "usingComponents": {
     "mp-icon": "weui-miniprogram/icon/icon",
     "mp-tabs": "/componets/tabs/index"

+ 1 - 1
pages/personorder/personorder.wxml

@@ -6,7 +6,7 @@
         <block wx:for="{{tabs}}" wx:key="title">
 
             <view class="tab-content" data-set="{{item}}" slot="tab-content-{{index}}" bind:tap="handleClick">
-                <view style="overflow-y: auto;height:{{orderHeight}}rpx" class="orders">
+                <view  class="orders">
                     <block wx:for="{{tabs[index].list}}" wx:key="id">
                         <view class="orderinfo card">
                             <view class="order-item" bindtap="showOrderInfo" data-orderid="{{item.id}}"