hn_cloud_web/smz-web/js/work/smallSubManagement/stat/personnelStatView.js

357 lines
14 KiB
JavaScript
Raw Normal View History

2025-11-27 16:55:35 +08:00
var example = null;
var pers = null;
var form,layer,laydate = null;
function receiveParamsPersonnel( params){
let idCard = params.idCard;
$("#idCard").val(idCard);
layui.use(['layer', 'laydate', 'form'], function () {
layer = layui.layer;
laydate = layui.laydate
form = layui.form;
getProject(form)
getGxs("",form)
// 初始化日期选择器
laydate.render({
elem: "#date-search",
range: true,
format: "yyyy-MM-dd",
})
pers = checkPermission();
form.on('select(proId)', function (data) {
//根据子公司查询项目部
getGxs(data.value,form)
});
//小包干人员详情
getDetailInfoByUser(idCard)
//项目出入场记录
initEntryExitTable(idCard);
//考勤记录
initAttendanceTable(idCard);
})
}
function getDetailInfoByUser(idCard){
$.ajax({
type: 'get',
2025-12-09 18:44:29 +08:00
url: smz_ht_url + '/dataCount/getDetailInfoByUser',
2025-11-27 16:55:35 +08:00
data: {
idCard: idCard
},
async: false,
success: function (data) {
if(data.res==1 || data.res=="1" ){
let l = data.succeed;
$("#userName").text(l.userName);
$("#postName").text(l.postName);
$("#proName").text(l.proName);
$("#subName").text(l.subName);
$("#entryAndExitStatus").text(l.entryAndExitStatus);
if(l.entryAndExitStatus=="出场"){
$("#entryAndExitStatus").addClass("status-active");
$("#entryAndExitStatus").removeClass("status-inactive");
}else{
$("#entryAndExitStatus").addClass("status-inactive");
$("#entryAndExitStatus").removeClass("status-active");
}
$("#phone").text(l.phone);
$("#postTypeName").text(l.postTypeName);
$("#teamName").text(l.teamName);
var imgElement = document.getElementById("photoPath");
2025-12-09 18:44:29 +08:00
imgElement.src = smz_ht_url +"/" + l.photoPath ;
2025-11-27 16:55:35 +08:00
}
},
error: function (err) {
console.log("获取小包干工序桩位详情出错:", err);
}
});
}
var entryExitTable, attendanceTable;
// 初始化出入场记录表格
function initEntryExitTable(idCard) {
entryExitTable = $("#entry-exit-table").DataTable({
"searching": false,
"processing": true,
"serverSide": false,
"paging": false,
"info": false,
"language": {
2025-12-09 18:44:29 +08:00
"url": "../../../../js/plugin/datatables/Chinese.lang",
2025-11-27 16:55:35 +08:00
},
"ajax": {
2025-12-09 18:44:29 +08:00
"url": smz_ht_url + "/dataCount/getEntryAndExitRecords",
2025-11-27 16:55:35 +08:00
"type": "get",
"data": function (d) {
d.idCard = idCard;
},
"dataSrc": function(json) {
console.log("数据:", json);
// 检查响应状态
if (json.res === 1) {
let data = []
if (json.obj) {
if (Array.isArray(json.obj)) {
data = json.obj
} else {
data = [json.obj]
}
}
return data
} else {
// 处理错误情况
layer.msg(json.resMsg || '数据加载失败');
return [];
}
},
"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 () {
2025-12-09 18:44:29 +08:00
location.href = smz_ht_url + '/login.html';
2025-11-27 16:55:35 +08:00
});
} else if (code == 403) {
console.log("未授权:" + message);
layer.msg('未授权');
} else if (code == 500) {
console.log('系统错误:' + message);
}
}
},
"drawCallback": () => {
var thisDataTable = $("#entry-exit-table").DataTable()
var wrapper = $("#entry-exit-table_wrapper")
var pagination = wrapper.find(".pagination")
// 检查是否已经添加过自定义控件
if (!pagination.find(".custom-page-jump-entry-exit").length) {
pagination.append(
"<li class='custom-page-jump-entry-exit'>" +
"<a class='paginate_button' style='padding:4px;' href='#' tabindex='0'>到 <input style='margin:0px;width:40px;' id='changePageEntryExit'> 页</a>" +
"<a class='paginate_button' style='margin-bottom:1px' href='#' tabindex='0' id='dataTable-btn-entry-exit'>确认</a></li>",
)
$("#dataTable-btn-entry-exit").click((e) => {
var redirectpage = $("#changePageEntryExit").val() - 1
if (redirectpage >= 0) {
thisDataTable.page(redirectpage).draw("page")
}
})
$("#changePageEntryExit").keypress((e) => {
if (e.keyCode == 13) {
var redirectpage = $("#changePageEntryExit").val() - 1
if (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'>",
columns: [
{ data: "contractCode", orderable: false, width: "200px",},
{ data: "postName", orderable: false, width: "120px" },
{ data: "teamName", orderable: false, width: "100px" },
{ data: "subName", orderable: false, width: "180px" },
{ data: "proName", orderable: false, width: "150px" },
{ data: "totalNum", orderable: false, width: "120px" },
{ data: "einTime", orderable: false, width: "150px" },
{ data: "exitTime", orderable: false, width: "150px",},
],
order: [],
})
}
// 初始化考勤记录表格
function initAttendanceTable(idCard) {
attendanceTable = $("#attendance-table").DataTable({
searching: false,
processing: true,
serverSide: true,
pagingType: "full_numbers",
language: {
2025-12-09 18:44:29 +08:00
url: "../../../../js/plugin/datatables/Chinese.lang",
2025-11-27 16:55:35 +08:00
},
"ajax": {
2025-12-09 18:44:29 +08:00
"url": smz_ht_url + "/dataCount/getAttRecordByUser",
2025-11-27 16:55:35 +08:00
"type": "POST",
"data": function (d) {
d.idCard = idCard;
d.proId = $("#proId").val();
d.gxId = $("#gxId").val();
d.dataType = $("#dataType").val();
var dateSearch = $("#date-search").val();
var dates = dateSearch.split(' - ');
var startTime = dates[0]; // 开始时间
var endTime = dates[1]; // 结束时间
d.startTime = startTime;
d.endTime = endTime;
},
"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 () {
2025-12-09 18:44:29 +08:00
location.href = smz_ht_url + '/login.html';
2025-11-27 16:55:35 +08:00
});
} else if (code == 403) {
console.log("未授权:" + message);
layer.msg('未授权');
} else if (code == 500) {
console.log('系统错误:' + message);
}
}
},
"lengthMenu": [[10, 20, 50], [10, 20, 50]],
"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'>",
"drawCallback": () => {
var thisDataTable = $("#attendance-table").DataTable()
var wrapper = $("#attendance-table_wrapper")
var pagination = wrapper.find(".pagination")
// 检查是否已经添加过自定义控件
if (!pagination.find(".custom-page-jump-attendance").length) {
pagination.append(
"<li class='custom-page-jump-attendance'>" +
"<a class='paginate_button' style='padding:4px;' href='#' tabindex='0'>到 <input style='margin:0px;width:40px;' id='changePageAttendance'> 页</a>" +
"<a class='paginate_button' style='margin-bottom:1px' href='#' tabindex='0' id='dataTable-btn-attendance'>确认</a></li>",
)
$("#dataTable-btn-attendance").click((e) => {
var redirectpage = $("#changePageAttendance").val() - 1
if (redirectpage >= 0) {
thisDataTable.page(redirectpage).draw("page")
}
})
$("#changePageAttendance").keypress((e) => {
if (e.keyCode == 13) {
var redirectpage = $("#changePageAttendance").val() - 1
if (redirectpage >= 0) {
thisDataTable.page(redirectpage).draw("page")
}
}
})
}
},
"columns": [
{
width: "60px",
orderable: false,
data: (row, type, set, meta) => {
var c = meta.settings._iDisplayStart + meta.row + 1
return c
},
},
{ data: "attDate", orderable: false, width: "100px" },
{
data: "attTypeName",
orderable: false,
width: "80px",
render: (data, type, row) => {
var className = ""
var attTypeName = row['attTypeName'];
switch (attTypeName) {
case "计件":
className = "attendance-type-piece"
break
case "计日":
className = "attendance-type-daily"
break
case "窝工":
className = "attendance-type-fixed"
break
case "休息":
className = "attendance-type-rest"
break
case "未考勤":
className = "attendance-type-absent"
break
}
return '<span class="' + className + '">' + attTypeName + "</span>"
},
},
{ data: "gxName", orderable: false, width: "180px",},
{ data: "proName", orderable: false, width: "150px" },
{ data: "address", orderable: false, width: "300px",},
],
order: [],
})
}
// 搜索功能
function searchAttendance() {
attendanceTable.ajax.reload();
}
function resetAttendance() {
$('#proId').val('');
$('#gxId').val('');
$('#dataType').val('');
$('#date-search').val('');
// 重新渲染 select 下拉框
layui.form.render("select");
attendanceTable.ajax.reload();
}
function exportAttendance() {
var idCard = $("#idCard").val();
var proId = $("#proId").val();
var gxId = $("#gxId").val();
var dataType = $("#dataType").val();
// var startTime = $("#startTime").val();
// var endTime = $("#endTime").val();
var dateSearch = $("#date-search").val();
var dates = dateSearch.split(' - ');
var startTime = dates[0]; // 开始时间
var endTime = dates[1]; // 结束时间
2025-12-05 15:39:43 +08:00
var token = localStorage.getItem("smz-token");
2025-11-27 16:55:35 +08:00
var loadingMsg = layer.msg('下载中,请稍候...', {icon: 16, scrollbar: false, time: 0});
2025-12-09 18:44:29 +08:00
var url = smz_ht_url + "/dataCount/downloadAttRecordByUserExcel?idCard=" + idCard +"&proId=" + proId +"&gxId=" + gxId +"&dataType=" + dataType +"&startTime=" + startTime +"&endTime=" +endTime + "&token=" + token;
2025-11-27 16:55:35 +08:00
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();
}