463 lines
17 KiB
JavaScript
463 lines
17 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_upload = require("../../utils/upload.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: "",
|
|
rectificationMeasures: "",
|
|
controlMeasures: "",
|
|
rectifyResult: "",
|
|
planCost: null,
|
|
actualCost: null,
|
|
rectifierName: "",
|
|
rectifyStatusName: ""
|
|
});
|
|
const formatMoney = (value) => {
|
|
if (value === null || value === void 0 || value === "") {
|
|
return "暂无";
|
|
}
|
|
const num = Number(value);
|
|
if (Number.isNaN(num)) {
|
|
return "暂无";
|
|
}
|
|
return `${num.toFixed(2)} 元`;
|
|
};
|
|
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 resolveAssignWithRectify = (assigns) => {
|
|
if (!(assigns == null ? void 0 : assigns.length))
|
|
return null;
|
|
if (rectifyId.value) {
|
|
const byRectifyId = assigns.find(
|
|
(item) => item.rectify && String(item.rectify.rectifyId) === String(rectifyId.value)
|
|
);
|
|
if (byRectifyId)
|
|
return byRectifyId;
|
|
}
|
|
if (assignId.value) {
|
|
const byAssignId = assigns.find(
|
|
(item) => String(item.assignId) === String(assignId.value) && item.rectify
|
|
);
|
|
if (byAssignId)
|
|
return byAssignId;
|
|
}
|
|
return assigns.find((item) => item.rectify) || null;
|
|
};
|
|
const applyRectifyData = (rectify) => {
|
|
if (!rectify)
|
|
return;
|
|
rectifyData.rectifyPlan = rectify.rectifyPlan || "";
|
|
rectifyData.rectificationMeasures = rectify.rectificationMeasures || "";
|
|
rectifyData.controlMeasures = rectify.controlMeasures || "";
|
|
rectifyData.rectifyResult = rectify.rectifyResult || "";
|
|
rectifyData.planCost = rectify.planCost ?? null;
|
|
rectifyData.actualCost = rectify.actualCost ?? null;
|
|
rectifyData.rectifierName = rectify.rectifierName || "";
|
|
rectifyData.rectifyStatusName = rectify.rectifyStatusName || "";
|
|
rectifyAttachments.value = rectify.attachments || [];
|
|
};
|
|
const fetchDetail = async () => {
|
|
if (!hazardId.value)
|
|
return;
|
|
try {
|
|
const res = await request_api.getHiddenDangerDetail({
|
|
hazardId: hazardId.value,
|
|
assignId: assignId.value
|
|
});
|
|
if (res.code === 0 && res.data) {
|
|
const assign = resolveAssignWithRectify(res.data.assigns);
|
|
if (assign == null ? void 0 : assign.rectify) {
|
|
applyRectifyData(assign.rectify);
|
|
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:240", "整改记录:", rectifyData);
|
|
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:241", "整改附件:", rectifyAttachments.value);
|
|
}
|
|
} else {
|
|
common_vendor.index.showToast({ title: res.msg || "获取详情失败", icon: "none" });
|
|
}
|
|
} catch (error) {
|
|
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:247", "获取隐患详情失败:", error);
|
|
common_vendor.index.showToast({ title: "请求失败", icon: "none" });
|
|
}
|
|
};
|
|
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.filter((f) => f.status === "success").map((file) => utils_upload.buildAttachmentItem(file));
|
|
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:311", "提交验收参数:", 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:333", "验收失败:", error);
|
|
common_vendor.index.showToast({
|
|
title: "请求失败",
|
|
icon: "none"
|
|
});
|
|
} finally {
|
|
isSubmitting.value = false;
|
|
}
|
|
};
|
|
const acceptUploadInstance = common_vendor.getCurrentInstance();
|
|
const { afterRead, deletePic } = utils_upload.createUploadListHandlers(fileList1, {
|
|
watermark: {
|
|
canvasId: "watermarkCanvas",
|
|
canvasWidthRef: canvasWidth,
|
|
canvasHeightRef: canvasHeight,
|
|
instance: acceptUploadInstance
|
|
}
|
|
});
|
|
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:466", "解析草稿失败:", 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 { url } = await utils_upload.uploadToCloud(tempFilePath);
|
|
signatureServerPath.value = url;
|
|
signatureUrl.value = url;
|
|
showCanvas.value = false;
|
|
isSignatureEmpty.value = false;
|
|
if (isSubmitting.value) {
|
|
await executeSubmit();
|
|
}
|
|
} catch (err) {
|
|
isSubmitting.value = false;
|
|
common_vendor.index.hideLoading();
|
|
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:536", "签名上传失败:", 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:547", "获取系统信息失败:", 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:558", "验收页面参数:", { 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.rectificationMeasures || "暂无"),
|
|
c: common_vendor.t(rectifyData.controlMeasures || "暂无"),
|
|
d: common_vendor.t(rectifyData.rectifyResult || "暂无"),
|
|
e: common_vendor.t(formatMoney(rectifyData.planCost)),
|
|
f: common_vendor.t(formatMoney(rectifyData.actualCost)),
|
|
g: common_vendor.t(rectifyData.rectifierName || "暂无"),
|
|
h: common_vendor.t(rectifyData.rectifyStatusName || "暂无"),
|
|
i: rectifyAttachments.value.length > 0
|
|
}, rectifyAttachments.value.length > 0 ? {
|
|
j: common_vendor.f(rectifyAttachments.value, (img, idx, i0) => {
|
|
return {
|
|
a: idx,
|
|
b: getFullPath(img.filePath),
|
|
c: common_vendor.o(($event) => previewImage(idx), idx)
|
|
};
|
|
})
|
|
} : {}, {
|
|
k: common_vendor.n(formData.result === 1 ? "active" : ""),
|
|
l: common_vendor.o(($event) => formData.result = 1),
|
|
m: common_vendor.n(formData.result === 2 ? "active" : ""),
|
|
n: common_vendor.o(($event) => formData.result = 2),
|
|
o: common_vendor.o(($event) => formData.verifyRemark = $event),
|
|
p: common_vendor.p({
|
|
placeholder: "请输入验收备注",
|
|
modelValue: formData.verifyRemark
|
|
}),
|
|
q: common_vendor.o(common_vendor.unref(afterRead)),
|
|
r: common_vendor.o(common_vendor.unref(deletePic)),
|
|
s: common_vendor.p({
|
|
fileList: fileList1.value,
|
|
name: "1",
|
|
multiple: true,
|
|
imageMode: "aspectFill",
|
|
maxCount: 10
|
|
}),
|
|
t: canvasWidth.value,
|
|
v: canvasHeight.value,
|
|
w: canvasWidth.value + "px",
|
|
x: canvasHeight.value + "px",
|
|
y: showCanvas.value
|
|
}, showCanvas.value ? {
|
|
z: common_vendor.o(clearSignature)
|
|
} : {
|
|
A: common_vendor.o(reSign)
|
|
}, {
|
|
B: !showCanvas.value
|
|
}, !showCanvas.value ? {
|
|
C: signatureUrl.value
|
|
} : {}, {
|
|
D: showCanvas.value
|
|
}, showCanvas.value ? {
|
|
E: common_vendor.sr(signatureRef, "39f9b795-2", {
|
|
"k": "signatureRef"
|
|
}),
|
|
F: common_vendor.o((res) => onSignatureConfirm(res.tempFilePath)),
|
|
G: common_vendor.o(($event) => isSignatureEmpty.value = false),
|
|
H: common_vendor.o(($event) => isSignatureEmpty.value = false),
|
|
I: common_vendor.o(($event) => isSignatureEmpty.value = true),
|
|
J: common_vendor.p({
|
|
width: signatureWidth.value,
|
|
height: 160,
|
|
backgroundColor: "#f8f8f8",
|
|
penColor: "#000000",
|
|
lineWidth: 3,
|
|
enableHistory: false
|
|
})
|
|
} : {}, {
|
|
K: common_vendor.o(handleCancel),
|
|
L: common_vendor.o(handleSubmit),
|
|
M: 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
|