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("