303 lines
12 KiB
JavaScript
303 lines
12 KiB
JavaScript
|
|
var example = null;
|
|||
|
|
var pers = null;
|
|||
|
|
layui.use(['layer'], function () {
|
|||
|
|
var layer = layui.layer;
|
|||
|
|
pers = checkPermission();
|
|||
|
|
$("#searchBt").click(function () {
|
|||
|
|
example.ajax.reload();
|
|||
|
|
});
|
|||
|
|
$("#saveZipButton").click(function(){
|
|||
|
|
importExcel();
|
|||
|
|
});
|
|||
|
|
init();
|
|||
|
|
|
|||
|
|
$("#exportBt").click(function () {
|
|||
|
|
var token = localStorage.getItem("token");
|
|||
|
|
var loadingMsg = layer.msg('下载中,请稍候...', {icon: 16, scrollbar: false, time: 0});
|
|||
|
|
var url = ctxPath + "/CommonProblem/exportCommonProblem?keyWord=" + $("#keyWord").val().trim()+ "&token=" + token;
|
|||
|
|
var xhr = new XMLHttpRequest();
|
|||
|
|
xhr.open("get", url, true);
|
|||
|
|
xhr.responseType = "blob"; // 转换流
|
|||
|
|
xhr.onload = function () {
|
|||
|
|
layer.close(loadingMsg);
|
|||
|
|
if (this.status === 200) {
|
|||
|
|
var 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 init() {
|
|||
|
|
example =
|
|||
|
|
$('#dt-table').DataTable({
|
|||
|
|
"searching": false,
|
|||
|
|
"processing": true, //加载数据时显示进度状态
|
|||
|
|
"serverSide": true,
|
|||
|
|
"pagingType": "full_numbers", //首页|尾页saveZipButton
|
|||
|
|
"language": {
|
|||
|
|
"url": ctxPath + "/js/plugin/datatables/Chinese.lang"
|
|||
|
|
},
|
|||
|
|
"ajax": {
|
|||
|
|
"url": ctxPath + "/CommonProblem",
|
|||
|
|
"type": "get",
|
|||
|
|
"data": function (d) {
|
|||
|
|
d.keyWord = $("#keyWord").val();
|
|||
|
|
},
|
|||
|
|
"error": function (xhr, textStatus, errorThrown) {
|
|||
|
|
var msg = xhr.responseText;
|
|||
|
|
var response = JSON.parse(msg);
|
|||
|
|
var code = response.code;
|
|||
|
|
var message = response.message;
|
|||
|
|
if (code == 400) {
|
|||
|
|
layer.msg(message);
|
|||
|
|
} else if (code == 401) {
|
|||
|
|
localStorage.removeItem("token");
|
|||
|
|
layer.msg("token过期,请先登录", {shift: -1, time: 1000}, function () {
|
|||
|
|
location.href = ctxPath + '/login.html';
|
|||
|
|
});
|
|||
|
|
} else if (code == 403) {
|
|||
|
|
console.log("未授权:" + message);
|
|||
|
|
layer.msg('未授权');
|
|||
|
|
} else if (code == 500) {
|
|||
|
|
console.log('系统错误:' + message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
"lengthMenu": [ [10, 20, 50], [10, 20, 50] ], // 设置每页显示数据量选项
|
|||
|
|
"drawCallback": function() {
|
|||
|
|
// alert( '表格重绘了' );
|
|||
|
|
var thisDataTable = $('#dt-table').DataTable();
|
|||
|
|
$(".pagination").append("<li>" +
|
|||
|
|
"<a class='paginate_button' style='padding:4px;' href='#' tabindex='0'>到 <input style='margin:0px;width:40px;' id='changePage'> 页</a>" +
|
|||
|
|
"<a class='paginate_button' style='margin-bottom:1px' href='#' tabindex='0' id='dataTable-btn'>确认</a></li>");
|
|||
|
|
//点击按钮跳转指定页数
|
|||
|
|
$('#dataTable-btn').click(function (e) {
|
|||
|
|
if ($("#changePage").val() && $("#changePage").val() > 0) {
|
|||
|
|
var redirectpage = $("#changePage").val() - 1;
|
|||
|
|
} else {
|
|||
|
|
var redirectpage = 0;
|
|||
|
|
}
|
|||
|
|
thisDataTable.page(redirectpage).draw( 'page' );
|
|||
|
|
});
|
|||
|
|
//敲击回车键跳转指定页数
|
|||
|
|
$("#changePage").keypress(function (e) {
|
|||
|
|
if(event.keyCode==13){
|
|||
|
|
if ($("#changePage").val() && $("#changePage").val() > 0) {
|
|||
|
|
var redirectpage = $("#changePage").val() - 1;
|
|||
|
|
} else {
|
|||
|
|
var redirectpage = 0;
|
|||
|
|
}
|
|||
|
|
thisDataTable.page(redirectpage).draw( 'page' );
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
},
|
|||
|
|
"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-4 col-xs-4 hidden-xs'i><'col-xs-8 col-sm-8' p v>><'dt-table-length'l>",
|
|||
|
|
"columns": [
|
|||
|
|
{
|
|||
|
|
width: '40px',
|
|||
|
|
"orderable": false,
|
|||
|
|
data: function (row, type, set, meta) {
|
|||
|
|
var c = meta.settings._iDisplayStart + meta.row + 1;
|
|||
|
|
return c;
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
{"data": "subsystem","orderable": false,"defaultContent": ""},//子系统
|
|||
|
|
{"data": "module", "orderable": false,"defaultContent": ""},//模块
|
|||
|
|
{"data": "problemDescription", "orderable": false, "defaultContent": ""},//问题描述
|
|||
|
|
{"data": "solution","orderable": false,"defaultContent": ""},//解决办法
|
|||
|
|
{"data": "remark","orderable": false,"defaultContent": ""},//备注
|
|||
|
|
{
|
|||
|
|
"data": "",
|
|||
|
|
"defaultContent": "",
|
|||
|
|
"orderable": false,
|
|||
|
|
"render": function (data, type, row) {
|
|||
|
|
var id = row['id'];
|
|||
|
|
var html = '';
|
|||
|
|
html += buttonEdits(id, "sys:Sub:update", pers); //修改
|
|||
|
|
html += buttonDel(id,"", pers); // 删除
|
|||
|
|
return html;
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
],
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 新增页面
|
|||
|
|
* */
|
|||
|
|
function addCommonProblem() {
|
|||
|
|
var height = '525px';
|
|||
|
|
var width = '925px';
|
|||
|
|
var index = layer.open({
|
|||
|
|
title: ['新增','color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
|||
|
|
type: 2,
|
|||
|
|
content: 'commonProblemForm.html',
|
|||
|
|
area: [width, height],
|
|||
|
|
maxmin: false,
|
|||
|
|
btn: ['确定', '关闭'],
|
|||
|
|
success:function(layero,index){
|
|||
|
|
var myIframe = window[layero.find('iframe')[0]['name']];
|
|||
|
|
/*myIframe.getCompanys(); //aaa()为子页面的方法*/
|
|||
|
|
},
|
|||
|
|
yes: function (index, layero) {
|
|||
|
|
// 获取弹出层中的form表单元素
|
|||
|
|
var formSubmit = layer.getChildFrame('form', index);
|
|||
|
|
var submited = formSubmit.find('button')[0];
|
|||
|
|
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
|
|||
|
|
submited.click();
|
|||
|
|
// example.ajax.reload(); // 刷新页面
|
|||
|
|
},
|
|||
|
|
btn2: function (index, layero) {
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 编辑按钮
|
|||
|
|
function buttonEdits(id, permission, pers) {
|
|||
|
|
if (permission != "") {
|
|||
|
|
if ($.inArray(permission, pers) < 0) {
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
var btn = $("<button class='layui-btn layui-btn-xs' title='编辑' onclick='edit(\"" + id + "\")'><i class='layui-icon'></i></button>");
|
|||
|
|
return btn.prop("outerHTML");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 编辑页面
|
|||
|
|
*/
|
|||
|
|
function edit(id) {
|
|||
|
|
$.ajax({
|
|||
|
|
type: 'POST',
|
|||
|
|
contentType: "application/x-www-form-urlencoded",
|
|||
|
|
url: ctxPath + '/CommonProblem/getCommonProblemById',
|
|||
|
|
data: {"id": id},
|
|||
|
|
dataType: 'json',
|
|||
|
|
success: function (data) {
|
|||
|
|
var height = '85%';
|
|||
|
|
var width = '85%';
|
|||
|
|
var index = layer.open({
|
|||
|
|
title: ['修改', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
|||
|
|
type: 2,
|
|||
|
|
content: 'commonProblemForm.html',
|
|||
|
|
area: [width, height],
|
|||
|
|
maxmin: false,
|
|||
|
|
btn: ['确定', '关闭'],
|
|||
|
|
success: function (layero, index) {
|
|||
|
|
var myIframe = window[layero.find('iframe')[0]['name']];
|
|||
|
|
var fnc = myIframe.setData(data); //aaa()为子页面的方法
|
|||
|
|
},
|
|||
|
|
yes: function (index, layero) {
|
|||
|
|
// 获取弹出层中的form表单元素
|
|||
|
|
var formSubmit = layer.getChildFrame('form', index);
|
|||
|
|
var submited = formSubmit.find('button')[0];
|
|||
|
|
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
|
|||
|
|
submited.click();
|
|||
|
|
// example.ajax.reload(); // 刷新页面
|
|||
|
|
},
|
|||
|
|
btn2: function (index, layero) {
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 删除按钮
|
|||
|
|
function buttonDel(id,permission, pers) {
|
|||
|
|
if (permission != "") {
|
|||
|
|
if ($.inArray(permission, pers) < 0) {
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
var btn = $("<button class='layui-btn layui-btn-xs' title='删除' onclick='del(\"" + id + "\")'><i class='layui-icon'></i></button>");
|
|||
|
|
return btn.prop("outerHTML");
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//删除
|
|||
|
|
function del(id){
|
|||
|
|
layer.confirm("您确定要删除此条数据吗?", function () {
|
|||
|
|
var form = {"id" : id};
|
|||
|
|
$.ajax({
|
|||
|
|
type: 'post',
|
|||
|
|
url: ctxPath + '/CommonProblem/delCommonProblem',
|
|||
|
|
contentType: "application/json; charset=utf-8",
|
|||
|
|
data: JSON.stringify(form),
|
|||
|
|
dataType: 'json',
|
|||
|
|
success: function (data) {
|
|||
|
|
if (data.resMsg == "删除成功") {
|
|||
|
|
layer.msg('删除成功', {icon: 1, time: 3000});
|
|||
|
|
example.ajax.reload(null, false); // 刷新页面
|
|||
|
|
} else {
|
|||
|
|
layer.msg(data.resMsg, {icon: 2, time: 3000});
|
|||
|
|
example.ajax.reload(null, false); // 刷新页面
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//导入excel文件
|
|||
|
|
function importExcel(){
|
|||
|
|
var formData = new FormData($('form')[0]);
|
|||
|
|
var name = $("#articleImageFile").val();
|
|||
|
|
if(name==null|| name == "") {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if(!(name.endsWith(".xls") || name.endsWith(".xlsx") || name.endsWith(".xlsm"))) {
|
|||
|
|
layer.msg("请上传正确的Excel表格!");
|
|||
|
|
$("#articleImageFile").val("");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
formData.append("file", $("#articleImageFile")[0].files[0]);
|
|||
|
|
var idx = layer.msg('正在提交数据,请稍等...', {
|
|||
|
|
icon: 16
|
|||
|
|
,shade: 0.01
|
|||
|
|
,time:'-1'
|
|||
|
|
});
|
|||
|
|
$.ajax({
|
|||
|
|
url : ctxPath + "/CommonProblem/importExcel",
|
|||
|
|
type : 'POST',
|
|||
|
|
async : false,
|
|||
|
|
data : formData,
|
|||
|
|
timeout:20000,
|
|||
|
|
// 告诉jQuery不要去处理发送的数据
|
|||
|
|
processData : false,
|
|||
|
|
// 告诉jQuery不要去设置Content-Type请求头
|
|||
|
|
contentType : false,
|
|||
|
|
success : function(data) {
|
|||
|
|
layer.close(idx);
|
|||
|
|
if(data.indexOf("导入成功") !=-1){
|
|||
|
|
layer.alert(data, {icon: 1});
|
|||
|
|
}else if(data.indexOf("导入失败") !=-1){
|
|||
|
|
console.log(data)
|
|||
|
|
layer.alert(data, {icon: 2});
|
|||
|
|
}
|
|||
|
|
example.ajax.reload(null, false); // 刷新页面
|
|||
|
|
},
|
|||
|
|
error:function(XMLHttpRequest, textStatus, errorThrown) {
|
|||
|
|
console.log(JSON.stringify(errorThrown));
|
|||
|
|
layer.close(idx);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
$("#articleImageFile").val("");
|
|||
|
|
}
|
|||
|
|
function downCommonProblem(){
|
|||
|
|
window.location.href = ctxPath + "/download/download?filename=湖南农民工实名制管理平台使用常见问题汇总.xlsx";
|
|||
|
|
}
|
|||
|
|
|