diff --git a/src/main/resources/static/js/evaluate/teamGroup/registerEdit.js b/src/main/resources/static/js/evaluate/teamGroup/registerEdit.js new file mode 100644 index 0000000..72d3390 --- /dev/null +++ b/src/main/resources/static/js/evaluate/teamGroup/registerEdit.js @@ -0,0 +1,624 @@ +let form, table, tree; +let alreadyChooseTrees = []; +let selectData = []; +let workTypeList = []; + +let infoFileUrl = ""; +let faceUrl = ""; +const sexList = [ + { + id: 1, + name: "男", + }, + { + id: 2, + name: "女", + }, +]; +let memberInfoList = [ + { + name: "", // 姓名 + phone: "", // 联系方式 + idCard: "", // 身份证号码 + workType: "", // 工种 + sex: "", // 性别 + isTeamLeader: 1, // 是否是班长 + faceUrl: "", // 人脸照片 + }, +]; + +function setParams(id,index){ + layui.use(["table", "form", "upload", "tree"], function () { + const $ = layui.$; + form = layui.form; + upload = layui.upload; + table = layui.table; + + + //查询数据 + $.ajax({ + url: `${ctxPath}` + '/organizational/getRegisterTeamGroup?id=' + id, + type: 'GET', + dataType: "JSON", + success: function (result) { + $("#id").val(id) + if (result.res === 1) { + setFormData(result.obj); + } + } + }); + + //回显数据 + function setFormData(data) { + if (!data) return + // 填充主表单字段 + if (data.teamGroupName) $("#teamGroupName").val(data.teamGroupName) + if (data.subContractor) $("#subContractor").val(data.subContractor) + if (data.teamType) $("#teamType").val(data.teamType) + if (data.name) $("#name").val(data.name) + if (data.phone) $("#phone").val(data.phone) + if (data.idCard) $("#idCard").val(data.idCard) + if (data.workType) $("#workType").val(data.workType) + if (data.sex) $("#sex").val(data.sex) + + // 设置文件URL + if (data.faceUrl) { + faceUrl = data.faceUrl + $("#fileInfo").html("已上传文件") + } + if (data.infoFileUrl) { + infoFileUrl = data.infoFileUrl + $("#fileInfo1").html("已上传文件") + } + + // 处理班组成员信息 + if (data.teamPersons && data.teamPersons.length > 0) { + // 清空现有成员信息 + memberInfoList.length = 0 + $("#memberInfo").empty() + + // 添加新的成员信息 + data.teamPersons.forEach((member, index) => { + memberInfoList.push({ + name: member.name || "", + phone: member.phone || "", + idCard: member.idCard || "", + workType: member.workType || "", + sex: member.sex || "", + isTeamLeader: member.isTeamLeader || 1, + faceUrl: member.faceUrl || "", + }) + + // 构建成员信息UI + constructMemberInfo(index).then(() => { + // 填充成员数据 + $(`#name-${index}`).val(member.name || "") + $(`#phone-${index}`).val(member.phone || "") + $(`#idCard-${index}`).val(member.idCard || "") + $(`#workType-${index}`).val(member.workType || "") + $(`#sex-${index}`).val(member.sex || "") + + if (member.faceUrl) { + $(`#fileInfo-${index}`).html("已上传文件") + } + + // 重新渲染表单 + form.render() + }) + }) + } + + // 重新渲染所有表单元素 + form.render() + } + + // 使用 layui 的 form.on 监听下拉框变化 + form.on("select(subContractor)", function (obj) { + const subContractorId = obj.value; // 获取选中的值 + console.log("subContractorId:", subContractorId); + + if (subContractorId) { + getPromanagerSelect(subContractorId); + } + }); + + // 让点击上传按钮触发文件输入框的点击事件 + $("#uploadBtn").on("click", function () { + $("#fileInput").click(); + }); + + // 让点击上传按钮触发文件输入框的点击事件 + $("#uploadBtn1").on("click", 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]; + 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, + }); + $("#fileInput").val(""); + $("#fileInfo").html(""); + } 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 () { + const file = $("#fileInput1")[0].files[0]; + const fileName = file.name; + const fileExtension = fileName.split(".").pop().toLowerCase(); + + // 校验文件类型,确保是 .xls 或 .xlsx 文件 + if ( + fileExtension !== "doc" && + fileExtension !== "docx" && + fileExtension !== "png" && + fileExtension !== "jpg" && + fileExtension !== "pdf" + ) { + layer.msg("请选择word、pdf或图片文件", { icon: 2, time: 2000 }); + $("#fileInput1").val(""); + $("#fileInfo1").html(""); + } else { + $("#fileInfo1").html("选中的文件:" + fileName); + } + + const formData = new FormData(); + formData.append("file", file); + + $.ajax({ + url: ctxPath + "/organizational/uploadInfo", + type: "POST", + data: formData, + processData: false, // 告诉jQuery不要处理数据 + contentType: false, + success: function (res) { + console.log(res, "上传成功"); + if(res.res == "1" || res.res == 1){ + infoFileUrl = res.obj; + } + }, + error: function (err) { + console.error(err); + }, + }); + }); + // 初始化下拉框 + getOutSourceSelected(); + getTeamGroupType(); + getWorkType(); + + // 设置下拉框选项 + function setSelectValue(list, selectName) { + let html = ''; + if (list && list.length > 0) { + $.each(list, function (index, item) { + html += ``; + }); + } + + $("#" + selectName) + .empty() + .append(html); + form.render("select"); + } + + // 获取外包商下拉数据 + function getOutSourceSelected() { + $.ajax({ + type: "POST", + url: ctxPath + "/organizational/getSubContractorSelected", + success: function (data) { + setSelectValue(data.obj, "subContractor"); + }, + }); + } + + // 根据外包商获取项目下拉数据(支持传参) + function getPromanagerSelect(subContractorId) { + $.ajax({ + type: "POST", + url: ctxPath + "/organizational/getProjectBySubContractor", + data: { + id: subContractorId, + }, + success: function (data) { + setSelectValue(data.obj, "project"); + }, + }); + } + + // 获取班组类型下拉框 + function getTeamGroupType() { + $.ajax({ + type: "POST", + url: ctxPath + "/organizational/getTeamGroupType", + success: function (data) { + setSelectValue(data.obj, "teamType"); + }, + }); + } + + // 获取工种类型下拉框 + function getWorkType() { + $.ajax({ + type: "POST", + url: ctxPath + "/organizational/getWorkType", + success: function (data) { + setSelectValue(data.obj, "workType"); + }, + }); + } + + $("#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() + formData.id = $("#id").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/updateRegisterTeamGroup", + 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 }); + return false; + } + console.log("表单数据:", JSON.stringify(field));*/ + + if(!infoFileUrl){ + layer.msg("请上传信息评审表文件", { icon: 2, time: 2000 }); + return false; + } + + // 班组成员信息数据 + 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 || "", + }; + }); + const submitData = { + id:field.id, + 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 + }; + $.ajax({ + url: ctxPath + "/organizational/updateRegisterTeamGroup", + 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); + } + } + }); + return false; // 阻止默认提交行为 + }); + + + // 获取工种类型下拉框 + async function getWorkTypeNew() { + await new Promise((resolve) => { + $.ajax({ + type: "POST", + url: ctxPath + "/organizational/getWorkType", + success: function (data) { + // setSelectValue(data.obj, element); + workTypeList = data.obj; + resolve(); + }, + }); + }); + } + + // 初始化班组成员信息 + function initMemberInfo() { + memberInfoList.forEach((item, index) => { + constructMemberInfo(index); + }); + } + + // 添加班组成员 + $("#addMemberBtn").on("click", function (e) { + e.preventDefault(); + const index = memberInfoList.length; + memberInfoList.push({ + name: "", + phone: "", + idCard: "", + workType: "", + sex: "", + isTeamLeader: 1, + faceUrl: "", + }); + constructMemberInfo(index); + }); + + // 构造成员信息 + async function constructMemberInfo(index) { + $("#memberInfo").append(` +
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ +
+
+ `); + + if (workTypeList.length < 1) { + await getWorkTypeNew(); + } + + setSelectValue(workTypeList, `workType-${index}`); + + setSelectValue(sexList, `sex-${index}`); + } + + initMemberInfo(); + + // 删除操作 + $("#memberInfo").on("click", ".deleteBtn", function (e) { + e.preventDefault(); + const index = $(this).attr("id").split("-")[1]; + console.log("删除", index); + 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/js/evaluate/teamGroup/teamGroupRegister.js b/src/main/resources/static/js/evaluate/teamGroup/teamGroupRegister.js index 2c2eb27..270c822 100644 --- a/src/main/resources/static/js/evaluate/teamGroup/teamGroupRegister.js +++ b/src/main/resources/static/js/evaluate/teamGroup/teamGroupRegister.js @@ -101,9 +101,12 @@ function initTable() { align: "center", templet: (d) => { let text = ""; - text += - '编辑'; + let auditStatus = d.auditStatus; + if(auditStatus ==0 || auditStatus == 5){ + text += + '编辑'; + } text += ' + + + + + + + 修改班组 + + + + +
+
+
+ +
+
+

班组信息

+
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+ + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+ +
+

班长信息

+
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+

+ 班组成员信息 +

+ +
+ + +
+ +
+ + +
+
+ + + +
+
+ +
+
+
+
+ + + + + + + + + + \ No newline at end of file