Files
threeonecheck_web/unpackage/dist/dev/mp-weixin/pages/Inspectionresult/Inspectionresult.js
2026-05-03 09:08:56 +08:00

558 lines
23 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 request_three_one_api_area = require("../../request/three_one_api/area.js");
if (!Array) {
const _easycom_u_radio2 = common_vendor.resolveComponent("u-radio");
const _easycom_u_radio_group2 = common_vendor.resolveComponent("u-radio-group");
const _easycom_up_textarea2 = common_vendor.resolveComponent("up-textarea");
const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload");
const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
const _easycom_up_choose2 = common_vendor.resolveComponent("up-choose");
const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
(_easycom_u_radio2 + _easycom_u_radio_group2 + _easycom_up_textarea2 + _easycom_up_upload2 + _easycom_up_input2 + _easycom_up_choose2 + _easycom_u_popup2)();
}
const _easycom_u_radio = () => "../../uni_modules/uview-plus/components/u-radio/u-radio.js";
const _easycom_u_radio_group = () => "../../uni_modules/uview-plus/components/u-radio-group/u-radio-group.js";
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_up_input = () => "../../uni_modules/uview-plus/components/u-input/u-input.js";
const _easycom_up_choose = () => "../../uni_modules/uview-plus/components/u-choose/u-choose.js";
const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
if (!Math) {
(_easycom_u_radio + _easycom_u_radio_group + _easycom_up_textarea + _easycom_up_upload + _easycom_up_input + _easycom_up_choose + _easycom_u_popup)();
}
const _sfc_main = {
__name: "Inspectionresult",
setup(__props) {
const oneTableId = common_vendor.ref("");
const checkData = common_vendor.ref(null);
const radiolist1 = common_vendor.reactive([
{
name: "正常",
value: 1,
disabled: false
},
{
name: "异常",
value: 2,
disabled: false
},
{
name: "不涉及",
value: 3,
disabled: false
}
]);
const radiovalue1 = common_vendor.ref("");
const groupChange = (n) => {
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:240", "groupChange", n);
if (n !== "异常") {
clearHazard();
}
};
const radioChange = (n) => {
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:248", "radioChange", n);
};
const value1 = common_vendor.ref("");
const showHazardPopup = common_vendor.ref(false);
const hazardFormData = common_vendor.reactive({
title: "",
level: 0,
source: 0,
description: "",
tagIndex: 0
});
const hazardAddress = common_vendor.ref("");
const hazardLng = common_vendor.ref(0);
const hazardLat = common_vendor.ref(0);
const showAreaPicker = common_vendor.ref(false);
const areaList = common_vendor.ref([]);
const selectedAreaId = common_vendor.ref("");
const selectedAreaName = common_vendor.ref("");
const tempAreaId = common_vendor.ref("");
const fetchAreaList = async () => {
try {
const res = await request_three_one_api_area.getAreaList();
if (res.code === 0 && res.data && res.data.records) {
areaList.value = res.data.records;
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/Inspectionresult/Inspectionresult.vue:288", "获取区域列表失败:", error);
}
};
const confirmAreaSelect = () => {
if (tempAreaId.value) {
selectedAreaId.value = tempAreaId.value;
const selected = areaList.value.find((item) => item.id === tempAreaId.value);
selectedAreaName.value = selected ? selected.name : "";
}
showAreaPicker.value = false;
};
const hazardFileList = common_vendor.ref([]);
const levelChooseRef = common_vendor.ref(null);
const aiAnalyzing = common_vendor.ref(false);
const hasHazardData = common_vendor.computed(() => {
return hazardFormData.title && hazardFileList.value.length > 0;
});
const progressPercent = common_vendor.computed(() => {
if (!checkData.value)
return 0;
const current = checkData.value.currentIndex || 1;
const total = checkData.value.totalCount || 1;
return Math.round(current / total * 100);
});
const levelOptions = common_vendor.ref([
{ id: 1, title: "轻微隐患" },
{ id: 2, title: "一般隐患" },
{ id: 3, title: "重大隐患" }
]);
const sourceOptions = common_vendor.ref([
{ id: 1, title: "随手拍" },
{ id: 2, title: "企业自查" },
{ id: 3, title: "行业互查" },
{ id: 4, title: "专家诊查" }
]);
const tagOptions = common_vendor.ref([]);
const fetchTagOptions = async () => {
try {
const res = await request_api.getHiddenDangerLabelList();
if (res.code === 0) {
tagOptions.value = res.data.map((item) => ({
id: item.id,
title: item.name
}));
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/Inspectionresult/Inspectionresult.vue:353", "获取标签列表失败:", error);
}
};
const openHazardPopup = () => {
showHazardPopup.value = true;
};
const editHazard = () => {
showHazardPopup.value = true;
};
const clearHazard = () => {
hazardFormData.title = "";
hazardFormData.level = 0;
hazardFormData.source = 0;
hazardFormData.description = "";
hazardFormData.tagIndex = 0;
hazardAddress.value = "";
hazardLng.value = 0;
hazardLat.value = 0;
hazardFileList.value = [];
selectedAreaId.value = "";
selectedAreaName.value = "";
};
const confirmHazard = () => {
if (hazardFileList.value.length === 0) {
common_vendor.index.showToast({ title: "请上传隐患图片/视频", icon: "none" });
return;
}
if (!hazardFormData.title) {
common_vendor.index.showToast({ title: "请输入隐患标题", icon: "none" });
return;
}
if (!hazardAddress.value) {
common_vendor.index.showToast({ title: "请输入隐患位置", icon: "none" });
return;
}
if (!hazardFormData.description) {
common_vendor.index.showToast({ title: "请输入隐患描述", icon: "none" });
return;
}
showHazardPopup.value = false;
common_vendor.index.showToast({ title: "隐患信息已暂存", icon: "success" });
};
const chooseLocation = () => {
showHazardPopup.value = false;
setTimeout(() => {
common_vendor.index.chooseLocation({
success: (res) => {
hazardAddress.value = res.address + (res.name ? `(${res.name})` : "");
hazardLng.value = res.longitude;
hazardLat.value = res.latitude;
showHazardPopup.value = true;
},
fail: (err) => {
showHazardPopup.value = true;
if (err.errMsg && err.errMsg.indexOf("cancel") === -1) {
common_vendor.index.showToast({ title: "选择位置失败", icon: "none" });
}
}
});
}, 300);
};
const deletePic = (event) => {
hazardFileList.value.splice(event.index, 1);
};
const afterRead = async (event) => {
let lists = [].concat(event.file);
let fileListLen = hazardFileList.value.length;
lists.map((item) => {
hazardFileList.value.push({
...item,
status: "uploading",
message: "上传中"
});
});
for (let i = 0; i < lists.length; i++) {
const result = await uploadFilePromise(lists[i].url);
let item = hazardFileList.value[fileListLen];
const serverPath = typeof result === "string" ? result : (result == null ? void 0 : result.url) || (result == null ? void 0 : result.path) || "";
hazardFileList.value.splice(fileListLen, 1, {
...item,
status: "success",
message: "",
url: request_request.baseUrl.replace("/prod-api", "") + 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/Inspectionresult/Inspectionresult.vue:479", "上传失败:", err);
reject(err);
}
});
});
};
const handleAiAnalyze = async () => {
const imageFiles = hazardFileList.value.filter((f) => {
return f.status === "success" && f.url.toLowerCase().match(/\.(jpg|jpeg|png|gif|bmp|webp)$/);
});
if (imageFiles.length === 0) {
common_vendor.index.showToast({ title: "请先上传隐患图片", icon: "none" });
return;
}
const fullImageUrl = imageFiles[0].url;
aiAnalyzing.value = true;
try {
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:500", "开始调用AI分析接口图片地址:", fullImageUrl);
const analyzeRes = await request_api.analyzeHazardImage({
imageUrl: fullImageUrl
});
if (analyzeRes.code === 0 && analyzeRes.data) {
const aiData = analyzeRes.data;
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:507", "AI分析结果:", aiData);
if (aiData.title)
hazardFormData.title = aiData.title;
if (aiData.description)
hazardFormData.description = aiData.description;
if (aiData.level) {
const levelMap = { "轻微": 0, "轻微隐患": 0, "一般": 1, "一般隐患": 1, "重大": 2, "重大隐患": 2 };
const levelIndex = levelMap[aiData.level];
if (levelIndex !== void 0) {
hazardFormData.level = levelIndex;
common_vendor.nextTick$1(() => {
if (levelChooseRef.value && levelChooseRef.value.$data) {
levelChooseRef.value.$data.currentIndex = levelIndex;
}
});
}
}
common_vendor.index.showToast({ title: "AI分析完成已自动填充", icon: "success", duration: 2e3 });
} else {
common_vendor.index.showToast({ title: analyzeRes.msg || "AI分析失败", icon: "none" });
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/Inspectionresult/Inspectionresult.vue:530", "AI分析接口调用失败:", error);
common_vendor.index.showToast({ title: "AI分析失败请重试", icon: "none" });
} finally {
aiAnalyzing.value = false;
}
};
const handleSubmit = async () => {
var _a, _b, _c, _d;
if (!radiovalue1.value) {
common_vendor.index.showToast({ title: "请选择检查结果", icon: "none" });
return;
}
const selectedItem = radiolist1.find((item) => item.name === radiovalue1.value);
const resultValue = selectedItem ? selectedItem.value : null;
if (!resultValue) {
common_vendor.index.showToast({ title: "请选择检查结果", icon: "none" });
return;
}
if (radiovalue1.value === "异常" && !hasHazardData.value) {
common_vendor.index.showToast({ title: "请填写隐患信息", icon: "none" });
return;
}
try {
common_vendor.index.showLoading({ title: "提交中..." });
if (radiovalue1.value === "异常" && hasHazardData.value) {
const attachments = hazardFileList.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 selectedTag = tagOptions.value[hazardFormData.tagIndex];
const tagId = selectedTag ? selectedTag.id : null;
const hazardParams = {
taskId: (_a = checkData.value) == null ? void 0 : _a.taskId,
checkPointId: (_b = checkData.value) == null ? void 0 : _b.checkPointId,
title: hazardFormData.title,
level: hazardFormData.level + 1,
lng: hazardLng.value || 0,
lat: hazardLat.value || 0,
address: hazardAddress.value || "",
areaId: selectedAreaId.value || null,
// 隐患区域ID
description: hazardFormData.description || "",
source: ((_c = sourceOptions.value[hazardFormData.source]) == null ? void 0 : _c.title) || "",
tagId,
attachments
};
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:604", "隐患参数:", hazardParams);
const hazardRes = await request_api.addHiddenDanger(hazardParams);
if (hazardRes.code !== 0) {
common_vendor.index.hideLoading();
common_vendor.index.showToast({ title: hazardRes.msg || "新增隐患失败", icon: "none" });
return;
}
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:613", "新增隐患成功");
}
const submitParams = {
taskId: (_d = checkData.value) == null ? void 0 : _d.taskId,
result: resultValue,
remark: value1.value
};
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:622", "提交参数:", submitParams);
const res = await request_api.submitCheckResult(submitParams);
common_vendor.index.hideLoading();
if (res.code === 0) {
if (res.data && res.data.allFinished === true) {
common_vendor.index.showToast({ title: "全部检查已完成", icon: "success" });
setTimeout(() => {
common_vendor.index.navigateBack();
}, 1500);
} else if (res.data && res.data.nextTask) {
common_vendor.index.showToast({ title: "提交成功,进入下一题", icon: "success" });
resetFormState();
checkData.value = res.data.nextTask;
} else {
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/Inspectionresult/Inspectionresult.vue:656", "提交失败:", error);
common_vendor.index.showToast({ title: "提交失败", icon: "none" });
}
};
const resetFormState = () => {
radiovalue1.value = "";
value1.value = "";
clearHazard();
};
const getCheckData = async () => {
try {
const res = await request_api.enterCheckPlan(oneTableId.value);
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:675", "检查项数据:", res);
if (res.code === 0) {
checkData.value = res.data;
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/Inspectionresult/Inspectionresult.vue:680", error);
}
};
common_vendor.onLoad((options) => {
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:686", "接收到的参数:", options);
if (options.id) {
oneTableId.value = options.id;
getCheckData();
}
fetchTagOptions();
fetchAreaList();
});
return (_ctx, _cache) => {
var _a, _b, _c, _d;
return common_vendor.e({
a: checkData.value
}, checkData.value ? {
b: common_vendor.t(checkData.value.currentIndex || 1),
c: common_vendor.t(checkData.value.totalCount || 1),
d: progressPercent.value + "%"
} : {}, {
e: common_vendor.t(((_a = checkData.value) == null ? void 0 : _a.name) || "加载中..."),
f: ((_b = checkData.value) == null ? void 0 : _b.point) || "",
g: common_vendor.f(radiolist1, (item, index, i0) => {
return {
a: index,
b: common_vendor.o(radioChange, index),
c: "643afff0-1-" + i0 + ",643afff0-0",
d: common_vendor.p({
customStyle: {
marginBottom: "8px"
},
label: item.name,
name: item.name
})
};
}),
h: common_vendor.o(groupChange),
i: common_vendor.o(($event) => radiovalue1.value = $event),
j: common_vendor.p({
placement: "row",
modelValue: radiovalue1.value
}),
k: radiovalue1.value === "异常"
}, radiovalue1.value === "异常" ? common_vendor.e({
l: !hasHazardData.value
}, !hasHazardData.value ? {
m: common_vendor.o(openHazardPopup)
} : common_vendor.e({
n: common_vendor.t(hazardFormData.title),
o: common_vendor.t((_c = levelOptions.value[hazardFormData.level]) == null ? void 0 : _c.title),
p: hazardFormData.level === 0 ? 1 : "",
q: hazardFormData.level === 1 ? 1 : "",
r: hazardFormData.level === 2 ? 1 : "",
s: common_vendor.t(((_d = sourceOptions.value[hazardFormData.source]) == null ? void 0 : _d.title) || "-"),
t: common_vendor.t(hazardAddress.value || "-"),
v: common_vendor.t(hazardFormData.description || "-"),
w: hazardFileList.value.length > 0
}, hazardFileList.value.length > 0 ? {
x: common_vendor.t(hazardFileList.value.length)
} : {}, {
y: common_vendor.o(editHazard),
z: common_vendor.o(clearHazard)
})) : {}, {
A: common_vendor.o(($event) => value1.value = $event),
B: common_vendor.p({
placeholder: "请输入备注信息",
modelValue: value1.value
}),
C: common_vendor.o(handleSubmit),
D: common_vendor.o(($event) => showHazardPopup.value = false),
E: common_vendor.o(afterRead),
F: common_vendor.o(deletePic),
G: common_vendor.p({
fileList: hazardFileList.value,
name: "1",
multiple: true,
maxCount: 10
}),
H: !aiAnalyzing.value
}, !aiAnalyzing.value ? {} : {}, {
I: common_vendor.t(aiAnalyzing.value ? "AI识别中..." : "AI 识别隐患"),
J: aiAnalyzing.value,
K: aiAnalyzing.value,
L: common_vendor.o(handleAiAnalyze),
M: common_vendor.o(($event) => hazardFormData.title = $event),
N: common_vendor.p({
placeholder: "请输入内容",
border: "surround",
modelValue: hazardFormData.title
}),
O: common_vendor.sr(levelChooseRef, "643afff0-6,643afff0-3", {
"k": "levelChooseRef"
}),
P: common_vendor.o(($event) => hazardFormData.level = $event),
Q: common_vendor.p({
options: levelOptions.value,
wrap: false,
["item-width"]: "183rpx",
["item-height"]: "72rpx",
modelValue: hazardFormData.level
}),
R: common_vendor.o(($event) => hazardFormData.source = $event),
S: common_vendor.p({
options: sourceOptions.value,
wrap: false,
["item-width"]: "183rpx",
["item-height"]: "72rpx",
modelValue: hazardFormData.source
}),
T: common_vendor.o(($event) => hazardAddress.value = $event),
U: common_vendor.p({
placeholder: "请输入地址",
border: "surround",
modelValue: hazardAddress.value
}),
V: common_vendor.o(chooseLocation),
W: common_vendor.t(selectedAreaName.value || "请选择隐患区域"),
X: !selectedAreaName.value ? 1 : "",
Y: common_vendor.o(($event) => showAreaPicker.value = true),
Z: common_vendor.o(($event) => hazardFormData.description = $event),
aa: common_vendor.p({
placeholder: "请输入内容",
modelValue: hazardFormData.description
}),
ab: common_vendor.o(($event) => hazardFormData.tagIndex = $event),
ac: common_vendor.p({
options: tagOptions.value,
modelValue: hazardFormData.tagIndex
}),
ad: common_vendor.o(($event) => showHazardPopup.value = false),
ae: common_vendor.o(confirmHazard),
af: common_vendor.o(($event) => showHazardPopup.value = false),
ag: common_vendor.p({
show: showHazardPopup.value,
mode: "center",
round: "20"
}),
ah: common_vendor.o(($event) => showAreaPicker.value = false),
ai: common_vendor.o(confirmAreaSelect),
aj: common_vendor.f(areaList.value, (item, k0, i0) => {
return common_vendor.e({
a: item.color,
b: common_vendor.t(item.name),
c: tempAreaId.value === item.id
}, tempAreaId.value === item.id ? {} : {}, {
d: item.id,
e: tempAreaId.value === item.id ? 1 : "",
f: common_vendor.o(($event) => tempAreaId.value = item.id, item.id)
});
}),
ak: areaList.value.length === 0
}, areaList.value.length === 0 ? {} : {}, {
al: common_vendor.o(($event) => showAreaPicker.value = false),
am: common_vendor.p({
show: showAreaPicker.value,
mode: "bottom",
round: "20"
}),
an: common_vendor.gei(_ctx, "")
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-643afff0"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/Inspectionresult/Inspectionresult.js.map