appointment_system/miniprogram/dist/build/h5/assets/pages-me-notification-page.103e4603.js
2025-12-19 00:37:31 +08:00

2 lines
6.0 KiB
JavaScript

import{_ as t,l as a,m as i,o as e,c as s,w as o,i as n,e as c,f as l,t as d,A as r,B as f,b as u,d as h,F as m,g as y,h as v,T as b}from"./index-a09151d6.js";import{A as g}from"./AppServer.888fd24d.js";import{_}from"./ic_back.5440bd15.js";import{_ as p}from"./ic_notice.f2babaad.js";const k=t({data:()=>({activeTab:"all",loading:!1,notificationList:[],unreadCount:{all:0,system:0,activity:0,service:0},pagination:{page:1,limit:10,total:0},hasMore:!0}),onLoad(){this.fetchUnreadCount(),this.fetchNotifications()},methods:{back(){a({delta:1})},switchTab(t){this.activeTab!==t&&(this.activeTab=t,this.pagination.page=1,this.notificationList=[],this.hasMore=!0,this.fetchNotifications())},async fetchUnreadCount(){try{const t=new g,a=await t.GetNotificationUnreadCount();0===a.code&&a.data&&(this.unreadCount=a.data)}catch(t){console.error("获取未读数量失败:",t)}},async fetchNotifications(){var t;if(!this.loading){this.loading=!0;try{const a=new g,i={page:this.pagination.page,limit:this.pagination.limit};"all"!==this.activeTab&&(i.type=this.activeTab);const e=await a.GetNotifications(i);if(0===e.code){const a=e.data||[];1===this.pagination.page?this.notificationList=a:this.notificationList=[...this.notificationList,...a],this.pagination.total=(null==(t=e.pagination)?void 0:t.total)||0,this.hasMore=a.length>=this.pagination.limit}}catch(a){console.error("获取通知列表失败:",a)}finally{this.loading=!1}}},loadMore(){this.hasMore&&!this.loading&&(this.pagination.page++,this.fetchNotifications())},async readNotification(t){if(!t.isRead)try{const a=new g;await a.MarkNotificationAsRead(t.id),t.isRead=!0,this.unreadCount.all=Math.max(0,this.unreadCount.all-1),this.unreadCount[t.type]=Math.max(0,this.unreadCount[t.type]-1)}catch(a){console.error("标记已读失败:",a)}},async markAllRead(){if(0!==this.unreadCount.all)try{const t=new g;await t.MarkAllNotificationsAsRead(),this.notificationList.forEach(t=>{t.isRead=!0}),this.unreadCount={all:0,system:0,activity:0,service:0},i({title:this.$t("common.success"),icon:"success"})}catch(t){console.error("标记全部已读失败:",t),i({title:this.$t("common.failed")||"操作失败",icon:"none"})}else i({title:this.$t("notification.allRead")||"已全部已读",icon:"none"})},formatTime(t){if(!t)return"";const a=Date.now()-new Date(t).getTime(),i=Math.floor(a/6e4),e=Math.floor(a/36e5),s=Math.floor(a/864e5);return i<1?this.$t("notification.justNow")||"刚刚":i<60?(this.$t("notification.minutesAgo")||"{n}分钟前").replace("{n}",i):e<24?(this.$t("notification.hoursAgo")||"{n}小时前").replace("{n}",e):(this.$t("notification.daysAgo")||"{n}天前").replace("{n}",s)}}},[["render",function(t,a,i,g,k,C){const T=y,w=n,$=v,M=b;return e(),s(w,{class:"content"},{default:o(()=>[c(w,{class:"header-row"},{default:o(()=>[c(w,{class:"back-button",onClick:C.back},{default:o(()=>[c(T,{src:_,class:"back-icon"})]),_:1},8,["onClick"]),c($,{class:"title"},{default:o(()=>[l(d(t.$t("me.notification")),1)]),_:1}),c(w,{class:"mark-read-btn",onClick:C.markAllRead},{default:o(()=>[c($,{class:"mark-read-text"},{default:o(()=>[l(d(t.$t("notification.markAllRead")),1)]),_:1})]),_:1},8,["onClick"])]),_:1}),c(w,{class:"tab-container"},{default:o(()=>[c(w,{class:r(["tab-item",{active:"all"===k.activeTab}]),onClick:a[0]||(a[0]=t=>C.switchTab("all"))},{default:o(()=>[c($,{class:r(["tab-text",{active:"all"===k.activeTab}])},{default:o(()=>[l(d(t.$t("notification.all")),1)]),_:1},8,["class"]),k.unreadCount.all>0?(e(),s(w,{key:0,class:"badge"},{default:o(()=>[l(d(k.unreadCount.all),1)]),_:1})):f("",!0)]),_:1},8,["class"]),c(w,{class:r(["tab-item",{active:"system"===k.activeTab}]),onClick:a[1]||(a[1]=t=>C.switchTab("system"))},{default:o(()=>[c($,{class:r(["tab-text",{active:"system"===k.activeTab}])},{default:o(()=>[l(d(t.$t("notification.system")),1)]),_:1},8,["class"]),k.unreadCount.system>0?(e(),s(w,{key:0,class:"badge"},{default:o(()=>[l(d(k.unreadCount.system),1)]),_:1})):f("",!0)]),_:1},8,["class"]),c(w,{class:r(["tab-item",{active:"activity"===k.activeTab}]),onClick:a[2]||(a[2]=t=>C.switchTab("activity"))},{default:o(()=>[c($,{class:r(["tab-text",{active:"activity"===k.activeTab}])},{default:o(()=>[l(d(t.$t("notification.activity")),1)]),_:1},8,["class"]),k.unreadCount.activity>0?(e(),s(w,{key:0,class:"badge"},{default:o(()=>[l(d(k.unreadCount.activity),1)]),_:1})):f("",!0)]),_:1},8,["class"]),c(w,{class:r(["tab-item",{active:"service"===k.activeTab}]),onClick:a[3]||(a[3]=t=>C.switchTab("service"))},{default:o(()=>[c($,{class:r(["tab-text",{active:"service"===k.activeTab}])},{default:o(()=>[l(d(t.$t("notification.service")),1)]),_:1},8,["class"]),k.unreadCount.service>0?(e(),s(w,{key:0,class:"badge"},{default:o(()=>[l(d(k.unreadCount.service),1)]),_:1})):f("",!0)]),_:1},8,["class"])]),_:1}),c(M,{class:"notification-list","scroll-y":"",onScrolltolower:C.loadMore,"show-scrollbar":!1},{default:o(()=>[(e(!0),u(m,null,h(k.notificationList,t=>(e(),s(w,{class:r(["notification-item",{unread:!t.isRead}]),key:t.id,onClick:a=>C.readNotification(t)},{default:o(()=>[c(w,{class:"item-header"},{default:o(()=>[c($,{class:"item-title"},{default:o(()=>[l(d(t.title),1)]),_:2},1024),t.isRead?f("",!0):(e(),s(w,{key:0,class:"unread-dot"}))]),_:2},1024),c($,{class:"item-content"},{default:o(()=>[l(d(t.content),1)]),_:2},1024),c($,{class:"item-time"},{default:o(()=>[l(d(C.formatTime(t.createdAt)),1)]),_:2},1024)]),_:2},1032,["class","onClick"]))),128)),k.loading?(e(),s(w,{key:0,class:"loading-more"},{default:o(()=>[c($,{class:"loading-text"},{default:o(()=>[l(d(t.$t("common.loading")),1)]),_:1})]),_:1})):f("",!0),!k.loading&&!k.hasMore&&k.notificationList.length>0?(e(),s(w,{key:1,class:"loading-more"},{default:o(()=>[c($,{class:"loading-text"},{default:o(()=>[l(d(t.$t("common.noMore")||"没有更多了"),1)]),_:1})]),_:1})):f("",!0),0!==k.notificationList.length||k.loading?f("",!0):(e(),s(w,{key:2,class:"empty-state"},{default:o(()=>[c(T,{src:p,class:"empty-icon",mode:"aspectFit"}),c($,{class:"no-data"},{default:o(()=>[l(d(t.$t("notification.noNotification")),1)]),_:1})]),_:1}))]),_:1},8,["onScrolltolower"])]),_:1})}],["__scopeId","data-v-a192f984"]]);export{k as default};