// package/AIOTOverview/AIOTOverview.js import { getThingsDeploy, getThingsStatus, getCardInfo,getRelationList,getNetworks} from "../../utils/getApiUrl"; import { Request } from "../../common"; const moment = require("../../utils/moment"); Page({ searchId:[], /** * 页面的初始数据 */ data: { count:{abnormal:0,normal:0},//宽带专网正常与欠费 data: [],//用电设备数据 normal: 0,//正常 abnormal: 0,//异常 unknown: 0,//未知 iotCardNormal: 0,//物联网卡正常 iotCardNonactivated: 0,//物联网卡欠费 iotCardHalt: 0,//物联网卡停机 iotaCardData: [],//物联网卡数据 }, //跳转流量监控明细 navigatorToFlow() { const jsonData = JSON.stringify(this.data.iotaCardData) wx.navigateTo({ url: `/package/AIOTOverview/flowMonitoring/flowMonitoring?data=` + encodeURIComponent(jsonData) }) }, //跳转用电监控明细 navigatorToEle() { const jsonData2 = JSON.stringify(this.searchId) wx.navigateTo({ url: `/package/AIOTOverview/electricityMonitoring/electricityMonitoring?data2=${encodeURIComponent(jsonData2)}` }) }, //跳转宽带专网 navigatorToNet() { wx.navigateTo({ url: `/package/AIOTOverview/network/network` }) }, /** * 生命周期函数--监听页面加载 */ async onLoad(options) { wx.showLoading({ title: '加载中...' }); const that = this const devices = await Request.get(getThingsDeploy()) const status = await Request.get(getThingsStatus()) const rslt = await Request.get(getRelationList()) let deviceId = [] //空开电源设备的id let deviceAll = [] let searchId=[]//查询e9c设备状态的id let controlId=[] if (devices) { const dataList = devices for (const id in dataList.instances) { const instances = dataList?.instances[id] if (instances.type == 's.d' && instances?.instance?.properties) { deviceAll.push({ id, name: instances.instance?.properties?.name, structId: instances.instance?.structId }) if (instances.type == 's.d' && instances.instance.properties.deviceType == 'sensor') { if (instances.instance.properties.model == 'E9C') { for (const key in instances?.instance?.interfaces) { const d=Object.values(instances?.instance?.interfaces[key]?.capabilities) if(d&&d.length){ searchId.push({deviceId:id,cid:d[1]?.dimension?.id,sid:d[0]?.dimension?.id,name: instances.instance?.properties?.name, structId: instances.instance?.structId }) } } } } if (instances?.instance?.properties?.model == 'JG-RTU-S270') { deviceId.push({ id, name: instances.instance?.properties?.name, structId: instances.instance?.structId,xjId:instances.instance?.xjId }) } } } } if (status && status.length) { const data = deviceId.map(item => { return { deviceId: item.id, name: item.name, status: status.find(q => q.deviceId == item.id)?.status, structId: item?.structId, xjId:item.xjId } }) // deviceAll.push({ id: '012ccc98-c99d-445e-8397-6da1b4567533', name: '设备二', structId: 'df48d7c5-d902-47b1-b671-d88d546ba3e4' }) if (deviceAll && deviceAll.length) { Request.post(getCardInfo(), { structIds: deviceAll }).then(res => { if (res) { if(rslt.rows.length){ controlId=res.map(item=>{ return { ...item, xjId:rslt.rows.find(q=>q.axyProjectId==item.thingId)?.structureId } }) } this.searchId=searchId that.setData({ iotaCardData: controlId, iotCardNormal: res?.filter(item => item.status == 0)?.length, iotCardNonactivated: res?.filter(item => item.status == 1)?.length, iotCardHalt: res?.filter(item => item.status == 2)?.length, }) } }) } that.setData({ data, normal: data?.filter(item => item.status == 1)?.length, unknown: data?.filter(item => item.status == -1)?.length, abnormal: data?.filter(item => item.status == 0)?.length }) } Request.get(getNetworks()).then(res=>{ if(res.rows.length){ let normal=0 let abnormal=0 res.rows.forEach(q => { if (moment(q.indate).isBefore(moment())) { abnormal += 1; } else { normal += 1; } }); that.setData({ count:{normal,abnormal} }) } }) wx.hideLoading() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })