From 419ad623db22db5fa34e88ab771d2161fe12e920 Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: 星期二, 01 八月 2023 16:08:25 +0800
Subject: [PATCH] 提交上拉加载

---
 pages/tabBar/current/current.vue |   66 ++++++++++++++++++++++++++------
 1 files changed, 53 insertions(+), 13 deletions(-)

diff --git a/pages/tabBar/current/current.vue b/pages/tabBar/current/current.vue
index 9ad74a3..2bf9410 100644
--- a/pages/tabBar/current/current.vue
+++ b/pages/tabBar/current/current.vue
@@ -9,6 +9,9 @@
 				<view class="barText">信息查看</view>
 			</view>
 		</view>
+    <div v-if="loading" style='display: flex;justify-content: center;position: absolute;width:100%;top: 40%;left: 0'>
+      <u-loading-icon></u-loading-icon>
+    </div>
 		<!-- 页面内容 -->
 		<view class="controlBar">
 			<view class="buttonGroup">
@@ -38,7 +41,9 @@
 		</view>
 		<view style="display: flex;flex-direction: column;margin-bottom: 55px;">
 			<view class="examineList">
-				<view class="listContent" v-if="InfoList.length > 0">
+<!--				<view class="listContent" v-if="InfoList.length > 0">-->
+        <scroll-view :scroll-top="scrollTop" scroll-y="true" class="listContent" @scrolltoupper="upper" v-if="InfoList.length > 0"
+                     @scrolltolower="lower" @scroll="scroll" lower-threshold="50">
 					<view v-for="(item, index) in InfoList" :key="index" class="itemContent">
 						<view class="content">
 							<text>[{{item.colorContent}}]</text>
@@ -62,7 +67,8 @@
 							</view>
 						</view>
 					</view>
-				</view>
+        </scroll-view>
+<!--				</view>-->
 				<view v-else>
 					<u-empty margin-top="40%" text="数据为空" mode="data"></u-empty>
 				</view>
@@ -84,12 +90,15 @@
 			return {
 				data: {
 					pageIndex: 1,
-					pageSize: 10000000,
+					pageSize: 10,
 					searchParams: {
 						emergType: null,//1-紧急;2-常规
 						warningLevel: null,//1-红色预警;2-橙色预警;3-黄色预警;4-蓝色预警
 					}
 				},
+        total: 0,
+        scrollTop: 0,
+        loading: false,
 				page: 'pages/tabBar/current/current',
 				checked: false,
 				isReadOnly: false,
@@ -125,31 +134,42 @@
 			uni.hideTabBar();
 		},
 		onShow() {
+      this.data.pageIndex = 1
 			this.getInfoList();
 		},
 		methods: {
 			goBack() {
-				console.log("1111")
 				uni.switchTab({
 				    url:'/pages/tabBar/firstPage/firstPage'
 				});
 			},
 			getInfoList() {
+        this.loading = true
 				this.data.searchParams.emergType = this.checked ? 1 : null;
 				this.data.searchParams.warningLevel = this.selectedSaleAnalysis == 'all' ? null : this.selectedSaleAnalysis =='red' ? 1 : this.selectedSaleAnalysis =='orange' ? 2: this.selectedSaleAnalysis =='yellow'? 3 : 4;
 				getPublished(this.data).then(res => {
 					if(res.code == 100) {
-						this.InfoList = res.data
+            let list = res.data?res.data: [];
+            if (res.pageIndex != 1) {
+              this.InfoList = this.InfoList.concat(list)
+            } else {
+              this.InfoList = list;
+            }
+            this.total = res.total
 						if(this.InfoList && this.InfoList.length > 0) {
 							this.InfoList.forEach((item, index) => {
 								this.InfoList[index].colorContent = item.warningLevel == 1 ? '红色预警': item.warningLevel == 2 ? '橙色预警': item.warningLevel == 3 ? '黄色预警':'蓝色预警'; 
 								this.InfoList[index].warningLevel = item.warningLevel;
 							});
 						}
-					}
+					}else{
+            uni.$u.toast(res.msg)
+          }
+          this.loading = false
 				})
 			},
 			handleButtonClick(button) {
+        this.data.pageIndex = 1
 				this.selectedSaleAnalysis = button.label;
 				this.getInfoList();
 			},
@@ -186,8 +206,26 @@
 				}, 1000);
 			},
 			clickSwitch(e) {
+        this.data.pageIndex = 1
 				this.getInfoList();
-			}
+			},
+
+      upper: function(e) {
+        // console.log(e)
+      },
+      lower: function(e) {
+        if (this.data.pageIndex * this.data.pageSize >= this.total){
+          uni.$u.toast('已加载全部数据')
+          return
+        }
+        //并且让页码+1,调用获取数据的方法获取第二页数据
+        this.data.pageIndex++
+        //此处调用自己获取数据列表的方法
+        this.getInfoList()
+      },
+      scroll: function(e) {
+        // console.log(e)
+      },
 		}
 	}
 
@@ -328,12 +366,14 @@
 	align-items: center;
 }
 .listContent{
-	display: flex;
-	flex-direction: column;
-	margin: 0 12px;
-	background: #fff;
-	border-radius: 5px;
-	box-shadow: 0 3px 12px rgba(0,0,0,0.05);
+  display: flex;
+  flex-direction: column;
+  width: calc(100% - 24px);
+  margin: 0 12px;
+  background: #fff;
+  border-radius: 5px;
+  box-shadow: 0 3px 12px rgba(0,0,0,0.05);
+  height: 100%;
 }
 .itemContent{
 	font-size: 16px;

--
Gitblit v1.9.2