var layer;
var timer1;
var timer2;
var screen = true;
var pageNo = 1;
var pageSize = 10;
var pageTotal = 1;
var inoutData = {};
var weightData = {};
var mediaAddr = camera.mediaAddr;
$(function() {
layui.use([ 'layer', 'laydate', 'form' ], function() {
layer = layui.layer;
// 初始页面
init();
$("body").dblclick(function() {
if (screen) {
requestFullScreen();
} else {
exitFullscreen();
}
});
});
});
function init() {
// 初始背景效果
initBg();
//标语
initDicSlogan();
//气象站信息
initWeather();
//时间
initTime();
// clearInterval(timer1);
// clearInterval(timer2);
//定时换页
timing();
//定时刷新视频
timingVideo();
// 初始化WebSocket
initWS(deptId, bizType, bizTag, userId);
initInoutData();
};
// socket信息返回處理
function socketOnMessage(pocket) {
console.log(pocket);
if (pocket.bizId == "slogan") {
var data = pocket.data;
dicSlogan = data;
initDicSlogan();
}
if (pocket.bizId == "weather") {
weatherInfo = pocket.data;
initWeather()
}
if (pocket.bizId == "IN_OUT_SUMMARY") {
//对数据进行过滤,只要入库且处于登记、称重和化验状态的数据
inoutData = filter(pocket.data.curList);
renderinoutData(inoutData,pageNo);
}
if (pocket.bizId == "WEIGHT_FULL") {
weightData = pocket.data;
renderweightData(weightData);
}
};
//过滤出入库状态为登记、满车称重和化验的数据
function filter(allData) {
var partData = [];
if(allData.length>0){
for (var i = 0; i < allData.length; i++) {
//只显示入库信息
if(allData[i].type === "IN" ) {
if(allData[i].progress==="WEIGHT_FULL" || allData[i].progress==="CHECK"){
partData.push(allData[i]);
}
}
}
}
return partData;
}
//定时换页
function timing() {
timer1 = setInterval(function() {
pageNo++;
if (pageNo > pageTotal) {
pageNo = 1;
}
renderinoutData(inoutData,pageNo);
}, 15000);
}
//定时更新监控
function timingVideo() {
timer2 = setInterval(function() {
updateVideo();
}, 3600000);
}
function updateVideo() {
$("#video").html("");
var html = "";
html += "";
$("#video").append(html);
}
/**
* 时间等
*/
function initTime() {
setInterval(function() {
var now = new Date();
var time = now.toLocaleString('chinese', {
hour12 : false
});
$(".time-info").text(time);
}, 1000);
}
//入库列表
function renderinoutData(inoutData,pNo) {
// 先清空,在渲染
$("#inoutShowMainDiv").html("");
if (inoutData == null || inoutData.length <= 0){
return;
}
pageNo = pNo - 1;
// 计算总页数
pageTotal = inoutData.length / pageSize;
if (!(inoutData.length % pageSize == 0)) {
pageTotal++;
}
var html = "";
for (var i = pageNo * pageSize + 1; i <= inoutData.length; i++) {
html += "
" + "- "
+ (inoutData[i - 1].id == null ? "" : inoutData[i - 1].id.substring(6))
+ "
";
html += "- " +inoutData[i - 1].plateNum + "
";
html += "- " + dateFormatStr(inoutData[i - 1].registerTime) + "
";
html += "
" ;
if (i == ((pageNo + 1) * pageSize)) {
break;
}
}
$("#inoutShowMainDiv").html(html);
pageNo++;
}
/**
* 通知后台推送一次出入库数据
*/
function initInoutData(){
$.ajax({
type : "POST",
url : "../../basic/databoard/init-check-data",
dataType : "json",
contentType : "application/json;charset=UTF-8",
data : JSON.stringify({
"companyId" : companyId
}),
success : function() {
console.log("初始成功!");
},
error : function(error) {
console.log(error);
console.log("初始失败!");
}
});
}
//称重信息
function renderweightData(weightData) {
// 先清空,在渲染
$("#showIdAndPlateNum").html("");
var html = "";
html += "当前称重 单据号:"+weightData.checkId.substring(4)+" 车牌号:"+weightData.plateNum;
$("#showIdAndPlateNum").html(html);
}
//格式化时间
function dateFormatStr(time) {
if(time){
var d = new Date(time);
return dateFtt("hh:mm",d);
}
return "";
}
//标语
function initDicSlogan() {
if (dicSlogan) {
if (dicSlogan.color == "red") {
$("#sloganText").css({
color : "#DE2910"
});
} else {
$("#sloganText").css({
color : "#7ddfff"
});
}
$("#sloganText").text(dicSlogan.content);
}
}
//气象站信息
function initWeather() {
if (weatherInfo) {
// console.log(weatherInfo);
var wendu = '';
if(weatherInfo.temp){
wendu = weatherInfo.temp.replace("℃", "");
}
$("#weather_wendu").html("" + wendu + "℃");
var shidu = '';
if(weatherInfo.humidity){
shidu = weatherInfo.humidity.replace("%", "");
}
$("#weather_shidu").html("" + shidu + "%");
var tianqi = '';
if(weatherInfo.weather){
tianqi = weatherInfo.weather;
}
$("#weather_tianqi").html("" + tianqi + "");
var windSpeed = '';
if(weatherInfo.windSpeed){
windSpeed = weatherInfo.windSpeed;
}
$("#windSpeed").html("" + windSpeed + "");
var fengxiang = '';
if(weatherInfo.windDirection){
fengxiang = weatherInfo.windDirection;
}
$("#weather_fengxiang").html("" + fengxiang + "");
var time = '';
if(weatherInfo.updateTimeStr){
time = weatherInfo.updateTimeStr;
}
$("#weather_time").text("更新时间 : " + time);
}
}
//双击退出全屏
function exitFullscreen() {
var de = document;
if (de.exitFullscreen) {
de.exitFullscreen();
} else if (de.mozCancelFullScreen) {
de.mozCancelFullScreen();
} else if (de.webkitCancelFullScreen) {
de.webkitCancelFullScreen();
}
screen = true;
}
//双击进入全屏
function requestFullScreen() {
var de = document.documentElement;
if (de.requestFullscreen) {
de.requestFullscreen();
} else if (de.mozRequestFullScreen) {
de.mozRequestFullScreen();
} else if (de.webkitRequestFullScreen) {
de.webkitRequestFullScreen();
}
screen = false;
}