const app = getApp() import Notify from '@vant/weapp/notify/notify'; import { getAllDeviceInfoByRoomIdRq, getAllPanelInfoByRoomIdRq, callApiByPanelIdRq, callApiByDeviceIdRq, getDeviceInfoRq } from "../../../api/meeting/equipment.js" Page({ /** * 页面的初始数据 */ data: { IMG_NAME: app.IMG_NAME, roomId: null, roomName: '', lockDoor: null, sceneList: [{ name: '茶歇模式', url: app.IMG_NAME + '/profile/static/shanghai_changyang/device/scene/' + 'chaxie1.png', selectUrl: app.IMG_NAME + '/profile/static/shanghai_changyang/device/scene/' + 'chaxie0.png', isSelect: false }, { name: '开门模式', url: app.IMG_NAME + '/profile/static/shanghai_changyang/device/scene/' + 'kaimen1.png', selectUrl: app.IMG_NAME + '/profile/static/shanghai_changyang/device/scene/' + 'kaimen0.png', isSelect: false }, ], equipmentList: [], // 设备列表 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let _this = this _this.setData({ ...options }) // 查询所有设备列表 _this.queryDeviceList() // 查询情景列表 _this.queryScene() }, // 查询情景列表 queryScene() { let _this = this getAllPanelInfoByRoomIdRq(_this.data.roomId).then(res => { console.log('getAllPanelInfoByRoomIdRq', res); let sceneList = res.data.map(item => { item.isSelect = false item.img = app.IMG_NAME + item.img item.imgOpen = app.IMG_NAME + item.imgOpen return item }) _this.setData({ sceneList }) }) }, // 查询所有设备列表 queryDeviceList() { let _this = this getAllDeviceInfoByRoomIdRq(_this.data.roomId).then(res => { console.log('getAllDeviceInfoByRoomIdRq', res); let equipmentList = res.data.map(item => _this.formatDevice(item)) equipmentList = equipmentList.filter(item => item.type != '门锁') equipmentList = equipmentList.filter(item => item.type != '开门控制器') let lockDoor = res.data.find(item => item.type == '门锁') let controlDoor = res.data.find(item => item.type == '开门控制器') console.log('开门控制器-------',controlDoor); _this.setData({ controlDoor, lockDoor, equipmentList }) // 查询设备详情 _this.queryDeviceInfo() }) }, // 格式化设备数据 formatDevice(item) { if (item.type == '灯条') { item.status = false item.lampCloseUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'lamp-close.png' item.lampOpenUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'lamp-open.png' item.switchCloseUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'switch-close.png' item.switchOpenUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'switch-open.png' } if (item.type == '雾化玻璃') { item.status = false item.glassImgUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/glass/glass-close.png' item.glassImgActivityUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/glass/glass-open.png' item.glassSwitchImgUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/glass/switch-close.png' item.glassSwitchImgActivityUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/glass/switch-open.png' } if (item.type == '窗帘') { item.subtype = 'curtain' item.status = 'close_cover' item.equipmentCurtainCurtainTopImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/curtainTop.png' item.equipmentCurtainWindowImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/window.png' item.equipmentCurtainCordFabricImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/cordFabric.png' item.curtainSwitchOpenImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/switch-open.png' item.curtainSwitchCloseImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/switch-close.png' item.curtainStopImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/curtain/stop-black.png' } if (item.type == '插座') { item.status = false item.socketImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/socket/socket.png' item.socketSwitchCloseImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/socket/switch-close.png' item.socketSwitchOpenImg = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/socket/switch-open.png' } if (item.type == '调光灯') { item.status = false item.lampCloseUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'lamp-close.png' item.lampOpenUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'lamp-open.png' item.switchCloseUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'switch-close.png' item.switchOpenUrl = app.IMG_NAME + '/profile/static/shanghai_changyang/device/equipment/lamp/' + 'switch-open.png' } return item }, // 查询设备详情 queryDeviceInfo() { let _this = this let equipmentList = _this.data.equipmentList for (let i = 0; i < equipmentList.length; i++) { let equipmentData = equipmentList[i]; if (equipmentData.type == '窗帘' || equipmentData.type == '门锁' || equipmentData.type == '开门控制器') { continue } // getDeviceInfoRq(equipmentData.id).then(res => { console.log('getDeviceInfoRq', equipmentData.type, res); if (equipmentData.type == '灯条') { equipmentData.status = res.on } if (equipmentData.type == '雾化玻璃') { equipmentData.status = res.on } if (equipmentData.type == '插座') { equipmentData.status = res.on } if (equipmentData.type == '调光灯') { equipmentData.status = res.on } _this.setData({ equipmentList }) }) } }, // 选择情景 selectScene(e) { console.log('selectScene', e); let _this = this let obj = e.currentTarget.dataset.obj let sceneList = _this.data.sceneList sceneList = sceneList.map(item => { if (item.id == obj.id) { item.isSelect = !item.isSelect if (item.isSelect) { callApiByPanelIdRq({ id: item.id }).then(res => { console.log('callApiByPanelIdRq', res); }) } } else { item.isSelect = false } return item }) _this.setData({ sceneList }) }, // 灯控 lampCall(e) { console.log('lampCall', e); let _this = this let id = e.currentTarget.dataset.obj.id let equipmentList = _this.data.equipmentList let equipmentData = equipmentList.find(item => item.id == id) equipmentData.status = !equipmentData.status _this.setData({ equipmentList }) // 调用设备接口 _this.callApiByDevice({ "deviceId": equipmentData.id, "actionArg": equipmentData.status, }) }, // 窗帘 curtainSwitch(e) { console.log('curtainSwitch', e); let _this = this let id = e.currentTarget.dataset.obj.id let status = e.currentTarget.dataset.status let equipmentList = _this.data.equipmentList let equipmentData = equipmentList.find(item => item.id == id) equipmentData.status = status _this.setData({ equipmentList }) // 调用设备接口 _this.callApiByDevice({ "deviceId": equipmentData.id, "coverType": equipmentData.status, }) }, // 雾化玻璃 glassSwitch(e) { console.log('glassSwitch', e); let _this = this let id = e.currentTarget.dataset.obj.id let equipmentList = _this.data.equipmentList let equipmentData = equipmentList.find(item => item.id == id) equipmentData.status = !equipmentData.status _this.setData({ equipmentList }) // 调用设备接口 _this.callApiByDevice({ "deviceId": equipmentData.id, "actionArg": equipmentData.status, }) }, // 调光灯 dimmingSwitch(e) { console.log('dimmingSwitch', e); let _this = this let id = e.currentTarget.dataset.obj.id let equipmentList = _this.data.equipmentList let equipmentData = equipmentList.find(item => item.id == id) equipmentData.status = !equipmentData.status _this.setData({ equipmentList }) // 调用设备接口 _this.callApiByDevice({ "deviceId": equipmentData.id, "actionArg": equipmentData.status, }) }, // 插座开关 socketSwitch(e) { console.log('socketSwitch', e); let _this = this let id = e.currentTarget.dataset.obj.id let equipmentList = _this.data.equipmentList let equipmentData = equipmentList.find(item => item.id == id) equipmentData.status = !equipmentData.status _this.setData({ equipmentList }) // 调用设备接口 _this.callApiByDevice({ "deviceId": equipmentData.id, "actionArg": equipmentData.status, }) }, // 开门 openLockDoor() { let _this = this let lockDoor = _this.data.lockDoor // 调用设备接口 callApiByDeviceIdRq({ "deviceId": lockDoor.id, }).then(res => { console.log('callApiByDeviceIdRq', res); if(res.code == 0){ app.vantNotifySuccess(Notify, res.msg) }else{ app.vantNotifyErr(Notify, res.msg) } }) }, //调用开门控制器 openControlDoor(){ console.log(11111); let _this = this let controlDoor = _this.data.controlDoor callApiByDeviceIdRq({ "deviceId": controlDoor.id, }).then(res => { console.log('callApiByDeviceIdRq', res); if(res.code == 0){ app.vantNotifySuccess(Notify, res.msg) }else{ app.vantNotifyErr(Notify, res.msg) } }) }, // 调用设备接口 callApiByDevice(data) { callApiByDeviceIdRq(data).then(res => { console.log('callApiByDeviceIdRq', res); }) }, // 初始化socket initSocket() { let _this = this let socketTask = wx.connectSocket({ url: app.socketUrl, header: { 'content-type': 'application/json' } }) socketTask.onMessage(res => { // console.log('onMessage data', res.data); console.log('onMessage data', JSON.parse(res.data)); let equipmentList = _this.data.equipmentList; // 推送数据 let sendData = JSON.parse(res.data); // 推送内容 let pushMsg = sendData.pushMsg; // 设备类型 let type = pushMsg.type // 推送类型 let pushMsgType = sendData.pushMsgType // if (type == 'KONKE_ZIGBEE_CHOPIN_LIGHT_PROJECT') { // 灯控面板、雾化玻璃 let id = pushMsg.id let on = pushMsg.status.on // true 开 false 关 let equipmentData = equipmentList.find(item => item.equipmentNum == id) if (equipmentData) { equipmentData.status = on } } else if (type == 'KONKE_ZIGBEE_Z3S_GALAXY_DIMMER_LIGHT') { // 调光灯 let id = pushMsg.id let on = pushMsg.status.on // true 开 false 关 let brightness = pushMsg.status.brightness // 亮度 [1,100] let whiteBri = pushMsg.status.whiteBri // 白光亮度 [1,100] let colourTemperature = pushMsg.status.colourTemperature // 色温[1,100] // let equipmentData = equipmentList.find(item => item.equipmentNum == id) if (equipmentData) { equipmentData.status = on } } else if (type == 'KONKE_ZIGBEE_CHOPIN_CURTAIN_CUSTOM') { // 窗帘 let id = pushMsg.id let MotorStatus = pushMsg.status.MotorStatus // OPEN 开 、CLOSE 关、 STOP 暂停 let equipmentData = equipmentList.find(item => item.equipmentNum == id) equipmentData.status = MotorStatus } else if (type == 'KONKE_ZIGBEE_CHOPIN_10A_SOCKET') { // 插座 let id = pushMsg.id let on = pushMsg.status.on // on 开关状态 true开 false关 let equipmentData = equipmentList.find(item => item.equipmentNum == id) equipmentData.status = on } else if (type == 'KONKE_ZIGBEE_KIT_TEMPSENSOR') { // 温度 let id = pushMsg.id let num = pushMsg.status.num } else if (type == 'KONKE_ZIGBEE_BANGDE_ILLUMSENSOR') { // 光照亮度 let id = pushMsg.id let num = pushMsg.status.num } else if (type == 'KONKE_ZIGBEE_KIT_HUMISENSOR') { // 湿度 let id = pushMsg.id let num = pushMsg.status.num } // 情景面板 if (pushMsgType == 'ShortcutPanelActivedEvent') { console.log('ShortcutPanelActivedEvent', sendData); } // 赋值 _this.setData({ equipmentList }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { let _this = this // 初始化socket _this.initSocket() }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })