jjsp_web/bns/js/supplement/rectification_punishment_li...

385 lines
9.0 KiB
JavaScript
Raw 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
let user=getUser();
console.log(user)
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);
//初始化下拉选
pages(1, 30, 1);
$(".layui-add").click(function(){
layer.open({
title: '新增',
type: 2,
area: ['40%','70%'],
content: '../../html/supplement/child/rectification_punishment_add.html',
cancel: function(){
// layer.msg('捕获就是从页面已经存在的元素上包裹layer的结构', {time: 5000, icon:6});
},
btn: ['确定', '取消'] //只是为了演示
,yes: function(index,leyuo){
var body = layer.getChildFrame('body', index);
body.find('#add-data').click();
}
,btn2: function(){
layer.closeAll();
}
});
})
$("#query").off().click(function(){
// if(/^[a-zA-Z0-9\u4e80-\u9fa5\\s-]+$/.test($("#keyWord").val()) || ""==$("#keyWord").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=='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/rectificationPunishment/getRectificationPunishmentList?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 + "",
status:$("#status").val(),
keyWord:$("#keyWord").val(),
};
} else {
obj = {
page: '1',
limit: '30',
status:"",
keyWord:"",
};
}
return obj;
}
//初始化表格
function initTable(dataList, limit, page) {
// 执行一个 table 实例
deviceTable=table.render({
id:'deviceTable',
elem: '#device-table',
height: "full-200",
data: dataList,
limit: limit,
cols: [[
{title: "序号", width: '5%', align: "center", templet: function (d) {
return (page - 1) * limit + d.LAY_INDEX;
}
},
{
field: "name",
title: "姓名",
width: '10%',
unresize: true,
align: "center",
style: 'word-break: break-all'
},
{
field: "type",
title: "违章类型",
width: '15%',
unresize: true,
align: "center",
style: 'word-break: break-all'
},
{
field: 'regulationsPath',
title: '违章图片',
width: '20%',
unresize: true,
align: 'center',
templet: function(d) {
// 假设 path 是一个有效的图片URL
if (d.regulationsPath) { // 检查路径是否为空
return `<img src="${d.regulationsPath}" alt="违章图片" style="max-width: 100%; height: auto; max-height: 80px;">`;
} else {
return '无'; // 或者返回其他默认内容
}
}
},
{
field: 'punishmentPath',
title: '处罚单',
width: '20%',
unresize: true,
align: 'center',
templet: function(d) {
// 假设 path 是一个有效的图片URL
if (d.punishmentPath) { // 检查路径是否为空
return `<img src="${d.punishmentPath}" alt="处罚单" style="max-width: 100%; height: auto; max-height: 80px;">`;
} else {
return '无'; // 或者返回其他默认内容
}
}
},
{field: 'uploadTime', title: '上传时间', width:'20%',align:'center'},
{fixed: 'right', title: '操作', width: '10%',align:'center', toolbar: '#device-bar'}
]],
done:function (res,curr,count){
}
});
}
//删除数据
function delData(keyId){
Ajax().post({
url: dataUrl + 'proteam/pot/rectificationPunishment/delDataById',
headers: {
"encrypt": sm3(JSON.stringify({'id':keyId}))
},
data: {
id: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);
}
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 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);
});
};