"use strict"; const common_vendor = require("../../common/vendor.js"); const common_assets = require("../../common/assets.js"); const request_api = require("../../request/api.js"); const request_three_one_api_info = require("../../request/three_one_api/info.js"); const request_request = require("../../request/request.js"); const utils_userInfo = require("../../utils/userInfo.js"); const utils_hazardNav = require("../../utils/hazardNav.js"); if (!Array) { const _easycom_u_navbar2 = common_vendor.resolveComponent("u-navbar"); const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon"); const _easycom_u_loadmore2 = common_vendor.resolveComponent("u-loadmore"); (_easycom_u_navbar2 + _easycom_u_icon2 + _easycom_u_loadmore2)(); } const _easycom_u_navbar = () => "../../uni_modules/uview-plus/components/u-navbar/u-navbar.js"; const _easycom_u_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js"; const _easycom_u_loadmore = () => "../../uni_modules/uview-plus/components/u-loadmore/u-loadmore.js"; if (!Math) { (_easycom_u_navbar + _easycom_u_icon + _easycom_u_loadmore)(); } const defaultAvatar = "/static/my/default_avater.png"; const PLAN_INITIAL_SIZE = 4; const HAZARD_PAGE_SIZE = 10; const _sfc_main = { __name: "index", setup(__props) { const loading = common_vendor.ref(true); const userInfo = common_vendor.reactive({ userId: "", username: "", nickName: "", deptId: "", deptName: "", role: "", avatar: "", phone: "", identityName: "", userIdentity: null }); const currentRoleKey = common_vendor.computed(() => utils_userInfo.resolveUserIdentityRoleKey(userInfo)); const isApprovalRole = common_vendor.computed(() => currentRoleKey.value === "approval"); const displayIdentityName = common_vendor.computed(() => { return utils_userInfo.resolveIdentityName(userInfo, userInfo.userIdentity); }); const loadUserInfoFromStorage = () => { try { const storedUserInfo = common_vendor.index.getStorageSync("userInfo"); if (storedUserInfo) { utils_userInfo.applyStoredUserInfo(userInfo, JSON.parse(storedUserInfo)); } } catch (storageError) { common_vendor.index.__f__("error", "at pages/index/index.vue:318", "从本地存储获取用户信息失败:", storageError); } }; const getImageUrl = (path) => { if (!path) return ""; return request_request.toImageUrl(path); }; const getUserInfo = async () => { try { const res = await request_three_one_api_info.getProfileDetail(); if (res.code === 0 && res.data) { utils_userInfo.applyProfileToUserInfo(userInfo, res.data); } } catch (e) { common_vendor.index.__f__("error", "at pages/index/index.vue:336", "获取用户信息失败:", e); loadUserInfoFromStorage(); } }; const allMenuList = [ { name: "成员管理", src: "/static/home_icon/chengyuangaunli.png" }, { name: "信息填报", src: "/static/home_icon/xinxitianbao.png" }, { name: "区域设置", src: "/static/home_icon/quyushezhi.png" }, { name: "检查清单", src: "/static/home_icon/jiachaqingdan.png" }, // { // name: '检查记录', // src: '/static/home_icon/jianchajilu.png' // }, { name: "证件管理", src: "/static/home_icon/zhengjianguanli.png" }, { name: "隐患排查", src: "/static/home_icon/yinhuanpaicha.png" }, { name: "隐患销号", src: "/static/home_icon/yinhuanxiaohao.png" } ]; const commonMenuNames = ["隐患排查", "隐患销号"]; const infoList = common_vendor.computed(() => { if (currentRoleKey.value === "approval") { return allMenuList.filter((item) => item.name === "隐患排查"); } if (currentRoleKey.value === "common") { return allMenuList.filter((item) => commonMenuNames.includes(item.name)); } return allMenuList; }); const formatProgress = (progress) => { const num = Number(progress); if (Number.isNaN(num)) return 0; return Math.min(100, Math.max(0, num)); }; const getTodayDateStr = () => { const date = /* @__PURE__ */ new Date(); const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, "0"); const d = String(date.getDate()).padStart(2, "0"); return `${y}-${m}-${d}`; }; const goTodayInspect = (item) => { const oneTableId = item.id; const taskDate = getTodayDateStr(); const tableId = item.tableId ?? item.id; if (!oneTableId || !taskDate) { common_vendor.index.showToast({ title: "缺少任务参数", icon: "none" }); return; } const name = item.name || ""; const tableIdQuery = tableId ? `&tableId=${tableId}` : ""; common_vendor.index.navigateTo({ url: `/pages/Inspectionresult/detail?oneTableId=${oneTableId}&taskDate=${encodeURIComponent(taskDate)}&name=${encodeURIComponent(name)}${tableIdQuery}` }); }; const goPlanCheckList = (item) => { const tableId = item.tableId ?? item.id; if (!tableId) { common_vendor.index.showToast({ title: "缺少检查表ID", icon: "none" }); return; } common_vendor.index.navigateTo({ url: `/pages/Inspectionresult/list?tableId=${tableId}&name=${encodeURIComponent(item.name || "")}` }); }; const handleMenuClick = (item) => { const menuRoutes = { "成员管理": "/pages/membermanagemen/membermanagemen", "信息填报": "/pages/corporateInformation/corporateInformation", "区域设置": "/pages/area/management", "检查清单": "/pages/checklist/checklist", "检查记录": "/pages/Inspectionlog/Inspectionlog", "证件管理": "/pages/Idphotomanagement/Idphotomanagement", "隐患排查": "/pages/hiddendanger/Inspection", "隐患销号": "/pages/closeout/application", "设备登记": "/pages/equipmentregistration/equipmentregistration" }; const url = menuRoutes[item.name]; if (url) { common_vendor.index.navigateTo({ url }); } else { common_vendor.index.showToast({ title: "功能开发中", icon: "none" }); } }; const checkPlanParams = common_vendor.ref({ pageNum: 1, pageSize: PLAN_INITIAL_SIZE, name: "" }); const checkPlanData = common_vendor.ref([]); const checkPlanTotal = common_vendor.ref(0); const planShowAll = common_vendor.ref(false); const expandedPlanMap = common_vendor.ref({}); const hasMoreCheckPlans = common_vendor.computed(() => { return !planShowAll.value && checkPlanTotal.value > PLAN_INITIAL_SIZE; }); const initPlanExpandedState = (records = [], { reset = false, expandFirst = false } = {}) => { const map = reset ? {} : { ...expandedPlanMap.value }; records.forEach((item, index) => { if (reset) { map[item.id] = expandFirst && index === 0; } else if (!(item.id in map)) { map[item.id] = false; } }); expandedPlanMap.value = map; }; const isPlanExpanded = (id) => !!expandedPlanMap.value[id]; const togglePlanExpand = (id) => { expandedPlanMap.value = { ...expandedPlanMap.value, [id]: !expandedPlanMap.value[id] }; }; const getCheckPlanLists = async () => { var _a, _b; planShowAll.value = false; try { const res = await request_api.getCheckPlanList({ pageNum: 1, pageSize: PLAN_INITIAL_SIZE, name: checkPlanParams.value.name }); if (res.code === 0) { const records = ((_a = res.data) == null ? void 0 : _a.records) || []; checkPlanTotal.value = Number(((_b = res.data) == null ? void 0 : _b.total) ?? records.length); checkPlanData.value = records; initPlanExpandedState(records, { reset: true, expandFirst: true }); } } catch (error) { common_vendor.index.__f__("error", "at pages/index/index.vue:509", error); } finally { loading.value = false; } }; const loadMoreCheckPlans = async () => { var _a; if (!hasMoreCheckPlans.value) return; try { const res = await request_api.getCheckPlanList({ pageNum: 1, pageSize: checkPlanTotal.value, name: checkPlanParams.value.name }); if (res.code === 0) { const records = ((_a = res.data) == null ? void 0 : _a.records) || []; initPlanExpandedState(records); checkPlanData.value = records; planShowAll.value = true; } else { common_vendor.index.showToast({ title: res.msg || "加载失败", icon: "none" }); } } catch (error) { common_vendor.index.__f__("error", "at pages/index/index.vue:532", error); common_vendor.index.showToast({ title: "加载失败", icon: "none" }); } }; const formatDate = (dateStr) => { if (!dateStr) return ""; return dateStr.split(" ")[0]; }; common_vendor.onShow(() => { loadUserInfoFromStorage(); getUserInfo().then(() => { if (isApprovalRole.value) { fetchWorkbenchList(); } else { getCheckPlanLists(); resetHiddenDangerList(); fetchHiddenDangerList(); } }); }); const hiddenDangerPageNum = common_vendor.ref(1); const hiddenDangerLoading = common_vendor.ref(false); const hiddenDangerLoadStatus = common_vendor.ref("loadmore"); const hiddenDangerData = common_vendor.ref([]); const dangerTabs = common_vendor.ref([ { label: "全部", value: null }, { label: "待交办", value: 1 }, { label: "待整改", value: 2 }, { label: "待验收", value: 3 }, { label: "待销号", value: 4 }, { label: "已完成", value: 5 } ]); const activeDangerTab = common_vendor.ref(0); const buildHiddenDangerListParams = () => { const params = { pageNum: hiddenDangerPageNum.value, pageSize: HAZARD_PAGE_SIZE }; const activeTab = dangerTabs.value[activeDangerTab.value]; if ((activeTab == null ? void 0 : activeTab.value) != null) { params.status = activeTab.value; } return params; }; const resetHiddenDangerList = () => { hiddenDangerPageNum.value = 1; hiddenDangerData.value = []; hiddenDangerLoadStatus.value = "loadmore"; }; const switchDangerTab = (index) => { if (activeDangerTab.value === index) return; activeDangerTab.value = index; resetHiddenDangerList(); fetchHiddenDangerList(); }; const fetchHiddenDangerList = async () => { var _a, _b; if (hiddenDangerLoading.value) return; if (hiddenDangerPageNum.value > 1 && hiddenDangerLoadStatus.value === "nomore") return; hiddenDangerLoading.value = true; if (hiddenDangerPageNum.value > 1) { hiddenDangerLoadStatus.value = "loading"; } try { const res = await request_api.getHiddenDangerList(buildHiddenDangerListParams()); if (res.code === 0) { const records = ((_a = res.data) == null ? void 0 : _a.records) || []; const total = Number(((_b = res.data) == null ? void 0 : _b.total) ?? 0); if (hiddenDangerPageNum.value === 1) { hiddenDangerData.value = records; } else { hiddenDangerData.value = [...hiddenDangerData.value, ...records]; } if (hiddenDangerData.value.length >= total || records.length < HAZARD_PAGE_SIZE) { hiddenDangerLoadStatus.value = "nomore"; } else { hiddenDangerLoadStatus.value = "loadmore"; } } else { if (hiddenDangerPageNum.value === 1) { hiddenDangerData.value = []; } hiddenDangerLoadStatus.value = "nomore"; } } catch (error) { common_vendor.index.__f__("error", "at pages/index/index.vue:635", error); if (hiddenDangerPageNum.value > 1) { hiddenDangerPageNum.value--; } hiddenDangerLoadStatus.value = "loadmore"; } finally { hiddenDangerLoading.value = false; loading.value = false; } }; const loadMoreHiddenDangerList = () => { if (hiddenDangerLoadStatus.value !== "loadmore" || hiddenDangerLoading.value) return; hiddenDangerPageNum.value++; fetchHiddenDangerList(); }; common_vendor.onLoad(() => { if (!isApprovalRole.value) { resetHiddenDangerList(); fetchHiddenDangerList(); } }); common_vendor.onReachBottom(() => { if (isApprovalRole.value) return; loadMoreHiddenDangerList(); }); const workbenchTabs = [ { label: "待办", value: "todo" }, { label: "已办", value: "done" } ]; const activeWorkbenchTab = common_vendor.ref(0); const workbenchList = common_vendor.ref([]); const workbenchLoading = common_vendor.ref(false); const normalizeWorkbenchItem = (item) => { if (!item) return {}; const hazard = item.hazard || item.hazardInfo || {}; return { ...item, hazardId: item.hazardId ?? hazard.hazardId ?? "", assignId: item.assignId ?? hazard.assignId ?? "", rectifyId: item.rectifyId ?? hazard.rectifyId ?? "", taskId: item.taskId ?? item.flowTaskId ?? item.currentTaskId ?? "", taskKey: item.taskKey ?? item.flowTaskKey ?? item.currentTaskKey ?? "", title: item.title ?? hazard.title ?? item.hazardTitle ?? "", address: item.address ?? hazard.address ?? "", source: item.source ?? hazard.source ?? item.hazardSourceName ?? "", statusName: item.statusName ?? hazard.statusName ?? item.hazardStatusName ?? hazard.hazardStatusName ?? item.taskName ?? "", hazardStatus: item.hazardStatus ?? hazard.hazardStatus ?? item.status ?? hazard.status ?? "", createdAt: item.discoveredAt ?? hazard.discoveredAt ?? "", levelName: item.levelName ?? hazard.levelName ?? "" }; }; const resolveWorkbenchRecords = (data) => { if (!data) return []; if (Array.isArray(data)) return data; if (Array.isArray(data.records)) return data.records; if (Array.isArray(data.list)) return data.list; return []; }; const getWorkbenchItemKey = (item) => { const taskId = item.taskId || item.flowTaskId || ""; const hazardId = item.hazardId || ""; if (taskId && hazardId) return `${taskId}-${hazardId}`; return taskId || hazardId || item.rectifyId || JSON.stringify(item); }; const switchWorkbenchTab = (index) => { if (activeWorkbenchTab.value === index) return; activeWorkbenchTab.value = index; fetchWorkbenchList(); }; const fetchWorkbenchList = async () => { workbenchLoading.value = true; try { const isTodo = activeWorkbenchTab.value === 0; const res = isTodo ? await request_api.getFlowTodoList() : await request_api.getFlowDoneList(); if (res.code === 0) { workbenchList.value = resolveWorkbenchRecords(res.data).map(normalizeWorkbenchItem); } else { workbenchList.value = []; common_vendor.index.showToast({ title: res.msg || "获取工作台数据失败", icon: "none" }); } } catch (error) { common_vendor.index.__f__("error", "at pages/index/index.vue:727", "获取工作台数据失败:", error); workbenchList.value = []; common_vendor.index.showToast({ title: "获取工作台数据失败", icon: "none" }); } finally { workbenchLoading.value = false; loading.value = false; } }; const goLeaderApproval = (item) => { const hazardStatus = Number(item.hazardStatus); const statusName = item.statusName || item.hazardStatusName || ""; if (hazardStatus === 4 || statusName === "待销号") { common_vendor.index.navigateTo({ url: utils_hazardNav.buildLeaderWriteoffApprovalUrl(item) }); return; } if (hazardStatus === 3 || statusName === "待验收") { common_vendor.index.navigateTo({ url: utils_hazardNav.buildAcceptanceApprovalUrl(item) }); return; } common_vendor.index.showToast({ title: "当前状态不支持领导审批", icon: "none" }); }; const viewHazardDetail = (item) => { common_vendor.index.navigateTo({ url: `/pages/hiddendanger/process-chain?hazardId=${item.hazardId}` }); }; const goRectification = (item) => { common_vendor.index.navigateTo({ url: utils_hazardNav.buildRectificationUrl(item) }); }; const editRectification = (item) => { common_vendor.index.navigateTo({ url: utils_hazardNav.buildEditRectificationUrl(item) }); }; const goAcceptance = (item) => { common_vendor.index.navigateTo({ url: utils_hazardNav.buildAcceptanceUrl(item) }); }; const assignHazard = (item) => { common_vendor.index.navigateTo({ url: utils_hazardNav.buildAssignmentUrl(item) }); }; const goWriteoffApply = (item) => { common_vendor.index.navigateTo({ url: utils_hazardNav.buildWriteoffApplyUrl(item) }); }; const goWriteoffApproval = (item) => { common_vendor.index.navigateTo({ url: utils_hazardNav.buildWriteoffApprovalUrl(item) }); }; const goSwitchIdentity = () => { common_vendor.index.navigateTo({ url: "/pages/personalcenter/identity" }); }; return (_ctx, _cache) => { return common_vendor.e({ a: common_assets._imports_0, b: common_vendor.p({ title: "湘西州“三个一”安全管理平台", placeholder: false, fixed: false, safeAreaInsetTop: true, bgColor: "transparent", titleColor: "#fff", border: false, leftIcon: "" }), c: getImageUrl(userInfo.avatar) || defaultAvatar, d: common_vendor.t(userInfo.deptName || "未知部门"), e: common_vendor.t(userInfo.phone || "未绑定"), f: displayIdentityName.value }, displayIdentityName.value ? { g: common_vendor.t(displayIdentityName.value) } : {}, { h: common_vendor.p({ name: "list", color: "#285CE9", size: "14" }), i: common_vendor.o(goSwitchIdentity), j: infoList.value.length > 0 }, infoList.value.length > 0 ? { k: common_vendor.f(infoList.value, (item, index, i0) => { return { a: item.src, b: common_vendor.t(item.name), c: index, d: common_vendor.o(($event) => handleMenuClick(item), index) }; }) } : {}, { l: !isApprovalRole.value }, !isApprovalRole.value ? common_vendor.e({ m: checkPlanData.value.length === 0 }, checkPlanData.value.length === 0 ? {} : {}, { n: common_vendor.f(checkPlanData.value, (item, k0, i0) => { return { a: common_vendor.t(item.name), b: "1cf27b2a-2-" + i0, c: common_vendor.p({ name: isPlanExpanded(item.id) ? "arrow-down" : "arrow-up", color: "#ffffff", size: "18" }), d: common_vendor.o(($event) => togglePlanExpand(item.id), item.id), e: common_vendor.o(($event) => togglePlanExpand(item.id), item.id), f: common_vendor.t(item.runModeName), g: common_vendor.t(item.cycle), h: common_vendor.t(formatDate(item.planStartTime)), i: common_vendor.t(formatDate(item.planEndTime)), j: formatProgress(item.progress) + "%", k: common_vendor.t(formatProgress(item.progress)), l: common_vendor.t(item.pendingCount ?? 0), m: common_vendor.t(item.waitCheckNum ?? 0), n: common_vendor.t(item.unusualNum ?? 0), o: common_vendor.t(item.finishedCount ?? 0), p: common_vendor.o(($event) => goTodayInspect(item), item.id), q: common_vendor.o(($event) => goPlanCheckList(item), item.id), r: isPlanExpanded(item.id), s: !isPlanExpanded(item.id) ? 1 : "", t: item.id }; }), o: hasMoreCheckPlans.value }, hasMoreCheckPlans.value ? { p: common_vendor.o(loadMoreCheckPlans) } : {}) : {}, { q: !isApprovalRole.value }, !isApprovalRole.value ? common_vendor.e({ r: common_vendor.f(dangerTabs.value, (tab, index, i0) => { return { a: common_vendor.t(tab.label), b: activeDangerTab.value === index ? 1 : "", c: index, d: common_vendor.o(($event) => switchDangerTab(index), index) }; }), s: hiddenDangerData.value.length === 0 && !hiddenDangerLoading.value }, hiddenDangerData.value.length === 0 && !hiddenDangerLoading.value ? {} : {}, { t: common_vendor.f(hiddenDangerData.value, (item, index, i0) => { return common_vendor.e({ a: common_vendor.t(item.title), b: common_vendor.t(item.levelName), c: item.levelName === "轻微隐患" ? 1 : "", d: item.levelName === "一般隐患" ? 1 : "", e: item.levelName === "重大隐患" ? 1 : "", f: common_vendor.t(item.address), g: common_vendor.t(item.source), h: common_vendor.t(item.statusName), i: common_vendor.t(item.createdAt), j: common_vendor.o(($event) => viewHazardDetail(item), item.hazardId), k: item.statusName === "待整改" && item.canEdit }, item.statusName === "待整改" && item.canEdit ? { l: common_vendor.o(($event) => assignHazard(item), item.hazardId) } : {}, { m: item.statusName === "待整改" && item.canEdit }, item.statusName === "待整改" && item.canEdit ? { n: common_vendor.o(($event) => goRectification(item), item.hazardId) } : {}, { o: item.statusName === "待验收" && item.canEdit }, item.statusName === "待验收" && item.canEdit ? { p: common_vendor.o(($event) => editRectification(item), item.hazardId) } : {}, { q: common_vendor.unref(utils_hazardNav.canShowAcceptanceButton)(item, currentRoleKey.value) }, common_vendor.unref(utils_hazardNav.canShowAcceptanceButton)(item, currentRoleKey.value) ? { r: common_vendor.o(($event) => goAcceptance(item), item.hazardId) } : {}, { s: item.statusName === "待交办" }, item.statusName === "待交办" ? { t: common_vendor.o(($event) => assignHazard(item), item.hazardId) } : {}, { v: common_vendor.unref(utils_hazardNav.canShowWriteoffApplyButton)(item) }, common_vendor.unref(utils_hazardNav.canShowWriteoffApplyButton)(item) ? { w: common_vendor.o(($event) => goWriteoffApply(item), item.hazardId) } : {}, { x: common_vendor.unref(utils_hazardNav.canShowWriteoffApprovalButton)(item, currentRoleKey.value) }, common_vendor.unref(utils_hazardNav.canShowWriteoffApprovalButton)(item, currentRoleKey.value) ? { y: common_vendor.o(($event) => goWriteoffApproval(item), item.hazardId) } : {}, { z: item.hazardId }); }), v: hiddenDangerData.value.length > 0 }, hiddenDangerData.value.length > 0 ? { w: common_vendor.p({ status: hiddenDangerLoadStatus.value }) } : {}) : {}, { x: isApprovalRole.value }, isApprovalRole.value ? common_vendor.e({ y: common_vendor.f(workbenchTabs, (tab, index, i0) => { return { a: common_vendor.t(tab.label), b: activeWorkbenchTab.value === index ? 1 : "", c: tab.value, d: common_vendor.o(($event) => switchWorkbenchTab(index), tab.value) }; }), z: workbenchLoading.value }, workbenchLoading.value ? {} : workbenchList.value.length === 0 ? {} : {}, { A: workbenchList.value.length === 0, B: common_vendor.f(workbenchList.value, (item, k0, i0) => { return common_vendor.e({ a: common_vendor.t(item.title), b: common_vendor.t(item.levelName), c: item.levelName === "轻微隐患" ? 1 : "", d: item.levelName === "一般隐患" ? 1 : "", e: item.levelName === "重大隐患" ? 1 : "", f: common_vendor.t(item.address), g: common_vendor.t(item.source), h: common_vendor.t(item.statusName), i: common_vendor.t(item.createdAt), j: common_vendor.o(($event) => viewHazardDetail(item), getWorkbenchItemKey(item)) }, activeWorkbenchTab.value === 0 ? { k: common_vendor.o(($event) => goLeaderApproval(item), getWorkbenchItemKey(item)) } : {}, { l: getWorkbenchItemKey(item) }); }), C: activeWorkbenchTab.value === 0 }) : {}, { D: common_vendor.gei(_ctx, "") }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map