const app = getApp() 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 != '门锁') let lockDoor = res.data.find(item => item.type == '门锁') _this.setData({ 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 == '门锁') { 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 // 调用设备接口 _this.callApiByDevice({ "deviceId": lockDoor.id, }) }, // 调用设备接口 callApiByDevice(data) { callApiByDeviceIdRq(data).then(res => { console.log('callApiByDeviceIdRq', res); }) }, // 初始化socket initSocket() { let socketTask = wx.connectSocket({ url: 'ws:///222.184.49.22:8081/websocket-server', header: { 'content-type': 'application/json' } }) socketTask.onMessage(res=>{ console.log('onMessage' , res); }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { let _this = this // 初始化socket _this.initSocket() }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })