微信小程序之房间管理(设备开关控制),根据房间标识,为每个房间赋值(1,开;2,关)

时间:2020-02-13 17:22:03   收藏:0   阅读:100
  1    var t, c;
  2     //定位当前家庭
  3     for (var i = 0; i < homeList.length; i++) {
  4       if (homeList[i].homeId == homeNumberr) {
  5         t = homeList[i];
  6       }
  7     }
  8   var setion=[];
  9         //去重,并把当前下标改为所对应的数值
 10         t.modelNameAll.forEach((vve, veIndex) => {
 11           if (vve.modelequimentDatalist.length > 0) {
 12             vve.modelequimentDatalist.forEach((v, vIndex) => {
 13               vve.modelequimentlist.forEach((vv, vvIndex) => {
 14                 if (v.srcAddr == vv.srcAddr && v.channel == vv.channel) {
 15                   setion.push(vv);
 16                   if (vv.length == 0) { } else {
 17                     vve.modelequimentlist.splice(vvIndex, 1);
 18                     wx.setStorageSync(‘homeList‘, homeList);
 19                   }
 20                 }
 21               })
 22             })
 23           }
 24         })
 25         t.modelNameAll.forEach((vve, veIndex) => {
 26           vve.modelequimentlist.forEach((vv, vvIndex) => {
 27             vv.modeOn.forEach((vvv, vvvIndex) => {
 28               if (vvv == 0) {
 29                 if (veIndex == vvvIndex) {
 30                   vv.modeOn[veIndex] = 2;
 31                   vv.modeOff[veIndex] = 2;
 32                   wx.setStorageSync(‘homeList‘, homeList);
 33                 }}else{
 34               }
 35              
 36             })
 37           })
 38         })
 39       }
 40 //数据源(也可以自定义数据)
 41 //已经操作的数据存入modelequipmentDatalist
 42 var selectEquipment_success = [...new Set(selectEquipment)];
 43 //拆分modeOn与modeOff
 44 var result = [],
 45 result_Modeon = [];
 46 //var result_modeOff = [];
 47 let newArr, len = 0;
 48 for (var a = 0; a < selectEquipment_success.length; a++) {
 49 for (var i = 0; i < selectEquipment_success[a].modeOn.length; i++) {
 50 var temp = [];
 51 var temp_modeOff = [];
 52 for (var t = 0; t < selectEquipment_success[a].modeOn.length; t++) {
 53 temp.push(t == i ? selectEquipment_success[a].modeOn[i] : 0);
 54 temp_modeOff.push(t == i ? selectEquipment_success[a].modeOff[i] : 0);
 55 if (t == i) {
 56 var obj = {};
 57 obj.id = len++;
 58 obj.srcAddr = selectEquipment_success[a].srcAddr;
 59 obj.name = selectEquipment_success[a].name;
 60 obj.images = selectEquipment_success[a].images;
 61 obj.channel = selectEquipment_success[a].channel;
 62 obj.switchChecked = selectEquipment_success[a].switchChecked_1;
 63 obj.state = selectEquipment_success[a].state;
 64 obj.selectFalse = selectEquipment_success[a].selectFalse;
 65 obj.selectTrue = selectEquipment_success[a].selectTrue;
 66 obj.checked = selectEquipment_success[a].checked;
 67 temp.map((t) => {
 68 if (t == 0) {} else {
 69 obj.modeOn = temp;
 70 obj.modeOff = temp_modeOff;
 71 }
 72 })
 73 for (var z = 0; z < temp.length; z++) {
 74 if (temp[z] !== 0) {
 75 obj.modeOnn = temp[z];
 76 obj.modeOfff = temp_modeOff[z];
 77 }
 78 }
 79 result_Modeon.push(obj);
 80 }
 81 }
 82 //result.push(temp);
 83 //result_modeOff.push(temp_modeOff);
 84 }
 85 }
 86 //为每个房间匹配相应的数据项(modelNameAll数据格式["id":0,modelequimentDatalist:[],"selectiLall":false])
 87 var ssId = wx.getStorageSync(‘sId‘);
 88 result_Modeon.map((a, aIndex) => {
 89 if (a.modeOn == undefined) {} else {
 90 a.modeOn.map((aa, aaIndex) => {
 91 e.modelNameAll.map((h, hIndex) => {
 92 if (aa !== 0 && aaIndex == hIndex) {
 93 if (sId == ssId) {
 94 h.modelequimentDatalist.push(a);
 95 }
 96 }
 97 })
 98 })
 99 }
100 })

 

技术图片

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!