var deviceData;
var deptId; //库区编码
var depotId; //仓库编码
var frontList = []; //仓库正面设备列表
var backList = []; //仓库反面设备列表
var leftList = []; //仓库左侧面设备列表
var rightList = []; //仓库右侧面设备列表
var deviceDetail = {
"passCode": "",
"serId": "",
"location": "",
"type": "",
"status": ""
}
//设备控制
var data = {
"interfaceId": "5402",
"outId": "10402",
"reqDateTime": new Date(),
"tokenAuth": "",
"data": [],
// {
// "deptId": "",
// "depotId": "",
// "type": "",
// "passCode": "",
// "serId": "",
// "targetStatus": ""
// }
};
//设备列表
var data1 = {
"interfaceId": "5401",
"outId": "10401",
"reqDateTime": new Date(),
"tokenAuth": "",
"data": {
"deptId": "",
"depotId": "",
"type": "01", //风窗
"type1": "02", //轴流风窗
"type2": "04", //环流风机
"type3": "0B", //通风口
"type4": "0C", //混流风口
"type5": "0D", //加压风机
}
};
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;
deptId = user.deptId;
//获取从上一个页面传递的数据
var self = plus.webview.currentWebview();
data.data.depotId = self.depotId
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 renderDevice() {
var html = '';
if (deviceData) {
var deviceList = deviceData.listDevice;
if (deviceList && deviceList.length > 0) {
$.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 += '
仓库正面
';
$.each(frontList, function(index, item) {
if (item.type == '01') { //风窗
html += '';
html += '
'
html += '
' + item
.name +
'
'
html += '
'
} else if (item.type == '02') { //轴流风机
html += '';
html += '
'
html += '
' + item
.name +
'
'
html += '
'
} else if (item.type == '04') { //环流风机
html += '';
html += '
'
html += '
' + item
.name + '
'
html += '
'
} else if (item.type == '0B') { //通风口
html += '';
html += '
'
html += '
'
html += '
'
} else if (item.type == '0C') { //混流风机
html += '
';
html += '
'
html += '
' + item
.name + '
'
html += '
'
} else if (item.type == '0D') { //加压风机
html += '
';
html += '
'
html += '
' + item
.name + '
'
html += '
'
}
})
html += '
'
} else if (backList && backList.length > 0) { //仓库反面
html += '仓库反面
';
$.each(backList, function(index, item) {
if (item.type == '01') { //风窗
html += '';
html += '
'
html += '
' + item
.name +
'
'
html += '
'
} else if (item.type == '02') { //轴流风机
html += '';
html += '
'
html += '
' + item
.name +
'
'
html += '
'
} else if (item.type == '04') { //环流风机
html += '';
html += '
'
html += '
' + item
.name + '
'
html += '
'
} else if (item.type == '0B') { //通风口
html += '';
html += '
'
html += '
'
html += '
'
} else if (item.type == '0C') { //混流风机
html += '
';
html += '
'
html += '
' + item
.name + '
'
html += '
'
} else if (item.type == '0D') { //加压风机
html += '
';
html += '
'
html += '
' + item
.name + '
'
html += '
'
}
})
html += '
'
} else if (leftList && leftList.length > 0) { //仓库左侧面
html += '仓库左侧面
';
$.each(leftList, function(index, item) {
if (item.type == '01') { //风窗
html += '';
html += '
'
html += '
' + item
.name +
'
'
html += '
'
} else if (item.type == '02') { //轴流风机
html += '';
html += '
'
html += '
' + item
.name +
'
'
html += '
'
} else if (item.type == '04') { //环流风机
html += '';
html += '
'
html += '
' + item
.name + '
'
html += '
'
} else if (item.type == '0B') { //通风口
html += '';
html += '
'
html += '
'
html += '
'
} else if (item.type == '0C') { //混流风机
html += '
';
html += '
'
html += '
' + item
.name + '
'
html += '
'
} else if (item.type == '0D') { //加压风机
html += '
';
html += '
'
html += '
' + item
.name + '
'
html += '
'
}
})
html += '
'
} else if (rightList && rightList.length > 0) { //仓库右侧面
html += '仓库右侧面
';
$.each(rightList, function(index, item) {
if (item.type == '01') { //风窗
html += '';
html += '
'
html += '
' + item
.name +
'
'
html += '
'
} else if (item.type == '02') { //轴流风机
html += '';
html += '
'
html += '
' + item
.name +
'
'
html += '
'
} else if (item.type == '04') { //环流风机
html += '';
html += '
'
html += '
' + item
.name + '
'
html += '
'
} else if (item.type == '0B') { //通风口
html += '';
html += '
'
html += '
'
html += '
'
} else if (item.type == '0C') { //混流风机
html += '
';
html += '
'
html += '
' + item
.name + '
'
html += '
'
} else if (item.type == '0D') { //加压风机
html += '
';
html += '
'
html += '
' + item
.name + '
'
html += '
'
}
})
html += '
'
}
} else {
html +=
'';
}
} else {
html +=
'';
}
$("#recordList").html(html);
}
//设备操作请求
function toControlDevice() {
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") {
window.setTimeout(function() {
renderDevice();
}, 200)
} else {
mui.alert(result.msg, "提示", ["确定"], function() {}, "div")
}
},
error: function() {
mui.alert("系统繁忙,请重试!", "提示", ["确定"], function() {}, "div")
}
})
}
mui('.mui-scroll-wrapper').scroll({
indicators: false, //是否显示滚动条
deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
bounce: false, //是否启用回弹
deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006
});
//风窗和通风口弹窗
mui(".mui-scroll-wrapper").on("tap", ".m-tf ul li .chuangkou", function() {
deviceDetail.passCode = this.getAttribute("passCode");
deviceDetail.serId = this.getAttribute("serId");
deviceDetail.location = this.getAttribute("location");
deviceDetail.type = this.getAttribute("type")
deviceDetail.status = this.getAttribute("status")
var name = this.getAttribute("name");
document.getElementById("Fname").innerText = name
$('#win_chuangkou').css('display', 'flex');
});
//环流弹窗
mui(".mui-scroll-wrapper").on("tap", ".m-tf ul li .huanliu", function() {
deviceDetail.passCode = this.getAttribute("passCode");
deviceDetail.serId = this.getAttribute("serId");
deviceDetail.location = this.getAttribute("location");
deviceDetail.status = this.getAttribute("status")
deviceDetail.type = '04'
var name = this.getAttribute("name");
document.getElementById("huanliuName").innerText = name
$('#win_huanliu').css('display', 'flex');
});
//混流弹窗
mui(".mui-scroll-wrapper").on("tap", ".m-tf ul li .hunliu", function() {
deviceDetail.passCode = this.getAttribute("passCode");
deviceDetail.serId = this.getAttribute("serId");
deviceDetail.location = this.getAttribute("location");
deviceDetail.status = this.getAttribute("status")
deviceDetail.type = "0C"
var name = this.getAttribute("name");
document.getElementById("hunliuName").innerText = name
$('#win_hunliu').css('display', 'flex');
});
//轴流弹窗
mui(".mui-scroll-wrapper").on("tap", ".m-tf ul li .zhouliu", function() {
deviceDetail.passCode = this.getAttribute("passCode");
deviceDetail.serId = this.getAttribute("serId");
deviceDetail.location = this.getAttribute("location");
deviceDetail.status = this.getAttribute("status")
deviceDetail.type = "02"
var name = this.getAttribute("name");
document.getElementById("zhouliuName").innerText = name
$('#win_zhouliu').css('display', 'flex');
});
//加压风机弹窗
mui(".mui-scroll-wrapper").on("tap", ".m-tf ul li .jiaya", function() {
deviceDetail.passCode = this.getAttribute("passCode");
deviceDetail.serId = this.getAttribute("serId");
deviceDetail.location = this.getAttribute("location");
deviceDetail.status = this.getAttribute("status");
deviceDetail.type = "0D"
var name = this.getAttribute("name");
document.getElementById("zhouliuName").innerText = name
$('#win_jiaya').css('display', 'flex');
});
//设备操作
mui(".m-pop").on("tap", ".inner a", function() {
//所进行的操作
var targetStatus = this.getAttribute("targetStatus");
//如果是轴流风机,先根据风机状态判断风机操作是否可以执行
if (deviceDetail.type == '02') {
//风机状态为风机开风窗开,即F_OPEN或者F_OPEN_F时,不能执行关风窗操作
if ((deviceDetail.status == 'F_OPEN' || deviceDetail.status == 'F_OPEN_F') && targetStatus == 'CLOSE') {
mui.alert("此风机正在运行,不能执行关闭风窗操作!", "提示", ["确定"], function() {}, "div")
return;
}
//风机状态为风机开风窗开,即F_OPEN或者F_OPEN_F时,不能执行风窗全关操作
if ((deviceDetail.status == 'F_OPEN' || deviceDetail.status == 'F_OPEN_F') && targetStatus ==
'W_CLOSE_ALL') {
mui.alert("此风机正在运行,不能执行风窗全关操作!", "提示", ["确定"], function() {}, "div")
return;
}
//风机状态为风机关风窗关,即W_CLOSE时,不能执行开风机操作
if (deviceDetail.status == 'W_CLOSE' && (targetStatus == 'F_CLOSE' || targetStatus == 'F_OPEN')) {
mui.alert("此风机的风窗关闭中,不能执行风机操作!", "提示", ["确定"], function() {}, "div")
return;
}
}
//如果是混流风机,先判断风机操作是否可以执行
if (deviceDetail.type == '0C') {
//风机状态为风机开风口开,即F_OPEN时,不能执行关风口操作
if ((deviceDetail.status == 'F_OPEN_F' || deviceDetail.status == 'F_OPEN') && targetStatus == 'CLOSE') {
mui.alert("此风机正在运行,不能执行关闭风口操作!", "提示", ["确定"], function() {}, "div")
return;
}
//风机状态为风机开风窗开,即F_OPEN时,不能执行风窗全关操作
if ((deviceDetail.status == 'F_OPEN_F' || deviceDetail.status == 'F_OPEN') && targetStatus ==
'W_CLOSE_ALL') {
mui.alert("此风机正在运行,不能执行风口全关操作!", "提示", ["确定"], function() {}, "div")
return;
}
//风机状态为风机关风窗关,即W_CLOSE时,不能执行开风窗操作
if (deviceDetail.status == 'W_CLOSE' && (targetStatus == 'F_CLOSE' || targetStatus == 'F_OPEN' ||
targetStatus == 'F_OPEN_F')) {
mui.alert("此风机的风口关闭中,不能执行风机操作!", "提示", ["确定"], function() {}, "div")
return;
}
//风机状态为风机开风窗开,即F_OPEN时,不能执行反转操作
if (deviceDetail.status == 'F_OPEN' && targetStatus == 'F_OPEN_F') {
mui.alert("此风机正转状态,不能执行反转操作!", "提示", ["确定"], function() {}, "div")
return;
}
//风机状态为风机开风窗开,即F_OPEN_F时,不能执行正转操作
if (deviceDetail.status == 'F_OPEN_F' && targetStatus == 'F_OPEN') {
mui.alert("此风机反转状态,不能执行正转操作!", "提示", ["确定"], function() {}, "div")
return;
}
}
//判断是否是批量
var batchTag = false;
if (targetStatus == 'W_OPEN_ALL') {
targetStatus = 'OPEN';
batchTag = true;
}
if (targetStatus == 'W_CLOSE_ALL') {
targetStatus = 'CLOSE';
batchTag = true;
}
if (targetStatus == 'OPEN_ALL') {
targetStatus = 'OPEN';
batchTag = true;
}
if (targetStatus == 'CLOSE_ALL') {
targetStatus = 'CLOSE';
batchTag = true;
}
//仓库前面
if (deviceDetail.location == "front") {
//参数清空
data.data = [];
if (batchTag) { //批量操作
$.each(frontList, function(index, item) {
if (deviceDetail.type == item.type) {
data.data.push({
"deptId": deptId,
"depotId": depotId,
"passCode": item.passCode,
"serId": item.serId,
"type": item.type,
"targetStatus": targetStatus
})
}
})
} else { //单设备操作
data.data.push({
"deptId": deptId,
"depotId": depotId,
"passCode": deviceDetail.passCode,
"serId": deviceDetail.serId,
"type": deviceDetail.type,
"targetStatus": targetStatus
})
}
} else if (deviceDetail.location == "back") {
//参数清空
data.data = [];
if (batchTag) { //批量操作
$.each(backList, function(index, item) {
if (deviceDetail.type == item.type) {
data.data.push({
"deptId": deptId,
"depotId": depotId,
"passCode": item.passCode,
"serId": item.serId,
"type": item.type,
"targetStatus": targetStatus
})
}
})
} else { //单设备操作
data.data.push({
"deptId": deptId,
"depotId": depotId,
"passCode": deviceDetail.passCode,
"serId": deviceDetail.serId,
"type": deviceDetail.type,
"targetStatus": targetStatus
})
}
} else if (deviceDetail.location == "left") {
//参数清空
data.data = [];
if (batchTag) { //批量操作
$.each(leftList, function(index, item) {
if (deviceDetail.type == item.type) {
data.data.push({
"deptId": deptId,
"depotId": depotId,
"passCode": item.passCode,
"serId": item.serId,
"type": item.type,
"targetStatus": targetStatus
})
}
})
} else { //单设备操作
data.data.push({
"deptId": deptId,
"depotId": depotId,
"passCode": deviceDetail.passCode,
"serId": deviceDetail.serId,
"type": deviceDetail.type,
"targetStatus": targetStatus
})
}
} else if (deviceDetail.location == "right") {
//参数清空
data.data = [];
if (batchTag) { //批量操作
$.each(rightList, function(index, item) {
if (deviceDetail.type == item.type) {
data.data.push({
"deptId": deptId,
"depotId": depotId,
"passCode": item.passCode,
"serId": item.serId,
"type": item.type,
"targetStatus": targetStatus
})
}
})
} else { //单设备操作
data.data.push({
"deptId": deptId,
"depotId": depotId,
"passCode": deviceDetail.passCode,
"serId": deviceDetail.serId,
"type": deviceDetail.type,
"targetStatus": targetStatus
})
}
}
//发送操作请求
toControlDevice();
closePop();
});
//关闭弹窗
function closePop() {
$(".m-pop").css('display', 'none');
}
$('.pop-bg,.m-pop .close').click(function(e) {
e.stopPropagation();
$('.m-pop').fadeOut();
});
var slider = mui(".mui-slider");
slider.slider({
interval: 3000
});