var layer; var bizCharts = {}; var pageDepot = 0; var totalDepot = 1; var pageGas = 1; var totalGas = 1; var grainIndex = 0; var gasIndex = 0; var timer; var screen = true; $(function () { layui.use(['layer', 'laydate', 'form'], function () { layer = layui.layer; // 初始页面 init(); $("body").dblclick(function () { if (screen) { requestFullScreen(); } else { exitFullscreen(); } }); }); // 初始化WebSocket initWS(deptId, bizType, bizTag, userId); }); function init() { // 初始背景效果 initBg(); initTime(); initDicSlogan(); initWeather(); // 初始化页面中7张echart图表 bizCharts = initCharts(); renderBasicInfo(); renderDepot(); renderGrain(); reloadChartGas(); reloadChartdepot(); // renderEsChart(); clearInterval(timer); timing(); initInoutData(); } // socket信息返回處理 function socketOnMessage(pocket) { //console.log(pocket); if (pocket.bizId == "slogan") { var data = pocket.data; dicSlogan = data; initDicSlogan(); } if (pocket.bizId == "grain") { var data = pocket.data; mapGrain = data; } if (pocket.bizId == "gas") { var data = pocket.data; mapGas = data; } if (pocket.bizId == "weather") { weatherInfo = pocket.data; initWeather() } if (pocket.bizId == "depot") { listDepot = pocket.data; pageDepot = 0; renderDepot(); reloadChartdepot(); } if (pocket.bizId == "es") {//能耗信息推送 esChart = pocket.data; renderEsChart(); } if (pocket.bizId == "IN_OUT_SUMMARY") { inoutData = pocket.data; renderSumData(inoutData); } }; function timing() { timer = setInterval(function () { dong(); renderGrain(); reloadChartGas(); }, 15000); } /** * 渲染库区基本信息 */ function renderBasicInfo() { if(deptInfo){ $("#cityAndCounty").html(deptInfo.addr == null ? "":deptInfo.addr); $("#deptName").html(deptInfo.deptName == null ? "":deptInfo.deptName); $("#depotNum").html(deptInfo.depotNum == null ? "0":deptInfo.depotNum); $("#depotOilNum").html(deptInfo.depotOilNum == null ? "0":deptInfo.depotOilNum); $("#foodStorage").html(deptInfo.foodStorage == null ? "0":deptInfo.foodStorage); $("#oilStorage").html(deptInfo.oilStorage == null ? "0":deptInfo.oilStorage); $("#storage").html(deptInfo.storage == null ? "0":deptInfo.storage); } } function initCharts() { // var chartEnergy = initChartEnergy(); var chartGasCO2 = initChartGasCO2(); var chartGasPH3 = initChartGasPH3(); var chartGasO2 = initChartGasO2(); var chartFoodType = initChartFoodType(); var chartFoodVariety = initChartFoodVariety(); var chartFoodLevel = initChartFoodLevel(); return { // "chartEnergy": chartEnergy, "chartGasCO2": chartGasCO2, "chartGasPH3": chartGasPH3, "chartGasO2": chartGasO2, "chartFoodType": chartFoodType, "chartFoodVariety": chartFoodVariety, "chartFoodLevel": chartFoodLevel }; } /** * 初始标语数据 */ 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 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 (result) { console.log("初始成功!"); }, error: function (result) { console.log("初始失败!"); } }); } /** * 渲染出入库统计信息 * @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 renderEsChart() { // if (!esChart) return; // var chartEnergy = bizCharts.chartEnergy; // chartEnergy.option.xAxis[0].data = esChart.xaxisData; // chartEnergy.option.series[0].data = esChart.series[0].data; // chartEnergy.chart.setOption(chartEnergy.option, true); // // bizCharts.chartEnergy = chartEnergy; // }; /** * 渲染仓库 */ function renderDepot() { if (listDepot == null || listDepot.length <= 0) return; // 先清空,在渲染 $("#depotShowDiv").html(""); $("#depotTabDiv").html(""); var pageNo = 1; // 计算总页数 var total = listDepot.length / 4; if (!(listDepot.length % 4 == 0)) { total++; } var html = "
" + "
" + "" + ""; } else if (curDepot.depotStatus == DepotStatus.S_03) { html += ""; html += "

入库

" + "

入库执行中

" + "" + "" + ""; } else if (curDepot.depotStatus == DepotStatus.S_04) { html += ""; html += "

出库

" + "

出库执行中

" + "" + "" + ""; } else if (curDepot.depotStatus == DepotStatus.S_05) { html += ""; html += "

气调

" + "

不可执行通风等操作

" + "" + "" + ""; } else if (curDepot.depotStatus == DepotStatus.S_06) { html += ""; html += "

熏蒸

" + "

请注意安全

" + "" + "" + ""; } else if (curDepot.depotStatus == DepotStatus.S_07) { html += ""; html += "

通风

" + "

请注意雨水天气

" + "" + "" + ""; } else if (curDepot.depotStatus == DepotStatus.S_08) { html += ""; html += "

维修

" + "

仓库维修中

" + "" + "" + ""; } else { html += ""; html += "

满仓

" + "

正常状态

" + "" + "" + ""; } if ((i % 4) == 0) { html += ""; pageNo++; if (pageNo <= total) { html += "
"; } } $("#depotShowDiv").html(html); var tabHtml = ""; for (var k = 0; k < total; k++) { if (k == 0) { tabHtml += ""; } else { tabHtml += ""; } } $("#depotTabDiv").html(tabHtml); // 绑定切换事件 totalDepot = $('.i-tab-hd span').length; pageDepot = 0; var $tabHd = $(".i-tab-hd span"); $tabHd.hover(function (a) { clearInterval(timer); var $index = $tabHd.index(this); var $tabBd = $(".i-tab-bd .i-tab-item"); i = $index; $(this).addClass("active").siblings().removeClass("active"); $tabBd.eq($index).addClass("show").siblings().removeClass("show"); }, function () { timer = setInterval(dong, 15000); }); } function dong() { pageDepot++; if (pageDepot >= totalDepot) { pageDepot = 0; } selectimg(pageDepot); } function selectimg(i) { var $tabHd = $(".i-tab-hd span"); $tabHd.eq(i).addClass("active").siblings().removeClass("active"); $(".i-tab-bd .i-tab-item").eq(i).addClass("show").siblings(".i-tab-item") .removeClass("show"); } /** * 渲染粮情,参数为页码 * * @param pageNoGrain */ function renderGrain() { if (listDepot == null || listDepot.length <= 0) return; // 先清空,在渲染 var html = ""; var dateStr; if (mapGrain) { var count = 0; for (var i = grainIndex; i < listDepot.length; i++, grainIndex++) { var grain = mapGrain[listDepot[grainIndex].id]; if (grain) { html += "
" + "
" + (listDepot[grainIndex].name == null ? "" : listDepot[grainIndex].name) + "
"; dateStr = grain.receiveDate; if (dateStr) { var d = new Date(dateStr); dateStr = (d.getMonth() + 1) + "-" + d.getDate(); } else { dateStr = ""; } html += "
" + (grain.tempMax == null ? "-" : (grain.tempMax == "-100" ? "备用":grain.tempMax.toFixed(1))) + "
"; html += "
" + (grain.tempMin == null ? "-" : (grain.tempMin == "-100" ? "备用":grain.tempMin.toFixed(1))) + "
"; html += "
" + (grain.tempAve == null ? "-" : (grain.tempAve == "-100" ? "备用":grain.tempAve.toFixed(1))) + "
"; html += "
" + (grain.tempIn == null ? "-" : (grain.tempIn == "-100" ? "备用":grain.tempIn.toFixed(1))) + "
"; html += "
" + (grain.humidityIn == null ? "-" : (grain.humidityIn == "-100" ? "备用":grain.humidityIn.toFixed(1))) + "
"; html += "
" + dateStr + "
" + "
"; count++; } if (grainIndex == (listDepot.length - 1)) { grainIndex = 0; break; } if (count == 10) { grainIndex++; break; } } } else { console.log("粮情信息为空!"); } if (html) { $("#grainShowDiv").html(""); $("#grainShowDiv").html(html); } } /** * 渲染气体图表 * * @param index */ function reloadChartGas() { var chartGasCO2 = bizCharts.chartGasCO2; var chartGasPH3 = bizCharts.chartGasPH3; var chartGasO2 = bizCharts.chartGasO2; if (mapGas) { if (gasIndex == (listDepot.length)) { gasIndex = 0; } var gas = mapGas[listDepot[gasIndex].id]; var depot = listDepot[gasIndex]; $("#gasDepotName").text((depot.name == null ? "" : depot.name)); if (gas) { var dateStr = gas.receiveDate; if (dateStr) { var d = new Date(dateStr); dateStr = (d.getMonth() + 1) + "-" + d.getDate(); } else { dateStr = ""; } $("#gasCheckTime").text("检测时间: " + dateStr); chartGasCO2.option.series[0].data[0].value = (gas.perCo2 == null ? 0 : gas.perCo2); chartGasCO2.chart.setOption(chartGasCO2.option, true); chartGasPH3.option.series[0].data[0].value = (gas.perPh3 == null ? 0 : gas.perPh3); chartGasPH3.chart.setOption(chartGasPH3.option, true); chartGasO2.option.series[0].data[0].value = (gas.perO2 == null ? 0 : gas.perO2); chartGasO2.chart.setOption(chartGasO2.option, true); }else { $("#gasCheckTime").text("检测时间: 00-00"); chartGasCO2.option.series[0].data[0].value = 0; chartGasCO2.chart.setOption(chartGasCO2.option, true); chartGasPH3.option.series[0].data[0].value = 0; chartGasPH3.chart.setOption(chartGasPH3.option, true); chartGasO2.option.series[0].data[0].value = 0; chartGasO2.chart.setOption(chartGasO2.option, true); } gasIndex++; } else { $("#gasDepotName").text("仓库"); $("#gasCheckTime").text("检测时间: 00-00"); chartGasCO2.option.series[0].data[0].value = 0; chartGasCO2.chart.setOption(chartGasCO2.option, true); chartGasPH3.option.series[0].data[0].value = 0; chartGasPH3.chart.setOption(chartGasPH3.option, true); chartGasO2.option.series[0].data[0].value = 0; chartGasO2.chart.setOption(chartGasO2.option, true); console.log("气体数据为空,显示默认数据") } bizCharts.chartGasCO2 = chartGasCO2; bizCharts.chartGasPH3 = chartGasPH3; bizCharts.chartGasO2 = chartGasO2; } // function reloadChartGas() { // var chartGasCO2 = bizCharts.chartGasCO2; // var chartGasPH3 = bizCharts.chartGasPH3; // var chartGasO2 = bizCharts.chartGasO2; // if (mapGas) { // var count = 0; // for (var i = gasIndex; i < listDepot.length; i++, gasIndex++) { // var gas = mapGas[listDepot[gasIndex].id]; // if (gas) { // var depot = listDepot[gasIndex]; // // $("#gasDepotName").text((depot.name == null ? "" : depot.name)); // var dateStr = gas.receiveDate; // if (dateStr) { // var d = new Date(dateStr); // dateStr = (d.getMonth() + 1) + "-" + d.getDate(); // } else { // dateStr = ""; // } // $("#gasCheckTime").text("检测时间: " + dateStr); // chartGasCO2.option.series[0].data[0].value = (gas.perCo2 == null ? 0 // : gas.perCo2); // chartGasCO2.chart.setOption(chartGasCO2.option, true); // chartGasPH3.option.series[0].data[0].value = (gas.perPh3 == null ? 0 // : gas.perPh3); // chartGasPH3.chart.setOption(chartGasPH3.option, true); // chartGasO2.option.series[0].data[0].value = (gas.perO2 == null ? 0 // : gas.perO2); // chartGasO2.chart.setOption(chartGasO2.option, true); // count++; // } // if (gasIndex == (listDepot.length - 1)) { // gasIndex = 0; // reloadChartGas(); // } // if (count == 1) { // gasIndex++; // break; // } // } // } else { // $("#gasDepotName").text("仓库"); // $("#gasCheckTime").text("检测时间: 00-00"); // chartGasCO2.option.series[0].data[0].value = 0; // chartGasCO2.chart.setOption(chartGasCO2.option, true); // chartGasPH3.option.series[0].data[0].value = 0; // chartGasPH3.chart.setOption(chartGasPH3.option, true); // chartGasO2.option.series[0].data[0].value = 0; // chartGasO2.chart.setOption(chartGasO2.option, true); // console.log("气体数据为空,显示默认数据") // } // bizCharts.chartGasCO2 = chartGasCO2; // bizCharts.chartGasPH3 = chartGasPH3; // bizCharts.chartGasO2 = chartGasO2; // } //从缓存中获取当前仓库 function gtDepotById(depotId) { $.each(listDepot, function (i, item) { if (item.id == depotId) return item; }); } /** * 仓储统计 */ function reloadChartdepot() { if (listDepot == null || listDepot.length <= 0) { return; } var foodTypeMap = new Map(); var foodType = null; var foodVarietyMap = new Map(); var foodVariety = null; var foodLevelMap = new Map(); var foodLevel = null; var depot = null; var value = 0.0; for (var i = 1; i <= listDepot.length; i++) { depot = listDepot[i - 1]; value = 0.0; // 粮食性质 foodType = depot.foodType; if (foodType) { if (foodTypeMap.has(foodType)) { value = foodTypeMap.get(foodType).value + depot.storageReal; } else { value = depot.storageReal; } foodTypeMap.set(foodType, { "name": depot.foodTypeName, "value": value }); } // 粮食等级 foodLevel = depot.foodLevel; if (foodLevel) { if (foodLevelMap.has(foodLevel)) { value = foodLevelMap.get(foodLevel).value + depot.storageReal; } else { value = depot.storageReal; } foodLevelMap.set(foodLevel, { "name": depot.foodLevelName, "value": value }); } // 粮食品种 foodVariety = depot.foodVariety; if (foodVariety) { if (foodVarietyMap.has(foodVariety)) { value = foodVarietyMap.get(foodVariety).value + depot.storageReal; } else { value = depot.storageReal; } foodVarietyMap.set(foodVariety, { "name": depot.foodVarietyName, "value": value }); } } var chartFoodTypeData = new Array(); var chartFoodVarietyData = new Array(); var chartFoodLevelData = new Array(); foodVarietyMap.forEach(function (value, key) { chartFoodVarietyData.push(value); }); foodTypeMap.forEach(function (value, key) { chartFoodTypeData.push(value); }); foodLevelMap.forEach(function (value, key) { chartFoodLevelData.push(value); }); var chartFoodLevel = bizCharts.chartFoodLevel; var chartFoodVariety = bizCharts.chartFoodVariety; var chartFoodType = bizCharts.chartFoodType; chartFoodLevel.option.series[0].data = chartFoodLevelData; chartFoodLevel.chart.setOption(chartFoodLevel.option, true); chartFoodType.option.series[0].data = chartFoodTypeData; chartFoodType.chart.setOption(chartFoodType.option, true); chartFoodVariety.option.series[0].data = chartFoodVarietyData; chartFoodVariety.chart.setOption(chartFoodVariety.option, true); bizCharts.chartFoodLevel = chartFoodLevel; bizCharts.chartFoodType = chartFoodType; bizCharts.chartFoodVariety = chartFoodVariety; } // 退出全屏 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; }