Files
threeonecheck_web/unpackage/dist/dev/mp-weixin/pages/hiddendanger/rectification.js

1244 lines
51 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
const common_vendor = require("../../common/vendor.js");
const request_api = require("../../request/api.js");
const utils_draftCache = require("../../utils/draftCache.js");
const utils_useDraftCache = require("../../utils/useDraftCache.js");
const utils_upload = require("../../utils/upload.js");
if (!Array) {
const _easycom_up_textarea2 = common_vendor.resolveComponent("up-textarea");
const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
const _easycom_up_datetime_picker2 = common_vendor.resolveComponent("up-datetime-picker");
const _easycom_up_checkbox2 = common_vendor.resolveComponent("up-checkbox");
const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload");
const _easycom_up_radio2 = common_vendor.resolveComponent("up-radio");
const _easycom_up_radio_group2 = common_vendor.resolveComponent("up-radio-group");
const _easycom_wd_signature2 = common_vendor.resolveComponent("wd-signature");
(_easycom_up_textarea2 + _easycom_up_input2 + _easycom_up_datetime_picker2 + _easycom_up_checkbox2 + _easycom_u_popup2 + _easycom_up_upload2 + _easycom_up_radio2 + _easycom_up_radio_group2 + _easycom_wd_signature2)();
}
const _easycom_up_textarea = () => "../../uni_modules/uview-plus/components/u-textarea/u-textarea.js";
const _easycom_up_input = () => "../../uni_modules/uview-plus/components/u-input/u-input.js";
const _easycom_up_datetime_picker = () => "../../uni_modules/uview-plus/components/u-datetime-picker/u-datetime-picker.js";
const _easycom_up_checkbox = () => "../../uni_modules/uview-plus/components/u-checkbox/u-checkbox.js";
const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
const _easycom_up_upload = () => "../../uni_modules/uview-plus/components/u-upload/u-upload.js";
const _easycom_up_radio = () => "../../uni_modules/uview-plus/components/u-radio/u-radio.js";
const _easycom_up_radio_group = () => "../../uni_modules/uview-plus/components/u-radio-group/u-radio-group.js";
const _easycom_wd_signature = () => "../../node-modules/wot-design-uni/components/wd-signature/wd-signature.js";
if (!Math) {
(_easycom_up_textarea + _easycom_up_input + _easycom_up_datetime_picker + _easycom_up_checkbox + _easycom_u_popup + _easycom_up_upload + _easycom_up_radio + _easycom_up_radio_group + _easycom_wd_signature)();
}
const EDIT_NEXT_STEP_NAME = "隐患验收";
const _sfc_main = {
__name: "rectification",
setup(__props) {
const hazardId = common_vendor.ref("");
const assignId = common_vendor.ref("");
const taskId = common_vendor.ref("");
const rectifyId = common_vendor.ref("");
const isEdit = common_vendor.ref(false);
const nextStepName = common_vendor.ref("");
const nextStepLoading = common_vendor.ref(false);
const nextStepDisplay = common_vendor.computed(() => {
if (isEdit.value)
return EDIT_NEXT_STEP_NAME;
if (nextStepLoading.value)
return "加载中...";
return nextStepName.value || "暂无下一步流程";
});
const resolveTaskIdFromDetail = (data) => {
if (!data)
return "";
if (data.taskId)
return String(data.taskId);
if (data.flowTaskId)
return String(data.flowTaskId);
if (data.currentTaskId)
return String(data.currentTaskId);
const assigns = data.assigns || [];
for (const assign of assigns) {
if (assign == null ? void 0 : assign.taskId)
return String(assign.taskId);
}
return "";
};
const resolveNextTaskName = (data) => {
var _a;
if (!data)
return "";
const branches = data.branches || [];
const matchedBranch = branches.find((item) => item.matched) || branches[0];
return ((_a = matchedBranch == null ? void 0 : matchedBranch.nextNode) == null ? void 0 : _a.taskName) || "";
};
const fetchNextStep = async () => {
nextStepLoading.value = true;
try {
let currentTaskId = taskId.value;
if (!currentTaskId && rectifyId.value) {
const rectifyRes = await request_api.getRectifyDetail({ rectifyId: rectifyId.value });
if (rectifyRes.code === 0 && rectifyRes.data) {
const rectifyData = rectifyRes.data;
currentTaskId = resolveTaskIdFromDetail(rectifyData);
if (!hazardId.value && rectifyData.hazardId) {
hazardId.value = rectifyData.hazardId;
}
if (!assignId.value && rectifyData.assignId) {
assignId.value = rectifyData.assignId;
}
if (currentTaskId) {
taskId.value = currentTaskId;
}
}
}
if (!currentTaskId && hazardId.value) {
const detailRes = await request_api.getHiddenDangerDetail({
hazardId: hazardId.value,
assignId: assignId.value
});
if (detailRes.code === 0 && detailRes.data) {
currentTaskId = resolveTaskIdFromDetail(detailRes.data);
if (currentTaskId) {
taskId.value = currentTaskId;
}
}
}
if (!currentTaskId) {
nextStepName.value = "";
return;
}
const res = await request_api.getFlowNextNodes({ taskId: currentTaskId });
if (res.code === 0) {
const payload = res.data && typeof res.data === "object" ? res.data : res;
nextStepName.value = resolveNextTaskName(payload);
} else {
nextStepName.value = "";
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:407", "获取下一步流程失败:", error);
nextStepName.value = "";
} finally {
nextStepLoading.value = false;
}
};
const canvasWidth = common_vendor.ref(300);
const canvasHeight = common_vendor.ref(300);
const showCanvas = common_vendor.ref(true);
const signatureUrl = common_vendor.ref("");
const signatureServerPath = common_vendor.ref("");
const signatureWidth = common_vendor.ref(340);
const signatureRef = common_vendor.ref(null);
const isSignatureEmpty = common_vendor.ref(true);
const isSubmitting = common_vendor.ref(false);
const signatureLocalPath = common_vendor.ref("");
const isDraftExporting = common_vendor.ref(false);
let signatureExportTimer = null;
const clearSignature = () => {
clearTimeout(signatureExportTimer);
isSignatureEmpty.value = true;
signatureLocalPath.value = "";
if (signatureRef.value) {
signatureRef.value.clear();
}
};
const resolveSignPathFromData = (data) => {
if (!data)
return "";
return data.signPath || data.signUrl || data.signature || data.signatureUrl || data.signaturePath || "";
};
const applySignatureFromServer = (signPath) => {
const url = signPath ? utils_upload.toSubmitFileUrl(signPath) : "";
if (!url) {
showCanvas.value = true;
signatureServerPath.value = "";
signatureUrl.value = "";
signatureLocalPath.value = "";
isSignatureEmpty.value = true;
return;
}
signatureServerPath.value = url;
signatureUrl.value = url;
signatureLocalPath.value = "";
showCanvas.value = false;
isSignatureEmpty.value = false;
};
const applySignatureFromLocal = (localPath) => {
if (!localPath)
return;
signatureLocalPath.value = localPath;
signatureUrl.value = localPath;
signatureServerPath.value = "";
showCanvas.value = false;
isSignatureEmpty.value = false;
};
const onSignatureStart = () => {
isSignatureEmpty.value = false;
};
const onSignatureSigning = () => {
isSignatureEmpty.value = false;
};
const onSignatureClear = () => {
isSignatureEmpty.value = true;
signatureLocalPath.value = "";
};
const scheduleSignatureDraftExport = () => {
clearTimeout(signatureExportTimer);
signatureExportTimer = setTimeout(() => {
if (!showCanvas.value || isSignatureEmpty.value || !signatureRef.value || isSubmitting.value || isDraftExporting.value) {
return;
}
isDraftExporting.value = true;
signatureRef.value.confirm();
}, 600);
};
const onSignatureEnd = () => {
isSignatureEmpty.value = false;
scheduleSignatureDraftExport();
};
const onSignatureImageError = () => {
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:517", "签名图片加载失败:", signatureUrl.value);
common_vendor.index.showToast({ title: "签名图片加载失败", icon: "none" });
};
const reSign = () => {
clearTimeout(signatureExportTimer);
isSignatureEmpty.value = true;
showCanvas.value = true;
signatureUrl.value = "";
signatureServerPath.value = "";
signatureLocalPath.value = "";
common_vendor.nextTick$1(() => {
if (signatureRef.value) {
signatureRef.value.clear();
}
});
};
const formData = common_vendor.reactive({
rectifyPlan: "",
// 整改方案
rectificationMeasures: "",
// 整改措施
controlMeasures: "",
// 管控措施
rectifyResult: "",
// 整改完成情况
planCost: "",
// 投资资金(计划)
actualCost: ""
// 投资资金(实际)
});
const selectedDeadlineDate = common_vendor.ref("");
const showRectifyTimePicker = common_vendor.ref(false);
const rectifyTimeValue = common_vendor.ref(Date.now());
const selectedRectifyTime = common_vendor.ref("");
const hazardEndRadio = common_vendor.ref("no");
const hazardEnd = common_vendor.computed(() => hazardEndRadio.value === "yes");
const normalizeHazardEndRadio = (value) => value === "yes" ? "yes" : "no";
const sendMsgFlagRadio = common_vendor.ref("yes");
const sendMsgFlag = common_vendor.computed(() => sendMsgFlagRadio.value === "yes");
const formatDateValue = (timestamp) => {
if (!timestamp)
return "";
const date = new Date(timestamp);
if (Number.isNaN(date.getTime()))
return "";
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");
const seconds = String(date.getSeconds()).padStart(2, "0");
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
const parseDeadlineToTimestamp = (deadline) => {
if (!deadline)
return null;
const decoded = decodeURIComponent(String(deadline)).trim();
const normalized = decoded.replace("T", " ").replace(/-/g, "/");
const ts = new Date(normalized).getTime();
return Number.isNaN(ts) ? null : ts;
};
const applyDeadlineFromOptions = (deadline) => {
const ts = parseDeadlineToTimestamp(deadline);
if (ts) {
selectedDeadlineDate.value = formatDateValue(ts);
} else if (deadline) {
selectedDeadlineDate.value = String(deadline).trim().replace("T", " ");
}
};
const applyAssigneeFromOptions = (assigneeId, assigneeName, assigneeIdentityId) => {
if (!assigneeIdentityId)
return;
const identityId = String(assigneeIdentityId);
const name = assigneeName ? decodeURIComponent(String(assigneeName)).trim() : "";
const exists = detailPersonPool.value.some((user) => String(user.identityId) === identityId);
if (!exists) {
detailPersonPool.value.push({
userId: assigneeId || "",
identityId: assigneeIdentityId,
nickName: name,
deptName: ""
});
}
if (!lockedIdentityIds.value.includes(identityId)) {
lockedIdentityIds.value = [...lockedIdentityIds.value, identityId];
}
selectedIdentityIds.value = mergeLockedIdentityIds([identityId]);
syncSelectedMembersFromIdentityIds(selectedIdentityIds.value);
};
const setLockedDefaultIdentities = (ids) => {
const normalized = parseIdList(ids);
if (!normalized.length)
return;
lockedIdentityIds.value = normalized;
selectedIdentityIds.value = mergeLockedIdentityIds(selectedIdentityIds.value);
syncSelectedMembersFromIdentityIds(selectedIdentityIds.value);
};
const parseIdList = (raw) => {
if (raw === null || raw === void 0 || raw === "")
return [];
if (Array.isArray(raw)) {
return raw.map((id) => String(id)).filter(Boolean);
}
return String(raw).split(",").map((id) => String(id).trim()).filter(Boolean);
};
const resolveManagerIdentityIdsFromDetail = (data) => {
const ids = parseIdList(data.managerIds ?? data.manageIds ?? data.manageIdentityIds ?? data.managerIdentityIds);
if (ids.length > 0)
return ids;
if (Array.isArray(data.managers) && data.managers.length > 0) {
return data.managers.map((item) => String(item.identityId ?? item.userId)).filter(Boolean);
}
return [];
};
const getMembersByIdentityIdsFromTree = (ids, tree) => {
const memberMap = /* @__PURE__ */ new Map();
(tree || []).forEach((dept) => {
(dept.users || []).forEach((user) => {
if (user.identityId != null && user.identityId !== "") {
memberMap.set(String(user.identityId), buildMemberItem(user, dept));
}
});
});
return ids.map((id) => memberMap.get(String(id))).filter(Boolean);
};
const mergeMembersFromDetailPool = (ids, resolvedMembers) => {
const memberMap = new Map(resolvedMembers.map((member) => [member.id, member]));
ids.forEach((id) => {
const key = String(id);
if (memberMap.has(key))
return;
const found = detailPersonPool.value.find((user) => String(user.identityId) === key);
if (found) {
memberMap.set(key, buildMemberItemFromDetail(found));
}
});
return ids.map((id) => memberMap.get(String(id))).filter(Boolean);
};
const applyRectifyTimeValue = (timeStr) => {
const ts = parseDeadlineToTimestamp(timeStr);
if (ts) {
rectifyTimeValue.value = ts;
selectedRectifyTime.value = formatDateValue(ts);
} else if (timeStr) {
selectedRectifyTime.value = String(timeStr).trim().replace("T", " ");
}
};
const initRectifyTimeDefault = () => {
rectifyTimeValue.value = Date.now();
selectedRectifyTime.value = formatDateValue(rectifyTimeValue.value);
};
const onRectifyTimeConfirm = (e) => {
rectifyTimeValue.value = e.value;
selectedRectifyTime.value = formatDateValue(e.value);
showRectifyTimePicker.value = false;
};
const managerDeptList = common_vendor.ref([]);
const deptList = common_vendor.ref([]);
const detailPersonPool = common_vendor.ref([]);
const showManagerPopup = common_vendor.ref(false);
const selectedManagerIdentityIds = common_vendor.ref([]);
const selectedManagers = common_vendor.ref([]);
const activeManagerDeptIndex = common_vendor.ref(0);
const managerPickerSelectedIdentityIds = common_vendor.ref([]);
const showUserPopup = common_vendor.ref(false);
const selectedIdentityIds = common_vendor.ref([]);
const selectedUsers = common_vendor.ref([]);
const lockedIdentityIds = common_vendor.ref([]);
const activeDeptIndex = common_vendor.ref(0);
const userPickerSelectedIdentityIds = common_vendor.ref([]);
const isLockedIdentity = (identityId) => lockedIdentityIds.value.includes(String(identityId));
const mergeLockedIdentityIds = (ids) => {
const merged = /* @__PURE__ */ new Set([
...(ids || []).map((id) => String(id)),
...lockedIdentityIds.value.map((id) => String(id))
]);
return [...merged];
};
const formatMemberDisplayName = (user) => {
if (user.identityName) {
return `${user.nickName}_${user.identityName}`;
}
if (user.postName) {
return `${user.nickName}_${user.postName}`;
}
return user.nickName || "";
};
const formatUserPickerLabel = (user) => {
const name = formatMemberDisplayName(user);
return isLockedIdentity(user.identityId) ? `${name}(默认)` : name;
};
const buildMemberItem = (user, dept) => ({
id: String(user.identityId),
userId: user.userId,
name: formatMemberDisplayName(user),
deptName: dept.deptName
});
const buildMemberItemFromDetail = (user) => ({
id: String(user.identityId || user.userId),
name: formatMemberDisplayName(user),
deptName: user.deptName || ""
});
const buildSelectedPersonText = (users) => {
if (users.length === 0)
return "";
if (users.length <= 2) {
return users.map((u) => u.name).join("、");
}
return `${users[0].name}${users.length}`;
};
const selectedManagersText = common_vendor.computed(() => buildSelectedPersonText(selectedManagers.value));
const selectedUsersText = common_vendor.computed(() => buildSelectedPersonText(selectedUsers.value));
const currentManagerDeptUsers = common_vendor.computed(() => {
const dept = managerDeptList.value[activeManagerDeptIndex.value];
return (dept == null ? void 0 : dept.users) || [];
});
const managerPickerSelectedText = common_vendor.computed(() => {
const users = getManagersByIdentityIds(managerPickerSelectedIdentityIds.value);
return buildSelectedPersonText(users);
});
const managerPickerSelectedSet = common_vendor.computed(() => {
return new Set(managerPickerSelectedIdentityIds.value.map((id) => String(id)));
});
const currentDeptUsers = common_vendor.computed(() => {
const dept = deptList.value[activeDeptIndex.value];
return (dept == null ? void 0 : dept.users) || [];
});
const userPickerSelectedText = common_vendor.computed(() => {
const users = getMembersByIdentityIds(userPickerSelectedIdentityIds.value);
return buildSelectedPersonText(users);
});
const userPickerSelectedSet = common_vendor.computed(() => {
return new Set(userPickerSelectedIdentityIds.value.map((id) => String(id)));
});
const getManagersByIdentityIds = (ids) => {
let members = getMembersByIdentityIdsFromTree(ids, managerDeptList.value);
if (members.length < ids.length) {
const deptMembers = getMembersByIdentityIdsFromTree(ids, deptList.value);
const memberMap = new Map(members.map((member) => [member.id, member]));
deptMembers.forEach((member) => {
if (!memberMap.has(member.id))
memberMap.set(member.id, member);
});
members = ids.map((id) => memberMap.get(String(id))).filter(Boolean);
}
return mergeMembersFromDetailPool(ids, members);
};
const getMembersByIdentityIds = (ids) => {
let members = getMembersByIdentityIdsFromTree(ids, deptList.value);
return mergeMembersFromDetailPool(ids, members);
};
const syncSelectedManagersFromIdentityIds = (ids) => {
selectedManagers.value = getManagersByIdentityIds(ids);
};
const syncSelectedMembersFromIdentityIds = (ids) => {
selectedUsers.value = getMembersByIdentityIds(ids);
};
const getManagerDeptSelectedCount = (dept) => {
var _a;
if (!((_a = dept.users) == null ? void 0 : _a.length))
return 0;
const selectedSet = new Set(managerPickerSelectedIdentityIds.value.map(String));
return dept.users.filter((user) => selectedSet.has(String(user.identityId))).length;
};
const getDeptSelectedCount = (dept) => {
var _a;
if (!((_a = dept.users) == null ? void 0 : _a.length))
return 0;
const selectedSet = new Set(userPickerSelectedIdentityIds.value.map(String));
return dept.users.filter((user) => selectedSet.has(String(user.identityId))).length;
};
function onManagerCheckChange(identityId, checked) {
const id = String(identityId);
if (checked) {
if (!managerPickerSelectedSet.value.has(id)) {
managerPickerSelectedIdentityIds.value = [...managerPickerSelectedIdentityIds.value, id];
}
return;
}
managerPickerSelectedIdentityIds.value = managerPickerSelectedIdentityIds.value.filter((item) => String(item) !== id);
}
function onUserCheckChange(identityId, checked) {
const id = String(identityId);
if (!checked && isLockedIdentity(id)) {
common_vendor.index.showToast({ title: "默认整改责任人不可取消", icon: "none" });
return;
}
if (checked) {
if (!userPickerSelectedSet.value.has(id)) {
userPickerSelectedIdentityIds.value = [...userPickerSelectedIdentityIds.value, id];
}
return;
}
userPickerSelectedIdentityIds.value = userPickerSelectedIdentityIds.value.filter((item) => String(item) !== id);
}
const openManagerPopup = () => {
managerPickerSelectedIdentityIds.value = [...selectedManagerIdentityIds.value];
const firstDeptWithUsers = managerDeptList.value.findIndex((dept) => {
var _a;
return ((_a = dept.users) == null ? void 0 : _a.length) > 0;
});
activeManagerDeptIndex.value = firstDeptWithUsers >= 0 ? firstDeptWithUsers : 0;
showManagerPopup.value = true;
};
const cancelManagerSelect = () => {
showManagerPopup.value = false;
};
const openUserPopup = () => {
userPickerSelectedIdentityIds.value = mergeLockedIdentityIds(selectedIdentityIds.value);
const firstDeptWithUsers = deptList.value.findIndex((dept) => {
var _a;
return ((_a = dept.users) == null ? void 0 : _a.length) > 0;
});
activeDeptIndex.value = firstDeptWithUsers >= 0 ? firstDeptWithUsers : 0;
showUserPopup.value = true;
};
const cancelUserSelect = () => {
showUserPopup.value = false;
};
const confirmManagerSelect = () => {
selectedManagerIdentityIds.value = managerPickerSelectedIdentityIds.value.map((id) => String(id));
syncSelectedManagersFromIdentityIds(selectedManagerIdentityIds.value);
showManagerPopup.value = false;
};
const confirmUserSelect = () => {
userPickerSelectedIdentityIds.value = mergeLockedIdentityIds(userPickerSelectedIdentityIds.value);
selectedIdentityIds.value = userPickerSelectedIdentityIds.value.map((id) => String(id));
syncSelectedMembersFromIdentityIds(selectedIdentityIds.value);
showUserPopup.value = false;
};
const fetchRelatedDeptUsers = async () => {
try {
const res = await request_api.getRelatedDeptUsers({ type: 2 });
if (res.code === 0 && res.data) {
managerDeptList.value = res.data;
deptList.value = res.data;
if (selectedManagerIdentityIds.value.length > 0) {
syncSelectedManagersFromIdentityIds(selectedManagerIdentityIds.value);
}
if (selectedIdentityIds.value.length > 0) {
syncSelectedMembersFromIdentityIds(selectedIdentityIds.value);
}
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:901", "获取关联部门人员列表失败:", error);
}
};
const fetchPersonnelLists = async () => {
await fetchRelatedDeptUsers();
if (selectedManagerIdentityIds.value.length > 0) {
syncSelectedManagersFromIdentityIds(selectedManagerIdentityIds.value);
}
};
const fileList1 = common_vendor.ref([]);
const rectifyUploadInstance = common_vendor.getCurrentInstance();
const { afterRead, deletePic } = utils_upload.createUploadListHandlers(fileList1, {
watermark: {
canvasId: "watermarkCanvas",
canvasWidthRef: canvasWidth,
canvasHeightRef: canvasHeight,
instance: rectifyUploadInstance
}
});
const buildSharedRectifyParams = (attachments) => {
const params = {
rectifyPlan: formData.rectifyPlan,
rectificationMeasures: formData.rectificationMeasures,
controlMeasures: formData.controlMeasures,
rectifyResult: formData.rectifyResult,
planCost: Number(formData.planCost) || 0,
actualCost: Number(formData.actualCost) || 0,
attachments,
managerIds: selectedManagerIdentityIds.value.map((id) => Number(id)),
memberIds: selectedIdentityIds.value.map((id) => Number(id)),
rectifyTime: selectedRectifyTime.value || formatDateValue(rectifyTimeValue.value),
signPath: signatureServerPath.value || "",
hazardEnd: hazardEnd.value,
sendMsgFlag: hazardEnd.value ? null : sendMsgFlag.value
};
if (selectedDeadlineDate.value) {
params.deadline = selectedDeadlineDate.value;
}
return params;
};
const executeSubmit = async () => {
const attachments = fileList1.value.filter((f) => f.status === "success").map((file) => utils_upload.buildAttachmentItem(file));
try {
let res;
if (isEdit.value) {
const updateParams = {
rectifyId: Number(rectifyId.value),
hazardId: hazardId.value,
assignId: assignId.value,
...buildSharedRectifyParams(attachments)
};
res = await request_api.updateRectification(updateParams);
} else {
const params = {
hazardId: hazardId.value,
assignId: assignId.value,
...buildSharedRectifyParams(attachments)
};
res = await request_api.submitRectification(params);
}
common_vendor.index.hideLoading();
if (res.code === 0) {
clearDraft(false);
common_vendor.index.showToast({
title: isEdit.value ? "保存成功" : "提交成功",
icon: "success"
});
setTimeout(() => {
common_vendor.index.navigateBack();
}, 1500);
} else {
common_vendor.index.showToast({
title: res.msg || (isEdit.value ? "保存失败" : "提交失败"),
icon: "none"
});
}
} catch (error) {
common_vendor.index.hideLoading();
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:1021", isEdit.value ? "保存整改失败:" : "提交整改失败:", error);
common_vendor.index.showToast({
title: "操作失败",
icon: "none"
});
} finally {
isSubmitting.value = false;
}
};
const onSignatureConfirm = async (tempFilePath) => {
if (isDraftExporting.value) {
isDraftExporting.value = false;
applySignatureFromLocal(tempFilePath);
saveDraft();
return;
}
try {
const { url } = await utils_upload.uploadToCloud(tempFilePath);
applySignatureFromServer(url);
saveDraft();
if (isSubmitting.value) {
await executeSubmit();
}
} catch (err) {
isSubmitting.value = false;
common_vendor.index.hideLoading();
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:1051", "签名上传失败:", err);
common_vendor.index.showToast({ title: "签名上传失败,请重试", icon: "none" });
}
};
const handleSubmit = async () => {
if (!formData.rectifyPlan) {
common_vendor.index.showToast({
title: "请输入整改方案",
icon: "none"
});
return;
}
if (!formData.rectificationMeasures) {
common_vendor.index.showToast({
title: "请输入整改措施",
icon: "none"
});
return;
}
if (!formData.controlMeasures) {
common_vendor.index.showToast({
title: "请输入管控措施",
icon: "none"
});
return;
}
if (!formData.rectifyResult) {
common_vendor.index.showToast({
title: "请输入整改完成情况",
icon: "none"
});
return;
}
if (!selectedRectifyTime.value) {
common_vendor.index.showToast({
title: "请选择实际整改时间",
icon: "none"
});
return;
}
if (selectedManagers.value.length === 0) {
common_vendor.index.showToast({
title: "请选择安全管理人员",
icon: "none"
});
return;
}
if (selectedUsers.value.length === 0) {
common_vendor.index.showToast({
title: "请选择整改责任人",
icon: "none"
});
return;
}
if (showCanvas.value) {
if (!signatureRef.value || isSignatureEmpty.value) {
common_vendor.index.showToast({
title: "请进行电子签名",
icon: "none"
});
return;
}
isSubmitting.value = true;
common_vendor.index.showLoading({ title: "正在提交...", mask: true });
signatureRef.value.confirm();
} else {
if (!signatureServerPath.value && !signatureLocalPath.value) {
common_vendor.index.showToast({
title: "请进行电子签名",
icon: "none"
});
return;
}
isSubmitting.value = true;
common_vendor.index.showLoading({ title: "正在提交...", mask: true });
try {
if (!signatureServerPath.value && signatureLocalPath.value) {
const { url } = await utils_upload.uploadToCloud(signatureLocalPath.value);
applySignatureFromServer(url);
}
await executeSubmit();
} catch (err) {
isSubmitting.value = false;
common_vendor.index.hideLoading();
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:1142", "签名上传失败:", err);
common_vendor.index.showToast({ title: "签名上传失败,请重试", icon: "none" });
}
}
};
const fetchRectifyDetail = async () => {
try {
common_vendor.index.showLoading({ title: "加载中..." });
const res = await request_api.getRectifyDetail({ rectifyId: rectifyId.value });
common_vendor.index.hideLoading();
if (res.code === 0 && res.data) {
const data = res.data;
formData.rectifyPlan = data.rectifyPlan || "";
formData.rectificationMeasures = data.rectificationMeasures || "";
formData.controlMeasures = data.controlMeasures || "";
formData.rectifyResult = data.rectifyResult || "";
formData.planCost = data.planCost ? String(data.planCost) : "";
formData.actualCost = data.actualCost ? String(data.actualCost) : "";
if (data.deadline) {
applyDeadlineFromOptions(data.deadline);
}
if (data.rectifyTime) {
applyRectifyTimeValue(data.rectifyTime);
}
const signPath = resolveSignPathFromData(data);
common_vendor.index.__f__("log", "at pages/hiddendanger/rectification.vue:1245", "整改详情签名路径:", signPath);
applySignatureFromServer(signPath);
hazardId.value = data.hazardId || "";
assignId.value = data.assignId || "";
const resolvedTaskId = resolveTaskIdFromDetail(data);
if (resolvedTaskId) {
taskId.value = resolvedTaskId;
}
detailPersonPool.value = [
...Array.isArray(data.managers) ? data.managers : [],
...Array.isArray(data.members) ? data.members : []
];
const managerIdentityIdArr = resolveManagerIdentityIdsFromDetail(data);
if (managerIdentityIdArr.length > 0) {
selectedManagerIdentityIds.value = managerIdentityIdArr;
}
const memberIdentityIdArr = parseIdList(data.memberIds ?? data.memberIdentityIds);
if (memberIdentityIdArr.length > 0) {
selectedIdentityIds.value = memberIdentityIdArr;
} else if (data.rectifierIdentityId) {
selectedIdentityIds.value = [String(data.rectifierIdentityId)];
}
if (data.assigneeIdentityId) {
setLockedDefaultIdentities(data.assigneeIdentityId);
} else if (data.rectifierIdentityId) {
setLockedDefaultIdentities(data.rectifierIdentityId);
}
await fetchPersonnelLists();
if (data.attachments && data.attachments.length > 0) {
fileList1.value = data.attachments.map((att) => utils_upload.mapServerFileToUploadItem(att));
}
common_vendor.index.setNavigationBarTitle({ title: "编辑整改信息" });
}
} catch (error) {
common_vendor.index.hideLoading();
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:1288", "获取整改详情失败:", error);
common_vendor.index.showToast({ title: "获取详情失败", icon: "none" });
}
};
const aiGenerating = common_vendor.ref(false);
const handleAiGenerate = async () => {
if (!hazardId.value) {
common_vendor.index.showToast({ title: "缺少隐患信息", icon: "none" });
return;
}
aiGenerating.value = true;
try {
const detailRes = await request_api.getHiddenDangerDetail({
hazardId: hazardId.value,
assignId: assignId.value
});
if (detailRes.code !== 0 || !detailRes.data) {
common_vendor.index.showToast({ title: "获取隐患详情失败", icon: "none" });
return;
}
const { title, description } = detailRes.data;
const aiRes = await request_api.generateRectifyPlan({ title, description });
if (aiRes.code === 0 && aiRes.data) {
if (aiRes.data.rawResponse) {
formData.rectifyPlan = aiRes.data.rawResponse;
}
common_vendor.index.showToast({ title: "AI生成完成", icon: "success", duration: 2e3 });
} else {
common_vendor.index.showToast({ title: aiRes.msg || "AI生成失败", icon: "none" });
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:1325", "AI生成整改方案失败:", error);
common_vendor.index.showToast({ title: "AI生成失败请重试", icon: "none" });
} finally {
aiGenerating.value = false;
}
};
const signaturePaths = common_vendor.ref([]);
const rectifyDraftHasContent = (data) => {
const form = data.formData || {};
return !!(form.rectifyPlan || form.rectificationMeasures || form.controlMeasures || form.rectifyResult || form.planCost || form.actualCost || data.fileList1 && data.fileList1.length > 0 || data.signatureServerPath || data.signatureLocalPath || data.signaturePaths && data.signaturePaths.length > 0);
};
const {
showRestoreBanner,
clear: clearDraft,
restore: restoreDraft,
save: saveDraft,
bindAutoSave
} = utils_useDraftCache.useDraftCache({
getKey: () => utils_draftCache.buildDraftKey(utils_draftCache.DRAFT_NS.RECTIFY, hazardId.value, rectifyId.value),
getFallbackKeys: () => {
const primary = utils_draftCache.buildDraftKey(utils_draftCache.DRAFT_NS.RECTIFY, hazardId.value, rectifyId.value);
const compact = utils_draftCache.buildDraftKeyCompact(utils_draftCache.DRAFT_NS.RECTIFY, hazardId.value, rectifyId.value);
return compact !== primary ? [compact] : [];
},
getPayload: () => ({
formData: {
rectifyPlan: formData.rectifyPlan,
rectificationMeasures: formData.rectificationMeasures,
controlMeasures: formData.controlMeasures,
rectifyResult: formData.rectifyResult,
planCost: formData.planCost,
actualCost: formData.actualCost
},
fileList1: fileList1.value,
signatureServerPath: signatureServerPath.value,
signatureUrl: signatureUrl.value,
signatureLocalPath: signatureLocalPath.value,
showCanvas: showCanvas.value,
signaturePaths: signaturePaths.value,
sendMsgFlagRadio: sendMsgFlagRadio.value,
hazardEndRadio: hazardEndRadio.value
}),
hasContent: rectifyDraftHasContent,
applyPayload: (data) => {
const form = data.formData || {};
formData.rectifyPlan = form.rectifyPlan || "";
formData.rectificationMeasures = form.rectificationMeasures || "";
formData.controlMeasures = form.controlMeasures || "";
formData.rectifyResult = form.rectifyResult || "";
formData.planCost = form.planCost || "";
formData.actualCost = form.actualCost || "";
fileList1.value = data.fileList1 || [];
signaturePaths.value = data.signaturePaths || [];
if (data.signatureServerPath || data.signatureUrl) {
applySignatureFromServer(data.signatureServerPath || data.signatureUrl);
} else if (data.signatureLocalPath) {
applySignatureFromLocal(data.signatureLocalPath);
} else if (data.showCanvas === false) {
showCanvas.value = false;
}
sendMsgFlagRadio.value = data.sendMsgFlagRadio === "no" ? "no" : "yes";
hazardEndRadio.value = normalizeHazardEndRadio(data.hazardEndRadio ?? (data.hazardEnd === true ? "yes" : "no"));
},
clearForm: () => {
formData.rectifyPlan = "";
formData.rectificationMeasures = "";
formData.controlMeasures = "";
formData.rectifyResult = "";
formData.planCost = "";
formData.actualCost = "";
fileList1.value = [];
signatureServerPath.value = "";
signatureUrl.value = "";
signatureLocalPath.value = "";
showCanvas.value = true;
signaturePaths.value = [];
if (signatureRef.value) {
signatureRef.value.clear();
}
sendMsgFlagRadio.value = "yes";
hazardEndRadio.value = "no";
},
canSave: () => !!(hazardId.value || rectifyId.value),
onAfterRestore: (data) => {
var _a;
if (data.signatureServerPath || data.signatureUrl || data.signatureLocalPath) {
return;
}
if (((_a = data.signaturePaths) == null ? void 0 : _a.length) > 0) {
setTimeout(() => {
if (signatureRef.value) {
isSignatureEmpty.value = false;
}
}, 450);
}
}
});
bindAutoSave(() => [
formData.rectifyPlan,
formData.rectificationMeasures,
formData.controlMeasures,
formData.rectifyResult,
formData.planCost,
formData.actualCost,
fileList1.value,
signatureServerPath.value,
signatureUrl.value,
signatureLocalPath.value,
showCanvas.value,
signaturePaths.value,
sendMsgFlagRadio.value,
hazardEndRadio.value
]);
common_vendor.onHide(() => {
if (showCanvas.value && !isSignatureEmpty.value && signatureRef.value && !isDraftExporting.value) {
isDraftExporting.value = true;
signatureRef.value.confirm();
}
saveDraft();
});
common_vendor.onLoad((options) => {
try {
const sysInfo = common_vendor.index.getSystemInfoSync();
signatureWidth.value = sysInfo.windowWidth - 40;
} catch (e) {
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:1467", "获取系统信息失败:", e);
}
if (options.hazardId) {
hazardId.value = options.hazardId;
}
if (options.assignId) {
assignId.value = options.assignId;
}
if (options.taskId) {
taskId.value = options.taskId;
}
if (!options.rectifyId && options.assigneeIdentityId) {
applyAssigneeFromOptions(options.assigneeId, options.assigneeName, options.assigneeIdentityId);
}
if (!options.rectifyId)
fetchPersonnelLists();
if (options.rectifyId) {
rectifyId.value = options.rectifyId;
isEdit.value = options.isEdit === "1";
fetchRectifyDetail();
} else {
restoreDraft();
initRectifyTimeDefault();
}
common_vendor.nextTick$1(() => {
hazardEndRadio.value = normalizeHazardEndRadio(hazardEndRadio.value);
});
if (options.deadline) {
applyDeadlineFromOptions(options.deadline);
}
if (!options.rectifyId) {
fetchNextStep();
}
});
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.unref(showRestoreBanner)
}, common_vendor.unref(showRestoreBanner) ? {
b: common_vendor.o(($event) => common_vendor.unref(clearDraft)(true))
} : {}, {
c: !aiGenerating.value
}, !aiGenerating.value ? {} : {}, {
d: common_vendor.t(aiGenerating.value ? "AI生成中..." : "AI生成整改方案"),
e: aiGenerating.value,
f: aiGenerating.value,
g: common_vendor.o(handleAiGenerate),
h: common_vendor.o(($event) => formData.rectifyPlan = $event),
i: common_vendor.p({
placeholder: "请输入内容",
maxlength: -1,
autoHeight: true,
modelValue: formData.rectifyPlan
}),
j: common_vendor.o(($event) => formData.rectificationMeasures = $event),
k: common_vendor.p({
placeholder: "请输入整改措施",
modelValue: formData.rectificationMeasures
}),
l: common_vendor.o(($event) => formData.controlMeasures = $event),
m: common_vendor.p({
placeholder: "请输入管控措施",
modelValue: formData.controlMeasures
}),
n: common_vendor.o(($event) => formData.rectifyResult = $event),
o: common_vendor.p({
placeholder: "请输入内容",
modelValue: formData.rectifyResult
}),
p: common_vendor.o(($event) => formData.planCost = $event),
q: common_vendor.p({
placeholder: "请输入内容",
type: "number",
modelValue: formData.planCost
}),
r: common_vendor.o(($event) => formData.actualCost = $event),
s: common_vendor.p({
placeholder: "请输入内容",
type: "number",
modelValue: formData.actualCost
}),
t: common_vendor.t(selectedDeadlineDate.value || "暂无"),
v: !selectedDeadlineDate.value ? 1 : "",
w: common_vendor.t(selectedRectifyTime.value || "请选择实际整改时间"),
x: !selectedRectifyTime.value ? 1 : "",
y: common_vendor.o(($event) => showRectifyTimePicker.value = true),
z: common_vendor.o(onRectifyTimeConfirm),
A: common_vendor.o(($event) => showRectifyTimePicker.value = false),
B: common_vendor.o(($event) => showRectifyTimePicker.value = false),
C: common_vendor.o(($event) => rectifyTimeValue.value = $event),
D: common_vendor.p({
show: showRectifyTimePicker.value,
mode: "datetime",
modelValue: rectifyTimeValue.value
}),
E: common_vendor.t(selectedManagers.value.length > 0 ? selectedManagersText.value : "请选择安全管理人员(可多选)"),
F: selectedManagers.value.length === 0 ? 1 : "",
G: common_vendor.o(openManagerPopup),
H: common_vendor.t(selectedUsers.value.length > 0 ? selectedUsersText.value : "请选择整改责任人(可多选)"),
I: selectedUsers.value.length === 0 ? 1 : "",
J: common_vendor.o(openUserPopup),
K: common_vendor.o(cancelManagerSelect),
L: managerPickerSelectedIdentityIds.value.length > 0
}, managerPickerSelectedIdentityIds.value.length > 0 ? {
M: common_vendor.t(managerPickerSelectedIdentityIds.value.length),
N: common_vendor.t(managerPickerSelectedText.value)
} : {}, {
O: common_vendor.f(managerDeptList.value, (dept, index, i0) => {
return common_vendor.e({
a: common_vendor.t(dept.deptName),
b: getManagerDeptSelectedCount(dept) > 0
}, getManagerDeptSelectedCount(dept) > 0 ? {
c: common_vendor.t(getManagerDeptSelectedCount(dept))
} : {}, {
d: "manager-dept-" + dept.deptId,
e: common_vendor.n({
active: activeManagerDeptIndex.value === index
}),
f: common_vendor.o(($event) => activeManagerDeptIndex.value = index, "manager-dept-" + dept.deptId)
});
}),
P: currentManagerDeptUsers.value.length === 0
}, currentManagerDeptUsers.value.length === 0 ? {} : {
Q: common_vendor.f(currentManagerDeptUsers.value, (user, k0, i0) => {
return {
a: common_vendor.o((checked) => onManagerCheckChange(user.identityId, checked), "manager-identity-" + user.identityId),
b: "f18ba0ce-8-" + i0 + ",f18ba0ce-7",
c: common_vendor.p({
usedAlone: true,
checked: managerPickerSelectedSet.value.has(String(user.identityId)),
label: formatMemberDisplayName(user),
activeColor: "#2667E9",
shape: "square"
}),
d: "manager-identity-" + user.identityId
};
})
}, {
R: "manager-dept-users-" + activeManagerDeptIndex.value,
S: common_vendor.o(cancelManagerSelect),
T: common_vendor.o(confirmManagerSelect),
U: common_vendor.o(cancelManagerSelect),
V: common_vendor.p({
show: showManagerPopup.value,
mode: "bottom",
round: "20"
}),
W: common_vendor.o(cancelUserSelect),
X: userPickerSelectedIdentityIds.value.length > 0
}, userPickerSelectedIdentityIds.value.length > 0 ? {
Y: common_vendor.t(userPickerSelectedIdentityIds.value.length),
Z: common_vendor.t(userPickerSelectedText.value)
} : {}, {
aa: common_vendor.f(deptList.value, (dept, index, i0) => {
return common_vendor.e({
a: common_vendor.t(dept.deptName),
b: getDeptSelectedCount(dept) > 0
}, getDeptSelectedCount(dept) > 0 ? {
c: common_vendor.t(getDeptSelectedCount(dept))
} : {}, {
d: dept.deptId,
e: common_vendor.n({
active: activeDeptIndex.value === index
}),
f: common_vendor.o(($event) => activeDeptIndex.value = index, dept.deptId)
});
}),
ab: currentDeptUsers.value.length === 0
}, currentDeptUsers.value.length === 0 ? {} : {
ac: common_vendor.f(currentDeptUsers.value, (user, k0, i0) => {
return {
a: common_vendor.o((checked) => onUserCheckChange(user.identityId, checked), "identity-" + user.identityId),
b: "f18ba0ce-10-" + i0 + ",f18ba0ce-9",
c: common_vendor.p({
usedAlone: true,
checked: userPickerSelectedSet.value.has(String(user.identityId)),
label: formatUserPickerLabel(user),
disabled: isLockedIdentity(user.identityId),
activeColor: "#2667E9",
shape: "square"
}),
d: "identity-" + user.identityId,
e: isLockedIdentity(user.identityId) ? 1 : ""
};
})
}, {
ad: "dept-users-" + activeDeptIndex.value,
ae: common_vendor.o(cancelUserSelect),
af: common_vendor.o(confirmUserSelect),
ag: common_vendor.o(cancelUserSelect),
ah: common_vendor.p({
show: showUserPopup.value,
mode: "bottom",
round: "20"
}),
ai: common_vendor.o(common_vendor.unref(afterRead)),
aj: common_vendor.o(common_vendor.unref(deletePic)),
ak: common_vendor.p({
fileList: fileList1.value,
name: "1",
multiple: true,
imageMode: "aspectFill",
maxCount: 10
}),
al: !showUserPopup.value && !showManagerPopup.value && !showRectifyTimePicker.value
}, !showUserPopup.value && !showManagerPopup.value && !showRectifyTimePicker.value ? {
am: canvasWidth.value,
an: canvasHeight.value,
ao: canvasWidth.value + "px",
ap: canvasHeight.value + "px"
} : {}, {
aq: !showUserPopup.value && !showManagerPopup.value && !showRectifyTimePicker.value
}, !showUserPopup.value && !showManagerPopup.value && !showRectifyTimePicker.value ? {
ar: canvasWidth.value,
as: canvasHeight.value,
at: canvasWidth.value + "px",
av: canvasHeight.value + "px"
} : {}, {
aw: common_vendor.p({
label: "否",
name: "no",
customStyle: {
marginRight: "48rpx"
}
}),
ax: common_vendor.p({
label: "是",
name: "yes"
}),
ay: "hazard-end-" + hazardEndRadio.value,
az: common_vendor.o(($event) => hazardEndRadio.value = $event),
aA: common_vendor.p({
placement: "row",
activeColor: "#2667e9",
modelValue: hazardEndRadio.value
}),
aB: !hazardEnd.value
}, !hazardEnd.value ? {
aC: common_vendor.t(nextStepDisplay.value),
aD: common_vendor.p({
label: "是",
name: "yes",
customStyle: {
marginRight: "48rpx"
}
}),
aE: common_vendor.p({
label: "否",
name: "no"
}),
aF: common_vendor.o(($event) => sendMsgFlagRadio.value = $event),
aG: common_vendor.p({
placement: "row",
activeColor: "#2667e9",
modelValue: sendMsgFlagRadio.value
})
} : {}, {
aH: showCanvas.value
}, showCanvas.value ? {
aI: common_vendor.o(clearSignature)
} : {
aJ: common_vendor.o(reSign)
}, {
aK: !showCanvas.value
}, !showCanvas.value ? common_vendor.e({
aL: signatureUrl.value
}, signatureUrl.value ? {
aM: signatureUrl.value,
aN: common_vendor.o(onSignatureImageError)
} : {}) : {}, {
aO: showCanvas.value && !showUserPopup.value && !showManagerPopup.value && !showRectifyTimePicker.value
}, showCanvas.value && !showUserPopup.value && !showManagerPopup.value && !showRectifyTimePicker.value ? {
aP: common_vendor.sr(signatureRef, "f18ba0ce-18", {
"k": "signatureRef"
}),
aQ: common_vendor.o((res) => onSignatureConfirm(res.tempFilePath)),
aR: common_vendor.o(onSignatureStart),
aS: common_vendor.o(onSignatureSigning),
aT: common_vendor.o(onSignatureEnd),
aU: common_vendor.o(onSignatureClear),
aV: common_vendor.p({
width: signatureWidth.value,
height: 160,
backgroundColor: "#f8f8f8",
penColor: "#000000",
lineWidth: 3,
enableHistory: false
})
} : {}, {
aW: common_vendor.t(isEdit.value ? "保存修改" : "提交整改"),
aX: common_vendor.o(handleSubmit),
aY: common_vendor.gei(_ctx, "")
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f18ba0ce"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/hiddendanger/rectification.js.map