notifications.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { Component, OnInit } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { Router } from '@angular/router';
  4. import { SvgIconComponent } from '../../../shared/components/svg-icons/svg-icons.component';
  5. @Component({
  6. selector: 'app-notifications',
  7. standalone: true,
  8. imports: [CommonModule, SvgIconComponent],
  9. templateUrl: './notifications.html',
  10. styleUrls: ['./notifications.scss']
  11. })
  12. export class NotificationsComponent implements OnInit {
  13. notifications = [
  14. {
  15. id: 1,
  16. type: 'system',
  17. title: '系统通知',
  18. message: '您的回收订单已完成,获得积分 50 分',
  19. time: '2024-01-15 10:30',
  20. read: false,
  21. icon: 'notification'
  22. },
  23. {
  24. id: 2,
  25. type: 'activity',
  26. title: '活动通知',
  27. message: '环保知识竞赛开始啦!参与即可获得额外积分',
  28. time: '2024-01-14 16:20',
  29. read: false,
  30. icon: 'activity'
  31. },
  32. {
  33. id: 3,
  34. type: 'reward',
  35. title: '奖励通知',
  36. message: '恭喜您完成每日回收任务,获得现金奖励 ¥5.00',
  37. time: '2024-01-14 09:15',
  38. read: true,
  39. icon: 'reward'
  40. },
  41. {
  42. id: 4,
  43. type: 'system',
  44. title: '系统通知',
  45. message: '您的账户余额已更新,当前余额 ¥125.50',
  46. time: '2024-01-13 14:45',
  47. read: true,
  48. icon: 'notification'
  49. }
  50. ];
  51. constructor(private router: Router) {}
  52. ngOnInit() {}
  53. goBack() {
  54. this.router.navigate(['/consumer/home']);
  55. }
  56. markAsRead(notification: any) {
  57. notification.read = true;
  58. }
  59. markAllAsRead() {
  60. this.notifications.forEach(notification => {
  61. notification.read = true;
  62. });
  63. }
  64. deleteNotification(id: number) {
  65. this.notifications = this.notifications.filter(notification => notification.id !== id);
  66. }
  67. getNotificationIcon(type: string): string {
  68. switch (type) {
  69. case 'system':
  70. return 'notification';
  71. case 'activity':
  72. return 'activity';
  73. case 'reward':
  74. return 'reward';
  75. default:
  76. return 'notification';
  77. }
  78. }
  79. }