270 lines
8.6 KiB
Plaintext
270 lines
8.6 KiB
Plaintext
let form, layer, table,tableIns,idParam;
|
||
let pageNum = 1, limitSize = 30; // 默认第一页,分页数量为10
|
||
function setParams(id){
|
||
idParam = id;
|
||
layui.use(['form', 'layer', 'table'], function () {
|
||
form = layui.form;
|
||
layer = layui.layer;
|
||
table = layui.table;
|
||
pages(1, 30, 1);
|
||
})
|
||
$('#myModal_edit').on('show.bs.modal', centerModals);
|
||
}
|
||
|
||
function pages(pageNum, pageSize, typeNum) {
|
||
let params = getReqParams(pageNum, pageSize, typeNum);
|
||
$.ajax({
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify(params))
|
||
},
|
||
url: dataUrl + "proteam/pot/superStatistics/getVoiInfoList?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) {
|
||
layui.use(['laypage'], function () {
|
||
let laypage = layui.laypage;
|
||
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 initTable(dataList, limit, page) {
|
||
let loadingMsg = layer.msg("数据加载中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
|
||
tableIns = table.render({
|
||
elem: "#viobBasisTable",
|
||
id: "viobBasisTable",
|
||
height: "full-150",
|
||
data: dataList,
|
||
limit:limit,
|
||
cols: [
|
||
[
|
||
//表头
|
||
{
|
||
title: "序号",
|
||
width: '10%',
|
||
unresize: true,
|
||
align: "center",
|
||
templet: function (d) {
|
||
return (page - 1) * limit + d.LAY_INDEX;
|
||
}
|
||
},
|
||
{
|
||
field: "notiInfo",
|
||
title: "违章条款",
|
||
width: '70%',
|
||
unresize: true,
|
||
align: "center",
|
||
sort:true
|
||
},
|
||
{
|
||
title: "操作",
|
||
width: '20%',
|
||
unresize: true,
|
||
align: "center",
|
||
templet: function (d) {
|
||
return "<a onclick=\"addVioBasis('" + d.id + "')\">修改</a><div>|</div>" +
|
||
"<a onclick=\"delData('" + d.id + '\')" style="color:#EB3330;">删除</a>';
|
||
}
|
||
}
|
||
],
|
||
],
|
||
done: function (res, curr, count) {
|
||
layer.close(loadingMsg);
|
||
$(".layui-laypage-skip").css("display","none");
|
||
table.resize("viobBasisTable");
|
||
count || this.elem.next(".layui-table-view").find(".layui-table-header").css("display", "inline-block");
|
||
count || this.elem.next(".layui-table-view").find(".layui-table-box").css("overflow", "auto");
|
||
},
|
||
});
|
||
}
|
||
|
||
|
||
// 获取参数
|
||
function getReqParams(page, limit, type) {
|
||
let obj = {};
|
||
if (!type) {
|
||
obj = {
|
||
page: page + "",
|
||
limit: limit + "",
|
||
notiInfo: $("#notiInfo").val(),
|
||
voiTypeId:idParam
|
||
};
|
||
} else {
|
||
obj = {
|
||
page: '1',
|
||
limit: '30',
|
||
notiInfo: '',
|
||
voiTypeId:idParam
|
||
};
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
/*新增/修改违章依据*/
|
||
function addVioBasis(id){
|
||
let title = '新增违章条款';
|
||
if(id){
|
||
title = '修改违章条款';
|
||
}
|
||
let layerIndex = parent.layer.open({
|
||
id: "add-voi-info",
|
||
title: ['<div style="border-left: 3px solid #2F82FB;display: flex;align-items: center;height: 20px;padding: 0 10px;">'+title+'</div>', 'font-size:16px;background-color:#f0f0f0;display: flex;align-items: center;'],
|
||
type: 2,
|
||
maxmin: false,
|
||
content: '../dutyTask/vioType/vioBasisForm.html',
|
||
area: ['664px', '444px'],
|
||
move: false,
|
||
success: function (layero, index) {
|
||
let iframeWin = parent.window["layui-layer-iframe" + layerIndex];
|
||
iframeWin.setParams(id,idParam);
|
||
}
|
||
});
|
||
}
|
||
|
||
/*删除违章依据*/
|
||
function delData(id){
|
||
layer.confirm("确定删除吗?",function (){
|
||
let loadingMsg = layer.msg('数据删除中,请稍候...', {icon: 16, scrollbar: false, time: 0});
|
||
$.ajax({
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify({
|
||
params:id
|
||
}))
|
||
},
|
||
url: dataUrl + 'proteam/pot/superStatistics/delVoiInfoById?token=' + token,
|
||
data: {
|
||
params: id,
|
||
},
|
||
type: 'post',
|
||
async: true,
|
||
success: function (result) {
|
||
layer.close(loadingMsg); // 关闭提示层
|
||
if(result.code === 200){
|
||
layer.msg('删除成功',{icon:1})
|
||
query()
|
||
}else if(result.code === 500){
|
||
layer.alert(result.msg, {icon: 2})
|
||
}else if (result.code === 401) {
|
||
logout(1);
|
||
}
|
||
}, error: function () {
|
||
layer.close(loadingMsg); // 关闭提示层
|
||
layer.msg('服务异常,请稍后重试', {icon: 16, scrollbar: false, time: 2000});
|
||
}
|
||
});
|
||
})
|
||
}
|
||
|
||
/*模板下载*/
|
||
function downLoadExcelModel(){
|
||
let loadingMsg = layer.msg('模板下载中,请稍候...', {icon: 16, scrollbar: false, time: 0});
|
||
let url = dataUrl + 'proteam/pot/superStatistics/downLoadExcelModel?token=' + token;
|
||
let xhr = new XMLHttpRequest();
|
||
xhr.open("get", url, true);
|
||
xhr.responseType = "blob"; // 转换流
|
||
xhr.setRequestHeader("encrypt",
|
||
sm3(JSON.stringify({})));
|
||
xhr.onload = function () {
|
||
layer.close(loadingMsg); // 关闭提示层
|
||
if (this.status === 200) {
|
||
let blob = this.response;
|
||
var a = document.createElement("a");
|
||
var url = window.URL.createObjectURL(blob);
|
||
a.href = url;
|
||
a.download = "违章依据-导入模板.xlsx"; // 文件名
|
||
} else {
|
||
layer.msg('服务异常,请稍后重试', {icon: 16, scrollbar: false, time: 2000});
|
||
}
|
||
a.click()
|
||
window.URL.revokeObjectURL(url)
|
||
};
|
||
xhr.send();
|
||
}
|
||
|
||
function reloadData(){
|
||
pages(pageNum,limitSize)
|
||
}
|
||
|
||
// 查询
|
||
function query() {
|
||
let pattern = new RegExp("[%_<>]");
|
||
if (pattern.test($("#notiInfo").val())) {
|
||
$("#notiInfo").val('');
|
||
return layer.msg('关键字查询包含特殊字符,请重新输入', {
|
||
icon: 2,
|
||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||
});
|
||
}
|
||
pageNum = 1;
|
||
pages(1,limitSize)
|
||
}
|
||
/*导入*/
|
||
function chooseFile(){
|
||
$("#import-excel").trigger("click");
|
||
}
|
||
|
||
$("#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") {
|
||
excelUpload3(this,idParam,dataUrl + "proteam/pot/superStatistics/importExcel?token=" + token)
|
||
} else {
|
||
layer.msg("仅支持上传文件格式为:xlx、xlsx", {icon: 5,});
|
||
$("#import-excel").val("");
|
||
}
|
||
}
|
||
});
|
||
|
||
// 弹出模态框
|
||
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 closePage() {
|
||
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
|
||
parent.layer.close(index); //再执行关闭
|
||
} |