var layer; var timer; var screen = true; var pageNo = 1; var pageSize = 15; var pageTotal = 1; var completePageNo = 1; var completePageSize = 6; var completePageTotal = 1; var inoutData = {}; var mapDepot = {}; $(function() { layui.use([ 'layer', 'laydate', 'form' ], function() { layer = layui.layer; // 初始页面 init(); $("body").dblclick(function() { if (screen) { requestFullScreen(); } else { exitFullscreen(); } }); }); }); function init() { // 初始背景效果 initBg(); initTime(); initDicSlogan(); initWeather(); //将仓库集合转map,供后面使用 depotListToMap(); clearInterval(timer); timing(); // 初始化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 = pocket.data; renderSumData(inoutData); renderinoutData(inoutData.curList,pageNo); renderinoutCompleteData(inoutData.complateList,completePageNo); } }; /** * 通知后台推送一次出入库数据 */ function initInoutData(){ $.ajax({ type : "POST", url : "../../basic/databoard/init-inout-data", dataType : "json", contentType : "application/json;charset=UTF-8", data : JSON.stringify({ "deptId" : deptId }), success : function() { console.log("初始成功!"); }, error : function(error) { console.log(error); console.log("初始失败!"); } }); } function timing() { timer = setInterval(function() { pageNo++; if (pageNo > pageTotal) { pageNo = 1; } renderinoutData(inoutData.curList,pageNo); completePageNo++; if (completePageNo > completePageTotal) { completePageNo = 1; } renderinoutCompleteData(inoutData.complateList,completePageNo); }, 15000); } /** * 渲染出入库统计信息 * @param sumData */ function renderSumData(sumData){ if(sumData){ $("#inCarNum").text((sumData.inSumNum != null ? sumData.inSumNum : 0)); $("#inCompleteCarNum").text((sumData.inComplateNum != null ? sumData.inComplateNum : 0)); $("#outCarNum").text((sumData.outSumNum != null ? sumData.outSumNum : 0)); $("#outCompleteCarNum").text((sumData.outComplateNum != null ? sumData.outComplateNum : 0)); $("#inPerDiv").animate({width:(sumData.perInComplate != null ? sumData.perInComplate : 0) + "%"},"normal"); $("#inPerSpan").text((sumData.perInComplate != null ? sumData.perInComplate : 0) + "%"); $("#outPerDiv").animate({width:(sumData.perOutComplate != null ? sumData.perOutComplate : 0) + "%"},"normal"); $("#outPerSpan").text((sumData.perOutComplate != null ? sumData.perOutComplate : 0) + "%"); } }; 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 += "
" + getInoutTypeName(inoutData[i - 1].type) + "
" + "
" + inoutData[i - 1].userName + "
" + "
" +inoutData[i - 1].plateNum + "
" + "
" + getInoutProgressName(inoutData[i - 1].progress)+ "
"; if(mapDepot[inoutData[i - 1].depotId] && inoutData[i - 1].progress != 'CHECK'){ //判断是否是不合格离库收卡 if(inoutData[i - 1].progress == 'CARD_BACK' && inoutData[i - 1].recordWeight == 0 && inoutData[i - 1].checkStatus == 'UNPASS'){ html += "
不合格
"; }else { html += "
" + mapDepot[inoutData[i - 1].depotId].name + "
"; } }else{ html += "
"; } html += "
" ; if (i == ((pageNo + 1) * pageSize)) { break; } } $("#inoutShowMainDiv").html(html); pageNo++; } function renderinoutCompleteData(inoutCompleteData,pNo) { // 先清空,在渲染 $("#inoutShowCompleteDiv").html(""); //计算总页数 if (inoutCompleteData == null || inoutCompleteData.length <= 0) return; completePageNo = pNo - 1; // 计算总页数 completePageTotal = inoutCompleteData.length / completePageSize; if (!(inoutCompleteData.length % completePageSize == 0)) { completePageTotal++; } var html = ""; for (var i = completePageNo * completePageSize + 1; i <= inoutCompleteData.length; i++) { html += "
" + "
" + getInoutTypeName(inoutCompleteData[i - 1].type) + "
"; html += "
" + inoutCompleteData[i - 1].userName + "
" + "
" + inoutCompleteData[i - 1].plateNum + "
" + "
" + dateFormatStr(inoutCompleteData[i - 1].completeTime) + "
"; html += "
" ; if (i == ((completePageNo + 1) * completePageSize)) { break; } } $("#inoutShowCompleteDiv").html(html); completePageNo++; } function getInoutTypeName(type) { if("IN" == type)return "入库"; if("OUT" == type)return "出库"; return ""; } function dateFormatStr(time) { if(time){ var d = new Date(time); return dateFtt("MM-dd hh:mm",d); } return ""; } function getInoutProgressName(progress) { if("REGISTER" == progress)return "登记"; if("CHECK" == progress)return "入库质检"; if("HANDLE" == progress)return "值仓"; if("WEIGHT_TAG" == progress)return "称重"; if("WEIGHT_FULL" == progress)return "满车称重"; if("WEIGHT_EMPTY" == progress)return "空车称重"; if("PAY" == progress)return "结算"; if("CARD_BACK" == progress)return "卡片回收"; if("RECORD" == progress)return "备案"; 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 initTime() { setInterval(function() { var now = new Date(); var time = now.toLocaleString('chinese', { hour12 : false }); $(".time-info").text(time); }, 1000); } function depotListToMap() { if(listDepot){ for(var index in listDepot){ mapDepot[listDepot[index].id] = listDepot[index]; } } console.log(listDepot); console.log(mapDepot); } // 退出全屏 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; }