"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_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 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) { console.error("获取任务信息失败:", error); } }; common_vendor.onLoad((options) => { if (options.id) { fetchTaskInfo(options.id); } }); const formData = common_vendor.reactive({ title: "", // 隐患标题 level: 0, // 隐患等级索引 description: "", // 隐患描述 tagIndex: 0, // 隐患标签索引 source: "" // 隐患来源 }); const lng = common_vendor.ref(0); const lat = common_vendor.ref(0); const selectedAddress = common_vendor.ref(""); const chooseLocation = () => { console.log("chooseLocation called"); showAddPopup.value = false; setTimeout(() => { common_vendor.index.chooseLocation({ success: (res) => { console.log("选择位置成功:", res); selectedAddress.value = res.address + (res.name ? `(${res.name})` : ""); lng.value = res.longitude; lat.value = res.latitude; showAddPopup.value = true; }, fail: (err) => { console.error("选择位置失败:", err); showAddPopup.value = true; if (err.errMsg && err.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; } 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 selectedTag = tagOptions.value[formData.tagIndex]; const tagId = selectedTag ? selectedTag.id : null; console.log("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 || "", //详细地址 description: formData.description || "", //隐患描述 tagId, //隐患标签ID taskId: taskId.value, //关联任务ID checkPointId: checkPointId.value, //关联检查点ID source: ((_a = sourceOptions.value[formData.source]) == null ? void 0 : _a.title) || "" //隐患来源(随手拍、企业自查、行业互查、专家诊查) }; 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 = ""; fileList1.value = []; fetchHiddenDangerList(); } else { common_vendor.index.showToast({ title: res.msg || "新增失败", icon: "none" }); } } catch (error) { console.error(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) { console.error(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 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]; 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); } }); }); }; 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) { console.error(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]; console.log("隐患来源选择结果:", { 索引: newVal, 选中项: selected, id: selected == null ? void 0 : selected.id, title: selected == null ? void 0 : selected.title }); }); return (_ctx, _cache) => { return { 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.statusName === "待验收" }, item.statusName === "待整改" || item.statusName === "待验收" ? { k: common_vendor.o(($event) => Rectification(item), item.hazardId) } : {}, { l: item.statusName === "待验收" }, item.statusName === "待验收" ? { m: common_vendor.o(($event) => acceptance(item), item.hazardId) } : {}, { n: item.statusName === "待交办" }, item.statusName === "待交办" ? { o: common_vendor.o(($event) => assignHazard(item), item.hazardId) } : {}, { p: 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: common_vendor.o(($event) => formData.title = $event), h: common_vendor.p({ placeholder: "请输入内容", border: "surround", modelValue: formData.title }), i: common_vendor.o(($event) => formData.level = $event), j: common_vendor.p({ options: levelOptions.value, wrap: false, ["item-width"]: "183rpx", ["item-height"]: "72rpx", modelValue: formData.level }), k: common_vendor.o(($event) => formData.source = $event), l: common_vendor.p({ options: sourceOptions.value, wrap: false, ["item-width"]: "183rpx", ["item-height"]: "72rpx", modelValue: formData.source }), m: common_vendor.t(selectedAddress.value || "请选择地址"), n: common_vendor.n(selectedAddress.value ? "" : "text-gray"), o: common_vendor.o(chooseLocation), p: common_vendor.o(chooseLocation), q: common_vendor.o(($event) => formData.description = $event), r: common_vendor.p({ placeholder: "请输入内容", modelValue: formData.description }), s: common_vendor.o(($event) => formData.tagIndex = $event), t: common_vendor.p({ options: tagOptions.value, modelValue: formData.tagIndex }), v: common_vendor.o(($event) => showAddPopup.value = false), w: common_vendor.o(handleAdd), x: common_vendor.o(($event) => showAddPopup.value = false), y: common_vendor.p({ show: showAddPopup.value, mode: "center", round: "20" }) }; }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b44c631d"]]); wx.createPage(MiniProgramPage);