Files
threeonecheck_web/unpackage/dist/dev/mp-weixin/pages/hiddendanger/acceptance.js
2026-01-18 16:06:37 +08:00

232 lines
7.8 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");
if (!Array) {
const _easycom_up_textarea2 = common_vendor.resolveComponent("up-textarea");
const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload");
(_easycom_up_textarea2 + _easycom_up_upload2)();
}
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";
if (!Math) {
(_easycom_up_textarea + _easycom_up_upload)();
}
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 getFullPath = (filePath) => {
if (!filePath)
return "";
if (filePath.startsWith("http://") || filePath.startsWith("https://")) {
return filePath;
}
return request_request.baseUrl + 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;
}
console.log("整改记录:", rectifyData);
console.log("整改附件:", rectifyAttachments.value);
}
}
} else {
common_vendor.index.showToast({ title: res.msg || "获取详情失败", icon: "none" });
}
} catch (error) {
console.error("获取隐患详情失败:", 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;
}
console.log("验收页面参数:", { 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;
}
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 || "";
}
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
};
console.log("提交验收参数:", params);
try {
const res = await request_api.acceptanceRectification(params);
if (res.code === 0) {
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) {
console.error("验收失败:", error);
common_vendor.index.showToast({
title: "请求失败",
icon: "none"
});
}
};
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++) {
const result = await uploadFilePromise(lists[i].url);
let item = fileList1.value[fileListLen];
fileList1.value.splice(fileListLen, 1, {
...item,
status: "success",
message: "",
url: result
});
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) => {
console.error("上传失败:", err);
reject(err);
}
});
});
};
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,
maxCount: 10
}),
n: common_vendor.o(handleCancel),
o: common_vendor.o(handleSubmit)
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-39f9b795"]]);
wx.createPage(MiniProgramPage);