var laypage; var layer; var laydate; var form; var page = 1; //页面,默认第1页 var request = {}; //请求数据 var LIST_DEVICE; var warnData; var checkbox_warn; var warnMap = []; var excel; $(function () { layui.use(['laypage', 'layer','form', 'laydate'], function () { laypage = layui.laypage; layer = layui.layer; form = layui.form; laydate = layui.laydate; //开始时间 laydate.render({ elem: '#start' , type: 'date' , trigger: 'click' , theme: 'custom' }); //截止时间 laydate.render({ elem: '#end' , type: 'date' , trigger: 'click' , theme: 'custom' }); renderPageInfo(2,50); //渲染按钮位置 renderParamBtn(); //请求设备列表 queryDevice(); //获取警告并渲染 // queryWarn(page); query(page); }); }); //请求获取设备列表 function queryDevice() { $.get("./cgi-bin/device/query-all", function (data, status) { if ("success" == status) { LIST_DEVICE = data; renderDeviceInfo(); } }, "json"); } //渲染设备下拉框 function renderDeviceInfo() { var html = ''; html += ''; if (LIST_DEVICE != null && LIST_DEVICE.length > 0) { $.each(LIST_DEVICE, function (index, item) { html += ''; }); } $("#deviceId").html(html); } //获取请求参数 function query(page) { //获取参数 request.id = $("#deviceId").val(); if(!request.id){ request.id = '0'; } request.beginTime = $("#start").val().replace('-', '').replace('-', ''); if (request.beginTime) { request.beginTime += '000000'; } request.endTime = $("#end").val().replace('-', '').replace('-', ''); if (request.endTime) { request.endTime += '235959'; } request.page = page; queryWarn(); } //请求获取报警数据 function queryWarn() { $.post("./cgi-bin/warn-list/query", JSON.stringify(request), function (data, status) { if ("success" == status) { warnData = data; //渲染警告列表 renderWarnInfo(warnData.data); //渲染页码 renderPageInfo(request.page, warnData.total); } else { window.parent.notify("数据查询出错,请重新操作!"); } }, "json"); } //渲染警告列表 function renderWarnInfo(data) { var html = ''; var total = 0; if (data != null && data.length > 0) { listSetMap(data); // $.each(data, function (index, item) { // if(item.flag == 0){ // total++; // } // }); $.each(data, function (index, item) { // if(item.flag == 0){ html += ''; // html += '' + (index + 1) + ''; html += '' + item.sn + ''; html += '' + item.name + ''; html += '' + item.id + ''; html += '' + timeStr(item.time) + ''; html += '' + (item.flag == 0 ? '未处理' : '已处理') + ''; var str = item.msg; str = str.replace("供电方式 : 0","供电方式 : 市电供电"); str = str.replace("供电方式 : 1","供电方式 : 电池供电"); str = str.replace("工作模式 : 0","工作模式 : 正常模式"); str = str.replace("工作模式 : 1","工作模式 : 旁路模式"); str = str.replace("工作模式 : 2","工作模式 : 电池供电"); // str = str.replaceAll(": 0",": 正常"); // str = str.replaceAll(": 2",": 告警"); html += '' + str + ''; if(item.flag==0){ html +=''; }else { html +=''; } html +=''; // } }); }else { html += '暂未查到数据'; } $("#warnList").html(html); // //渲染页码 // renderPageInfo(request.page, total); } //修改警报状态 function warnUpdate() { //获取表单内容 var data = form.val('edit_warn_example'); if(data.note){ console.log(data); var comData={ "sn": data.sn, "flag": 1, "note": data.note, "processTime": timeStr1(data.processTime), "id": data.id }; // console.log(comData); $.post("./cgi-bin/warn-list/update", JSON.stringify(comData), function (data, status) { if ("success" == status) { //关闭弹窗 closepopBtn(); //重新刷新此页面数据 queryWarn(); } else { window.parent.notify("处理失败,请重新操作!"); } }, "json"); } } //警报处理弹窗 function warnTodo(index) { var winInfo = warnData.data[index]; $("#note").removeAttr("readOnly"); $(".pop-complete-btn").show(); form.val('edit_warn_example', { "sn": winInfo.sn, "name": winInfo.name, "id": winInfo.id, "flag": winInfo.flag == 0?'未处理':'已处理', "time": timeStr(winInfo.time), "msg": winInfo.msg, "note": winInfo.note, "processTime": new Date().Format("yyyy-MM-dd hh:mm:ss") }); var paramWH = getWH("detail"); layer.open({ skin: 'mypop', type: 1, title: false, // area: ['50%', '62%'], area: [paramWH.w, paramWH.h], closeBtn: 0, shade: 0, scrollbar: false, content: $('#editWarnDom') }); }; //警报查看弹窗 function warnDetail(index) { var winInfo = warnData.data[index]; $("#note").attr("readOnly","readOnly"); $(".pop-complete-btn").hide(); form.val('edit_warn_example', { "sn": winInfo.sn, "name": winInfo.name, "id": winInfo.id, "flag": winInfo.flag == 0?'未处理':'已处理', "time": timeStr(winInfo.time), "msg": winInfo.msg, "note": winInfo.note, "processTime": new Date().Format("yyyy-MM-dd hh:mm:ss") }); var paramWH = getWH("detail"); layer.open({ skin: 'mypop', type: 1, title: false, // area: ['50%', '62%'], area: [paramWH.w, paramWH.h], closeBtn: 0, shade: 0, scrollbar: false, content: $('#editWarnDom') }); } //页码渲染 function renderPageInfo(page, total) { laypage.render({ elem: 'pdgxq-page', count: total, theme: '#e45163', layout: ['prev', 'page', 'next', 'skip'], curr: page, limit: 10, jump: function (obj, first) { if (!first) { page = obj.curr; query(page); } } }); } //标准时间格式化 Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, // 月份 "d+": this.getDate(), // 日 "h+": this.getHours(), // 小时 "m+": this.getMinutes(), // 分 "s+": this.getSeconds(), // 秒 "q+": Math.floor((this.getMonth() + 3) / 3), // 季度 "S": this.getMilliseconds() // 毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }; //时间格式处理,20210226101010-----2021-02-26 10:10:10 function timeStr(time) { return time.substring(0, 4) + "-" + time.substring(4, 6) + "-" + time.substring(6, 8) + " " + time.substring(8, 10) + ":" + time.substring(10, 12) + ":" + time.substring(12, 14) } //时间格式处理,2021-02-26 10:10:10-----20210226101010 function timeStr1(time) { return time.replace('-','').replace('-','').replace(' ','').replace(':','').replace(':',''); } function closepopBtn(){ layer.closeAll(); } /*------------------ tableToExcel导出模块-start ----------------- */ //初始化Excel导出,id=table表格的id //导出Excel点击事件 function generateClick(){ queryAllWarn(); } function queryAllWarn(){ $.post("./cgi-bin/warn-list/excel-warn", JSON.stringify(request), function (data, status) { if ("success" == status) { //渲染警告列表 var html = renderTable(data.data); tableToExcel(html); } else { window.parent.notify("数据查询出错,请重新操作!"); } }, "json"); } function renderTable(data){ //表头 var thead = ""; thead += ""; thead += "序号"; thead += "设备ID"; thead += "设备名称"; thead += "警告时间"; thead += "警告内容"; thead += "警告状态"; thead += "处理时间"; thead += "处理备注"; thead += ""; var tbody = ""; if (data != null && data.length > 0) { $.each(data, function (index, item) { tbody += "" + item.sn + ""; tbody += "" + item.id + ""; tbody += "" + item.name + ""; tbody += "" + timeStr(item.time) + ""; tbody += "" + item.msg + ""; tbody += "" + (item.flag == 0 ? "未处理": "已处理") + ""; tbody += "" + timeStr(item.processTime) + ""; tbody += "" + item.note + ""; }); }else { tbody += '暂未查到数据'; } var html = thead + tbody; return html; } function tableToExcel(html) { var name = "告警记录"; var uri = 'data:application/vnd.ms-excel;base64,'; var template = '{table}
'; if(!html){ layer.msg("没有获取到要导出的内容!"); } var ctx = {worksheet: name || 'Worksheet', table: html}; window.location.href = uri + base64(format(template, ctx)) } function format(s, c) { return s.replace(/{(\w+)}/g,function(m, p) { return c[p]; }); } function base64(s) { return window.btoa(unescape(encodeURIComponent(s))) }; /*------------------ tableToExcel导出模块-end ----------------- */ function listSetMap(list) { $.each(list,function (index,data) { warnMap[data.sn] = data; }) } //批处理 function batchHandle() { $("#batch_processTime").attr("readOnly","readOnly"); $("#batch_processTime").val(new Date().Format("yyyy-MM-dd hh:mm:ss")); var paramWH = getWH("batchHandle"); layer.open({ skin: 'mypop', type: 1, // title: '警报信息', title: false, // area: ['50%', '35%'], area: [paramWH.w, paramWH.h], closeBtn: 0, shade: 0, scrollbar: false, content: $('#batchWarnDom') }); } function allCheckbox() { var b = $("#all").is(":checked"); $(".ckeck").prop('checked', b); } //批量修改警报状态 function warnUpdateBatch() { //同步进行 $.ajaxSettings.async = false; var param = {}; var note = $("#batch_note").val(); var processTime = $("#batch_processTime").val(); var sns = ""; var ids = ""; if(note){ param = { // "sn": sns, "note": note, "processTime": timeStr1(processTime) }; $.post("./cgi-bin/warn-list/update-all", JSON.stringify(param), function (data, status) { if ("success" == status) { //关闭弹窗 closepopBtn(); //重新刷新此页面数据 queryWarn(); } else { window.parent.notify("处理失败,请重新操作!"); } }, "json"); }else{ layer.msg("处理说明不能为空!"); console.log("处理说明不能为空!"); } } function renderParamBtn() { if(screen.width==1920 && screen.height==1080){ // $("#param-btn").addClass("layui-col-md6"); $("#param-btn").removeClass("layui-col-md6"); }else if(screen.width==1280 && screen.height==1024){ // $("#param-btn").addClass("layui-col-md4"); $("#param-btn").removeClass("layui-col-md4"); }else if(screen.width==1280 && screen.height==800){ // $("#param-btn").addClass("layui-col-md4"); $("#param-btn").removeClass("layui-col-md4"); }else{ // $("#param-btn").addClass("layui-col-md6"); $("#param-btn").removeClass("layui-col-md6"); } $("#param-btn").show(); } function getWH(tag) { var res = { w:"50%", h:"64%" }; if(screen.width==1920 && screen.height==1080){ res = {w:"80%",h:"64%"}; if(tag == "batchHandle"){ res = {w:"80%",h:"64%"}; } }else if(screen.width==1280 && screen.height==1024){ res = {w:"80%",h:"64%"}; if(tag == "detail"){ res = {w:"80%",h:"95%"}; } if(tag == "batchHandle"){ res = {w:"80%",h:"64%"}; } }else if(screen.width==1280 && screen.height==800){ res = {w:"80%",h:"64%"}; if(tag == "detail"){ res = {w:"80%",h:"95%"}; } if(tag == "batchHandle"){ res = {w:"80%",h:"64%"}; } } return res; }