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

329 lines
12 KiB
JavaScript
Raw Normal View History

2025-11-27 16:55:35 +08:00
var example = null;
var pers = null;
var form,layer = null;
function receiveParamsGx(params) {
let id = params.id;
$("#id").val(id);
layui.use(['layer', 'form'], function () {
layer = layui.layer;
form = layui.form;
pers = checkPermission();
//小包干工序桩位详情
getDetailByGxZw(id);
//小包干工序桩位信息
initProcessTable(id);
//人员信息
initPersonnelTable(id);
});
}
function getDetailByGxZw(id) {
$.ajax({
type: 'get',
url: ctxPath + '/dataCount/getDetailByGxZw',
data: {
gxId: id
},
async: false,
success: function (data) {
if(data.res==1 || data.res=="1" ){
let l = data.succeed;
let workerCost = "技工:" + l.technicianWorkload + "普工:" + l.generalWorkerWorkload;
$("#workerCost").text(workerCost);
let num = l.technicianWorkload * l.technicianCost + l.generalWorkerWorkload * l.generalWorkerCost;
let workload = l.technicianWorkload + "*" + l.technicianCost + "+" + l.generalWorkerWorkload + "*" + l.generalWorkerCost +"=" + num;
$("#workload").text(workload);
$("#contractCode").text(l.contractCode);
$("#contractCode1").text(l.contractCode);
$("#proName").text(l.proName);
$("#subName").text(l.subName);
$("#totalNum").text(l.totalNum);
$("#teamName").text(l.teamName);
$("#attDayNum").text(l.attDayNum);
}
},
error: function (err) {
console.log("获取小包干工序桩位详情出错:", err);
}
});
}
var processDataTable, personnelTable;
// 初始化合同信息表格
function initProcessTable(id) {
processDataTable = $("#process-table").DataTable({
"searching": false,
"processing": true,
"serverSide": false,
"paging": false,
"info": false,
"language": {
2025-12-02 14:22:34 +08:00
"url": contentPath + "/js/plugin/datatables/Chinese.lang",
2025-11-27 16:55:35 +08:00
},
"ajax": {
"url": ctxPath + "/dataCount/getDetailInfoByGxZw",
"type": "get",
"data": function (d) {
d.gxId = id;
},
"dataSrc": function(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 () {
location.href = ctxPath + '/login.html';
});
} else if (code == 403) {
console.log("未授权:" + message);
layer.msg('未授权');
} else if (code == 500) {
console.log('系统错误:' + message);
}
}
},
"drawCallback": () => {
var thisDataTable = $("#process-table").DataTable()
var wrapper = $("#process-table_wrapper")
var pagination = wrapper.find(".pagination")
// 检查是否已经添加过自定义控件
if (!pagination.find(".custom-page-jump-process").length) {
pagination.append(
"<li class='custom-page-jump-process'>" +
"<a class='paginate_button' style='padding:4px;' href='#' tabindex='0'>到 <input style='margin:0px;width:40px;' id='changePageProcess'> 页</a>" +
"<a class='paginate_button' style='margin-bottom:1px' href='#' tabindex='0' id='dataTable-btn-process'>确认</a></li>",
)
$("#dataTable-btn-process").click((e) => {
var redirectpage = $("#changePageProcess").val() - 1
if (redirectpage >= 0) {
thisDataTable.page(redirectpage).draw("page")
}
})
$("#changePageProcess").keypress((e) => {
if (e.keyCode == 13) {
var redirectpage = $("#changePageProcess").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": "bandDate", "orderable": false, "width": "150px" },
{ "data": "fistAttDate", "orderable": false, "width": "150px" },
{ "data": "lastAttDate", "orderable": false, "width": "150px" },
{ "data": "attUserName", "orderable": false, "width": "200px" },
],
"order": [],
})
}
/**
* 小包干人员详情
* */
function personnelView(item) {
let idCard = item.idCard
var height = '85%';
var width = '91%';
var index = parent.layer.open({
title: ['小包干人员详情','color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
type: 2,
content: 'personnelStatView.html',
area: [width, height],
maxmin: false,
btn: ['关闭'],
success: function (layero, index) {
// 延迟执行,确保 iframe 完全加载
setTimeout(() => {
var iframe = layero.find("iframe")[0]
if (iframe && iframe.contentWindow && iframe.contentWindow.receiveParamsPersonnel) {
iframe.contentWindow.receiveParamsPersonnel({
idCard: idCard,
})
}
}, 100)
}
});
}
// 初始化人员信息表格
function initPersonnelTable(id) {
personnelTable = $("#personnel-table").DataTable({
"searching": false,
"processing": true,
"serverSide": true,
"pagingType": "full_numbers",
"language": {
2025-12-02 14:22:34 +08:00
"url": contentPath + "/js/plugin/datatables/Chinese.lang"
2025-11-27 16:55:35 +08:00
},
"ajax": {
"url": ctxPath + "/dataCount/getDetailPersonListByGxZw",
"type": "POST",
"data": function (d) {
d.gxId = id;
d.userName = $("#userName").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);
}
}
},
"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": function() {
var thisDataTable = $('#staff-table').DataTable();
$("#staff-table_wrapper .pagination").append("<li>" +
"<a class='paginate_button' style='padding:4px;' href='#' tabindex='0'>到 <input style='margin:0px;width:40px;' id='changePageStaff'> 页</a>" +
"<a class='paginate_button' style='margin-bottom:1px' href='#' tabindex='0' id='dataTable-btn-staff'>确认</a></li>");
$('#dataTable-btn-staff').click(function (e) {
if ($("#changePageStaff").val() && $("#changePageStaff").val() > 0) {
var redirectpage = $("#changePageStaff").val() - 1;
} else {
var redirectpage = 0;
}
thisDataTable.page(redirectpage).draw('page');
});
$("#changePageStaff").keypress(function (e) {
if(event.keyCode==13){
if ($("#changePageStaff").val() && $("#changePageStaff").val() > 0) {
var redirectpage = $("#changePageStaff").val() - 1;
} else {
var 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: "", orderable: false, width: "120px",
"render": function (data, type, row) {
var userName = row['userName'];
var html = "<button class='layui-btn layui-btn-xs' style='background-color: transparent; color: #002CFF;' onclick='personnelView("+JSON.stringify(row)+")'>"+userName+"</button>";
return html
}
},
{ data: "phone", orderable: false, width: "120px" },
{ data: "postName", orderable: false, width: "150px" },
{ data: "attDate", orderable: false, width: "120px" },
],
order: [],
})
}
// 搜索功能
function searchPersonnel() {
personnelTable.ajax.reload();
}
function resetPersonnel() {
$('#userName').val('');
// 重新渲染 select 下拉框
layui.form.render("select");
personnelTable.ajax.reload();
}
function exportPersonnel() {
var gxId = $('#id').val();
var userName = $('#userName').val();
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});
var url = ctxPath + "/dataCount/downloadDetailPersonByGxZwExcel?userName=" + userName +"&gxId=" + gxId + "&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 searchStaff() {
var searchValue = $('#staff-search').val();
staffTable.search(searchValue).draw();
}
function resetStaff() {
$('#staff-search').val('');
$('#staff-status').val('');
// 重新渲染 select 下拉框
layui.form.render("select");
staffTable.search('').draw();
}
function exportStaff() {
alert('导出功能');
}