"use strict"; const common_vendor = require("../../common/vendor.js"); const modules_api_AppServer = require("../../modules/api/AppServer.js"); require("../../modules/Config.js"); const _sfc_main = { data() { return { activeTab: "all", loading: false, notificationList: [], unreadCount: { all: 0, system: 0, activity: 0, service: 0 }, pagination: { page: 1, limit: 10, total: 0 }, hasMore: true }; }, onLoad() { this.fetchUnreadCount(); this.fetchNotifications(); }, methods: { back() { common_vendor.index.navigateBack({ delta: 1 }); }, switchTab(tab) { if (this.activeTab === tab) return; this.activeTab = tab; this.pagination.page = 1; this.notificationList = []; this.hasMore = true; this.fetchNotifications(); }, async fetchUnreadCount() { try { const appserver = new modules_api_AppServer.AppServer(); const res = await appserver.GetNotificationUnreadCount(); if (res.code === 0 && res.data) { this.unreadCount = res.data; } } catch (e) { console.error("获取未读数量失败:", e); } }, async fetchNotifications() { var _a; if (this.loading) return; this.loading = true; try { const appserver = new modules_api_AppServer.AppServer(); const params = { page: this.pagination.page, limit: this.pagination.limit }; if (this.activeTab !== "all") { params.type = this.activeTab; } const res = await appserver.GetNotifications(params); if (res.code === 0) { const newList = res.data || []; if (this.pagination.page === 1) { this.notificationList = newList; } else { this.notificationList = [...this.notificationList, ...newList]; } this.pagination.total = ((_a = res.pagination) == null ? void 0 : _a.total) || 0; this.hasMore = newList.length >= this.pagination.limit; } } catch (e) { console.error("获取通知列表失败:", e); } finally { this.loading = false; } }, loadMore() { if (!this.hasMore || this.loading) return; this.pagination.page++; this.fetchNotifications(); }, async readNotification(item) { if (item.isRead) return; try { const appserver = new modules_api_AppServer.AppServer(); await appserver.MarkNotificationAsRead(item.id); item.isRead = true; this.unreadCount.all = Math.max(0, this.unreadCount.all - 1); this.unreadCount[item.type] = Math.max(0, this.unreadCount[item.type] - 1); } catch (e) { console.error("标记已读失败:", e); } }, async markAllRead() { if (this.unreadCount.all === 0) { common_vendor.index.showToast({ title: this.$t("notification.allRead") || "已全部已读", icon: "none" }); return; } try { const appserver = new modules_api_AppServer.AppServer(); await appserver.MarkAllNotificationsAsRead(); this.notificationList.forEach((item) => { item.isRead = true; }); this.unreadCount = { all: 0, system: 0, activity: 0, service: 0 }; common_vendor.index.showToast({ title: this.$t("common.success"), icon: "success" }); } catch (e) { console.error("标记全部已读失败:", e); common_vendor.index.showToast({ title: this.$t("common.failed") || "操作失败", icon: "none" }); } }, formatTime(timestamp) { if (!timestamp) return ""; const now = Date.now(); const time = new Date(timestamp).getTime(); const diff = now - time; const minutes = Math.floor(diff / (1e3 * 60)); const hours = Math.floor(diff / (1e3 * 60 * 60)); const days = Math.floor(diff / (1e3 * 60 * 60 * 24)); if (minutes < 1) return this.$t("notification.justNow") || "刚刚"; if (minutes < 60) return (this.$t("notification.minutesAgo") || "{n}分钟前").replace("{n}", minutes); if (hours < 24) return (this.$t("notification.hoursAgo") || "{n}小时前").replace("{n}", hours); return (this.$t("notification.daysAgo") || "{n}天前").replace("{n}", days); } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: common_vendor.o((...args) => $options.back && $options.back(...args)), b: common_vendor.t(_ctx.$t("me.notification")), c: common_vendor.t(_ctx.$t("notification.markAllRead")), d: common_vendor.o((...args) => $options.markAllRead && $options.markAllRead(...args)), e: common_vendor.t(_ctx.$t("notification.all")), f: $data.activeTab === "all" ? 1 : "", g: $data.unreadCount.all > 0 }, $data.unreadCount.all > 0 ? { h: common_vendor.t($data.unreadCount.all) } : {}, { i: $data.activeTab === "all" ? 1 : "", j: common_vendor.o(($event) => $options.switchTab("all")), k: common_vendor.t(_ctx.$t("notification.system")), l: $data.activeTab === "system" ? 1 : "", m: $data.unreadCount.system > 0 }, $data.unreadCount.system > 0 ? { n: common_vendor.t($data.unreadCount.system) } : {}, { o: $data.activeTab === "system" ? 1 : "", p: common_vendor.o(($event) => $options.switchTab("system")), q: common_vendor.t(_ctx.$t("notification.activity")), r: $data.activeTab === "activity" ? 1 : "", s: $data.unreadCount.activity > 0 }, $data.unreadCount.activity > 0 ? { t: common_vendor.t($data.unreadCount.activity) } : {}, { v: $data.activeTab === "activity" ? 1 : "", w: common_vendor.o(($event) => $options.switchTab("activity")), x: common_vendor.t(_ctx.$t("notification.service")), y: $data.activeTab === "service" ? 1 : "", z: $data.unreadCount.service > 0 }, $data.unreadCount.service > 0 ? { A: common_vendor.t($data.unreadCount.service) } : {}, { B: $data.activeTab === "service" ? 1 : "", C: common_vendor.o(($event) => $options.switchTab("service")), D: common_vendor.f($data.notificationList, (item, k0, i0) => { return common_vendor.e({ a: common_vendor.t(item.title), b: !item.isRead }, !item.isRead ? {} : {}, { c: common_vendor.t(item.content), d: common_vendor.t($options.formatTime(item.createdAt)), e: !item.isRead ? 1 : "", f: item.id, g: common_vendor.o(($event) => $options.readNotification(item), item.id) }); }), E: $data.loading }, $data.loading ? { F: common_vendor.t(_ctx.$t("common.loading")) } : {}, { G: !$data.loading && !$data.hasMore && $data.notificationList.length > 0 }, !$data.loading && !$data.hasMore && $data.notificationList.length > 0 ? { H: common_vendor.t(_ctx.$t("common.noMore") || "没有更多了") } : {}, { I: $data.notificationList.length === 0 && !$data.loading }, $data.notificationList.length === 0 && !$data.loading ? { J: common_vendor.t(_ctx.$t("notification.noNotification")) } : {}, { K: common_vendor.o((...args) => $options.loadMore && $options.loadMore(...args)) }); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "F:/gitCode/uniapp/appointment_system/miniprogram/src/pages/me/notification-page.vue"]]); wx.createPage(MiniProgramPage);