const api = require('../../api/index.js'); Page({ data: { // 点位类型:station(电站)/user(用电点) type: '', // 点位详情信息 info: {}, // 模拟全量点位数据(实际项目中从接口获取) allPointData: { // 电站详情 station001: { id: 'station001', type: 'station', name: '张江电站', address: '上海市浦东新区张江路1238号张江高科技园区东区', longitude: 121.482000, latitude: 31.235000, status: '正常运行', powerCapacity: 5000, // 装机容量(kW) currentPower: 4200, // 当前出力(kW) todayGenerate: 85000,// 今日发电量(kWh) operationRate: 98.5, // 运行率(%) contactPerson: '王经理', contactPhone: '13800138000', buildTime: '2023-06-15', area: '浦东新区-张江', remark: '光伏+储能一体化电站,主要供应张江园区企业用电' }, station002: { id: 'station002', type: 'station', name: '漕河泾电站', address: '上海市徐汇区虹漕路461号漕河泾新兴技术开发区', longitude: 121.440000, latitude: 31.205000, status: '正常运行', powerCapacity: 3000, currentPower: 2850, todayGenerate: 56000, operationRate: 99.2, contactPerson: '李主管', contactPhone: '13900139000', buildTime: '2023-09-20', area: '徐汇区-漕河泾', remark: '储能电站,配套园区峰谷电价调节' }, // 用电点详情 user001: { id: 'user001', type: 'user', name: '陆家嘴商业中心', address: '上海市浦东新区陆家嘴环路1000号上海环球金融中心', longitude: 121.506377, latitude: 31.238039, status: '用电正常', currentPower: 1200, // 当前用电功率(kW) todayConsume: 28800, // 今日用电量(kWh) peakPower: 1800, // 今日峰值功率(kW) contractPower: 2000, // 合同功率(kW) contactPerson: '张经理', contactPhone: '13700137000', buildTime: '2023-01-10', area: '浦东新区-陆家嘴', remark: '商业综合体,24小时用电,峰值集中在10:00-22:00' }, user002: { id: 'user002', type: 'user', name: '人民广场商圈', address: '上海市黄浦区人民大道120号人民广场地下商城', longitude: 121.473081, latitude: 31.230664, status: '用电正常', currentPower: 800, todayConsume: 19200, peakPower: 1200, contractPower: 1500, contactPerson: '刘主管', contactPhone: '13600136000', buildTime: '2023-03-18', area: '黄浦区-人民广场', remark: '商圈配套用电,节假日峰值提升30%' } }, activeTab:0, alertData: [], // 补充:告警列表数据(核心缺失字段) pageNum: 1, // 当前页码 pageSize: 10, // 每页条数 totalPages: 0, // 总数据量(建议字段名改为 totalCount 更易理解) hasMore: true, // 是否还有更多数据 isLoading: false, // 是否正在加载(防止重复请求) options:'', electricitydata:[], powerstationdata:[] }, onLoad(options) { // 接收从列表页传递的参数:id(点位ID)、type(点位类型) console.log(options); this.setData({ options:options }) const { id, type } = options; if (!id || !type) { wx.showToast({ title: '参数错误', icon: 'none' }); wx.navigateBack(); return; } // 设置点位类型和详情信息 this.setData({ type: type, info: this.data.allPointData[id] || {} }, () => { // 设置导航栏标题 wx.setNavigationBarTitle({ title: this.data.type === 'station' ? '电站详情' : '用电点详情' }); }); // 实际项目中替换为接口请求 // this.getPointDetail(id, type); this.initAlertData() this.Electricalrecording() this.gitpowerstation() }, // 充放电记录 gitpowerstation(){ let data = { addressId: this.data.options.id, } api.request(`/sysaddress/selectaddressdetails`, 'post', data, { isPublic: false }) .then((data) => { console.log('实时数据:', data.data); if (data.code === 200) { this.setData({ powerstationdata: data.data }) } }) .catch((err) => { console.error('实时数据请求失败:', err); }); }, /** * 实际项目中:从接口获取点位详情 * @param {String} id 点位ID * @param {String} type 点位类型 */ getPointDetail(id, type) { wx.showLoading({ title: '加载中...' }); wx.request({ url: `https://你的接口地址/${type}/${id}`, method: 'GET', success: (res) => { if (res.data.code === 200) { this.setData({ info: res.data.data }); wx.setNavigationBarTitle({ title: type === 'station' ? '电站详情' : '用电点详情' }); } else { wx.showToast({ title: res.data.msg || '加载失败', icon: 'none' }); } }, fail: () => { wx.showToast({ title: '网络错误', icon: 'none' }); }, complete: () => { wx.hideLoading(); } }); }, // 充放电记录 Electricalrecording(){ let data = { addressId: this.data.options.id, pageNum:1, pageSize:10 } api.request(`/sysworkorder/selectpartnerworkorder`, 'post', data, { isPublic: false }) .then((data) => { console.log('实时数据:', data.data); if (data.code === 200) { this.setData({ electricitydata: data.data.data }) } }) .catch((err) => { console.error('实时数据请求失败:', err); }); }, /** * 点击按钮:跳转回地图页并定位到该点位 */ navigateToMap() { const { id, type, longitude, latitude } = this.data.info; // 跳转回地图页(根据实际页面路径调整) wx.reLaunch({ url: `/pages/index/index?targetId=${id}&targetType=${type}&lng=${longitude}&lat=${latitude}` }); }, /** * 点击按钮:拨打联系人电话 */ callContact() { const { contactPhone } = this.data.info; wx.makePhoneCall({ phoneNumber: contactPhone, fail: () => { wx.showToast({ title: '拨打电话失败', icon: 'none' }); } }); }, // 切换标签页(补充:切换后可根据标签筛选告警,示例逻辑) changeTab(e) { const index = e.currentTarget.dataset.index; this.setData({activeTab: index}, () => { // 可选:切换标签后重新加载对应状态的告警数据 // this.initAlertData(true); }); }, // 告警数据加载(完整补充版) initAlertData(isRefresh = true) { // 防止重复加载 if (this.data.isLoading) return; // 设置加载状态 this.setData({ isLoading: true }); // 分页参数处理:刷新重置为1,加载更多则+1 const pageNum = isRefresh ? 1 : this.data.pageNum + 1; const pageSize = this.data.pageSize; // 请求参数(关联当前车辆ID) let data = { addressId: this.data.options.id, pageNum, pageSize }; api.request(`/alarm/selectsysfault`, 'post', data, { isPublic: false }) .then((res) => { console.log('告警数据请求结果:', res); if (res.code === 200) { const { data: responseData } = res; const { data: list, totalPages } = responseData; // 数据处理:刷新=覆盖,加载更多=追加 const newAlertData = isRefresh ? list : [...this.data.alertData, ...list]; // 修正:判断是否还有更多数据(当前列表长度 < 总数据量) const hasMore = newAlertData.length < totalPages; console.log('告警列表:', newAlertData); console.log('当前页码:', pageNum); console.log('总数据量:', totalPages); console.log('是否有更多:', hasMore); // 更新数据 this.setData({ alertData: newAlertData, // 告警列表 pageNum: pageNum, // 更新当前页码 totalPages: totalPages, // 更新总数据量 hasMore: hasMore // 更新是否有更多数据 }); } }) .catch((err) => { console.error('告警数据请求失败:', err); wx.showToast({ title: '告警数据加载失败', icon: 'none', duration: 1500 }); }) .finally(() => { // 无论成功失败,都结束加载状态 this.setData({ isLoading: false }); }); }, /** * 下拉刷新:重新加载详情 */ onPullDownRefresh() { const { id, type } = this.data; this.getPointDetail(id, type).then(() => { wx.stopPullDownRefresh(); }); }, onUnload() {} });