| | |
| | | const app = getApp(); |
| | | const { get } = require('../../api/request'); |
| | | |
| | | Page({ |
| | | /** |
| | |
| | | |
| | | console.log('设置后的数据:', this.data); |
| | | |
| | | // 设置导航栏标题 |
| | | wx.setNavigationBarTitle({ |
| | | title: this.data.groupName || '轮灌组详情' |
| | | }); |
| | | |
| | | this.loadWaterOutletData(); |
| | | } |
| | | }, |
| | |
| | | refreshing: true |
| | | }); |
| | | |
| | | console.log('加载取水口数据,灌溉状态:', this.data.isIrrigating); |
| | | |
| | | // 模拟数据 |
| | | let mockData = { |
| | | waterOutlets: [] |
| | | }; |
| | | |
| | | // 生成取水口数据,所有取水口都有命令状态 |
| | | mockData.waterOutlets = [ |
| | | { |
| | | id: 1, |
| | | name: '取水口 A-1', |
| | | status: 'online', |
| | | commandStatus: 'sent' // 命令已下发 |
| | | get({ |
| | | url: '/wx/irrigation/getGroupDetails', |
| | | data: { |
| | | groupId: this.data.groupId |
| | | }, |
| | | { |
| | | id: 2, |
| | | name: '取水口 A-2', |
| | | status: 'online', |
| | | commandStatus: 'unsent' // 命令未下发 |
| | | }, |
| | | { |
| | | id: 3, |
| | | name: '取水口 A-3', |
| | | status: 'offline', |
| | | commandStatus: 'unsent' // 命令未下发 |
| | | isShowLoding: true |
| | | }).then(res => { |
| | | console.log('轮灌组详情接口返回:', res); |
| | | |
| | | if (res.success) { |
| | | this.handleGroupDetailsResponse(res); |
| | | } else { |
| | | wx.showToast({ |
| | | title: res.msg || '获取数据失败', |
| | | icon: 'none' |
| | | }); |
| | | this.setData({ |
| | | refreshing: false |
| | | }); |
| | | } |
| | | ]; |
| | | |
| | | // 模拟网络请求延迟 |
| | | setTimeout(() => { |
| | | }).catch(err => { |
| | | console.error('请求失败:', err); |
| | | wx.showToast({ |
| | | title: '网络错误', |
| | | icon: 'none' |
| | | }); |
| | | this.setData({ |
| | | waterOutletList: mockData.waterOutlets, |
| | | refreshing: false |
| | | }); |
| | | console.log('设置取水口数据完成:', this.data.waterOutletList); |
| | | }, 1000); |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 处理轮灌组详情响应数据 |
| | | */ |
| | | handleGroupDetailsResponse: function(response) { |
| | | const data = response.content; |
| | | |
| | | // 实际项目中应该使用wx.request获取数据 |
| | | // wx.request({ |
| | | // url: `https://your-api-url/groups/${this.data.groupId}/waterOutlets`, |
| | | // method: 'GET', |
| | | // success: (res) => { |
| | | // if (res.data && res.data.code === 0) { |
| | | // this.setData({ |
| | | // waterOutletList: res.data.data.waterOutlets, |
| | | // refreshing: false |
| | | // }); |
| | | // } else { |
| | | // wx.showToast({ |
| | | // title: '获取数据失败', |
| | | // icon: 'none' |
| | | // }); |
| | | // this.setData({ |
| | | // refreshing: false |
| | | // }); |
| | | // } |
| | | // }, |
| | | // fail: () => { |
| | | // wx.showToast({ |
| | | // title: '网络错误', |
| | | // icon: 'none' |
| | | // }); |
| | | // this.setData({ |
| | | // refreshing: false |
| | | // }); |
| | | // } |
| | | // }); |
| | | // 处理取水口数据 |
| | | const waterOutletList = data.intakes.map(item => { |
| | | return { |
| | | id: item.rtuAddr, // 使用rtuAddr作为ID |
| | | name: item.intakeName, |
| | | rtuAddr: item.rtuAddr, |
| | | status: item.isOnLine ? 'online' : 'offline' |
| | | }; |
| | | }); |
| | | |
| | | this.setData({ |
| | | projectName: data.projectName || this.data.projectName, |
| | | groupName: data.groupName || this.data.groupName, |
| | | waterOutletList: waterOutletList, |
| | | refreshing: false |
| | | }); |
| | | |
| | | console.log('设置取水口数据完成:', this.data.waterOutletList); |
| | | }, |
| | | |
| | | /** |