"use strict"; const common_vendor = require("../../common/vendor.js"); const common_assets = require("../../common/assets.js"); const store_message = require("../../store/message.js"); const api_message = require("../../api/message.js"); if (!Math) { CustomTabbar(); } const CustomTabbar = () => "../../components/custom-tabbar/custom-tabbar.js"; const _sfc_main = { __name: "message", setup(__props) { const activeTab = common_vendor.ref("all"); const filterTabs = [ { name: "全部", key: "all" }, { name: "未读", key: "unread" }, { name: "已读", key: "read" } ]; const messages = common_vendor.ref([]); const loading = common_vendor.ref(false); const fetchMessages = async () => { loading.value = true; try { const res = await api_message.getMessageList(); if (res.code === 200) { let list = []; if (Array.isArray(res.data)) { list = res.data; } else if (res.rows) { list = res.rows; } else if (res.data && res.data.list) { list = res.data.list; } messages.value = list.map((item) => ({ id: item.id, title: item.title || "系统通知", position: item.positionName || "系统消息", company: item.companyName || "审计之家", status: item.status, desc: item.content, time: item.createTime ? item.createTime.substring(5, 16) : "", unread: item.isRead === 0 })); updateGlobalUnread(); } } catch (e) { common_vendor.index.__f__("error", "at pages/message/message.vue:113", "获取消息列表失败", e); } finally { loading.value = false; } }; const updateGlobalUnread = () => { const count = messages.value.filter((m) => m.unread).length; store_message.messageStore.setUnreadCount(count); }; common_vendor.onMounted(() => { fetchMessages(); }); common_vendor.onShow(() => { fetchMessages(); }); common_vendor.onPullDownRefresh(async () => { await fetchMessages(); common_vendor.index.stopPullDownRefresh(); }); const onTabChange = (key) => { activeTab.value = key; }; const getCount = (key) => { if (key === "unread") return store_message.messageStore.unreadCount; if (key === "all") return messages.value.length; if (key === "read") return messages.value.filter((m) => !m.unread).length; return 0; }; const filteredMessages = common_vendor.computed(() => { if (activeTab.value === "unread") return messages.value.filter((m) => m.unread); if (activeTab.value === "read") return messages.value.filter((m) => !m.unread); return messages.value; }); const markAllAsRead = async () => { try { const res = await api_message.readAllMessages(); if (res.code === 200) { messages.value.forEach((m) => m.unread = false); updateGlobalUnread(); common_vendor.index.showToast({ title: "已全部设为已读", icon: "none" }); } } catch (e) { common_vendor.index.__f__("error", "at pages/message/message.vue:167", "标记已读失败", e); } }; const goToDetail = async (msg) => { if (msg.unread) { try { await api_message.readMessage(msg.id); msg.unread = false; store_message.messageStore.setUnreadCount(Math.max(0, store_message.messageStore.unreadCount - 1)); } catch (e) { common_vendor.index.__f__("error", "at pages/message/message.vue:179", "标记单条已读失败", e); } } common_vendor.index.navigateTo({ url: `/pages/message/msgdetail?data=${encodeURIComponent(JSON.stringify(msg))}` }); }; return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.f(filterTabs, (tab, k0, i0) => { return common_vendor.e({ a: common_vendor.t(tab.name), b: getCount(tab.key) > 0 }, getCount(tab.key) > 0 ? { c: common_vendor.t(getCount(tab.key)) } : {}, { d: tab.key, e: common_vendor.n(activeTab.value === tab.key ? "active" : ""), f: common_vendor.o(($event) => onTabChange(tab.key), tab.key) }); }), b: common_vendor.unref(store_message.messageStore).unreadCount > 0 }, common_vendor.unref(store_message.messageStore).unreadCount > 0 ? { c: common_vendor.o(markAllAsRead) } : {}, { d: common_vendor.f(filteredMessages.value, (msg, index, i0) => { return common_vendor.e({ a: common_vendor.t(msg.title), b: msg.unread }, msg.unread ? {} : { c: common_vendor.t(msg.time) }, { d: common_vendor.t(msg.position), e: common_vendor.t(msg.company), f: msg.unread }, msg.unread ? { g: common_vendor.t(msg.time) } : {}, { h: index, i: common_vendor.o(($event) => goToDetail(msg), index) }); }), e: common_assets._imports_8, f: filteredMessages.value.length === 0 }, filteredMessages.value.length === 0 ? {} : {}, { g: common_vendor.p({ activeIndex: 2 }) }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4c1b26cf"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/message/message.js.map