var targetStatus; var targetModel; var targetTemp; var deviceData; //空调控制 var data = { "interfaceId": "5403", "outId": "10403", "reqDateTime": new Date(), "tokenAuth": "", "data": { "deptId": "", "depotId": "", "type": "05", "passCode": "", "serId": "", "targetStatus": "", "targetModel": "", "targetTemp": "", "name": "" } }; //设备列表 - 空调 var data1 = { "interfaceId": "5401", "outId": "10401", "reqDateTime": new Date(), "tokenAuth": "", "data": { "deptId": "", "depotId": "", "type": "05", } }; function init() { var user = JSON.parse(localStorage.getItem('user')); var selectDeptId = JSON.parse(localStorage.getItem('selectDeptId')); url = user.url + "/api-phone/v35/gateway"; data.tokenAuth = user.tokenAuth; data.data.deptId = user.deptId; data1.tokenAuth = user.tokenAuth; data1.data.deptId = user.deptId; //获取从上一个页面传递的数据 var self = plus.webview.currentWebview(); data.data.depotId = self.depotId data1.data.depotId = self.depotId // depotType = self.depotType // depotName = self.depotName getDeviceList(); } //获取设备列表(空调) function getDeviceList() { mui.ajax(url, { type: "POST", dataType: "json", crossDomain: true, contentType: "application/json;charset=utf-8", data: JSON.stringify(data1), success: function(result) { if (result.code == "0000") { deviceData = result.data; renderDevice(); } else { mui.toast(result.msg); renderDevice(); } }, error: function() { mui.alert("系统繁忙,请重试!", "提示", ["确定"], function() {}, "div") } }) } //温控管理 function setTemp() { console.log(JSON.stringify(data.data)) mui.ajax(url, { type: "POST", dataType: "json", crossDomain: true, contentType: "application/json;charset=utf-8", data: JSON.stringify(data), success: function(result) { if (result.code == "0000") { mui.toast(result.msg); } else { mui.toast(result.msg); } }, error: function() { mui.alert("系统繁忙,请重试!", "提示", ["确定"], function() {}, "div") } }) } //渲染页面 function renderDevice() { var html = ''; if (deviceData) { var deviceList = deviceData.listDevice if (deviceList && deviceList.length > 0) { var frontList = []; var backList = []; var leftList = []; var rightList = []; $.each(deviceList, function(index, item) { if (item.location == '01') { frontList.push(item) } else if (item.location == '02') { backList.push(item) } else if (item.location == '03') { leftList.push(item) } else if (item.location == '04') { rightList.push(item) } }) if (frontList && frontList.length > 0) { html += '
仓库正面
' }) html += '' } if (backList && backList.length > 0) { html += '
仓库反面
' }) html += '' } if (leftList && leftList.length > 0) { html += '
仓库左侧面
' }) html += '' } if (rightList && rightList.length > 0) { html += '
仓库右侧面
' }) html += '' } } else { html += '
暂无数据
'; } } else { html += '
暂无数据
'; } $("#recordList").html(html); } var slider = mui(".mui-slider"); slider.slider({ interval: 3000 }); $('#range').on('input propertychange', function() { //实时事件(获取每个变化的值) var val = $('#range').val(); $('.subbar').css({ width: ((val - 9) / 16) * 100 + '%' }) }) //监听开关状态 document.getElementById("vibrationSwitch").addEventListener("toggle", function(event) { if (event.detail.isActive) { targetStatus = 'OPEN'; data.data.targetStatus = targetStatus; console.log("你启动了开关"); } else { targetStatus = 'CLOSE'; data.data.targetStatus = targetStatus; console.log("你关闭了开关"); } }) //空调操作 mui(".mui-scroll-wrapper").on("tap", ".m-tf ul li .con", function() { targetStatus = this.getAttribute("targetStatus") data.data.targetStatus = targetStatus var html = ''; if (targetStatus == 'OPEN') { document.getElementById("vibrationSwitch").classList.add('mui-active'); $('.mui-switch-handle').css("-webkit-transform", "translate3d(16px, 0, 0)"); console.log("开") } else if (targetStatus == 'CLOSE') { document.getElementById("vibrationSwitch").classList.remove('mui-active'); $('.mui-switch-handle').css("-webkit-transform", "translate3d(0, 0, 0)"); console.log("关") } var passCode = this.getAttribute("passCode"); var serId = this.getAttribute("serId"); var name = this.getAttribute("name"); data.data.passCode = passCode; data.data.serId = serId; data.data.name = name; $('.m-pop').css('display', 'flex'); }); //空调模式选择 mui(".m-pop").on("tap", ".inner .group .val", function() { var modelPicker = new mui.PopPicker(); modelPicker.setData([{ value: "HEATING", text: "制热" }, { value: "01-REFRIGERATION", text: "制冷" }, { value: "02-AERATION", text: "通风" }, { value: "DEHU", text: "除湿" }]) modelPicker.show(function(selectItems) { targetModel = selectItems[0].value; document.getElementById("targetModel").innerText = selectItems[0].text }) }); //确定按键,把选的参数传给后端 mui(".m-pop").on("tap", ".inner .confirm", function() { var id = this.getAttribute("id"); targetTemp = document.getElementById("range").value; data.data.targetModel = targetModel; data.data.targetTemp = targetTemp setTemp(); closePop(); document.getElementById("range").value = 17 $('.subbar').css({ width: ((17 - 9) / 16) * 100 + '%' }) }); //关闭弹窗 function closePop() { $(".m-pop").css('display', 'none'); } $('.pop-bg,.m-pop .close').click(function(e) { e.stopPropagation(); $('.m-pop').fadeOut(); }); mui('.mui-scroll-wrapper').scroll({ indicators: false, //是否显示滚动条 deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏 bounce: false, //是否启用回弹 deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006 });