502 lines
18 KiB
JavaScript
502 lines
18 KiB
JavaScript
"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_upload2 = common_vendor.resolveComponent("up-upload");
|
|
const _easycom_wd_signature2 = common_vendor.resolveComponent("wd-signature");
|
|
(_easycom_up_textarea2 + _easycom_up_upload2 + _easycom_wd_signature2)();
|
|
}
|
|
const _easycom_up_textarea = () => "../../uni_modules/uview-plus/components/u-textarea/u-textarea.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_upload + _easycom_wd_signature)();
|
|
}
|
|
const _sfc_main = {
|
|
__name: "acceptance",
|
|
setup(__props) {
|
|
const rectifyId = common_vendor.ref("");
|
|
const hazardId = common_vendor.ref("");
|
|
const assignId = common_vendor.ref("");
|
|
const rectifyData = common_vendor.reactive({
|
|
rectifyPlan: "",
|
|
rectifyResult: ""
|
|
});
|
|
const rectifyAttachments = common_vendor.ref([]);
|
|
const formData = common_vendor.reactive({
|
|
result: 1,
|
|
// 验收结果 1.通过 2.不通过
|
|
verifyRemark: ""
|
|
// 验收备注
|
|
});
|
|
const fileList1 = common_vendor.ref([]);
|
|
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 hasDraft = common_vendor.ref(false);
|
|
const showRestoreBanner = common_vendor.ref(false);
|
|
const isRestoring = common_vendor.ref(false);
|
|
const isInitialized = common_vendor.ref(false);
|
|
const signaturePaths = common_vendor.ref([]);
|
|
const getDraftKey = () => `draft_accept_${rectifyId.value || ""}`;
|
|
const getFullPath = (filePath) => {
|
|
if (!filePath)
|
|
return "";
|
|
if (filePath.startsWith("http://") || filePath.startsWith("https://")) {
|
|
return request_request.toImageUrl(filePath);
|
|
}
|
|
return request_request.toImageUrl(filePath);
|
|
};
|
|
const previewImage = (index) => {
|
|
const urls = rectifyAttachments.value.map((item) => getFullPath(item.filePath));
|
|
common_vendor.index.previewImage({
|
|
current: index,
|
|
urls
|
|
});
|
|
};
|
|
const fetchDetail = async () => {
|
|
if (!hazardId.value || !assignId.value)
|
|
return;
|
|
try {
|
|
const res = await request_api.getHiddenDangerDetail({ hazardId: hazardId.value, assignId: assignId.value });
|
|
if (res.code === 0 && res.data) {
|
|
if (res.data.assigns && res.data.assigns.length > 0) {
|
|
const assign = res.data.assigns[0];
|
|
if (assign.rectify) {
|
|
rectifyData.rectifyPlan = assign.rectify.rectifyPlan || "";
|
|
rectifyData.rectifyResult = assign.rectify.rectifyResult || "";
|
|
if (assign.rectify.attachments) {
|
|
rectifyAttachments.value = assign.rectify.attachments;
|
|
}
|
|
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:167", "整改记录:", rectifyData);
|
|
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:168", "整改附件:", rectifyAttachments.value);
|
|
}
|
|
}
|
|
} else {
|
|
common_vendor.index.showToast({ title: res.msg || "获取详情失败", icon: "none" });
|
|
}
|
|
} catch (error) {
|
|
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:175", "获取隐患详情失败:", error);
|
|
common_vendor.index.showToast({ title: "请求失败", icon: "none" });
|
|
}
|
|
};
|
|
common_vendor.onLoad((options) => {
|
|
if (options.rectifyId) {
|
|
rectifyId.value = options.rectifyId;
|
|
}
|
|
if (options.hazardId) {
|
|
hazardId.value = options.hazardId;
|
|
}
|
|
if (options.assignId) {
|
|
assignId.value = options.assignId;
|
|
}
|
|
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:190", "验收页面参数:", { rectifyId: rectifyId.value, hazardId: hazardId.value, assignId: assignId.value });
|
|
fetchDetail();
|
|
});
|
|
const handleCancel = () => {
|
|
common_vendor.index.navigateBack();
|
|
};
|
|
const handleSubmit = async () => {
|
|
if (!rectifyId.value) {
|
|
common_vendor.index.showToast({
|
|
title: "缺少整改ID",
|
|
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 executeSubmit = async () => {
|
|
const attachments = fileList1.value.map((file) => {
|
|
let url = "";
|
|
if (typeof file.url === "string") {
|
|
url = file.url;
|
|
} else if (file.url && typeof file.url === "object") {
|
|
url = file.url.url || file.url.path || "";
|
|
}
|
|
if (typeof url === "string" && url.startsWith("http")) {
|
|
url = url.replace(request_request.imageBaseUrl, "");
|
|
}
|
|
const fileName = typeof url === "string" && url ? url.split("/").pop() : file.name || "";
|
|
return {
|
|
fileName: fileName || "",
|
|
filePath: url || "",
|
|
fileType: file.type || "image/png",
|
|
fileSize: file.size || 0
|
|
};
|
|
});
|
|
const params = {
|
|
rectifyId: Number(rectifyId.value),
|
|
result: formData.result,
|
|
verifyRemark: formData.verifyRemark || "",
|
|
attachments,
|
|
signPath: signatureServerPath.value || ""
|
|
// 电子签名路径
|
|
};
|
|
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:271", "提交验收参数:", params);
|
|
try {
|
|
const res = await request_api.acceptanceRectification(params);
|
|
common_vendor.index.hideLoading();
|
|
if (res.code === 0) {
|
|
clearDraft(false);
|
|
common_vendor.index.showToast({
|
|
title: "验收成功",
|
|
icon: "success"
|
|
});
|
|
setTimeout(() => {
|
|
common_vendor.index.navigateBack();
|
|
}, 1500);
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: res.msg || "验收失败",
|
|
icon: "none"
|
|
});
|
|
}
|
|
} catch (error) {
|
|
common_vendor.index.hideLoading();
|
|
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:293", "验收失败:", error);
|
|
common_vendor.index.showToast({
|
|
title: "请求失败",
|
|
icon: "none"
|
|
});
|
|
} finally {
|
|
isSubmitting.value = false;
|
|
}
|
|
};
|
|
const deletePic = (event) => {
|
|
fileList1.value.splice(event.index, 1);
|
|
};
|
|
const addWatermark = (tempFilePath) => {
|
|
const instance = common_vendor.getCurrentInstance();
|
|
return utils_watermark.addTimestampWatermark({
|
|
tempFilePath,
|
|
canvasId: "watermarkCanvas",
|
|
canvasWidthRef: canvasWidth,
|
|
canvasHeightRef: canvasHeight,
|
|
instance
|
|
});
|
|
};
|
|
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++) {
|
|
try {
|
|
const watermarkedUrl = await addWatermark(lists[i].url);
|
|
const result = await uploadFilePromise(watermarkedUrl);
|
|
let item = fileList1.value[fileListLen];
|
|
fileList1.value.splice(fileListLen, 1, {
|
|
...item,
|
|
status: "success",
|
|
message: "",
|
|
url: request_request.toImageUrl(result.url || result.filePath || result)
|
|
});
|
|
} catch (e) {
|
|
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:352", "加水印或上传失败:", e);
|
|
let item = fileList1.value[fileListLen];
|
|
fileList1.value.splice(fileListLen, 1, {
|
|
...item,
|
|
status: "failed",
|
|
message: "处理失败"
|
|
});
|
|
}
|
|
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/acceptance.vue:382", "上传失败:", err);
|
|
reject(err);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
const saveDraft = () => {
|
|
if (isRestoring.value || !isInitialized.value)
|
|
return;
|
|
const key = getDraftKey();
|
|
const hasContent = formData.verifyRemark || fileList1.value.length > 0 || signatureServerPath.value || signaturePaths.value.length > 0;
|
|
if (!hasContent) {
|
|
common_vendor.index.removeStorageSync(key);
|
|
hasDraft.value = false;
|
|
return;
|
|
}
|
|
const data = {
|
|
formData: {
|
|
result: formData.result,
|
|
verifyRemark: formData.verifyRemark
|
|
},
|
|
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.result = 1;
|
|
formData.verifyRemark = "";
|
|
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.verifyRemark || data.fileList1 && data.fileList1.length > 0 || data.signatureServerPath || data.signaturePaths && data.signaturePaths.length > 0;
|
|
if (!hasContent) {
|
|
isInitialized.value = true;
|
|
return;
|
|
}
|
|
isRestoring.value = true;
|
|
formData.result = data.formData.result !== void 0 ? data.formData.result : 1;
|
|
formData.verifyRemark = data.formData.verifyRemark || "";
|
|
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;
|
|
isInitialized.value = true;
|
|
});
|
|
common_vendor.index.showToast({
|
|
title: "已自动恢复您上次未提交的内容",
|
|
icon: "none",
|
|
duration: 2500
|
|
});
|
|
} catch (e) {
|
|
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:502", "解析草稿失败:", e);
|
|
isRestoring.value = false;
|
|
isInitialized.value = true;
|
|
}
|
|
} else {
|
|
isInitialized.value = true;
|
|
}
|
|
};
|
|
common_vendor.watch(
|
|
() => [
|
|
formData.result,
|
|
formData.verifyRemark,
|
|
fileList1.value,
|
|
signatureServerPath.value,
|
|
signaturePaths.value
|
|
],
|
|
() => {
|
|
if (rectifyId.value) {
|
|
saveDraft();
|
|
}
|
|
},
|
|
{ deep: true }
|
|
);
|
|
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 onSignatureConfirm = async (tempFilePath) => {
|
|
try {
|
|
const res = await uploadFilePromise(tempFilePath);
|
|
const path = res && typeof res === "object" ? res.url || res.filePath || "" : res || "";
|
|
signatureServerPath.value = path;
|
|
signatureUrl.value = path.startsWith("http") ? path : request_request.baseUrl.replace("/api", "") + path;
|
|
if (isSubmitting.value) {
|
|
await executeSubmit();
|
|
}
|
|
} catch (err) {
|
|
isSubmitting.value = false;
|
|
common_vendor.index.hideLoading();
|
|
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:573", "签名上传失败:", err);
|
|
common_vendor.index.showToast({ title: "签名上传失败,请重试", icon: "none" });
|
|
}
|
|
};
|
|
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/acceptance.vue:584", "获取系统信息失败:", e);
|
|
}
|
|
if (options.rectifyId) {
|
|
rectifyId.value = options.rectifyId;
|
|
}
|
|
if (options.hazardId) {
|
|
hazardId.value = options.hazardId;
|
|
}
|
|
if (options.assignId) {
|
|
assignId.value = options.assignId;
|
|
}
|
|
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:595", "验收页面参数:", { rectifyId: rectifyId.value, hazardId: hazardId.value, assignId: assignId.value });
|
|
fetchDetail();
|
|
restoreDraft();
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: common_vendor.t(rectifyData.rectifyPlan || "暂无"),
|
|
b: common_vendor.t(rectifyData.rectifyResult || "暂无"),
|
|
c: rectifyAttachments.value.length > 0
|
|
}, rectifyAttachments.value.length > 0 ? {
|
|
d: common_vendor.f(rectifyAttachments.value, (img, idx, i0) => {
|
|
return {
|
|
a: idx,
|
|
b: getFullPath(img.filePath),
|
|
c: common_vendor.o(($event) => previewImage(idx), idx)
|
|
};
|
|
})
|
|
} : {}, {
|
|
e: common_vendor.n(formData.result === 1 ? "active" : ""),
|
|
f: common_vendor.o(($event) => formData.result = 1),
|
|
g: common_vendor.n(formData.result === 2 ? "active" : ""),
|
|
h: common_vendor.o(($event) => formData.result = 2),
|
|
i: common_vendor.o(($event) => formData.verifyRemark = $event),
|
|
j: common_vendor.p({
|
|
placeholder: "请输入验收备注",
|
|
modelValue: formData.verifyRemark
|
|
}),
|
|
k: common_vendor.o(afterRead),
|
|
l: common_vendor.o(deletePic),
|
|
m: common_vendor.p({
|
|
fileList: fileList1.value,
|
|
name: "1",
|
|
multiple: true,
|
|
imageMode: "aspectFill",
|
|
maxCount: 10
|
|
}),
|
|
n: canvasWidth.value,
|
|
o: canvasHeight.value,
|
|
p: canvasWidth.value + "px",
|
|
q: canvasHeight.value + "px",
|
|
r: showCanvas.value
|
|
}, showCanvas.value ? {
|
|
s: common_vendor.o(clearSignature)
|
|
} : {
|
|
t: common_vendor.o(reSign)
|
|
}, {
|
|
v: !showCanvas.value
|
|
}, !showCanvas.value ? {
|
|
w: signatureUrl.value
|
|
} : {}, {
|
|
x: showCanvas.value
|
|
}, showCanvas.value ? {
|
|
y: common_vendor.sr(signatureRef, "39f9b795-2", {
|
|
"k": "signatureRef"
|
|
}),
|
|
z: common_vendor.o((res) => onSignatureConfirm(res.tempFilePath)),
|
|
A: common_vendor.o(($event) => isSignatureEmpty.value = false),
|
|
B: common_vendor.o(($event) => isSignatureEmpty.value = false),
|
|
C: common_vendor.o(($event) => isSignatureEmpty.value = true),
|
|
D: common_vendor.p({
|
|
width: signatureWidth.value,
|
|
height: 160,
|
|
backgroundColor: "#f8f8f8",
|
|
penColor: "#000000",
|
|
lineWidth: 3,
|
|
enableHistory: false
|
|
})
|
|
} : {}, {
|
|
E: common_vendor.o(handleCancel),
|
|
F: common_vendor.o(handleSubmit),
|
|
G: common_vendor.gei(_ctx, "")
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-39f9b795"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/hiddendanger/acceptance.js.map
|