// pages/irrigation/irrigation.js Page({ /** * 页面的初始数据 */ data: { currentTab: 0, // 当前选中的标签页索引 activeList: [], // 进行中的轮灌列表 completedList: [], // 已完成的轮灌列表 currentList: [], // 当前显示的列表 isRefreshing: false, // 是否正在刷新 isWXRefreshing: false // 微信原生下拉刷新状态 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.loadIrrigationData(); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.loadIrrigationData(); }, /** * 加载轮灌数据 */ loadIrrigationData: function () { // 这里应该调用API获取数据 // 模拟数据 const mockData = { activeList: [ { id: '1', title: 'LG-2023-001', status: '未发布', irrigationTime: '2023-05-20 08:00 - 17:00' }, { id: '2', title: 'LG-2023-002', status: '已发布', irrigationTime: '2023-05-22 09:00 - 18:00' }, { id: '2', title: 'LG-2023-002', status: '已发布', irrigationTime: '2023-05-22 09:00 - 18:00' }, { id: '2', title: 'LG-2023-002', status: '已发布', irrigationTime: '2023-05-22 09:00 - 18:00' }, { id: '2', title: 'LG-2023-002', status: '已发布', irrigationTime: '2023-05-22 09:00 - 18:00' }, { id: '3', title: 'LG-2023-003', status: '执行中', irrigationTime: '2023-05-18 07:30 - 16:30', irrigatedTime: '3小时25分钟', irrigatedGroups: '1组、2组、3组' }, { id: '2', title: 'LG-2023-002', status: '已发布', irrigationTime: '2023-05-22 09:00 - 18:00' }, { id: '3', title: 'LG-2023-003', status: '执行中', irrigationTime: '2023-05-18 07:30 - 16:30', irrigatedTime: '3小时25分钟', irrigatedGroups: '1组、2组、3组' }, { id: '2', title: 'LG-2023-002', status: '已发布', irrigationTime: '2023-05-22 09:00 - 18:00' }, { id: '3', title: 'LG-2023-003', status: '执行中', irrigationTime: '2023-05-18 07:30 - 16:30', irrigatedTime: '3小时25分钟', irrigatedGroups: '1组、2组、3组' } ] // completedList: [ // { // id: '4', // title: 'LG-2023-004', // status: '已完成', // irrigationTime: '2023-05-10 10:00 - 19:00' // } // ] }; // 模拟网络请求延迟 setTimeout(() => { this.setData({ activeList: mockData.activeList || [], completedList: mockData.completedList || [], currentList: this.data.currentTab === 0 ? mockData.activeList || [] : mockData.completedList || [], isRefreshing: false, // 结束刷新状态 isWXRefreshing: false // 结束微信原生下拉刷新状态 }); }, 1000); }, /** * 切换标签页 */ switchTab: function (e) { const index = parseInt(e.currentTarget.dataset.index); if (this.data.currentTab === index) { return; } const activeList = this.data.activeList || []; const completedList = this.data.completedList || []; this.setData({ currentTab: index, currentList: index === 0 ? activeList : completedList }); }, /** * 点击发布按钮 */ onPublish: function (e) { const id = e.currentTarget.dataset.id; wx.showModal({ title: '确认发布', content: '确定要发布该轮灌计划吗?', success: (res) => { if (res.confirm) { // 这里应该调用API发布轮灌计划 wx.showToast({ title: '发布成功', icon: 'success' }); // 刷新数据 this.loadIrrigationData(); } } }); }, /** * 点击终止按钮 */ onStop: function (e) { const id = e.currentTarget.dataset.id; wx.showModal({ title: '确认终止', content: '确定要终止该轮灌计划吗?', success: (res) => { if (res.confirm) { // 这里应该调用API终止轮灌计划 wx.showToast({ title: '已终止', icon: 'success' }); // 刷新数据 this.loadIrrigationData(); } } }); }, /** * 点击立即执行按钮 */ onExecute: function (e) { const id = e.currentTarget.dataset.id; wx.showModal({ title: '确认执行', content: '确定要立即执行该轮灌计划吗?', success: (res) => { if (res.confirm) { // 这里应该调用API立即执行轮灌计划 wx.showToast({ title: '执行成功', icon: 'success' }); // 刷新数据 this.loadIrrigationData(); } } }); }, /** * 点击新建轮灌按钮 */ onAddIrrigation: function () { wx.navigateTo({ url: '/pages/createIrrigation/createIrrigation' }); }, /** * 开始下拉刷新 */ startPullDownRefresh: function() { if (!this.data.isWXRefreshing) { this.setData({ isRefreshing: true }); this.loadIrrigationData(); } }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.setData({ isWXRefreshing: true }); this.loadIrrigationData(); } })