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

596 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_three_one_api_area = require("../../request/three_one_api/area.js");
const request_request = require("../../request/request.js");
if (!Array) {
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_up_textarea2 = common_vendor.resolveComponent("up-textarea");
const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
(_easycom_up_upload2 + _easycom_up_input2 + _easycom_up_choose2 + _easycom_up_textarea2 + _easycom_u_popup2)();
}
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_up_textarea = () => "../../uni_modules/uview-plus/components/u-textarea/u-textarea.js";
const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
if (!Math) {
(_easycom_up_upload + _easycom_up_input + _easycom_up_choose + _easycom_up_textarea + _easycom_u_popup)();
}
const _sfc_main = {
__name: "Inspection",
setup(__props) {
const showAddPopup = common_vendor.ref(false);
const levelChooseRef = common_vendor.ref(null);
const userRole = common_vendor.ref("");
const canAcceptance = common_vendor.computed(() => {
return userRole.value === "admin" || userRole.value === "manage";
});
const getUserRole = () => {
try {
const userInfoStr = common_vendor.index.getStorageSync("userInfo");
if (userInfoStr) {
const userInfo = JSON.parse(userInfoStr);
userRole.value = userInfo.role || "";
common_vendor.index.__f__("log", "at pages/hiddendanger/Inspection.vue:211", "当前用户角色:", userRole.value);
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/Inspection.vue:214", "获取用户信息失败:", error);
}
};
getUserRole();
const taskId = common_vendor.ref("");
const checkPointId = common_vendor.ref("");
const fetchTaskInfo = async (oneTableId) => {
try {
const startRes = await request_api.enterCheckPlan(oneTableId);
if (startRes.code === 0 && startRes.data) {
const tid = startRes.data.taskId;
const detailRes = await request_api.getCheckTaskDetail(tid);
if (detailRes.code === 0 && detailRes.data) {
taskId.value = detailRes.data.taskId;
checkPointId.value = detailRes.data.checkPointId;
}
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/Inspection.vue:239", "获取任务信息失败:", error);
}
};
common_vendor.onLoad((options) => {
if (options.id) {
fetchTaskInfo(options.id);
}
});
const formData = common_vendor.reactive({
title: "",
// 隐患标题
level: 0,
// 隐患等级索引
description: "",
// 隐患描述
tagIndex: 0,
// 隐患标签索引
source: ""
// 隐患来源
});
common_vendor.ref(0);
const lng = common_vendor.ref(0);
const lat = common_vendor.ref(0);
const selectedAddress = common_vendor.ref("");
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/hiddendanger/Inspection.vue:283", "获取区域列表失败:", error);
}
};
fetchAreaList();
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 chooseLocation = () => {
common_vendor.index.__f__("log", "at pages/hiddendanger/Inspection.vue:299", "chooseLocation called");
showAddPopup.value = false;
setTimeout(() => {
common_vendor.index.getLocation({
type: "gcj02",
// 使用国测局坐标系(腾讯地图使用)
success: (locationRes) => {
common_vendor.index.__f__("log", "at pages/hiddendanger/Inspection.vue:308", "获取当前位置成功:", locationRes);
common_vendor.index.chooseLocation({
latitude: locationRes.latitude,
longitude: locationRes.longitude,
success: (res) => {
common_vendor.index.__f__("log", "at pages/hiddendanger/Inspection.vue:314", "选择位置成功:", res);
selectedAddress.value = res.address + (res.name ? `(${res.name})` : "");
lng.value = res.longitude;
lat.value = res.latitude;
showAddPopup.value = true;
},
fail: (err) => {
common_vendor.index.__f__("error", "at pages/hiddendanger/Inspection.vue:323", "选择位置失败:", err);
showAddPopup.value = true;
if (err.errMsg && err.errMsg.indexOf("cancel") === -1) {
common_vendor.index.showToast({
title: "选择位置失败",
icon: "none"
});
}
}
});
},
fail: (err) => {
common_vendor.index.__f__("error", "at pages/hiddendanger/Inspection.vue:337", "获取当前位置失败:", err);
common_vendor.index.chooseLocation({
success: (res) => {
common_vendor.index.__f__("log", "at pages/hiddendanger/Inspection.vue:341", "选择位置成功:", res);
selectedAddress.value = res.address + (res.name ? `(${res.name})` : "");
lng.value = res.longitude;
lat.value = res.latitude;
showAddPopup.value = true;
},
fail: (chooseErr) => {
common_vendor.index.__f__("error", "at pages/hiddendanger/Inspection.vue:348", "选择位置失败:", chooseErr);
showAddPopup.value = true;
if (chooseErr.errMsg && chooseErr.errMsg.indexOf("cancel") === -1) {
common_vendor.index.showToast({
title: "选择位置失败",
icon: "none"
});
}
}
});
}
});
}, 300);
};
const handleAdd = async () => {
var _a;
if (!formData.title) {
common_vendor.index.showToast({
title: "请输入隐患标题",
icon: "none"
});
return;
}
if (fileList1.value.length === 0) {
common_vendor.index.showToast({
title: "请上传隐患图片/视频",
icon: "none"
});
return;
}
const attachments = fileList1.value.map((file) => {
const path = file.serverPath || "";
const fileName = path ? path.split("/").pop() : file.name || "";
return {
fileName: fileName || "",
filePath: path,
fileType: file.type || "image/png",
fileSize: file.size || 0
};
});
const selectedTag = tagOptions.value[formData.tagIndex];
const tagId = selectedTag ? selectedTag.id : null;
common_vendor.index.__f__("log", "at pages/hiddendanger/Inspection.vue:395", "innnn", sourceOptions);
const params = {
title: formData.title,
//标题
level: formData.level + 1,
// 1.轻微隐患 2.一般隐患 3.重大隐患
lng: lng.value || 0,
//经度
lat: lat.value || 0,
//纬度
address: selectedAddress.value || "",
//详细地址
areaId: selectedAreaId.value || null,
//隐患区域ID
description: formData.description || "",
//隐患描述
tagId,
//隐患标签ID
taskId: taskId.value,
//关联任务ID
checkPointId: checkPointId.value,
//关联检查点ID
source: ((_a = sourceOptions.value[formData.source]) == null ? void 0 : _a.title) || "",
//隐患来源(随手拍、企业自查、行业互查、专家诊查)
attachments
//附件列表(图片/视频)
};
common_vendor.index.__f__("log", "at pages/hiddendanger/Inspection.vue:413", "提交的参数:", params);
try {
const res = await request_api.addHiddenDanger(params);
if (res.code === 0) {
common_vendor.index.showToast({
title: "新增成功",
icon: "success"
});
showAddPopup.value = false;
formData.title = "";
formData.level = 0;
formData.description = "";
formData.tagIndex = 0;
selectedAddress.value = "";
selectedAreaId.value = "";
selectedAreaName.value = "";
fileList1.value = [];
fetchHiddenDangerList();
} else {
common_vendor.index.showToast({
title: res.msg || "新增失败",
icon: "none"
});
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/Inspection.vue:441", error);
common_vendor.index.showToast({
title: "请求失败",
icon: "none"
});
}
};
const hiddenDangerList = common_vendor.ref([]);
const fetchHiddenDangerList = async () => {
try {
const res = await request_api.getMyHiddenDangerList();
if (res.code === 0) {
hiddenDangerList.value = res.data.records;
} else {
common_vendor.index.showToast({
title: res.msg || "获取隐患列表失败",
icon: "none"
});
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/Inspection.vue:462", error);
common_vendor.index.showToast({
title: "请求失败",
icon: "none"
});
}
};
common_vendor.onShow(() => {
fetchHiddenDangerList();
});
const details = (item) => {
common_vendor.index.navigateTo({
url: `/pages/hiddendanger/view?hazardId=${item.hazardId}&assignId=${item.assignId}`
});
};
const Rectification = (item) => {
common_vendor.index.navigateTo({
url: `/pages/hiddendanger/rectification?hazardId=${item.hazardId}&assignId=${item.assignId}`
});
};
const editRectification = (item) => {
common_vendor.index.navigateTo({
url: `/pages/hiddendanger/rectification?rectifyId=${item.rectifyId}&isEdit=1`
});
};
const acceptance = (item) => {
common_vendor.index.navigateTo({
url: `/pages/hiddendanger/acceptance?hazardId=${item.hazardId}&assignId=${item.assignId}&rectifyId=${item.rectifyId}`
});
};
const assignHazard = (item) => {
common_vendor.index.navigateTo({
url: `/pages/hiddendanger/assignment?hazardId=${item.hazardId}&assignId=${item.assignId}`
});
};
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++) {
const result = await uploadFilePromise(lists[i].url);
let item = fileList1.value[fileListLen];
const serverPath = typeof result === "string" ? result : (result == null ? void 0 : result.url) || (result == null ? void 0 : result.path) || "";
fileList1.value.splice(fileListLen, 1, {
...item,
status: "success",
message: "",
// url: baseUrl + serverPath,
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/hiddendanger/Inspection.vue:558", "上传失败:", err);
reject(err);
}
});
});
};
const aiAnalyzing = common_vendor.ref(false);
const handleAiAnalyze = async () => {
const imageFiles = fileList1.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/hiddendanger/Inspection.vue:580", "开始调用AI分析接口图片地址:", fullImageUrl);
const analyzeRes = await request_api.analyzeHazardImage({
// imageUrl: 'https://yx.zhihuixiangxi.com:58880/1.png' ,
imageUrl: fullImageUrl
});
if (analyzeRes.code === 0 && analyzeRes.data) {
const aiData = analyzeRes.data;
common_vendor.index.__f__("log", "at pages/hiddendanger/Inspection.vue:588", "AI分析结果:", aiData);
if (aiData.title)
formData.title = aiData.title;
if (aiData.description)
formData.description = aiData.description;
if (aiData.level) {
const levelMap = { "轻微": 0, "轻微隐患": 0, "一般": 1, "一般隐患": 1, "重大": 2, "重大隐患": 2 };
const levelIndex = levelMap[aiData.level];
if (levelIndex !== void 0) {
formData.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/hiddendanger/Inspection.vue:611", "AI分析接口调用失败:", error);
common_vendor.index.showToast({ title: "AI分析失败请重试", icon: "none" });
} finally {
aiAnalyzing.value = false;
}
};
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
}));
} else {
common_vendor.index.showToast({
title: res.msg || "获取标签列表失败",
icon: "none"
});
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/Inspection.vue:634", error);
common_vendor.index.showToast({
title: "请求失败",
icon: "none"
});
}
};
fetchTagOptions();
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: "专家诊查"
}
]);
common_vendor.watch(() => formData.source, (newVal) => {
const selected = sourceOptions.value[newVal];
common_vendor.index.__f__("log", "at pages/hiddendanger/Inspection.vue:680", "隐患来源选择结果:", {
索引: newVal,
选中项: selected,
id: selected == null ? void 0 : selected.id,
title: selected == null ? void 0 : selected.title
});
});
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.f(hiddenDangerList.value, (item, k0, i0) => {
return common_vendor.e({
a: common_vendor.t(item.title),
b: common_vendor.t(item.statusName),
c: common_vendor.t(item.levelName),
d: item.levelName === "轻微隐患" ? 1 : "",
e: item.levelName === "一般隐患" ? 1 : "",
f: item.levelName === "重大隐患" ? 1 : "",
g: common_vendor.t(item.address),
h: common_vendor.t(item.createdAt),
i: common_vendor.o(($event) => details(item), item.hazardId),
j: item.statusName === "待整改" && item.canEdit
}, item.statusName === "待整改" && item.canEdit ? {
k: common_vendor.o(($event) => assignHazard(item), item.hazardId)
} : {}, {
l: item.statusName === "待整改" && item.canEdit
}, item.statusName === "待整改" && item.canEdit ? {
m: common_vendor.o(($event) => Rectification(item), item.hazardId)
} : {}, {
n: item.statusName === "待验收" && item.canEdit
}, item.statusName === "待验收" && item.canEdit ? {
o: common_vendor.o(($event) => editRectification(item), item.hazardId)
} : {}, {
p: item.statusName === "待验收" && canAcceptance.value
}, item.statusName === "待验收" && canAcceptance.value ? {
q: common_vendor.o(($event) => acceptance(item), item.hazardId)
} : {}, {
r: item.statusName === "待交办"
}, item.statusName === "待交办" ? {
s: common_vendor.o(($event) => assignHazard(item), item.hazardId)
} : {}, {
t: item.hazardId
});
}),
b: common_vendor.o(($event) => showAddPopup.value = true),
c: common_vendor.o(($event) => showAddPopup.value = false),
d: common_vendor.o(afterRead),
e: common_vendor.o(deletePic),
f: common_vendor.p({
fileList: fileList1.value,
name: "1",
multiple: true,
maxCount: 10
}),
g: !aiAnalyzing.value
}, !aiAnalyzing.value ? {} : {}, {
h: common_vendor.t(aiAnalyzing.value ? "AI识别中..." : "AI 识别隐患"),
i: aiAnalyzing.value,
j: aiAnalyzing.value,
k: common_vendor.o(handleAiAnalyze),
l: common_vendor.o(($event) => formData.title = $event),
m: common_vendor.p({
placeholder: "请输入内容",
border: "surround",
modelValue: formData.title
}),
n: common_vendor.sr(levelChooseRef, "b44c631d-3,b44c631d-0", {
"k": "levelChooseRef"
}),
o: common_vendor.o(($event) => formData.level = $event),
p: common_vendor.p({
options: levelOptions.value,
wrap: false,
["item-width"]: "183rpx",
["item-height"]: "72rpx",
modelValue: formData.level
}),
q: common_vendor.o(($event) => formData.source = $event),
r: common_vendor.p({
options: sourceOptions.value,
wrap: false,
["item-width"]: "183rpx",
["item-height"]: "72rpx",
modelValue: formData.source
}),
s: common_vendor.o(($event) => selectedAddress.value = $event),
t: common_vendor.p({
placeholder: "请输入地址",
border: "surround",
modelValue: selectedAddress.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) => formData.description = $event),
A: common_vendor.p({
placeholder: "请输入内容",
modelValue: formData.description
}),
B: common_vendor.o(($event) => formData.tagIndex = $event),
C: common_vendor.p({
options: tagOptions.value,
modelValue: formData.tagIndex
}),
D: common_vendor.o(($event) => showAddPopup.value = false),
E: common_vendor.o(handleAdd),
F: common_vendor.o(($event) => showAddPopup.value = false),
G: common_vendor.p({
show: showAddPopup.value,
mode: "center",
round: "20"
}),
H: common_vendor.o(($event) => showAreaPicker.value = false),
I: common_vendor.o(confirmAreaSelect),
J: 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)
});
}),
K: areaList.value.length === 0
}, areaList.value.length === 0 ? {} : {}, {
L: common_vendor.o(($event) => showAreaPicker.value = false),
M: common_vendor.p({
show: showAreaPicker.value,
mode: "bottom",
round: "20"
}),
N: common_vendor.gei(_ctx, "")
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b44c631d"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/hiddendanger/Inspection.js.map