cc-jjsp-web/bns/html/device/early/todayEarly.js

365 lines
9.4 KiB
JavaScript
Raw Normal View History

2025-09-23 09:28:02 +08:00
let table,orgList,formSelects;
let deviceTable;
let form;
let per;
let laypage,laydate;
let user = getUser(), checkedDate = getNowTime();
let pageNum = 1, limitSize = 30; // 默认第一页分页数量为10
layui.config({
base: "../../../js/layui/", //此处路径请自行处理, 可以使用绝对路径
}).extend({
formSelects: 'formSelects-v4'
}).use(['layer', 'form', 'element','formSelects','laypage','laydate'], function(){
formSelects = layui.formSelects;
var layer = layui.layer; //弹层
laypage = layui.laypage; //分页
table = layui.table; //表格
laydate = layui.laydate;
form=layui.form;
orgList = getOrgSelect();
laydate.render({
elem: '#warnDay', //指定元素 元素选择器
type: 'date', //选择时间类型 可选值:year(年) month(年月) date(年月日) time(时分秒) datetime(年月日时分秒)
trigger: 'click',
format: 'yyyy-MM-dd', //时间格式 常用时间格式:yyyy-MM-dd HH:mm:ss
btns: ['clear', 'now', 'confirm'], //选择框右下角显示的按钮 清除-现在-确定
done: function (value, date) { //时间回调
}
});
$("#warnDay").val(checkedDate)
if(user.nickName!='zhangyn' && user.nickName!='!jysp' && user.nickName!='wb_zhux4635'){
$("#delbtn").css("display","none");
}
//注册权限
pages(1, 30, 1);
$(".layui-refresh").click(function(){
refresh("");
})
$(".layui-cz").click(function(){
refreshDevice("");
})
$("#query").off().click(function(){
pages(1, limitSize,false);
return ;
})
$("#export").off().click(function(){
exportEarlyWarn();
return ;
})
//重置
$("#reset").off().click(function(){
$("#warnDay").val(checkedDate)
pages(1, limitSize,true);
})
$(".layui-del").click(function(){
//删除
var checkStatus = table.checkStatus('deviceTable'); // yourTableId 是表格容器的id
var data = checkStatus.data; // 获取选中行的数据
let delId=[];
for (var i = 0; i < data.length; i++) {
delId.push(data[i].id)
}
layer.msg('确定删除该预警?', {
time: 10000, //10s后自动关闭
btn: ['确定', '取消']
,yes: function(index,leyuo){
layer.closeAll();
delData(delId.join("@"));
}
});
})
//查询按钮
})
function pages(pageNum, pageSize, typeNum) {
let params = getReqParams(pageNum, pageSize, typeNum);
$.ajax({
headers: {
"encrypt": sm3(JSON.stringify(params))
},
url: dataUrl+'proteam/pot/early/getWarnPageList?token='+token,
data: params,
type: 'POST',
async: false,
success: function (result) {
if (result.code === 200) {
if (result.data) {
initTable(result.data, result.limit, result.curr)
laypages(result.count, result.curr, result.limit)
}
} else if (result.code === 500) {
layer.alert(result.msg, {icon: 2})
} else if (result.code === 401) {
logout(1);
}
}, error: function () {
}
});
}
function laypages(total, page, limit) {
laypage.render({
elem: 'voi-page',
count: total,
curr: page,
limit: limit,
limits: [30,50,100],
layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
groups: 5,
jump: function (obj, first) {
if (!first) {
pageNum = obj.curr, limitSize = obj.limit;
pages(obj.curr, obj.limit, null);
}
}
});
}
// 获取参数
function getReqParams(page, limit, type) {
let obj = {};
if (!type) {
obj = {
page: page + "",
limit: limit + "",
keyWord:$("#keyWord").val(),
warnDay:$("#warnDay").val(),
handle:$("#handle").val(),
org:formSelects.value('buildCode', 'val').toString()
};
} else {
obj = {
page: '1',
limit: '30',
keyWord:"",
warnDay:$("#warnDay").val(),
handle:"",
gbCode:"",
org:''
};
}
return obj;
}
function exportEarlyWarn(){
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
let url = dataUrl + "proteam/pot/early/exportEarlyWarn?" + getParam()+'&token='+token;
let xhr = new XMLHttpRequest();
let a = document.createElement("a");
xhr.open("get", url, true);
xhr.responseType = "blob"; // 转换流
xhr.setRequestHeader("encrypt",sm3(JSON.stringify(getParames())));
xhr.setRequestHeader("encryption","encryption");
xhr.onload = function () {
layer.close(loadingMsg);
if (this.status === 200) {
let url = window.URL.createObjectURL(new Blob([this.response]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', "预警任务.xlsx")
document.body.appendChild(link)
link.click()
// 释放URL对象所占资源
window.URL.revokeObjectURL(url)
// 用完即删
document.body.removeChild(link)
} else {
layer.msg("数据发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000});
}
};
xhr.send();
}
function getParam(){
var params="keyWord="+$("#keyWord").val()+"&warnDay="+$("#warnDay").val()+"&handle="+$("#handle").val()
+"&org="+formSelects.value('buildCode', 'val').toString()
return params;
}
//初始化表格
function initTable(dataList, limit, page) {
// 执行一个 table 实例
deviceTable=table.render({
id:'deviceTable',
elem: '#device-table',
height: "full-250",
data: dataList,
limit: limit,
title: '设备表',
cols: [[ //表头
{type: 'checkbox', fixed: 'left'},
{title: "序号", width: 80, align: "center", templet: function (d) {
return (page - 1) * limit + d.LAY_INDEX;
}
}
,{field: 'warnType', title: '告警内容', width:200,align:'center'}
,{field: 'cityName', title: '组织机构', width: 200,align:'center'}
,{field: 'proName', title: '工程名称', width: 200,align:'center'}
,{field: 'riskLevel', title: '风险等级', width: 200,align:'center',templet:function(d){
return setRiskLevelColor(d.riskLevel);
}}
,{field: 'userName', title: '督查人', width: 200,align:'center'}
,{field: 'handle', title: '是否核实', width:210,align:'center', templet:function(d){
if(d.handle==1){
return '已核实';
}else{
return '未核实';
}
} }
,{field: 'isHl', title: '是否符合', width:210,align:'center', templet:function(d){
if(d.isHl){
if(d.isHl==1){
return '符合';
}else if(d.isHl==2){
return '不符合';
}else{
return '--';
}
}else{
return '--';
}
} }
,{field: 'handleUser', title: '核实人', width: 200,align:'center'}
,{field: 'openTime', title: '开始处理时间', width:250,align:'center'}
,{field: 'handleTime', title: '核实时间', width:250,align:'center'}
,{field: 'handelRemark', title: '备注', width:250,align:'center'}
// ,{fixed: 'right', title: '操作', width: 200,align:'center', toolbar: '#device-bar'}
]],
done:function (res,curr,count){
}
});
}
//删除数据
function delData(keyId){
$.ajax({
type:'post',
url: dataUrl + 'proteam/pot/early/delWarnInfo',
headers: {
"encrypt": sm3(JSON.stringify({'keyId':keyId}))
},
data: {
keyId:keyId
},
async : true,
success : function(data) {
pages(1, limitSize,false);
if(data.code=='200') {
layer.msg(data.msg, {
icon: 1,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}else{
layer.msg(data.msg, {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
}
});
}
function query(){
pages(1, limitSize,false);
}
function reloadTable(pageNum,limitSize){
pages(pageNum, limitSize,false);
// var curr = deviceTable.config.page.curr;
// var limit = deviceTable.config.limit
// table.reload('deviceTable', {
// page: {
// curr: curr //重新从第 1 页开始
// ,limit:limit
// }
//
// })
}
function getOrgSelect() {
let keys = [];
$.ajax({
headers: {
"encrypt": sm3(JSON.stringify({}))
},
url: dataUrl + 'proteam/pot/team/getOrgSelected' + '?token=' + token,
type: 'post',
success: function (data) {
$.each(data.data, function (index, item) {
let temp = {
"name": item.name,
"value": item.code
};
keys.push(temp);
})
formSelects.data('buildCode', 'local', {
arr: keys
});
layui.form.render();
}
});
}
function getParames(){
var params={
deviceName:$("#deviceName").val(),
macId:$("#macId").val(),
gbCode:$("#gbCode").val(),
typeCode:$("#typeCode").val(),
ssdw:$("#ssdw").val(),
ist:$("#ist").val(),
tName:$("#tName").val(),
tCode:$("#tCode").val(),
keyWord:$("#keyWord").val(),
}
return params;
}
// 弹出模态框
function centerModals() {
$('#myModal_edit').each(function (i) {
var $clone = $(this).clone().css('display', 'block').appendTo('body');
var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 3);
top = top > 0 ? top : 0;
$clone.remove();
$(this).find('.modal-content').css("margin-top", top);
});
};
function setOrg() {
let keys = [];
$.each(orgList, function (index, item) {
let temp = {
"name": item.name,
"value": item.code,
"titleName": item.name
};
keys.push(temp);
})
formSelects.data('buildCode', 'local', {
arr: keys
});
layui.form.render();
}