anxiao_web/pages/cmddispatch/js/eventHistory.js

369 lines
13 KiB
JavaScript
Raw Permalink Normal View History

2024-07-24 09:22:32 +08:00
import { layuiObj,loginInfo } from "./index.js";
import { getCurrData } from "../../../public/js/timestamp.js";
import { getSchoolOptions } from "./schoolSearch.js";
import { stationurl,movedeviceurl,brigade } from "../../../public/js/url.js";
import { deviceHash } from "../api/moveDeviceWebsocket.js";
import { notifyDetailList } from "./popNotifyDetail.js";
let notifyListMore=[];
let earlyWarningHistoryList=[];
let imgUrlArr=[];
function openAlarmHistory(){
layuiObj["layer"].open({
type: 1,
title: "事件查询", //不显示标题栏
// closeBtn: false,
area: ['1260px', '560px'],
id: new Date().getTime(), //设定一个id防止重复弹出
btnAlign: 'c',
resize:false,
// moveType: 0, //拖拽模式0或者1
content:`<div class="popintellEarlyWarningInfo">
<div class="intellEarlyWarningInfo">
<div class="intellEarlyWarningInfoContent">
<form class="layui-form" action="" id="intellEarlyWarningHistoryForm" lay-filter="intellEarlyWarningHistoryForm" >
<div class="layui-input-inline">
<select name="interest" lay-filter="intellEarlyWarningTypeSelect" id="intellEarlyWarningTypeSelect" lay-search>
<option value=1>报警事件</option>
<option value=2>通知事件</option>
<option value=3>拍照事件</option>
</select>
</div>
<div class="layui-input-inline">
<select name="interest" lay-filter="intellEarlyWarningSchoolSelect" id="intellEarlyWarningSchoolSelect" lay-search></select>
</div>
<div class="layui-input-inline">
<input type="text" class="layui-input" id="intellEarlyWarningHistoryStart" placeholder="请输入开始时间" value='${getCurrData()} 00:00:00'>
</div>
<div class="layui-input-inline">
<input type="text" class="layui-input" id="intellEarlyWarningHistoryEnd" placeholder="请输入结束时间" value='${getCurrData()} 23:59:59'>
</div>
<div class="layui-input-inline">
<button class="layui-btn" id="intellEarlyWarningHistoryBtn" style="height:38px !important;line-height:38px !important;">查询</button>
</div>
</form>
<div class="intellEarlyWarningList">
<table class="layui-hide" id="intellEarlyWarningTable" lay-filter="intellEarlyWarningTable"></table>
</div>
</div>
</div>
</div>`,
success:function(){
renderClockFrom();
intellEarlyWarningSelectEvent();
}
})
}
function renderClockFrom(){
$("#intellEarlyWarningSchoolSelect").html(getSchoolOptions());
layuiObj.layuiForm.render("select","intellEarlyWarningHistoryForm");
$("#intellEarlyWarningSchoolSelect").siblings("div.layui-form-select").find("div.layui-select-title").find("input").attr("onfocus","this.select()");
layuiObj.laydate.render({
elem: '#intellEarlyWarningHistoryStart',
type: 'datetime',
});
layuiObj.laydate.render({
elem: '#intellEarlyWarningHistoryEnd',
type: 'datetime',
});
}
function intellEarlyWarningSelectEvent(){
$("#intellEarlyWarningHistoryBtn").off('')
$("#intellEarlyWarningHistoryBtn").on('click',(e)=>{
var start=$("#intellEarlyWarningHistoryStart").val();
var end=$("#intellEarlyWarningHistoryEnd").val();
var station=$("#intellEarlyWarningSchoolSelect").find("option:selected").val();
var type=$("#intellEarlyWarningTypeSelect").find("option:selected").val();
var data={
"brigade":brigade,
"start":start,
"end":end
}
if(station!="000"){
data["station"]=station
}
$(".intellEarlyWarningList").removeClass("commonfile");
switch(type){
case "1":
selectAlarmByOrg(data);
break;
case "2":
getNotifyCountMore(data);
break;
case "3":
$(".intellEarlyWarningList").addClass("commonfile")
selectCommonfile(data);
break;
default:
break;
}
return false;
})
}
function selectAlarmByOrg(data){
alarmByorgGetlist(data).then(res=>{
earlyWarningHistoryList=[];
var code=res["data"]["code"];
if(code==0){
var data=res["data"]["data"];
earlyWarningHistoryList=data;
if(earlyWarningHistoryList.length>0){
earlyWarningHistoryList.reverse();
}
}
showAlarmByorgTable();
})
}
function alarmByorgGetlist(data){
var alarmOrgUrl=movedeviceurl+"/mdev/alarm/byorg/getlist";
return axios({
method: 'post',
url:alarmOrgUrl,
data:data
})
}
//获取通知列表
function getNotifyCountMore(reqData){
reqData["sender"]=loginInfo["user_name"];
notifyListMore=[];
let nurlCount=movedeviceurl+"/mdev/notice/getcount";
axios({
method: 'post',
url:nurlCount,
data:reqData
}).then(res => {
var code=res["data"]["code"];
if(code==0){
var data=res["data"]["data"];
var count=data["count"];
if(count!=0){
var reqList=getPageReq(reqData,count);
//获取列表
var pArr=reqList.map((item)=>{
reqData=item;
let nurlList=movedeviceurl+"/mdev/notice/getlist";
return axios({
method: 'post',
url:nurlList,
data:reqData
})
})
Promise.all(pArr).then((result) => {
console.log(result);
for(var i=0;i<result.length;i++){
var code=result[i]["data"]["code"];
if(code==0){
var data=result[i]["data"]["data"];
for(var j=0;j<data.length;j++){
var receiver=data[j]["receiver"];
if(receiver in deviceHash){
data[j]["showname"]=deviceHash[receiver]["showname"]
}else{
data[j]["showname"]="/";
}
data[j]["readtime"]="/";
notifyListMore.unshift(data[j]);
}
}
}
selectNotifyMoreStatus();
})
}else{
alarmEventListTable([])
}
}
})
}
function selectNotifyMoreStatus(){
let notifyStatus=[];
notifyListMore.map((item)=>{
var reqData={
"noticeid":item.noticeid
}
let nsurl=movedeviceurl+"/mdev/notice/getstatus";
notifyStatus.push( axios({
method: 'post',
url:nsurl,
data:reqData
}));
})
Promise.all(notifyStatus).then(res=>{
for(var i =0;i<res.length;i++){
var data=res[i]["data"]["data"];
if(data!=null){
for(var j=0;j<data.length;j++){
var deviceid=data[j]["deviceid"];
var noticeid=data[j]["noticeid"];
for(var k=0;k<notifyListMore.length;k++){
if((noticeid==notifyListMore[k]["noticeid"])&&(deviceid==notifyListMore[k]["receiver"])){
notifyListMore[k]={...notifyListMore[k],...data[j]}
}
}
}
}
}
var readImg="<img src='./pages/cmddispatch/image/notifyRead.png' class='notifyImg'>";
var unreadImg="<img src='./pages/cmddispatch/image/notifyUnRead.png' class='notifyImg'>";
for(var i=0;i<notifyListMore.length;i++){
if("state" in notifyListMore[i]){
var status=notifyListMore[i]["state"];
}else{
var status="unread";
}
if(status!="read"){
notifyListMore[i]["img"]=unreadImg;
notifyListMore[i]["statusText"]="未读";
}else{
notifyListMore[i]["img"]=readImg;
notifyListMore[i]["statusText"]="已读";
}
}
alarmEventListTable(notifyListMore);
})
}
function showAlarmByorgTable(){
layuiObj.layuitable.render({
elem:'#intellEarlyWarningTable',
data:earlyWarningHistoryList,
toolbar: '#toolbarDemo', // 重点,可默认,也可自己设置按钮
defaultToolbar: ['filter', 'exports'], // exports为导出按钮
cols: [[
{field:'station', width:"20%", title: '学校',templet : function(data) {// 替换数据
var deviceid=data["deviceid"];
if(deviceid in deviceHash){
return `${deviceHash[deviceid]["station"]}`;
}
}},
{field:'address', width:"20%", title: '地址'},
{field:'timestamp', width:"20%", title: '时间'},
{field:'deviceid', width:"20%", title: '名称',templet : function(data) {// 替换数据
var deviceid=data["deviceid"];
if(deviceid in deviceHash){
return `${deviceHash[deviceid]["showname"]}`;
}
}},
{field:'deviceid', width:"20%", title: '设备号'},
]],
limit:Number.MAX_VALUE // 数据表格默认全部显示
});
}
function alarmEventListTable(eventTemp){
layuiObj.layuitable.render({
elem:'#intellEarlyWarningTable',
data:eventTemp,
toolbar: '#toolbarDemo', // 重点,可默认,也可自己设置按钮
defaultToolbar: ['filter', 'exports'], // exports为导出按钮
cols: [[
{field:'title', width:"12%", title: '标题',event:"showNotifyDetail"},
{field:'content', width:"22%", title: '内容'},
{field:'timestamp', width:"18%", title: '下发时间',sort:true},
{field:'showname', width:"14%", title: '接受者'},
{field:'statusText', width:"10%", title: '消息状态'},
{field:'sender', width:"14%", title: '发送者'},
{field:'edit', width:"10%", title: '操作',event:'handle',templet:function(data) {
return `<a class="layui-btn">详情</a>`
}
},
]],
limit:Number.MAX_VALUE // 数据表格默认全部显示
});
listenEarlyWarningTable();
}
function listenEarlyWarningTable(){
layuiObj.layuitable.on('tool(intellEarlyWarningTable)', function(obj){
var event=obj["event"];
var data = obj.data;
switch(event){
case "handle":
notifyDetailList(data)
break;
default:
break;
}
})
}
//分页请求
function getPageReq(reqOrgData,count){
let number=1000;
let page=Math.ceil(count/number);
let reqList=[];
for(let i=0;i<page;i++){
let reqData=JSON.parse(JSON.stringify(reqOrgData));
reqData["pagesize"]=number;
reqData["pageindex"]=i;
reqList.push(reqData);
}
return reqList;
}
function selectCommonfile(data){
selectCommonfileGetlist(data).then(res=>{
var code=res["data"]["code"];
if(code==0){
var data=res["data"]["data"];
showCommonfileTable(data)
}
})
}
function selectCommonfileGetlist(data){
var commonfileUrl=stationurl+"/firectrl/school/commonfile/getlist";
return axios({
method: 'post',
url:commonfileUrl,
data:data
})
}
function showCommonfileTable(data){
console.log(data);
imgUrlArr=[];
layuiObj.layuitable.render({
elem:'#intellEarlyWarningTable',
data:data,
cols: [[
{field:'comment', width:"20%", title: '标题'},
{field:'station', width:"20%", title: '学校'},
{field:'creator', width:"20%", title: '使用者'},
{field:'timestamp', width:"20%", title: '上传时间'},
{field:'imageUrls', width:"20%", title: '文件',templet:function(data) {
return `${getImageUrl(data)}`
}
},
]],
limit:Number.MAX_VALUE // 数据表格默认全部显示
});
for(var i=0;i<imgUrlArr.length;i++){
new Viewer(document.getElementById(`hiddenDangerImg${imgUrlArr[i]}`),{
url: 'data-original'
});
}
}
function getImageUrl(item){
var imgUrl=JSON.parse(item["imageUrls"]);
var imgs="";
for(var i=0;i<imgUrl.length;i++){
var url=stationurl+imgUrl[i];
imgUrlArr.push(url)
imgs+=`<div class="schoolStyle_pop_img commonFile"><img src="${url}" id='hiddenDangerImg${url}'></div>`
}
return imgs;
}
export {openAlarmHistory}