390 lines
16 KiB
JavaScript
390 lines
16 KiB
JavaScript
var example = null;
|
||
var pers = null;
|
||
var layer = null;
|
||
var form = null;
|
||
var token = localStorage.getItem("token");
|
||
layui.use(['layer', 'form', 'laydate'], function () {
|
||
layer = layui.layer;
|
||
form = layui.form;
|
||
var laydate = layui.laydate;
|
||
laydate.render({
|
||
elem: '#monthTime',
|
||
type: 'month',
|
||
format: 'yyyy-MM',
|
||
});
|
||
$('#monthTime').val(getNowTime());
|
||
getProject(form);
|
||
init();
|
||
pers = checkPermission();
|
||
$("#searchBt").click(function () {
|
||
example.ajax.reload();
|
||
});
|
||
});
|
||
|
||
function init() {
|
||
example =
|
||
$('#dt-table').DataTable({
|
||
"searching": false,
|
||
"processing": true, //加载数据时显示进度状态
|
||
"serverSide": true,
|
||
//表头固定
|
||
"fixedHeader": true,
|
||
"scrollX": "500px",
|
||
"scrollY": "650px",
|
||
"scrollCollapse": true,
|
||
"language": {
|
||
"url": ctxPath + "/js/plugin/datatables/Chinese.lang"
|
||
},
|
||
"ajax": {
|
||
"url": ctxPath + "/wagesInfoReceipt",
|
||
"type": "get",
|
||
"data": function (d) {
|
||
d.proId = $("#proId").val();
|
||
d.keyWord = $("#keyWord").val();
|
||
d.receiptFlage = $("#receiptFlage").val();
|
||
var date = $("#monthTime").val();
|
||
date = date.split("-");
|
||
var year = date[0];
|
||
var month = date[1];
|
||
d.year =year;
|
||
d.month =month;
|
||
},
|
||
"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>>",
|
||
"columns": [
|
||
{
|
||
width: '4%',
|
||
orderable: false,
|
||
data: function (row, type, set, meta) {
|
||
var c = meta.settings._iDisplayStart + meta.row + 1;
|
||
return c;
|
||
}
|
||
},
|
||
{"data": "proName","width":"5%"},
|
||
{"data": "teamName","width":"5%"},
|
||
{"data": "subName","width":"5%"},
|
||
{"data": "month","width":"5%","orderable": false,},
|
||
{"data": "startTime","width":"5%","orderable": false,
|
||
"render":function(data,type,row){
|
||
var seTime = row['seTime'];
|
||
var html = '';
|
||
html +="<span >"+seTime+"</span>";
|
||
return html;
|
||
}
|
||
},
|
||
|
||
{"data": "teamNum","width":"5%","orderable": false,},
|
||
{"data": "checkNum","width":"5%","orderable": false, },
|
||
{"data": "payNum","width":"5%","orderable": false,},
|
||
{"data": "withhold","width":"5%","orderable": false,
|
||
//代扣代缴
|
||
"render":function (data,type,row) {
|
||
var withhold = row['withhold'];
|
||
if(withhold==null || withhold=="null"){
|
||
withhold=0;
|
||
}
|
||
var withholds = Number(withhold);
|
||
withholds =withholds.toFixed(2);
|
||
var html = '';
|
||
html += "<span>"+withholds+"</span>";
|
||
return html;
|
||
}
|
||
|
||
},
|
||
{"data": "realPay","width":"5%","orderable": false,
|
||
//实发工资
|
||
"render":function (data,type,row) {
|
||
var realPay = row['realPay'];
|
||
if(realPay==null|| realPay=="null"){
|
||
realPay=0;
|
||
}
|
||
var realPays = Number(realPay);
|
||
realPays =realPays.toFixed(2);
|
||
var html = '';
|
||
html += "<span>"+realPays+"</span>";
|
||
return html;
|
||
}
|
||
},
|
||
|
||
{"data": "","width":"5%","orderable": false,
|
||
"render":function(data,type,row){
|
||
var receiptFlage = row['receiptFlage'];
|
||
var html = '';
|
||
if(receiptFlage==1){
|
||
html +="已上传";
|
||
}else{
|
||
html +="<span style='color: red'>未上传</span>";
|
||
}
|
||
return html;
|
||
}
|
||
},
|
||
/*{"data": "","width":"5%",
|
||
"render": function (data, type, row) {
|
||
var grantSuccee = row['grantSuccee'];
|
||
var grantFail = row['grantFail'];
|
||
if(grantFail==null || grantFail=="null"){
|
||
grantFail = 0;
|
||
}
|
||
var html = '';
|
||
html +="<div>";
|
||
html +="<span style='color:green;'>成功:"+grantSuccee+"</span>";
|
||
html +="</div>";
|
||
html +="<div>";
|
||
html +="<span style='color:red;'>失败:"+grantFail+"</span>";
|
||
html +="</div>";
|
||
return html;
|
||
}
|
||
},*/
|
||
{"data": "","width":"5%","orderable": false,
|
||
"render": function (data, type, row) {
|
||
var id = row['id'];
|
||
var receiptNum = row['receiptNum'];
|
||
var html = "";
|
||
if(receiptNum=="0" || receiptNum==0){
|
||
html += "<span >"+receiptNum+"</span>";
|
||
}else{
|
||
html += "<a style = 'color:#09A8F1;cursor: pointer' onclick = 'receiptFileView(\"" + id + "\")'>" + receiptNum + "</a>";
|
||
}
|
||
return html;
|
||
}
|
||
},
|
||
// {"data": "remark","width":"5%"},
|
||
{
|
||
"data": "",
|
||
"width":"10%",
|
||
"defaultContent": "",
|
||
"orderable": false,
|
||
"render": function (data, type, row) {
|
||
var id = row['id'];
|
||
var submitFlage = row['submitFlage'];
|
||
var year = row['year'];
|
||
var month = row['month'];
|
||
var proId = row['proId'];
|
||
var proName = row['proName'];
|
||
var teamId = row['teamId'];
|
||
var teamName = row['teamName'];
|
||
var subId = row['subId'];
|
||
var subName = row['subName'];
|
||
var seTime = row['seTime'];
|
||
var html = '';
|
||
html += buttonView(id,year,month,proId,proName,teamId,teamName,subId,subName,seTime, "", pers);
|
||
html += buttonDownload(id,year,month,proId,proName,teamId,teamName,subId,subName,seTime, "sys:wagesInfoReceipt:download", pers);
|
||
html += buttonUpload(id,year,month,proId,proName,teamId,teamName,subId,subName, seTime,"sys:wagesInfoReceipt:upload", pers);
|
||
return html;
|
||
}
|
||
}
|
||
|
||
],
|
||
"order": [[1, "desc"],[2, "desc"],[3, "desc"]] //在栏目列上显示排序功能
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 详情按钮
|
||
* */
|
||
function view(id,year,month,proId,proName,teamId,teamName,subId,subName,seTime ) {
|
||
localStorage.setItem("id",id);
|
||
localStorage.setItem("year",year);
|
||
localStorage.setItem("month",month);
|
||
localStorage.setItem("proId",proId);
|
||
localStorage.setItem("proName",proName);
|
||
localStorage.setItem("teamId",teamId);
|
||
localStorage.setItem("teamName",teamName);
|
||
localStorage.setItem("subId",subId);
|
||
localStorage.setItem("subName",subName);
|
||
localStorage.setItem("seTime ",seTime );
|
||
var height = '750px';
|
||
var width = '1650px';
|
||
var index = layer.open({
|
||
title: ['工资发放结果详情', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'wagesInfoReceiptDetails.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['关闭'],
|
||
});
|
||
}
|
||
|
||
// 详情按钮
|
||
function buttonView(id,year,month,proId,proName,teamId,teamName,subId,subName,seTime, permission, pers) {
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='详情' onclick='view(\"" + id + "\",\"" + year + "\",\"" + month + "\",\"" + proId + "\",\"" + proName + "\",\"" + teamId + "\",\"" + teamName + "\",\"" + subId + "\",\"" + subName + "\",\"" + seTime + "\")'><i class='layui-icon'></i></button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
|
||
// 下载按钮
|
||
function buttonDownload(id,year,month,proId,proName,teamId,teamName,subId,subName,seTime, permission, pers) {
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='下载' onclick='templateDownload(\"" + id + "\",\"" + year + "\",\"" + month + "\",\"" + proId + "\",\"" + proName + "\",\"" + teamId + "\",\"" + teamName + "\",\"" + subId + "\",\"" + subName + "\",\"" + seTime + "\")'><i class='layui-icon'></i></button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
|
||
function templateDownload(id,year,month,proId,proName,teamId,teamName,subId,subName,seTime ){
|
||
var token = localStorage.getItem("token");
|
||
var loadingMsg = layer.msg('下载中,请稍候...', {icon: 16, scrollbar: false, time: 0});
|
||
var seTimes = seTime.split("~");
|
||
var startTime = seTimes[0];
|
||
var endTime = seTimes[1];
|
||
|
||
var url = ctxPath + "/wagesInfoReceipt/exportWagesReceipt?id=" + id + "&startTime=" + startTime + "&endTime=" + endTime + "&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 = "工资支付详情表-"+ proName +"-"+teamName+ "-"+ year+ "-"+ month + ".xlsx"; // 文件名
|
||
}else {
|
||
layer.msg('导出发生异常,请稍后重试', {icon: 16, scrollbar: false, time: 2000});
|
||
}
|
||
a.click()
|
||
window.URL.revokeObjectURL(url)
|
||
};
|
||
xhr.send();
|
||
}
|
||
|
||
// 上传按钮
|
||
function buttonUpload(id,year,month,proId,proName,teamId,teamName,subId,subName,seTime, permission, pers) {
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='回执单上传' onclick='upload(\"" + id + "\",\"" + year + "\",\"" + month + "\",\"" + proId + "\",\"" + proName + "\",\"" + teamId + "\",\"" + teamName + "\",\"" + subId + "\",\"" + subName + "\",\"" + seTime + "\")'><i class='layui-icon'></i></button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
|
||
function upload(id,year,month,proId,proName,teamId,teamName,subId,subName,seTime ) {
|
||
localStorage.setItem("id",id);
|
||
localStorage.setItem("year",year);
|
||
localStorage.setItem("month",month);
|
||
localStorage.setItem("proId",proId);
|
||
localStorage.setItem("proName",proName);
|
||
localStorage.setItem("teamId",teamId);
|
||
localStorage.setItem("teamName",teamName);
|
||
localStorage.setItem("subId",subId);
|
||
localStorage.setItem("subName",subName);
|
||
localStorage.setItem("seTime",seTime );
|
||
var height = '750px';
|
||
var width = '1650px';
|
||
var index = layer.open({
|
||
title: ['回执单上传', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'wagesInfoReceiptForm.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['关闭'],
|
||
success: function (layero, index) {
|
||
var myIframe = window[layero.find('iframe')[0]['name']];
|
||
|
||
},
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 获得当前时间 yyyy-MM
|
||
* @returns {string}
|
||
*/
|
||
function getNowTime() {
|
||
var time = new Date();
|
||
var year = time.getFullYear();
|
||
var month = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1);
|
||
return year + "-" + month ;
|
||
}
|
||
|
||
//查看附件详情
|
||
function receiptFileView(id) {
|
||
//去后台查数据
|
||
var formUrl = ctxPath + "/wagesInfoReceipt/getReceipt";
|
||
$.ajax({
|
||
type: 'POST',
|
||
async: true, // 默认异步true,false表示同步
|
||
url: formUrl, // 请求地址
|
||
data: {"id":id}, //获取提交的表单字段
|
||
success: function (data) {
|
||
var filePaths = new Array();
|
||
if (data.length>0) {
|
||
for(var i=0; i<data.length; i++){
|
||
var filePath = data[i].path ;
|
||
filePaths.push(filePath)
|
||
}
|
||
localStorage.setItem("filePaths", filePaths);
|
||
var height = '525px';
|
||
var width = '800px';
|
||
var index = layer.open({
|
||
title: ["查看", 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: '../../receiptFileView.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
});
|
||
} else {
|
||
parent.layer.msg('回执单查询失败', {icon: 2, time: 2000});
|
||
}
|
||
},
|
||
error: function (XMLHttpRequest, textStatus, e) {
|
||
layer.msg('数据请求发生异常,请稍后重试', {icon: 16, scrollbar: false});
|
||
}
|
||
});
|
||
}
|
||
|