Parcourir la source

feat:更新代码

jinx il y a 4 ans
Parent
commit
5412521f4b
6 fichiers modifiés avec 157 ajouts et 74 suppressions
  1. 28 16
      pages/index/index.js
  2. 27 14
      pages/searchRoom/searchRoom.js
  3. 71 27
      pages/sence/sence.js
  4. 1 1
      pages/sence/sence.wxml
  5. 29 16
      pages/store/store.js
  6. 1 0
      utils/util.js

+ 28 - 16
pages/index/index.js

@@ -92,7 +92,8 @@ Router({
       page: 1,
       size: 20,
       name: ''
-    }
+    },
+    loading: false,
 
   },
 
@@ -163,23 +164,34 @@ Router({
           'fetcherData.address': app.globalData.city,
         })
       }
+      if (!this.data.loading) {
+        this.setData({
+          loading: true
+        })
+        util.request(api.BrandList, this.data.fetcherData).then((res) => {
+          this.setData({
+            loading: false
+          })
+          if (res.errno === 0) {
+            if (res.data.data.length != 0) {
+              this.setData({
+                roomList: this.data.roomList.concat(res.data.data),
+                'fetcherData.page': this.data.fetcherData.page + 1
+              })
 
-      util.request(api.BrandList, this.data.fetcherData).then((res) => {
-        console.log(res)
-        if (res.errno === 0) {
-          if (res.data.data.length != 0) {
-            this.setData({
-              roomList: this.data.roomList.concat(res.data.data),
-              'fetcherData.page': this.data.fetcherData.page + 1
-            })
-
-          } else {
-            this.setData({
-              hasData: false
-            })
+            } else {
+              this.setData({
+                hasData: false
+              })
+            }
           }
-        }
-      });
+        }).catch(err => {
+          this.setData({
+            loading: false
+          })
+        });
+      }
+
     } else {
       console.log('没有更多数据')
     }

+ 27 - 14
pages/searchRoom/searchRoom.js

@@ -13,6 +13,7 @@ Page({
     roomList: [],
     storeList: [],
     isSearch: false,
+    loading: false,
     fetcherData: {
       type: null,
       address: app.globalData.city,
@@ -68,26 +69,38 @@ Page({
         })
       }
     }
+    if (!this.data.loading) {
+      this.setData({
+        loading: true
+      })
+      util.request(api.BrandList, this.data.fetcherData).then((res) => {
+        this.setData({
+          loading: false
+        })
+        wx.hideLoading()
+        if (res.errno === 0) {
 
-    util.request(api.BrandList, this.data.fetcherData).then((res) => {
-      wx.hideLoading()
-      if (res.errno === 0) {
+          if (this.data.fetcherData.type == '21') {
 
-        if (this.data.fetcherData.type == '21') {
+            this.setData({
+              storeList: res.data.data,
+            })
+          } else {
 
-          this.setData({
-            storeList: res.data.data,
-          })
-        } else {
+            this.setData({
+              roomList: res.data.data,
+            })
+          }
 
-          this.setData({
-            roomList: res.data.data,
-          })
-        }
 
+        }
+      }).catch(err => {
+        this.setData({
+          loading: false1
+        })
+      });
+    }
 
-      }
-    });
   },
   /**
    * 生命周期函数--监听页面加载

+ 71 - 27
pages/sence/sence.js

@@ -10,6 +10,8 @@ Page({
   data: {
     roomList: [],
     hasData: true,
+    loading: false,
+    isSearch: false,
     fetcherData: {
       type: null,
       address: '',
@@ -28,7 +30,9 @@ Page({
       wx.showLoading({
         title: '加载中...',
       });
-      // console.log(this.data.searchKey)
+      this.setData({
+        isSearch: true
+      })
       this.searchRoomList()
     } else {
       wx.showToast({
@@ -40,42 +44,78 @@ Page({
 
   },
   getRoomList() {
+
     if (this.data.hasData) {
-      util.request(api.BrandList, this.data.fetcherData).then((res) => {
-        console.log(res)
-        if (res.errno === 0) {
-          if (res.data.data.length != 0) {
-            this.setData({
-              roomList: this.data.roomList.concat(res.data.data),
-              'fetcherData.page': this.data.fetcherData.page + 1
-            })
-
-          } else {
-            this.setData({
-              hasData: false
-            })
+
+      if (!this.data.loading) {
+
+        this.setData({
+          loading: true
+        })
+
+        util.request(api.BrandList, this.data.fetcherData).then((res) => {
+          this.setData({
+            loading: false
+          })
+          if (res.errno === 0) {
+            if (res.data.data.length != 0) {
+              this.setData({
+                roomList: this.data.roomList.concat(res.data.data),
+                'fetcherData.page': this.data.fetcherData.page + 1
+              })
+
+            } else {
+              this.setData({
+                hasData: false
+              })
+            }
           }
-        }
-      });
+        }).catch(err => {
+          this.setData({
+            loading: false
+          })
+        });
+      }
+
     } else {
       console.log('没有更多数据')
     }
 
   },
-  searchRoomList() {
+  reloadData() {
     this.setData({
-      'fetcherData.page': 1,
-      'fetcherData.size': 100,
+      hasData: true
+    }, () => {
+      this.getRoomList()
     })
-    util.request(api.BrandList, this.data.fetcherData).then((res) => {
-      wx.hideLoading()
-      if (res.errno === 0) {
+  },
+  searchRoomList() {
+    if (!this.data.loading) {
+      this.setData({
+        loading: false
+      })
+      this.setData({
+        'fetcherData.page': 1,
+        'fetcherData.size': 100,
+      })
+      util.request(api.BrandList, this.data.fetcherData).then((res) => {
         this.setData({
-          roomList: res.data.data,
+          loading: false
         })
+        wx.hideLoading()
+        if (res.errno === 0) {
+          this.setData({
+            roomList: res.data.data,
+          })
+
+        }
+      }).catch(err => {
+        this.setData({
+          loading: false
+        })
+      });
+    }
 
-      }
-    });
   },
   gotoWV: function (event) {
     let id = event.detail
@@ -116,7 +156,9 @@ Page({
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow: function () {},
+  onShow: function () {
+
+  },
 
   /**
    * 生命周期函数--监听页面隐藏
@@ -143,7 +185,9 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-    this.getRoomList()
+    if (!this.data.isSearch) {
+      this.getRoomList()
+    }
   },
 
   /**

+ 1 - 1
pages/sence/sence.wxml

@@ -1,6 +1,6 @@
 <view>
   <lip-sync />
-  <auth bindlogin="getRoomList" />
+  <auth bindlogin="reloadData" />
   <view class="storeContent">
     <view class="storeSearch">
       <image src="../../static/images/icon/search@2x.png"></image>

+ 29 - 16
pages/store/store.js

@@ -11,6 +11,7 @@ Page({
     type: 21,
     storeList: [],
     hasData: true,
+    loading:false,
     fetcherData: {
       type: 21,
       address: '',
@@ -34,23 +35,35 @@ Page({
   },
   getStoreList() {
     if (this.data.hasData) {
-      util.request(api.BrandList, this.data.fetcherData).then((res) => {
-        console.log(res)
-        if (res.errno === 0) {
-          if (res.data.data.length != 0) {
-            this.setData({
-              storeList: this.data.storeList.concat(res.data.data),
-              'fetcherData.page': this.data.fetcherData.page + 1
-            })
-
-          } else {
-            this.setData({
-              hasData: false
-            })
-
+      if(!this.data.loading){
+        this.setData({
+          loading:true
+        })
+        util.request(api.BrandList, this.data.fetcherData).then((res) => {
+          this.setData({
+            loading:false
+          })
+          if (res.errno === 0) {
+            if (res.data.data.length != 0) {
+              this.setData({
+                storeList: this.data.storeList.concat(res.data.data),
+                'fetcherData.page': this.data.fetcherData.page + 1
+              })
+  
+            } else {
+              this.setData({
+                hasData: false
+              })
+  
+            }
           }
-        }
-      });
+        }).catch(err=>{
+          this.setData({
+            loading:false
+          })
+        });
+      }
+     
     } else {
       console.log('没有更多数据')
     }

+ 1 - 0
utils/util.js

@@ -62,6 +62,7 @@ function request(url, data = {}, method = "POST", header = "application/x-www-fo
                     let currPage = pages[pages.length - 1].route
                     let notLogins = ['pages/index/index', 'pages/catalog/catalog', 'pages/category/category', 'pages/ucenter/index/index']
                     if (res.data.errno == 401 && !~notLogins.indexOf(currPage)) {
+                        resolve(res.data);
                         gotoLogin()
                     } else {
                         const jx = (data) => {