|  |  |  | 
|---|
|  |  |  | planId: '', | 
|---|
|  |  |  | planStatusText: '', | 
|---|
|  |  |  | planStatusClass: '', | 
|---|
|  |  |  | failureCount: 0 | 
|---|
|  |  |  | failureCount: 0, | 
|---|
|  |  |  | realStopTime: '', | 
|---|
|  |  |  | originalStatus: '', | 
|---|
|  |  |  | currentStatus: null | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | 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', | 
|---|
|  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取灌溉计划数据 | 
|---|
|  |  |  | * 获取常规灌溉计划详细数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | fetchIrrigationData: function(planId) { | 
|---|
|  |  |  | fetchNormalIrrigationData: function(planId) { | 
|---|
|  |  |  | const { get } = require('../../api/request'); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const data = { | 
|---|
|  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取已终止灌溉计划详细数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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: '取消开阀'} | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 处理计划状态 | 
|---|
|  |  |  | 
|---|
|  |  |  | projectName: data.projectName, | 
|---|
|  |  |  | startTime: data.planStartTime, | 
|---|
|  |  |  | stopTime: data.planStopTime, | 
|---|
|  |  |  | realStopTime: data.realStopTime || '', | 
|---|
|  |  |  | groupList: groupList, | 
|---|
|  |  |  | planStatusText: planStatusText, | 
|---|
|  |  |  | planStatusClass: planStatusClass, | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|