From aec1b6ec73897b5e5f3a85f2985447726a399ed0 Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期六, 19 四月 2025 15:56:48 +0800 Subject: [PATCH] 更新灌溉计划页面,添加灌溉计划列表刷新标记,优化项目选择器和时间选择器的逻辑;更新样式以提升用户体验,确保在切换标签时只加载必要的数据。 --- pages/irrigation/irrigation.js | 136 ++++++++++++++++++++++++++++++-------------- 1 files changed, 92 insertions(+), 44 deletions(-) diff --git a/pages/irrigation/irrigation.js b/pages/irrigation/irrigation.js index 18aac0c..e30bf8d 100644 --- a/pages/irrigation/irrigation.js +++ b/pages/irrigation/irrigation.js @@ -51,44 +51,42 @@ /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ - // onShow: function () { - // // 璁剧疆椤甸潰涓哄姞杞戒腑鐘舵�� - // wx.showLoading({ - // title: '鍔犺浇涓�', - // mask: true - // }); + onShow: function () { + // 妫�鏌ュ叏灞�鍙橀噺锛屽垽鏂槸鍚﹂渶瑕佸埛鏂板垪琛ㄥ苟鍒囨崲鍒板綋鍓嶈鍒� + const app = getApp(); - // // 鍏堝姞杞藉綋鍓嶉〉闈㈡墍闇�鐨勬暟鎹� - // 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 - // }); - // } + // 鍒锋柊鎵�鏈夋暟鎹紙褰撳墠璁″垝鍜屽巻鍙茶鍒掞級锛岀‘淇濇暟鎹渶鏂� + wx.showLoading({ + title: '鍒锋柊鏁版嵁涓�', + mask: true + }); + + // 鍚屾椂鑾峰彇褰撳墠璁″垝鍜屽巻鍙茶鍒掓暟鎹� + Promise.all([ + this.loadIrrigationData(), + this.loadCompletedIrrigationData(true) // 浼犲叆true琛ㄧず鏄噸鏂板姞杞界涓�椤� + ]).then(() => { + wx.hideLoading(); - // this.loadCompletedIrrigationData() - // .then(() => { - // wx.hideLoading(); - // }) - // .catch(() => { - // wx.hideLoading(); - // }); - // } - // }, + // 濡傛灉闇�瑕佸埛鏂板苟鍒囨崲鍒板綋鍓嶈鍒� + if (app.globalData.needRefreshIrrigationList) { + // 閲嶇疆鍏ㄥ眬鍙橀噺 + app.globalData.needRefreshIrrigationList = false; + + console.log('妫�娴嬪埌闇�瑕佸埛鏂扮亴婧夎鍒掑垪琛�'); + + // 鍒囨崲鍒板綋鍓嶇亴婧夎鍒掓爣绛鹃〉 + if (this.data.currentTab !== 0) { + this.setData({ + currentTab: 0, + currentList: this.data.activeList + }); + } + } + }).catch(() => { + wx.hideLoading(); + }); + }, /** * 鍔犺浇杞亴鏁版嵁 @@ -148,10 +146,18 @@ /** * 鍔犺浇宸插畬鎴愮殑杞亴鏁版嵁 */ - loadCompletedIrrigationData: function () { + loadCompletedIrrigationData: function (isFirstPage) { // 濡傛灉姝e湪鍔犺浇鎴栨病鏈夋洿澶氭暟鎹紝鍒欎笉鍐嶈姹� if (this.data.loadingMore && !this.data.hasMoreData) { return Promise.resolve(); + } + + // 濡傛灉鏄噸鏂板姞杞界涓�椤碉紝閲嶇疆椤电爜鍜岀姸鎬� + if (isFirstPage) { + this.setData({ + pageCurr: 1, + hasMoreData: true + }); } // 璁剧疆鍔犺浇鐘舵�� @@ -320,7 +326,7 @@ // 瀵艰埅鍒扮亴婧夎鎯呴〉闈紝骞朵紶閫掑弬鏁� wx.navigateTo({ - url: `/pages/irrigationDetail/irrigationDetail?planId=${id}&fromList=true` + url: `/pages/irrigationDetail/irrigationDetail?planId=${id}&fromList=true&status=${status}` }); }, @@ -358,10 +364,17 @@ } }).catch(err => { console.error('鍙戝竷澶辫触锛�', err); - wx.showToast({ - title: '鍙戝竷澶辫触', - icon: 'none' - }); + if(err.code==='1003'){ + wx.showToast({ + title: err.msg || '鍙戝竷澶辫触', + icon: 'none' + }); + }else{ + wx.showToast({ + title: '鍙戝竷澶辫触', + icon: 'none' + }); + } }); } } @@ -443,8 +456,13 @@ title: '缁堟鎴愬姛', icon: 'success' }); - // 鍒锋柊鏁版嵁 - this.loadIrrigationData(); + // 鍚屾椂鍒锋柊褰撳墠璁″垝鍒楄〃鍜屽巻鍙茶鍒掑垪琛� + Promise.all([ + this.loadIrrigationData(), + this.loadCompletedIrrigationData(true) // 浼犲叆true琛ㄧず閲嶆柊鍔犺浇绗竴椤� + ]).catch(err => { + console.error('鍒锋柊鏁版嵁澶辫触:', err); + }); } else { wx.showToast({ title: res.msg || '缁堟澶辫触', @@ -578,5 +596,35 @@ console.error('鍔犺浇鏇村鍘嗗彶鏁版嵁澶辫触:', err); }); } + }, + + /** + * 浠庡垱寤虹亴婧夎鍒掗〉闈㈣繑鍥炴椂锛屽垏鎹㈠埌褰撳墠璁″垝鍒楄〃骞跺埛鏂版暟鎹� + */ + switchToCurrentPlans: function() { + console.log('浠庡垱寤洪〉闈㈣繑鍥烇紝鍒囨崲鍒板綋鍓嶈鍒掑垪琛ㄥ苟鍒锋柊'); + + // 濡傛灉褰撳墠涓嶅湪 "褰撳墠鐏屾簤璁″垝" 鏍囩椤碉紝鍏堝垏鎹㈠埌璇ユ爣绛鹃〉 + if (this.data.currentTab !== 0) { + this.setData({ + currentTab: 0, + currentList: this.data.activeList + }); + } + + // 鏄剧ず鍔犺浇鎻愮ず + wx.showLoading({ + title: '鍒锋柊鏁版嵁涓�', + mask: true + }); + + // 鍒锋柊褰撳墠鐏屾簤璁″垝鏁版嵁 + this.loadIrrigationData() + .then(() => { + wx.hideLoading(); + }) + .catch(() => { + wx.hideLoading(); + }); } }) \ No newline at end of file -- Gitblit v1.8.0