From c94d978e833641be844cbfb0f631441b56279a8b Mon Sep 17 00:00:00 2001 From: lSun <15893999301@qq.com> Date: Tue, 19 Aug 2025 15:36:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8F=AD=E7=BB=84=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mappers/evaluate/OrganizationalMapper.xml | 2 +- .../js/evaluate/teamGroup/registerForm.js | 216 ++++++++++++++++-- .../evaluate/teamGroup/registerForm.html | 2 + 3 files changed, 196 insertions(+), 24 deletions(-) diff --git a/src/main/resources/mappers/evaluate/OrganizationalMapper.xml b/src/main/resources/mappers/evaluate/OrganizationalMapper.xml index b34d3df..6a1e073 100644 --- a/src/main/resources/mappers/evaluate/OrganizationalMapper.xml +++ b/src/main/resources/mappers/evaluate/OrganizationalMapper.xml @@ -312,7 +312,7 @@ audit_status, info_file_url, apply_man, - create_time, + create_time, status, diff --git a/src/main/resources/static/js/evaluate/teamGroup/registerForm.js b/src/main/resources/static/js/evaluate/teamGroup/registerForm.js index 7ca68c4..57c912c 100644 --- a/src/main/resources/static/js/evaluate/teamGroup/registerForm.js +++ b/src/main/resources/static/js/evaluate/teamGroup/registerForm.js @@ -2,6 +2,9 @@ let form, table, tree; let alreadyChooseTrees = []; let selectData = []; let workTypeList = []; + +let infoFileUrl = ""; +let faceUrl = ""; const sexList = [ { id: 1, @@ -19,8 +22,8 @@ let memberInfoList = [ idCard: "", // 身份证号码 workType: "", // 工种 sex: "", // 性别 - faceUrl: "", // 人脸照片 isTeamLeader: 1, // 是否是班长 + faceUrl: "", // 人脸照片 }, ]; @@ -49,6 +52,63 @@ layui.use(["table", "form", "upload", "tree"], function () { $("#fileInput1").click(); }); + // 班组成员人脸照片上传事件委托 + $("#memberInfo").on("click", ".uploadBtn", function () { + const index = $(this).attr("id").split("-")[1] + $(`#fileInput-${index}`).click() + }) + + // 班组成员人脸照片文件选择处理 + $("#memberInfo").on("change", "input[type='file']", function () { + const index = $(this).attr("id").split("-")[1] + const file = $(this)[0].files[0] + + if (!file) return + + const fileName = file.name + const fileExtension = fileName.split(".").pop().toLowerCase() + + // 校验文件类型,确保是 .jpg 或 .png 文件 + if (fileExtension !== "jpg" && fileExtension !== "png") { + layer.msg("请选择图片文件(.jpg 或 .png)", { + icon: 2, + time: 2000, + }) + $(this).val("") + $(`#fileInfo-${index}`).html("") + return + } + + $(`#fileInfo-${index}`).html("选中的文件:" + fileName) + + const formData = new FormData() + formData.append("file", file) + + $.ajax({ + url: ctxPath + "/organizational/uploadFaceImg", + type: "POST", + data: formData, + processData: false, + contentType: false, + success: (res) => { + console.log(res, `成员${index}人脸上传成功`) + if (res.res == "1" || res.res == 1) { + // 将上传成功的URL存储到对应成员的数据中 + if (memberInfoList[index]) { + memberInfoList[index].faceUrl = res.obj + } + layer.msg("上传成功", { icon: 6, time: 1500 }) + } + }, + error: (err) => { + console.error(err) + layer.msg("上传失败,请重试", { icon: 5, time: 2000 }) + }, + }) + }) + + + // 文件选择后的回调处理 $("#fileInput").on("change", function () { const file = $("#fileInput")[0].files[0]; @@ -66,6 +126,27 @@ layui.use(["table", "form", "upload", "tree"], function () { } else { $("#fileInfo").html("选中的文件:" + fileName); } + + + const formData = new FormData(); + formData.append("file", file); + + $.ajax({ + url: ctxPath + "/organizational/uploadFaceImg", + type: "POST", + data: formData, + processData: false, // 告诉jQuery不要处理数据 + contentType: false, + success: function (res) { + console.log(res, "人脸上传成功"); + if(res.res == "1" || res.res == 1){ + faceUrl = res.obj; + } + }, + error: function (err) { + console.error(err); + }, + }); }); // 文件选择后的回调处理 $("#fileInput1").on("change", function () { @@ -99,6 +180,9 @@ layui.use(["table", "form", "upload", "tree"], function () { contentType: false, success: function (res) { console.log(res, "上传成功"); + if(res.res == "1" || res.res == 1){ + infoFileUrl = res.obj; + } }, error: function (err) { console.error(err); @@ -172,13 +256,76 @@ layui.use(["table", "form", "upload", "tree"], function () { }); } + $("#stagingBtn").on("click", () => { + const formData = {} + formData.teamGroupName = $("#teamGroupName").val() + formData.subContractor = $("#subContractor").val() + formData.teamType = $("#teamType").val() + formData.name = $("#name").val() + formData.phone = $("#phone").val() + formData.idCard = $("#idCard").val() + formData.workType = $("#workType").val() + formData.sex = $("#sex").val() + + console.log("暂存表单数据:", JSON.stringify(formData)) + + const groupMemberList = memberInfoList.map((e, index) => { + return { + name: $(`#name-${index}`).val() || "", + phone: $(`#phone-${index}`).val() || "", + idCard: $(`#idCard-${index}`).val() || "", + workType: $(`#workType-${index}`).val() || "", + sex: $(`#sex-${index}`).val() || "", + isTeamLeader: 1, + faceUrl: e.faceUrl || "", + } + }) + + console.log("暂存班组成员信息数据:", groupMemberList) + + const submitData = { + teamGroupName: formData.teamGroupName || "", + subContractor: formData.subContractor || "", + infoFileUrl: infoFileUrl || "", + teamType: formData.teamType || "", + name: formData.name || "", + tableSource: "pm_dept", + level: 5, + phone: formData.phone || "", + idCard: formData.idCard || "", + workType: formData.workType || "", + sex: formData.sex || "", + auditStatus: 0, + isTeamLeader: 0, + faceUrl: faceUrl || "", + teamPersons: groupMemberList, + } + + $.ajax({ + url: ctxPath + "/organizational/registerTeamGroup", + type: "POST", + contentType: "application/json;charset=utf-8", + data: JSON.stringify(submitData), + success: (res) => { + if (res.res === 1) { + layer.msg("暂存成功", { icon: 6 }, () => { + parent.layer.close(parent.layer.getFrameIndex(window.name)) + window.parent.location.reload() + }) + } else { + layer.msg(res.resMsg) + } + }, + }) + }) + form.on("submit(formSubmit)", function (data) { // 表单提交事件监听 const field = data.field; // 校验文件是否选择 const file = $("#fileInput1")[0].files[0]; if (!file) { - layer.msg("请上传文件", { icon: 2, time: 2000 }); + layer.msg("请上传信息评审表文件", { icon: 2, time: 2000 }); return false; } console.log("表单数据:", JSON.stringify(field)); @@ -193,6 +340,7 @@ layui.use(["table", "form", "upload", "tree"], function () { workType: $(`#workType-${index}`).val(), sex: $(`#sex-${index}`).val(), isTeamLeader: 1, + faceUrl: e.faceUrl || "", }; }); @@ -201,45 +349,60 @@ layui.use(["table", "form", "upload", "tree"], function () { formDataWithFile.append("teamGroupName", field.teamGroupName); formDataWithFile.append("subContractor", field.subContractor); - formDataWithFile.append("infoFileUrl", file); // 信息评审表url + formDataWithFile.append("infoFileUrl", infoFileUrl); // 信息评审表url formDataWithFile.append("teamType", field.teamType); formDataWithFile.append("name", field.name); + formDataWithFile.append("tableSource", "pm_dept"); + formDataWithFile.append("level", 5); // 固定值 formDataWithFile.append("phone", field.phone); formDataWithFile.append("idCard", field.idCard); formDataWithFile.append("workType", field.workType); formDataWithFile.append("sex", field.sex); - formDataWithFile.append("faceUrl", file); // 人脸照片url - formDataWithFile.append("level", 5); // 固定值 - formDataWithFile.append("tableSource", "pm_dept"); - formDataWithFile.append("isTeamLeader", 0); // 固定值 formDataWithFile.append("auditStatus", 1); - formDataWithFile.append("teamPersons", groupMemberList); + formDataWithFile.append("isTeamLeader", 0); // 固定值 + formDataWithFile.append("faceUrl", file); // 人脸照片url + + const submitData = { + teamGroupName: field.teamGroupName, + subContractor: field.subContractor, + infoFileUrl: infoFileUrl, + teamType: field.teamType, + name: field.name, + tableSource:"pm_dept", + level: 5, + phone: field.phone, + idCard: field.idCard, + workType: field.workType, + sex: field.sex, + auditStatus: 1, + isTeamLeader: 0, + faceUrl: faceUrl, // 上传后返回的 URL + teamPersons: groupMemberList + }; + + //班组成员信息 + formDataWithFile.append("teamPersons", JSON.stringify(groupMemberList)); $.ajax({ url: ctxPath + "/organizational/registerTeamGroup", type: "POST", - dataType: "json", - processData: false, - contentType: false, - data: formDataWithFile, - success: function (res) { + contentType: "application/json;charset=utf-8", + data: JSON.stringify(submitData), + success: res => { if (res.res === 1) { - layer.msg("新增成功", { icon: 6, time: 1500 }, function () { - var index = parent.layer.getFrameIndex(window.name); // 获取当前 iframe 层的索引 + layer.msg("成功", { icon: 6 }, () => { + parent.layer.close(parent.layer.getFrameIndex(window.name)); window.parent.location.reload(); - parent.layer.close(index); // 关闭弹窗 }); - } else if (res.res === 0) { - layer.msg(res.resMsg, { icon: 5 }); + } else { + layer.msg(res.resMsg); } - }, - error: function () { - layer.msg("网络异常,请重试", { icon: 5 }); - }, + } }); return false; // 阻止默认提交行为 }); + // 获取工种类型下拉框 async function getWorkTypeNew() { await new Promise((resolve) => { @@ -272,8 +435,8 @@ layui.use(["table", "form", "upload", "tree"], function () { idCard: "", workType: "", sex: "", - faceUrl: "", isTeamLeader: 1, + faceUrl: "", }); constructMemberInfo(index); }); @@ -379,5 +542,12 @@ layui.use(["table", "form", "upload", "tree"], function () { memberInfoList.splice(index, 1); console.log("删除", memberInfoList); $(`#memberInfo-${index}`).remove(); + + // 重新渲染所有成员信息以更新索引 + $("#memberInfo").empty() + memberInfoList.forEach((item, newIndex) => { + constructMemberInfo(newIndex) + }) + }); }); diff --git a/src/main/resources/static/pages/evaluate/teamGroup/registerForm.html b/src/main/resources/static/pages/evaluate/teamGroup/registerForm.html index 795f129..e36042c 100644 --- a/src/main/resources/static/pages/evaluate/teamGroup/registerForm.html +++ b/src/main/resources/static/pages/evaluate/teamGroup/registerForm.html @@ -244,6 +244,8 @@
+ +