Files
threeonecheck_web/unpackage/dist/dev/mp-weixin/pages/hiddendanger/rectification.js
2026-06-03 10:16:37 +08:00

647 lines
25 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 request_request = require("../../request/request.js");
const utils_watermark = require("../../utils/watermark.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_up_checkbox_group2 = common_vendor.resolveComponent("up-checkbox-group");
const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload");
const _easycom_wd_signature2 = common_vendor.resolveComponent("wd-signature");
(_easycom_up_textarea2 + _easycom_up_input2 + _easycom_up_datetime_picker2 + _easycom_up_checkbox2 + _easycom_up_checkbox_group2 + _easycom_u_popup2 + _easycom_up_upload2 + _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_up_checkbox_group = () => "../../uni_modules/uview-plus/components/u-checkbox-group/u-checkbox-group.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_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_up_checkbox_group + _easycom_u_popup + _easycom_up_upload + _easycom_wd_signature)();
}
const _sfc_main = {
__name: "rectification",
setup(__props) {
const hazardId = common_vendor.ref("");
const assignId = common_vendor.ref("");
const rectifyId = common_vendor.ref("");
const isEdit = common_vendor.ref(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 clearSignature = () => {
isSignatureEmpty.value = true;
if (signatureRef.value) {
signatureRef.value.clear();
}
};
const reSign = () => {
isSignatureEmpty.value = true;
showCanvas.value = true;
signatureUrl.value = "";
signatureServerPath.value = "";
common_vendor.nextTick$1(() => {
if (signatureRef.value) {
signatureRef.value.clear();
}
});
};
const formData = common_vendor.reactive({
rectifyPlan: "",
// 整改方案
rectifyResult: "",
// 整改完成情况
planCost: "",
// 投资资金(计划)
actualCost: ""
// 投资资金(实际)
});
const show = common_vendor.ref(false);
const value1 = common_vendor.ref(Date.now());
common_vendor.ref("");
const cateList = common_vendor.ref([]);
const showUserPopup = common_vendor.ref(false);
const selectedUserIds = common_vendor.ref([]);
const selectedUsers = common_vendor.ref([]);
const selectedUsersText = common_vendor.computed(() => {
if (selectedUsers.value.length === 0)
return "";
if (selectedUsers.value.length <= 2) {
return selectedUsers.value.map((u) => u.name).join("、");
}
return `${selectedUsers.value[0].name}${selectedUsers.value.length}`;
});
const onUserChange = (ids) => {
common_vendor.index.__f__("log", "at pages/hiddendanger/rectification.vue:211", "选中的ID:", ids);
};
const confirmUserSelect = () => {
selectedUsers.value = cateList.value.filter((item) => selectedUserIds.value.includes(item.id));
showUserPopup.value = false;
common_vendor.index.__f__("log", "at pages/hiddendanger/rectification.vue:219", "选中的整改人员:", selectedUsers.value);
};
const fetchDeptUsers = async () => {
common_vendor.index.__f__("log", "at pages/hiddendanger/rectification.vue:224", "当前hazardId:", hazardId.value);
try {
const res = await request_api.getDeptUsersWithSubordinates({ hazardId: hazardId.value });
if (res.code === 0 && res.data) {
const userList = [];
res.data.forEach((dept) => {
if (dept.users && dept.users.length > 0) {
dept.users.forEach((user) => {
userList.push({
id: String(user.userId),
name: `${user.nickName}${dept.deptName}`
});
});
}
});
cateList.value = userList;
common_vendor.index.__f__("log", "at pages/hiddendanger/rectification.vue:242", "整改人员列表:", cateList.value);
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:245", "获取部门人员失败:", error);
}
};
const fileList1 = common_vendor.ref([]);
const deletePic = (event) => {
fileList1.value.splice(event.index, 1);
};
const afterRead = async (event) => {
let lists = [].concat(event.file);
let fileListLen = fileList1.value.length;
lists.map((item) => {
fileList1.value.push({
...item,
status: "uploading",
message: "上传中"
});
});
for (let i = 0; i < lists.length; i++) {
let watermarkedUrl = lists[i].url;
try {
const instance = common_vendor.getCurrentInstance();
watermarkedUrl = await utils_watermark.addTimestampWatermark({
tempFilePath: lists[i].url,
canvasId: "watermarkCanvas",
canvasWidthRef: canvasWidth,
canvasHeightRef: canvasHeight,
instance
});
} catch (e) {
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:281", "加水印失败,将使用原图上传:", e);
}
const result = await uploadFilePromise(watermarkedUrl);
let item = fileList1.value[fileListLen];
const serverPath = typeof result === "string" ? result : (result == null ? void 0 : result.url) || (result == null ? void 0 : result.filePath) || (result == null ? void 0 : result.path) || "";
fileList1.value.splice(fileListLen, 1, {
...item,
status: "success",
message: "",
url: request_request.toImageUrl(serverPath),
serverPath
});
fileListLen++;
}
};
const uploadFilePromise = (filePath) => {
return new Promise((resolve, reject) => {
common_vendor.index.uploadFile({
url: request_request.baseUrl + "/frontend/attachment/upload",
filePath,
name: "file",
header: {
"Authorization": request_request.getToken()
},
success: (res) => {
const data = JSON.parse(res.data);
if (data.code === 0) {
resolve(data.data);
} else {
reject(data.msg || "上传失败");
}
},
fail: (err) => {
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:317", "上传失败:", err);
reject(err);
}
});
});
};
const executeSubmit = async () => {
const attachments = fileList1.value.map((file) => {
const path = request_request.toRelativeFilePath(file.serverPath || file.filePath || file.url || "");
const fileName = path ? path.split("/").pop() : file.name || "";
return {
fileName: fileName || "",
filePath: path || "",
fileType: file.type || "image/png",
fileSize: file.size || 0
};
});
const params = {
hazardId: hazardId.value,
assignId: assignId.value,
rectifyPlan: formData.rectifyPlan,
rectifyResult: formData.rectifyResult,
planCost: Number(formData.planCost) || 0,
actualCost: Number(formData.actualCost) || 0,
attachments,
// 整改人员ID数组
rectifyUserIds: selectedUserIds.value.map((id) => Number(id)),
signPath: signatureServerPath.value || ""
// 电子签名路径
};
if (rectifyId.value) {
params.rectifyId = rectifyId.value;
}
try {
const 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:377", "提交整改失败:", error);
common_vendor.index.showToast({
title: "操作失败",
icon: "none"
});
} finally {
isSubmitting.value = false;
}
};
const onSignatureConfirm = async (tempFilePath) => {
try {
const res = await uploadFilePromise(tempFilePath);
const path = res && typeof res === "object" ? res.url || res.filePath || "" : res || "";
signatureServerPath.value = request_request.toRelativeFilePath(path);
signatureUrl.value = request_request.toImageUrl(signatureServerPath.value);
if (isSubmitting.value) {
await executeSubmit();
}
} catch (err) {
isSubmitting.value = false;
common_vendor.index.hideLoading();
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:402", "签名上传失败:", err);
common_vendor.index.showToast({ title: "签名上传失败,请重试", icon: "none" });
}
};
const handleSubmit = async () => {
if (!formData.rectifyPlan) {
common_vendor.index.showToast({
title: "请输入整改方案",
icon: "none"
});
return;
}
if (!formData.rectifyResult) {
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) {
common_vendor.index.showToast({
title: "请进行电子签名",
icon: "none"
});
return;
}
isSubmitting.value = true;
common_vendor.index.showLoading({ title: "正在提交...", mask: true });
await executeSubmit();
}
};
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.rectifyResult = data.rectifyResult || "";
formData.planCost = data.planCost ? String(data.planCost) : "";
formData.actualCost = data.actualCost ? String(data.actualCost) : "";
if (data.signPath) {
signatureServerPath.value = request_request.toRelativeFilePath(data.signPath);
signatureUrl.value = request_request.toImageUrl(signatureServerPath.value);
showCanvas.value = false;
}
hazardId.value = data.hazardId || "";
assignId.value = data.assignId || "";
await fetchDeptUsers();
if (data.attachments && data.attachments.length > 0) {
fileList1.value = data.attachments.map((att) => {
const serverPath = request_request.toRelativeFilePath(att.filePath);
return {
url: request_request.toImageUrl(serverPath),
status: "success",
message: "",
name: att.fileName,
type: att.fileType,
serverPath
};
});
}
if (data.memberIds) {
const memberIdArr = data.memberIds.split(",").map((id) => String(id.trim()));
selectedUserIds.value = memberIdArr;
setTimeout(() => {
selectedUsers.value = cateList.value.filter((item) => memberIdArr.includes(item.id));
}, 500);
} else if (data.rectifierId) {
selectedUserIds.value = [String(data.rectifierId)];
setTimeout(() => {
selectedUsers.value = cateList.value.filter((item) => item.id === String(data.rectifierId));
}, 500);
}
common_vendor.index.setNavigationBarTitle({ title: "编辑整改信息" });
}
} catch (error) {
common_vendor.index.hideLoading();
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:600", "获取整改详情失败:", 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:637", "AI生成整改方案失败:", error);
common_vendor.index.showToast({ title: "AI生成失败请重试", icon: "none" });
} finally {
aiGenerating.value = false;
}
};
const hasDraft = common_vendor.ref(false);
const showRestoreBanner = common_vendor.ref(false);
const isRestoring = common_vendor.ref(false);
const signaturePaths = common_vendor.ref([]);
const getDraftKey = () => `draft_rectify_${hazardId.value || ""}_${rectifyId.value || ""}`;
const saveDraft = () => {
if (isRestoring.value)
return;
const key = getDraftKey();
const hasContent = formData.rectifyPlan || formData.rectifyResult || formData.planCost || formData.actualCost || fileList1.value.length > 0 || signatureServerPath.value || signaturePaths.value.length > 0;
if (!hasContent) {
common_vendor.index.removeStorageSync(key);
hasDraft.value = false;
return;
}
const data = {
formData: {
rectifyPlan: formData.rectifyPlan,
rectifyResult: formData.rectifyResult,
planCost: formData.planCost,
actualCost: formData.actualCost
},
fileList1: fileList1.value,
signatureServerPath: signatureServerPath.value,
signatureUrl: signatureUrl.value,
showCanvas: showCanvas.value,
signaturePaths: signaturePaths.value
};
common_vendor.index.setStorageSync(key, JSON.stringify(data));
hasDraft.value = true;
};
const clearDraft = (showToast = true) => {
const key = getDraftKey();
common_vendor.index.removeStorageSync(key);
hasDraft.value = false;
showRestoreBanner.value = false;
isRestoring.value = true;
formData.rectifyPlan = "";
formData.rectifyResult = "";
formData.planCost = "";
formData.actualCost = "";
fileList1.value = [];
signatureServerPath.value = "";
signatureUrl.value = "";
showCanvas.value = true;
signaturePaths.value = [];
if (signatureRef.value) {
signatureRef.value.clear();
}
common_vendor.nextTick$1(() => {
isRestoring.value = false;
});
if (showToast) {
common_vendor.index.showToast({ title: "草稿已清空", icon: "none" });
}
};
const restoreDraft = () => {
const key = getDraftKey();
const cached = common_vendor.index.getStorageSync(key);
if (cached) {
try {
const data = JSON.parse(cached);
const hasContent = data.formData.rectifyPlan || data.formData.rectifyResult || data.formData.planCost || data.formData.actualCost || data.fileList1 && data.fileList1.length > 0 || data.signatureServerPath || data.signaturePaths && data.signaturePaths.length > 0;
if (!hasContent)
return;
isRestoring.value = true;
formData.rectifyPlan = data.formData.rectifyPlan || "";
formData.rectifyResult = data.formData.rectifyResult || "";
formData.planCost = data.formData.planCost || "";
formData.actualCost = data.formData.actualCost || "";
fileList1.value = data.fileList1 || [];
signatureServerPath.value = data.signatureServerPath || "";
signatureUrl.value = data.signatureUrl || "";
showCanvas.value = data.showCanvas !== void 0 ? data.showCanvas : true;
signaturePaths.value = data.signaturePaths || [];
hasDraft.value = true;
showRestoreBanner.value = true;
if (signaturePaths.value.length > 0) {
setTimeout(() => {
if (signatureRef.value) {
isSignatureEmpty.value = false;
}
}, 450);
}
common_vendor.nextTick$1(() => {
isRestoring.value = false;
});
common_vendor.index.showToast({
title: "已自动恢复您上次未提交的内容",
icon: "none",
duration: 2500
});
} catch (e) {
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:772", "解析草稿失败:", e);
isRestoring.value = false;
}
}
};
common_vendor.watch(
() => [
formData.rectifyPlan,
formData.rectifyResult,
formData.planCost,
formData.actualCost,
fileList1.value,
signatureServerPath.value,
signaturePaths.value
],
() => {
if (hazardId.value || rectifyId.value) {
saveDraft();
}
},
{ deep: true }
);
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:803", "获取系统信息失败:", e);
}
if (options.hazardId) {
hazardId.value = options.hazardId;
}
if (options.assignId) {
assignId.value = options.assignId;
}
if (!options.rectifyId)
fetchDeptUsers();
if (options.rectifyId) {
rectifyId.value = options.rectifyId;
isEdit.value = options.isEdit === "1";
fetchRectifyDetail();
} else {
restoreDraft();
}
});
return (_ctx, _cache) => {
return common_vendor.e({
a: showRestoreBanner.value
}, showRestoreBanner.value ? {
b: common_vendor.o(($event) => 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.rectifyResult = $event),
k: common_vendor.p({
placeholder: "请输入内容",
modelValue: formData.rectifyResult
}),
l: common_vendor.o(($event) => formData.planCost = $event),
m: common_vendor.p({
placeholder: "请输入内容",
type: "number",
modelValue: formData.planCost
}),
n: common_vendor.o(($event) => formData.actualCost = $event),
o: common_vendor.p({
placeholder: "请输入内容",
type: "number",
modelValue: formData.actualCost
}),
p: common_vendor.o(($event) => value1.value = $event),
q: common_vendor.p({
hasInput: true,
show: show.value,
mode: "date",
modelValue: value1.value
}),
r: common_vendor.t(selectedUsers.value.length > 0 ? selectedUsersText.value : "请选择整改人员(可多选)"),
s: selectedUsers.value.length === 0 ? 1 : "",
t: common_vendor.o(($event) => showUserPopup.value = true),
v: common_vendor.o(($event) => showUserPopup.value = false),
w: common_vendor.f(cateList.value, (item, k0, i0) => {
return {
a: "f18ba0ce-7-" + i0 + ",f18ba0ce-6",
b: common_vendor.p({
label: item.name,
name: item.id,
activeColor: "#2667E9",
shape: "square"
}),
c: item.id
};
}),
x: common_vendor.o(onUserChange),
y: common_vendor.o(($event) => selectedUserIds.value = $event),
z: common_vendor.p({
placement: "column",
modelValue: selectedUserIds.value
}),
A: common_vendor.o(($event) => showUserPopup.value = false),
B: common_vendor.o(confirmUserSelect),
C: common_vendor.o(($event) => showUserPopup.value = false),
D: common_vendor.p({
show: showUserPopup.value,
mode: "bottom",
round: "20"
}),
E: common_vendor.o(afterRead),
F: common_vendor.o(deletePic),
G: common_vendor.p({
fileList: fileList1.value,
name: "1",
multiple: true,
imageMode: "aspectFill",
maxCount: 10
}),
H: canvasWidth.value,
I: canvasHeight.value,
J: canvasWidth.value + "px",
K: canvasHeight.value + "px",
L: showCanvas.value
}, showCanvas.value ? {
M: common_vendor.o(clearSignature)
} : {
N: common_vendor.o(reSign)
}, {
O: !showCanvas.value
}, !showCanvas.value ? {
P: signatureUrl.value
} : {}, {
Q: showCanvas.value && !showUserPopup.value
}, showCanvas.value && !showUserPopup.value ? {
R: common_vendor.sr(signatureRef, "f18ba0ce-9", {
"k": "signatureRef"
}),
S: common_vendor.o((res) => onSignatureConfirm(res.tempFilePath)),
T: common_vendor.o(($event) => isSignatureEmpty.value = false),
U: common_vendor.o(($event) => isSignatureEmpty.value = false),
V: common_vendor.o(($event) => isSignatureEmpty.value = true),
W: common_vendor.p({
width: signatureWidth.value,
height: 160,
backgroundColor: "#f8f8f8",
penColor: "#000000",
lineWidth: 3,
enableHistory: false
})
} : {}, {
X: common_vendor.t(isEdit.value ? "保存修改" : "提交整改"),
Y: common_vendor.o(handleSubmit),
Z: 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