From fb805f6ff1d167951e94198b6e9fc320649e8643 Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期五, 11 四月 2025 17:57:20 +0800 Subject: [PATCH] Merge branch 'doing' of http://8.140.179.55:20000/r/wm/pipIrr into doing --- pages/irrigation/irrigation.js | 373 +++++++++++++++++++++++++++++++--------- pages/irrigation/irrigation.wxml | 25 ++ pages/irrigation/irrigation.wxss | 87 +++++++++ 3 files changed, 398 insertions(+), 87 deletions(-) diff --git a/pages/irrigation/irrigation.js b/pages/irrigation/irrigation.js index e4adbc2..18aac0c 100644 --- a/pages/irrigation/irrigation.js +++ b/pages/irrigation/irrigation.js @@ -13,7 +13,12 @@ currentList: [], // 褰撳墠鏄剧ず鐨勫垪琛� isRefreshing: false, // 鏄惁姝e湪鍒锋柊 isWXRefreshing: false, // 寰俊鍘熺敓涓嬫媺鍒锋柊鐘舵�� - projectId: null // Added to store projectId + projectId: null, // Added to store projectId + // 娣诲姞鍒嗛〉鐩稿叧鏁版嵁 + pageCurr: 1, // 褰撳墠椤电爜锛屼粠1寮�濮� + pageSize: 10, // 姣忛〉璁板綍鏁� + hasMoreData: true, // 鏄惁杩樻湁鏇村鏁版嵁 + loadingMore: false // 鏄惁姝e湪鍔犺浇鏇村 }, /** @@ -26,63 +31,116 @@ projectId: options.projectId }); } - this.loadIrrigationData(); - this.loadCompletedIrrigationData(); + + // 璁剧疆鍔犺浇鐘舵�� + wx.showLoading({ + title: '鍔犺浇涓�', + mask: true + }); + + // 榛樿鍏堝姞杞藉綋鍓嶇亴婧夎鍒� + this.loadIrrigationData() + .then(() => { + wx.hideLoading(); + }) + .catch(() => { + wx.hideLoading(); + }); }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ - onShow: function () { - this.loadIrrigationData(); - this.loadCompletedIrrigationData(); - }, + // onShow: function () { + // // 璁剧疆椤甸潰涓哄姞杞戒腑鐘舵�� + // wx.showLoading({ + // title: '鍔犺浇涓�', + // mask: true + // }); + + // // 鍏堝姞杞藉綋鍓嶉〉闈㈡墍闇�鐨勬暟鎹� + // const currentTab = this.data.currentTab; + // if (currentTab === 0) { + // // 褰撳墠鏍囩鏄�"褰撳墠鐏屾簤璁″垝"锛屽姞杞借繖涓� + // this.loadIrrigationData() + // .then(() => { + // wx.hideLoading(); + // }) + // .catch(() => { + // wx.hideLoading(); + // }); + // } else { + // // 褰撳墠鏍囩鏄�"鍘嗗彶璁″垝" + // // 鍙姞杞界涓�椤垫暟鎹紝淇濈暀鍒嗛〉鐘舵�� + // if (this.data.completedList.length === 0) { + // // 濡傛灉鍘嗗彶鍒楄〃涓虹┖锛岄噸缃垎椤电姸鎬� + // this.setData({ + // pageCurr: 1, + // hasMoreData: true + // }); + // } + + // this.loadCompletedIrrigationData() + // .then(() => { + // wx.hideLoading(); + // }) + // .catch(() => { + // wx.hideLoading(); + // }); + // } + // }, /** * 鍔犺浇杞亴鏁版嵁 */ loadIrrigationData: function () { - get({ - url: '/wx/plan/getNotCompletePlans' - }).then(res => { - if (res.success) { - const activeList = res.content.map(item => { - // 纭繚灏唒lanState杞崲涓哄瓧绗︿覆 - const planState = String(item.planState); - return { - id: item.planId, - title: item.planName, - projectName: item.projectName || '鏈垎閰嶉」鐩�', - status: planState, - planStartTime: item.planStartTime, - planStopTime: item.planStopTime, - duration: item.duration, - startupMode: item.startupMode - }; + return new Promise((resolve, reject) => { + get({ + url: '/wx/plan/getNotCompletePlans' + }).then(res => { + if (res.success) { + const activeList = res.content.map(item => { + // 纭繚灏唒lanState杞崲涓哄瓧绗︿覆 + const planState = String(item.planState); + return { + id: item.planId, + title: item.planName, + projectName: item.projectName || '鏈垎閰嶉」鐩�', + status: planState, + planStartTime: item.planStartTime, + planStopTime: item.planStopTime, + duration: item.duration, + startupMode: item.startupMode + }; + }); + + console.log('杞亴璁″垝鏁版嵁锛�', activeList); + + this.setData({ + activeList: activeList, + currentList: this.data.currentTab === 0 ? activeList : this.data.completedList, + isRefreshing: false, + isWXRefreshing: false + }); + resolve(); + } else { + wx.showToast({ + title: res.msg || '鍔犺浇澶辫触', + icon: 'none' + }); + reject(); + } + }).catch(err => { + console.error('鍔犺浇澶辫触:', err); + wx.showToast({ + title: '鍔犺浇澶辫触', + icon: 'none' }); - - console.log('杞亴璁″垝鏁版嵁锛�', activeList); - this.setData({ - activeList: activeList, - currentList: this.data.currentTab === 0 ? activeList : this.data.completedList, isRefreshing: false, isWXRefreshing: false }); - } else { - wx.showToast({ - title: res.msg || '鍔犺浇澶辫触', - icon: 'none' - }); - } - }).catch(err => { - wx.showToast({ - title: '鍔犺浇澶辫触', - icon: 'none' - }); - this.setData({ - isRefreshing: false, - isWXRefreshing: false + reject(); }); }); }, @@ -91,47 +149,85 @@ * 鍔犺浇宸插畬鎴愮殑杞亴鏁版嵁 */ loadCompletedIrrigationData: function () { - get({ - url: '/wx/plan/getCompletedPlans' - }).then(res => { - if (res.success) { - const completedList = res.content.map(item => { - // 纭繚灏唒lanState杞崲涓哄瓧绗︿覆 - const planState = String(item.planState); - return { - id: item.planId, - title: item.planName, - projectName: item.projectName || '鏈垎閰嶉」鐩�', - status: planState, - planStartTime: item.planStartTime, - planStopTime: item.planStopTime, - duration: item.duration, - startupMode: item.startupMode + // 濡傛灉姝e湪鍔犺浇鎴栨病鏈夋洿澶氭暟鎹紝鍒欎笉鍐嶈姹� + if (this.data.loadingMore && !this.data.hasMoreData) { + return Promise.resolve(); + } + + // 璁剧疆鍔犺浇鐘舵�� + this.setData({ + loadingMore: true + }); + + return new Promise((resolve, reject) => { + get({ + url: '/wx/plan/getCompletedPlans', + data: { + pageCurr: this.data.pageCurr, + pageSize: this.data.pageSize + } + }).then(res => { + if (res.success) { + const newCompletedList = res.content.obj ? res.content.obj.map(item => { + // 纭繚灏唒lanState杞崲涓哄瓧绗︿覆 + const planState = String(item.planState); + return { + id: item.planId, + title: item.planName, + projectName: item.projectName || '鏈垎閰嶉」鐩�', + status: planState, + planStartTime: item.planStartTime, + planStopTime: item.planStopTime, + duration: item.duration, + startupMode: item.startupMode + }; + }) : []; + + console.log('宸插畬鎴愯疆鐏岃鍒掓暟鎹細', newCompletedList); + + // 鑾峰彇鍒嗛〉淇℃伅 + const pageInfo = { + itemTotal: res.content.itemTotal || 0, // 鎬昏褰曟暟 + pageCurr: res.content.pageCurr || 1, // 褰撳墠椤电爜 + pageSize: res.content.pageSize || 20, // 姣忛〉澶у皬 + pageTotal: res.content.pageTotal || 1 // 鎬婚〉鏁� }; - }); + + console.log('鍒嗛〉淇℃伅锛�', pageInfo); - console.log('宸插畬鎴愯疆鐏岃鍒掓暟鎹細', completedList); + // 鍒ゆ柇鏄惁杩樻湁鏇村鏁版嵁 - 褰撳墠椤靛皬浜庢�婚〉鏁� + const hasMoreData = pageInfo.pageCurr < pageInfo.pageTotal; + // 鍚堝苟鏁版嵁锛岀涓�椤电洿鎺ユ浛鎹紝涔嬪悗鐨勯〉闈㈣拷鍔� + const completedList = this.data.pageCurr === 1 ? + newCompletedList : [...this.data.completedList, ...newCompletedList]; + + this.setData({ + completedList: completedList, + currentList: this.data.currentTab === 1 ? completedList : this.data.activeList, + isRefreshing: false, + isWXRefreshing: false, + loadingMore: false, + hasMoreData: hasMoreData + }); + resolve(); + } else { + this.setData({ + loadingMore: false + }); + // 涓嶆樉绀烘彁绀猴紝鍥犱负鍙兘鏄湪鍚庡彴鍔犺浇 + console.error('鍘嗗彶璁″垝鍔犺浇澶辫触:', res.msg); + reject(); + } + }).catch(err => { + console.error('鍘嗗彶璁″垝鍔犺浇澶辫触:', err); this.setData({ - completedList: completedList, - currentList: this.data.currentTab === 1 ? completedList : this.data.activeList, isRefreshing: false, - isWXRefreshing: false + isWXRefreshing: false, + loadingMore: false }); - } else { - wx.showToast({ - title: res.msg || '鍔犺浇澶辫触', - icon: 'none' - }); - } - }).catch(err => { - wx.showToast({ - title: '鍔犺浇澶辫触', - icon: 'none' - }); - this.setData({ - isRefreshing: false, - isWXRefreshing: false + // 涓嶆樉绀烘彁绀猴紝鍥犱负鍙兘鏄湪鍚庡彴鍔犺浇 + reject(); }); }); }, @@ -148,10 +244,58 @@ const activeList = this.data.activeList || []; const completedList = this.data.completedList || []; - this.setData({ - currentTab: index, - currentList: index === 0 ? activeList : completedList - }); + // 鍒囨崲鏍囩椤垫椂锛岀洿鎺ヤ娇鐢ㄥ凡鍔犺浇鐨勬暟鎹紝涓嶉噸鏂拌姹� + if (index === 1) { + // 鍒囨崲鍒板巻鍙茶鍒掓爣绛� + this.setData({ + currentTab: index, + currentList: completedList + }); + + // 濡傛灉鍘嗗彶鍒楄〃涓虹┖锛屾墠杩涜鍔犺浇 + if (completedList.length === 0) { + wx.showLoading({ + title: '鍔犺浇涓�', + mask: true + }); + + this.setData({ + pageCurr: 1, + hasMoreData: true, + loadingMore: true // 鏄剧ず鍔犺浇鎸囩ず鍣� + }); + + this.loadCompletedIrrigationData() + .then(() => { + wx.hideLoading(); + }) + .catch(() => { + wx.hideLoading(); + }); + } + } else { + // 鍒囨崲鍒板綋鍓嶇亴婧夎鍒掓爣绛� + this.setData({ + currentTab: index, + currentList: activeList + }); + + // 濡傛灉褰撳墠鐏屾簤璁″垝鍒楄〃涓虹┖锛屾墠杩涜鍔犺浇 + if (activeList.length === 0) { + wx.showLoading({ + title: '鍔犺浇涓�', + mask: true + }); + + this.loadIrrigationData() + .then(() => { + wx.hideLoading(); + }) + .catch(() => { + wx.hideLoading(); + }); + } + } }, /** @@ -363,8 +507,27 @@ this.setData({ isRefreshing: true }); - this.loadIrrigationData(); - this.loadCompletedIrrigationData(); + + // 鏍规嵁褰撳墠鏍囩椤靛彧鍒锋柊瀵瑰簲鐨勬暟鎹� + const currentTab = this.data.currentTab; + if (currentTab === 0) { + // 褰撳墠鏍囩鏄�"褰撳墠鐏屾簤璁″垝"锛屽彧鍒锋柊杩欎釜 + this.loadIrrigationData() + .finally(() => { + this.setData({ isRefreshing: false }); + }); + } else { + // 褰撳墠鏍囩鏄�"鍘嗗彶璁″垝"锛屽皢鍒嗛〉閲嶇疆鍒扮涓�椤靛苟鍒锋柊 + this.setData({ + pageCurr: 1, + hasMoreData: true + }); + + this.loadCompletedIrrigationData() + .finally(() => { + this.setData({ isRefreshing: false }); + }); + } } }, @@ -375,7 +538,45 @@ this.setData({ isWXRefreshing: true }); - this.loadIrrigationData(); - this.loadCompletedIrrigationData(); + + // 鏍规嵁褰撳墠鏍囩椤靛彧鍒锋柊瀵瑰簲鐨勬暟鎹� + const currentTab = this.data.currentTab; + if (currentTab === 0) { + // 褰撳墠鏍囩鏄�"褰撳墠鐏屾簤璁″垝"锛屽彧鍒锋柊杩欎釜 + this.loadIrrigationData() + .finally(() => { + this.setData({ isWXRefreshing: false }); + }); + } else { + // 褰撳墠鏍囩鏄�"鍘嗗彶璁″垝"锛屽皢鍒嗛〉閲嶇疆鍒扮涓�椤靛苟鍒锋柊 + this.setData({ + pageCurr: 1, + hasMoreData: true + }); + + this.loadCompletedIrrigationData() + .finally(() => { + this.setData({ isWXRefreshing: false }); + }); + } + }, + + /** + * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� + */ + onReachBottom: function() { + console.log('瑙﹀簳鍔犺浇鏇村, 褰撳墠鏍囩:', this.data.currentTab); + // 褰撳墠鏄凡瀹屾垚鍒楄〃涓旇繕鏈夋洿澶氭暟鎹椂鍔犺浇鏇村 + if (this.data.currentTab === 1 && this.data.hasMoreData && !this.data.loadingMore) { + this.setData({ + pageCurr: this.data.pageCurr + 1 + }); + + // 鍔犺浇鏇村鍘嗗彶鏁版嵁 + this.loadCompletedIrrigationData() + .catch(err => { + console.error('鍔犺浇鏇村鍘嗗彶鏁版嵁澶辫触:', err); + }); + } } }) \ No newline at end of file diff --git a/pages/irrigation/irrigation.wxml b/pages/irrigation/irrigation.wxml index 93bcaaf..99ea2cc 100644 --- a/pages/irrigation/irrigation.wxml +++ b/pages/irrigation/irrigation.wxml @@ -10,7 +10,17 @@ </view> <!-- 涓棿鍒楄〃 - 浣跨敤scroll-view瀹炵幇涓嬫媺鍒锋柊 --> - <scroll-view class="scroll-view" scroll-x="false" scroll-y="true" refresher-enabled="{{isRefreshing==false?true:false}}" refresher-threshold="50" bindrefresherrefresh="onPullDownRefresh" refresher-triggered="{{isWXRefreshing}}"> + <scroll-view class="scroll-view" + scroll-x="false" + scroll-y="true" + refresher-enabled="{{isRefreshing==false?true:false}}" + refresher-threshold="50" + bindrefresherrefresh="onPullDownRefresh" + refresher-triggered="{{isWXRefreshing}}" + lower-threshold="100" + bindscrolltolower="{{currentTab === 1 ? 'onReachBottom' : ''}}" + enhanced="{{true}}" + id="scrollView"> <view wx:if="{{isRefreshing}}" class="refresh-view"> <view class="dot"></view> <view class="dot"></view> @@ -92,6 +102,19 @@ </view> </view> </view> + + <!-- 鍔犺浇鏇村鎻愮ず - 浠呭湪鍘嗗彶璁″垝鏍囩椤垫樉绀� --> + <view wx:if="{{currentTab === 1}}" class="loading-more-container"> + <view wx:if="{{loadingMore}}" class="loading-more"> + <view class="loading-dot"></view> + <view class="loading-dot"></view> + <view class="loading-dot"></view> + <text>鍔犺浇涓�...</text> + </view> + <view wx:elif="{{!hasMoreData && completedList.length > 0}}" class="no-more-data"> + <text>鈥� 宸插姞杞藉叏閮ㄦ暟鎹� 鈥�</text> + </view> + </view> </block> <block wx:else> diff --git a/pages/irrigation/irrigation.wxss b/pages/irrigation/irrigation.wxss index 2d5116d..51a20dc 100644 --- a/pages/irrigation/irrigation.wxss +++ b/pages/irrigation/irrigation.wxss @@ -337,4 +337,91 @@ .add-button-hover { opacity: 0.8; +} + +/* 鍔犺浇鏇村鏍峰紡 */ +.loading-more-container { + padding: 20rpx 0; + text-align: center; +} + +.loading-more { + display: flex; + align-items: center; + justify-content: center; + padding: 20rpx 0; +} + +.loading-dot { + width: 16rpx; + height: 16rpx; + border-radius: 50%; + background-color: #0052d9; + margin: 0 8rpx; + animation: loading 1.4s infinite ease-in-out both; +} + +.loading-dot:nth-child(1) { + animation-delay: -0.32s; +} + +.loading-dot:nth-child(2) { + animation-delay: -0.16s; +} + +@keyframes loading { + 0%, 80%, 100% { + transform: scale(0); + } + 40% { + transform: scale(1); + } +} + +.loading-more text { + margin-left: 12rpx; + font-size: 28rpx; + color: #999; +} + +.no-more-data { + color: #999; + font-size: 26rpx; + line-height: 80rpx; +} + +/* 鍒锋柊鍔ㄧ敾鏍峰紡 */ +.refresh-view { + text-align: center; + height: 80rpx; + line-height: 80rpx; + display: flex; + justify-content: center; + align-items: center; +} + +.refresh-view .dot { + width: 16rpx; + height: 16rpx; + background-color: #0052d9; + border-radius: 50%; + margin: 0 8rpx; + animation: refresh 1.4s infinite ease-in-out both; +} + +.refresh-view .dot:nth-child(1) { + animation-delay: -0.32s; +} + +.refresh-view .dot:nth-child(2) { + animation-delay: -0.16s; +} + +@keyframes refresh { + 0%, 80%, 100% { + transform: scale(0); + } + 40% { + transform: scale(1); + } } \ No newline at end of file -- Gitblit v1.8.0