From ab8b53407a4d2213b1b3cdaf3cf649ef6c457dae Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期一, 28 四月 2025 15:52:19 +0800 Subject: [PATCH] 优化首页项目选择逻辑,添加临时选择变量以支持未确认的项目选择;更新登录页面逻辑,确保从登录页返回时正确刷新数据并处理项目选择确认,提升用户体验。 --- pages/irrigationDetail/irrigationDetail.js | 135 +++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 124 insertions(+), 11 deletions(-) diff --git a/pages/irrigationDetail/irrigationDetail.js b/pages/irrigationDetail/irrigationDetail.js index 597a4c7..fff0558 100644 --- a/pages/irrigationDetail/irrigationDetail.js +++ b/pages/irrigationDetail/irrigationDetail.js @@ -11,7 +11,11 @@ groupList: [], planId: '', planStatusText: '', - planStatusClass: '' + planStatusClass: '', + failureCount: 0, + realStopTime: '', + originalStatus: '', + currentStatus: null }, /** @@ -22,7 +26,35 @@ this.setData({ planId: options.planId }); - this.fetchIrrigationData(options.planId); + + // 鑾峰彇鏈�鏂扮姸鎬� + this.fetchPlanLatestState(options.planId).then(res => { + if (res.success) { + const currentStatus = res.content; + this.setData({ + currentStatus: currentStatus, + originalStatus: currentStatus + }); + + // 鏍规嵁鏈�鏂扮姸鎬佽皟鐢ㄧ浉搴旂殑鎺ュ彛 + if (currentStatus === 5) { + this.fetchTerminatedIrrigationData(options.planId); + } else { + this.fetchNormalIrrigationData(options.planId); + } + } else { + wx.showToast({ + title: res.msg || '鑾峰彇鐘舵�佸け璐�', + icon: 'none' + }); + } + }).catch(err => { + console.error('鑾峰彇鐘舵�佸け璐ワ細', err); + wx.showToast({ + title: '鑾峰彇鐘舵�佸け璐�', + icon: 'none' + }); + }); } else { wx.showToast({ title: '缂哄皯璁″垝ID', @@ -35,9 +67,9 @@ }, /** - * 鑾峰彇鐏屾簤璁″垝鏁版嵁 + * 鑾峰彇甯歌鐏屾簤璁″垝璇︾粏鏁版嵁 */ - fetchIrrigationData: function(planId) { + fetchNormalIrrigationData: function(planId) { const { get } = require('../../api/request'); const data = { @@ -68,6 +100,57 @@ }, /** + * 鑾峰彇宸茬粓姝㈢亴婧夎鍒掕缁嗘暟鎹� + */ + fetchTerminatedIrrigationData: function(planId) { + const { get } = require('../../api/request'); + + const data = { + planId: planId || this.data.planId, + }; + + get({ + url: 'wx/plan/getTerminateResults', + isShowLoding: true, + useParams: true, + data: data + }).then(res => { + if (res.success) { + this.processIrrigationData(res.content); + } else { + wx.showToast({ + title: res.msg || '鑾峰彇鏁版嵁澶辫触', + icon: 'none' + }); + } + }).catch(err => { + console.error('璇锋眰澶辫触锛�', err); + wx.showToast({ + title: '璇锋眰澶辫触', + icon: 'none' + }); + }); + }, + + /** + * 鑾峰彇璁″垝鏈�鏂扮姸鎬� + */ + fetchPlanLatestState: function(planId) { + const { get } = require('../../api/request'); + + const data = { + planId: planId || this.data.planId, + }; + + return get({ + url: 'wx/plan/getPlanLatestState', + isShowLoding: true, + useParams: true, + data: data + }); + }, + + /** * 澶勭悊鎺ュ彛杩斿洖鐨勬暟鎹� */ processIrrigationData: function(data) { @@ -77,7 +160,9 @@ const statusMap = { 2: {status: 'pending', statusText: '鏈紑濮�'}, 3: {status: 'in_progress', statusText: '鐏屾簤涓�'}, - 4: {status: 'completed', statusText: '宸茬粨鏉�'} + 4: {status: 'completed', statusText: '宸茬粨鏉�'}, + 5: {status: 'terminated', statusText: '涓�斿叧闃�'}, + 6: {status: 'canceled', statusText: '鍙栨秷寮�闃�'} }; // 澶勭悊璁″垝鐘舵�� @@ -139,9 +224,11 @@ projectName: data.projectName, startTime: data.planStartTime, stopTime: data.planStopTime, + realStopTime: data.realStopTime || '', groupList: groupList, planStatusText: planStatusText, - planStatusClass: planStatusClass + planStatusClass: planStatusClass, + failureCount: data.failureCount || 0 }); }, @@ -180,15 +267,41 @@ this.setData({ isRefreshing: true }); - - this.fetchIrrigationData(this.data.planId); - // 瀹屾垚鍒锋柊 - setTimeout(() => { + // 鑾峰彇鏈�鏂扮姸鎬佸苟鍒锋柊鏁版嵁 + this.fetchPlanLatestState(this.data.planId).then(res => { + if (res.success) { + const currentStatus = res.content; + this.setData({ + currentStatus: currentStatus + }); + + if (currentStatus === 5) { + this.fetchTerminatedIrrigationData(this.data.planId); + } else { + this.fetchNormalIrrigationData(this.data.planId); + } + } else { + wx.showToast({ + title: res.msg || '鑾峰彇鐘舵�佸け璐�', + icon: 'none' + }); + } + + // 瀹屾垚鍒锋柊 this.setData({ isRefreshing: false }); - }, 1000); + }).catch(err => { + console.error('鑾峰彇鐘舵�佸け璐ワ細', err); + wx.showToast({ + title: '鑾峰彇鐘舵�佸け璐�', + icon: 'none' + }); + this.setData({ + isRefreshing: false + }); + }); }, /** -- Gitblit v1.8.0