IntelligentRecognition/ah-jjsp-web/.svn/pristine/ac/ac8205757b5b57e975ec4ec6975...

512 lines
14 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let table;
let deviceTable;
let form;
let per;
let laypage;
let pageNum = 1, limitSize = 30; // 默认第一页分页数量为10
layui.use(['layer', 'form', 'element','laypage'], function(){
var layer = layui.layer; //弹层
laypage = layui.laypage; //分页
table = layui.table; //表格
form=layui.form;
//注册权限
// per=getPer();
$('#myModal_edit').on('show.bs.modal', centerModals);
//初始化下拉选
initDeviceTypeSelect('');//设备类型下拉选
initSsdwSelected('');//所属单位
pages(1, 30, 1);
$(".layui-add").click(function(){
layer.open({
title: '新增设备',
type: 2,
area: ['40%','70%'],
content: '../../../html/device/equment/deviceAdd.html',
cancel: function(){
// layer.msg('捕获就是从页面已经存在的元素上包裹layer的结构', {time: 5000, icon:6});
},
btn: ['确定', '取消'] //只是为了演示
,yes: function(index,leyuo){
var body = layer.getChildFrame('body', index);
body.find('#add-device').click();
}
,btn2: function(){
layer.closeAll();
}
});
})
$(".layui-td").click(function(){
layer.open({
title: '设备通道',
type: 2,
area: ['35%','40%'],
content: '../../../html/device/equment/deviceTd.html',
cancel: function(){
// layer.msg('捕获就是从页面已经存在的元素上包裹layer的结构', {time: 5000, icon:6});
},
btn: ['确定', '取消'] //只是为了演示
,success: function (layero, index) {
var body = layer.getChildFrame('body', index);
var iframeWin = window[layero.find('iframe')[0]['name']];//获得iframe页的窗口对象执行iframe页的方法
iframeWin.setForm(form);//调用子页面的方法,页面锁定
}
,yes: function(index,leyuo){
var body = layer.getChildFrame('body', index);
body.find('#add-td').click();
}
,btn2: function(){
layer.closeAll();
}
});
})
$(".layui-export").click(function(){
exportData();
})
$("#downloadExcel").click(function(){
window.open(dataUrl + 'proteam/pot/device/downloadExcel' + '?token=' + token);
})
$(".layui-import").click(function(){
$("#import-excel").trigger('click');
})
$(".layui-refresh").click(function(){
refresh("");
})
$(".layui-cz").click(function(){
refreshDevice("");
})
$("#import-excel").change(function () {
if($(this).val()){
let files = $(this)[0].files[0];
let fileType = files.name.substring(
files.name.lastIndexOf(".") + 1,
files.name.length
);
if (fileType === "xlsx" || fileType === "xls") {
excelUpload(this, dataUrl + "proteam/pot/device/importExcel" + '?token=' + token, "");
} else {
layer.msg("仅支持上传文件格式为xlx、xlsx", {icon: 5,});
$("#import-excel").val("");
}
}
});
$("#query").off().click(function(){
if(/^[a-zA-Z0-9\u4e80-\u9fa5\\s-]+$/.test($("#deviceName").val()) || ""==$("#deviceName").val()){
}else {
layer.msg("不能包合特殊字符", {icon: 5,});
return;
}
pages(1, limitSize,false);
return ;
})
//重置
$("#reset").off().click(function(){
pages(1, limitSize,true);
})
// 头工具栏事件
table.on('tool(device-table)', function(obj){
console.log(obj);
var event=obj.event;
var key=obj.data.id;//唯一值
if(event=='detail'){//查看详情
layer.open({
title: '设备详情',
type: 2,
area: ['40%','70%'],
content: '../../../html/device/equment/deviceDetail.html',
btn: ['确定', '取消'] //只是为了演示
,success: function (layero, index) {
var body = layer.getChildFrame('body', index);
var iframeWin = window[layero.find('iframe')[0]['name']];//获得iframe页的窗口对象执行iframe页的方法
iframeWin.setForm(key);//调用子页面的方法,页面锁定
}
,yes: function(index,leyuo){
layer.closeAll();
}
,btn2: function(){
layer.closeAll();
}
});
}else if(event=='update'){//修改数据
layer.open({
title: '修改设备',
type: 2,
area: ['40%','70%'],
content: '../../../html/device/equment/deviceAdd.html',
btn: ['确定', '取消']
,success: function (layero, index) {
var body = layer.getChildFrame('body', index);
var iframeWin = window[layero.find('iframe')[0]['name']];//获得iframe页的窗口对象执行iframe页的方法
iframeWin.setForm(key,pageNum,limitSize);//调用子页面的方法,页面锁定
}
,yes: function(index,leyuo){
var body = layer.getChildFrame('body', index);
body.find('#add-device').click();
}
,btn2: function(){
layer.closeAll();
}
});
}else if(event=='del'){//删除数据
layer.msg('确定注销该设备?', {
time: 10000, //10s后自动关闭
btn: ['确定', '取消']
,yes: function(index,leyuo){
layer.closeAll();
delData(key)
}
});
}
})
//查询按钮
})
function pages(pageNum, pageSize, typeNum) {
let params = getReqParams(pageNum, pageSize, typeNum);
$.ajax({
headers: {
"encrypt": sm3(JSON.stringify(params))
},
url: dataUrl+'proteam/pot/device/getDeviceList?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 + "",
deviceName:$("#deviceName").val(),
macId:$("#macId").val(),
puId:$("#puId").val(),
gbCode:$("#gbCode").val(),
typeCode:$("#typeCode").val(),
ssdw:$("#ssdw").val(),
ist:$("#ist").val(),
tCode:$("#tCode").val(),
tName:$("#tName").val(),
keyWord:$("#keyWord").val(),
};
} else {
obj = {
page: '1',
limit: '30',
deviceName:"",
macId:"",
puId:"",
gbCode:"",
typeCode:"",
ssdw:"",
ist:"",
tCode:"",
tName:"",
keyWord:"",
};
}
return obj;
}
//初始化表格
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: 'deviceName', title: '设备名称', width:200,align:'center'}
,{field: 'macId', title: 'MACID', width: 200,align:'center'}
,{field: 'gbCode', title: '国标编码', width:210,align:'center' }
,{field: 'puId', title: 'puId', width: 200,align:'center'}
,{field: 'ssdwName', title: '所属单位', width:250,align:'center'}
,{field: 'typeName', title: '设备类型', width: 200,align:'center'}
,{field: 'ist', title: '是否接入统一视频', width: 200,align:'center'}
,{field: 'tName', title: '统一视频名称', width: 200,align:'center'}
,{field: 'tCode', title: '统一视频编码', width: 200,align:'center'}
,{field: 'twCode', title: '统一视频前端协议编码', width: 200,align:'center'}
,{field: 'tdCode', title: '统一视频设备协议编码', width: 200,align:'center'}
,{field: 'remark', title: '备注', width: 200,align:'center'}
,{field: 'updateTime', title: '更新日期', width: 200,align:'center'}
,{field: 'state', title: '状态', width: 200,align:'center'}
,{field: 'qjxh', title: '球机信号值', width: 200,align:'center'}
,{fixed: 'right', title: '操作', width: 200,align:'center', toolbar: '#device-bar'}
]],
done:function (res,curr,count){
}
});
}
//删除数据
function delData(keyId){
Ajax().post({
url: dataUrl + 'proteam/pot/device/deleteDevice',
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 refreshDevice(keyId){
Ajax().post({
url: dataUrl + 'proteam/pot/device/refreshDevice',
headers: {
"encrypt": sm3(JSON.stringify({'params':"refresh"}))
},
data: {
params: "refresh"
},
async : true,
success : function(data) {
if(data.code==200){
console.log("刷新成功");
}
}
});
}
function refresh(keyId){
Ajax().post({
url: dataUrl + 'proteam/pot/device/refresh',
headers: {
"encrypt": sm3(JSON.stringify({'params':"refresh"}))
},
data: {
params: "refresh"
},
async : true,
success : function(data) {
if(data.code==200){
console.log("刷新成功");
}
}
});
}
//设备类型下拉选
function initDeviceTypeSelect(keyId){
Ajax().post({
url: dataUrl + 'system/sys/selected/getDeviceTypeSelected',
headers: {
"encrypt": sm3(JSON.stringify({'params':"device_type"}))
},
data: {
params: "device_type"
},
async : true,
success : function(data) {
console.log(data);
var html="";
$(".typeCode").empty();
html+="<option value=''>请选择设备类型</option>"
if(data!=null &&data.length>0){
for(var i = 0;i<data.length;i++){ //循环LIST
var code = data[i].code;//获取LIST里面的对象
var name = data[i].name;//获取LIST里面的对象
if(keyId==code){
html+="<option value='"+code+"' selected>"+name+"</option>";
}else {
html+="<option value='"+code+"'>"+name+"</option>";
}
};
}
$(".typeCode").append(html);
form.render();
}
});
}
//所属单位
function initSsdwSelected(keyId){
Ajax().post({
url: dataUrl + 'system/sys/selected/getDictSelected',
headers: {
"encrypt": sm3(JSON.stringify({'params':"ss_dw"}))
},
data: {
params: "ss_dw"
},
async : true,
success : function(data) {
console.log(data);
var html="";
$(".ssdw").empty();
html+="<option value=''>请选择所属单位</option>"
if(data!=null &&data.length>0){
for(var i = 0;i<data.length;i++){ //循环LIST
var code = data[i].code;//获取LIST里面的对象
var name = data[i].name;//获取LIST里面的对象
if(keyId==code){
html+="<option value='"+code+"' selected>"+name+"</option>";
}else {
html+="<option value='"+code+"'>"+name+"</option>";
}
};
}
$(".ssdw").append(html);
form.render();
}
});
}
//导出
function exportData() {
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
let url = dataUrl + "proteam/pot/device/exportDevice?" + 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.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="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 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);
});
};