const {getloop,getDevice} = require ('../api/device') // 分组下拉 function Groupdrop() { var group = wx.getStorageSync('group') var groups = [] for (let i = 0; i < group.length; i++) { groups.push(group[i].groupName) } //改变分组下标 if (wx.getStorageSync('groupName') != '') { let GroupName = groups for (let n = 0; n < GroupName.length; n++) { if (GroupName[n] == wx.getStorageSync('groupName')) { return {n,groups} } } } else { wx.setStorageSync('groupName', groups[0]) } } //设备下拉 function Devicedrop(groupName, groupIndex) { var group = wx.getStorageSync('group') var device = [] for (let j = 0; j < group.length; j++) { if (groupName[groupIndex] == group[j].groupName) { if (group[j].devices != null && group[j].devices.length != 0) { for (let p = 0; p < group[j].devices.length; p++) { device.push(group[j].devices[p].deviceName) } if (wx.getStorageSync('deviceName') != '') { for (let m = 0; m < device.length; m++) { if (device[m] == wx.getStorageSync('deviceName')) { return {m,device} } } } else { wx.setStorageSync('deviceName', device[0]) return {device} } } else { return '离线' } } } } //设备id,key function deviceMessage(groupNames, deviceNames) { var group = wx.getStorageSync('group') for (let d = 0; d < group.length; d++) { if (groupNames == group[d].groupName) { var id = group[d].id for (let g = 0; g < group[d].devices.length; g++) { if (deviceNames == group[d].devices[g].deviceName) { var Device = group[d].devices[g].id //旧设备 if (group[d].devices[g].module == 0) { var loopnum = group[d].devices[g].circuits var deviceId = group[d].devices[g].deviceId var deviceKey = group[d].devices[g].deviceKey var modules = group[d].devices[g].module return {loopnum,deviceId,deviceKey,modules,id,Device} //新设备 } else { var loopNum = group[d].devices[g].circuits var loopnum = loopNum.split(',') var modules = group[d].devices[g].module var ID = group[d].devices[g].deviceId return {id,Device,loopnum,modules,ID} } } } } } } //旧设备信息 function deviceinfo(data,loopnum,arr,brr,time,state,state1, fixed1,fixed2,fixed3,fixed4,address, radio1,radio2,radio3,index,indexs) { //以下为回路 for (let i = 1; i < data.length; i++) { //回路数量 if (data[i].id == "RelayCount") { var num = data[i].current_value num = parseInt(num) loopnum = loopnum.split(',') var num1 = [] for (let a = 0; a < num; a++) { num1.push(loopnum[a]) } num1.push('所有回路') var crr = num1 } //时控一开时间 else if (data[i].id == "R1_DayOpenTime1") { var timeopen1 = data[i].current_value } //时控一关时间 else if (data[i].id == "R1_DayCloseTime1") { var timeshut1 = data[i].current_value } //时控二开时间 else if (data[i].id == "R1_DayOpenTime2") { var timeopen2 = data[i].current_value } //时控二关时间 else if (data[i].id == "R1_DayCloseTime2") { var timeshut2 = data[i].current_value } //日期调控 else if (data[i].id == "R1_Week") { var weeks = data[i].current_value var recorddate = weeks weeks = parseInt(weeks) weeks = weeks.toString(2) weeks = weeks + '' } //功能1 else if (data[i].id == "R1_FunctionStatus1") { var Function1 = data[i].current_value var par = parseInt(Function1) par = par.toString(2) par = par + '' switch (par.length) { case 1: par = '00000' + par break; case 2: par = '0000' + par break; case 3: par = '000' + par break; case 4: par = '00' + par break; case 5: par = '0' + par break; default: par = par } } //功能二 else if (data[i].id == "R1_FunctionStatus2") { var Function2 = data[i].current_value var qur = parseInt(Function2) qur = qur.toString(2) qur = qur + '' switch (qur.length) { case 1: qur = '000' + qur break; case 2: qur = '00' + qur break; case 3: qur = '0' + qur break; case 4: qur = qur break; } } //报警 else if (data[i].id == "R1_RelayStatus") { var police = data[i].current_value } //光控开 else if (data[i].id == "R1_LcOn") { var Lightcontrolopen = data[i].current_value for (let i = 0; i < 100; i++) { arr[i] = i } Lightcontrolopen = parseInt(Lightcontrolopen) var index = Lightcontrolopen } //光控关 else if (data[i].id == "R1_LcOff") { var Lightcontrolshut = data[i].current_value for (let j = 0; j < 100; j++) { brr[j] = j } Lightcontrolshut = parseInt(Lightcontrolshut) var indexs = Lightcontrolshut } } //时控一开时间 var timeOpen1 switch (timeopen1.length) { case 1: timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0, 1) break; case 2: timeOpen1 = '00' + ':' + timeopen1.substring(0, 2) break; case 3: var timeOpen1 = '0' + timeopen1.substring(0, 1) + ':' + timeopen1.substring(1, 3) break; case 4: var timeOpen1 = timeopen1.substring(0, 2) + ':' + timeopen1.substring(2, 4) break; } //时控一关时间 var timeShut1 switch (timeshut1.length) { case 1: timeShut1 = '00' + ':' + '0' + timeshut1.substring(0, 1) break; case 2: timeShut1 = '00' + ':' + timeshut1.substring(0, 2) break; case 3: var timeShut1 = '0' + timeshut1.substring(0, 1) + ':' + timeshut1.substring(1, 3) break; case 4: var timeShut1 = timeshut1.substring(0, 2) + ':' + timeshut1.substring(2, 4) break; } //时控二开时间 var timeOpen2 switch (timeopen2.length) { case 1: timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0, 1) break; case 2: timeOpen2 = '00' + ':' + timeopen2.substring(0, 2) break; case 3: var timeOpen2 = '0' + timeopen2.substring(0, 1) + ':' + timeopen2.substring(1, 3) break; case 4: var timeOpen2 = timeopen2.substring(0, 2) + ':' + timeopen2.substring(2, 4) break; } //时控二关时间 var timeShut2 switch (timeshut2.length) { case 1: timeShut2 = '00' + ':' + '0' + timeshut2.substring(0, 1) break; case 2: timeShut2 = '00' + ':' + timeshut2.substring(0, 2) break; case 3: var timeShut2 = '0' + timeshut2.substring(0, 1) + ':' + timeshut2.substring(1, 3) break; case 4: var timeShut2 = timeshut2.substring(0, 2) + ':' + timeshut2.substring(2, 4) break; } //功能1 for (var i = 0; i < par.length; i++) { switch (par.substring(i, i + 1)) { case "0": switch (i) { case 0: state[3] = false break; case 1: state[2] = false break; case 2: fixed2 = "固定" break; case 3: fixed1 = "固定" break; case 4: state[1] = false break; case 5: state[0] = false break; } break; case "1": switch (i) { case 0: state[3] = true break; case 1: state[2] = true break; case 2: fixed2 = "经纬" break; case 3: fixed1 = "经纬" break; case 4: state[1] = true break; case 5: state[0] = true break; } break; } } //功能2 for (let j = 0; j < qur.length; j++) { switch (qur.substring(j, j + 1)) { case "0": switch (j) { case 0: fixed4 = "固定" break; case 1: fixed3 = "固定" break; case 2: state1[1] = false break; case 3: state1[0] = false break; } break; case "1": switch (j) { case 0: fixed4 = "经纬" break; case 1: fixed3 = "经纬" break; case 2: state1[1] = true break; case 3: state1[0] = true break; } break; } } //日期调控 if (weeks == '0') { for (let x = 0; x < weeks.length; x++) { address[x] = "/image/false.png" } } else { for (let i = 0; i < weeks.length; i++) { switch (weeks.substring(i, i + 1)) { case '0': address[weeks.length - i - 1] = "/image/false.png" break; case '1': address[weeks.length - i - 1] = "/image/true.png" break; } } } //报警状态 police = parseInt(police) police = police.toString(2) switch (police.length) { case 1: police = '000' + police break; case 2: police = '00' + police break; case 3: police = '0' + police break; default: police = police break; } if (police.substring(1, 2) == '0' && police.substring(0, 1) == '0') { radio1 = true } else if (police.substring(1, 2) == '1' && police.substring(0, 1) == '0') { radio2 = true } else if (police.substring(1, 2) == '0' && police.substring(0, 1) == '1') { radio3 = true } time[0] = timeOpen1 time[1] = timeShut1 time[2] = timeOpen2 time[3] = timeShut2 return {crr,recorddate,arr,brr,time,state,state1, fixed1,fixed2,fixed3,fixed4,address, radio1,radio2,radio3,index,indexs} } //新设备信息 function newDeviceinfo(Device,Group){ getDevice(Device,Group).then(res => { }) } //时间开关选择器(新设备) module.exports = { Groupdrop: Groupdrop, Devicedrop: Devicedrop, deviceMessage: deviceMessage, deviceinfo:deviceinfo, newDeviceinfo:newDeviceinfo }