230 lines
8.5 KiB
JavaScript
230 lines
8.5 KiB
JavaScript
|
|
var example = null;
|
|||
|
|
var pers = checkPermission();
|
|||
|
|
var laydate;
|
|||
|
|
var times = getCurrentDateTimeArr();
|
|||
|
|
var nextTimes = getCurrentMonthAndLastMonth();
|
|||
|
|
layui.use(['form', 'layer', 'laydate'], function () {
|
|||
|
|
laydate = layui.laydate;
|
|||
|
|
|
|||
|
|
// 年月范围
|
|||
|
|
laydate.render({
|
|||
|
|
elem: '#months',
|
|||
|
|
type: 'month',
|
|||
|
|
range: true,
|
|||
|
|
btns: [ 'now', 'confirm'],
|
|||
|
|
value: times[0]+ "-" + times[1] + " - " + times[0]+ "-" + times[1]
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
init();
|
|||
|
|
$("#searchBt").click(function () {
|
|||
|
|
example.ajax.reload();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 重置按钮
|
|||
|
|
*/
|
|||
|
|
$("#resetBt").click(function () {
|
|||
|
|
$("#name").val("");
|
|||
|
|
$("#proName").val("");
|
|||
|
|
$("#subName").val("");
|
|||
|
|
$("#months").val(times[0]+ "-" + times[1] + " - " + times[0]+ "-" + times[1]);
|
|||
|
|
example.ajax.reload();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 导出数据
|
|||
|
|
*/
|
|||
|
|
$("#exportBt").click(function () {
|
|||
|
|
var months = $("#months").val();
|
|||
|
|
var startMonth, endMonth;
|
|||
|
|
if(months == ""){
|
|||
|
|
startMonth = times[0]+ "-" + times[1];
|
|||
|
|
endMonth = times[0]+ "-" + times[1];
|
|||
|
|
}else{
|
|||
|
|
startMonth = months.split(" - ")[0].trim();
|
|||
|
|
endMonth = months.split(" - ")[1].trim();
|
|||
|
|
}
|
|||
|
|
var name = $("#name").val();
|
|||
|
|
var proName = $("#proName").val();
|
|||
|
|
var subName = $("#subName").val();
|
|||
|
|
|
|||
|
|
|
|||
|
|
var token = localStorage.getItem("token")
|
|||
|
|
|
|||
|
|
let loadingMsg = layer.msg('数据导出中,请稍候...', {icon: 16, scrollbar: false, time: 0});
|
|||
|
|
let url = ctxPath + "/salaryPaymentAndAttendanceRecords/exportData?token=" + token +"&startMonth=" + startMonth + "&endMonth=" + endMonth + "&name=" + name + "&proName=" + proName + "&subName=" + subName;
|
|||
|
|
let xhr = new XMLHttpRequest();
|
|||
|
|
xhr.open("get", url, true);
|
|||
|
|
xhr.responseType = "blob"; // 转换流
|
|||
|
|
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 init() {
|
|||
|
|
example =
|
|||
|
|
$('#dt-table').DataTable({
|
|||
|
|
"searching": false,
|
|||
|
|
"processing": true, //加载数据时显示进度状态
|
|||
|
|
"serverSide": true,
|
|||
|
|
"pagingType": "full_numbers", //首页|尾页
|
|||
|
|
"bLengthChange": false,
|
|||
|
|
"language": {
|
|||
|
|
"url": ctxPath + "/js/plugin/datatables/Chinese.lang"
|
|||
|
|
},
|
|||
|
|
"ajax": {
|
|||
|
|
"url": ctxPath + "/salaryPaymentAndAttendanceRecords/getList",
|
|||
|
|
"type": "get",
|
|||
|
|
"data": function (d) {
|
|||
|
|
var months = $("#months").val();
|
|||
|
|
if(months == ""){
|
|||
|
|
d.startMonth = times[0]+ "-" + times[1];
|
|||
|
|
d.endMonth = times[0]+ "-" + times[1];
|
|||
|
|
}else{
|
|||
|
|
d.startMonth = months.split(" - ")[0].trim();
|
|||
|
|
d.endMonth = months.split(" - ")[1].trim();
|
|||
|
|
}
|
|||
|
|
d.name = $("#name").val();
|
|||
|
|
d.proName = $("#proName").val();
|
|||
|
|
d.subName = $("#subName").val();
|
|||
|
|
},
|
|||
|
|
"error": function (xhr, textStatus, errorThrown) {
|
|||
|
|
var msg = xhr.responseText;
|
|||
|
|
console.log(msg);
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
"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": "name",'width': '85px'},
|
|||
|
|
{"data": "idNumber",'width': '100px'},
|
|||
|
|
{"data": "month",'width': '45px'},
|
|||
|
|
{"data": "attenNum",'width': '40px'},
|
|||
|
|
{"data": "payable",'width': '80px'},
|
|||
|
|
{"data": "payIn",'width': '80px'},
|
|||
|
|
{"data": "proName",'width': '160px'},
|
|||
|
|
{"data": "subName",'width': '150px'},
|
|||
|
|
{"data": "rewordNum",'width': '70px'},
|
|||
|
|
{
|
|||
|
|
"data": "",
|
|||
|
|
'width': '80px',
|
|||
|
|
"defaultContent": "",
|
|||
|
|
"orderable": false,
|
|||
|
|
"render": function (data, type, row) {
|
|||
|
|
var idNumber = row['idNumber'];
|
|||
|
|
var month = row['month'];
|
|||
|
|
var html = '';
|
|||
|
|
html += detailsBtn(idNumber, month, "", pers);
|
|||
|
|
return html;
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
],
|
|||
|
|
"order": [[1, "desc"]] //在栏目列上显示排序功能
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 详情按钮
|
|||
|
|
function detailsBtn(idNumber, month, permission, pers) {
|
|||
|
|
if (permission != "") {
|
|||
|
|
if ($.inArray(permission, pers) < 0) {
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
var btn = $("<button class='layui-btn layui-btn-xs' title='详情' onclick='detailsView(\""+idNumber+"\", \""+month+"\")'><i class='layui-icon'></i>详情</button>");
|
|||
|
|
return btn.prop("outerHTML");
|
|||
|
|
}
|
|||
|
|
/**
|
|||
|
|
* 详情
|
|||
|
|
* */
|
|||
|
|
function detailsView(idNumber, month) {
|
|||
|
|
$.ajax({
|
|||
|
|
type: 'POST',
|
|||
|
|
contentType: "application/x-www-form-urlencoded",
|
|||
|
|
url: ctxPath + '/salaryPaymentAndAttendanceRecords/getDetailData',
|
|||
|
|
data:{
|
|||
|
|
"idNumber":idNumber,
|
|||
|
|
"month": month
|
|||
|
|
},
|
|||
|
|
dataType: 'json',
|
|||
|
|
success: function (data) {
|
|||
|
|
var height = '100%';
|
|||
|
|
var width = '100%';
|
|||
|
|
var index = layer.open({
|
|||
|
|
title: ['详情','color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
|||
|
|
type: 2,
|
|||
|
|
content: './salaryAttendanceDetails.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()为子页面的方法
|
|||
|
|
},
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|