| | |
| | | /** |
| | | * 生命周期函数--监听页面显示 |
| | | */ |
| | | // 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(); |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 加载轮灌数据 |
| | |
| | | /** |
| | | * 加载已完成的轮灌数据 |
| | | */ |
| | | loadCompletedIrrigationData: function () { |
| | | loadCompletedIrrigationData: function (isFirstPage) { |
| | | // 如果正在加载或没有更多数据,则不再请求 |
| | | if (this.data.loadingMore && !this.data.hasMoreData) { |
| | | return Promise.resolve(); |
| | | } |
| | | |
| | | // 如果是重新加载第一页,重置页码和状态 |
| | | if (isFirstPage) { |
| | | this.setData({ |
| | | pageCurr: 1, |
| | | hasMoreData: true |
| | | }); |
| | | } |
| | | |
| | | // 设置加载状态 |
| | |
| | | |
| | | // 导航到灌溉详情页面,并传递参数 |
| | | wx.navigateTo({ |
| | | url: `/pages/irrigationDetail/irrigationDetail?planId=${id}&fromList=true` |
| | | url: `/pages/irrigationDetail/irrigationDetail?planId=${id}&fromList=true&status=${status}` |
| | | }); |
| | | }, |
| | | |
| | |
| | | } |
| | | }).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' |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | |
| | | title: '终止成功', |
| | | icon: 'success' |
| | | }); |
| | | // 刷新数据 |
| | | this.loadIrrigationData(); |
| | | // 同时刷新当前计划列表和历史计划列表 |
| | | Promise.all([ |
| | | this.loadIrrigationData(), |
| | | this.loadCompletedIrrigationData(true) // 传入true表示重新加载第一页 |
| | | ]).catch(err => { |
| | | console.error('刷新数据失败:', err); |
| | | }); |
| | | } else { |
| | | wx.showToast({ |
| | | title: res.msg || '终止失败', |
| | |
| | | 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(); |
| | | }); |
| | | } |
| | | }) |