NotificacoesAssociadoPage.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div>
  3. <DefaultHeaderPage />
  4. <div class="q-pt-sm">
  5. <div v-if="loading" class="flex flex-center q-pa-xl">
  6. <q-spinner color="violet-normal" size="50px" />
  7. </div>
  8. <div v-else-if="pagedItems.length === 0" class="flex flex-center q-pa-xl text-grey-6">
  9. {{ $t('notification.empty') }}
  10. </div>
  11. <div v-else>
  12. <div class="notifications-grid q-px-md">
  13. <NotificationCard
  14. v-for="item in pagedItems"
  15. :key="item.id"
  16. :notification="item.notification"
  17. :unread="!item.read"
  18. :date="item.created_at"
  19. @click="openDetail(item)"
  20. />
  21. </div>
  22. <div v-if="totalPages > 1" class="flex flex-center q-mt-lg">
  23. <q-pagination
  24. v-model="currentPage"
  25. :max="totalPages"
  26. :max-pages="6"
  27. boundary-numbers
  28. color="violet-normal"
  29. active-color="violet-normal"
  30. direction-links
  31. />
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script setup>
  38. import { ref, computed, onMounted } from "vue";
  39. import { useQuasar } from "quasar";
  40. import { getMyNotificationsAssociado } from "src/api/notification";
  41. import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
  42. import NotificationCard from "src/components/NotificationCard.vue";
  43. import NotificationDetailDialog from "src/components/NotificationDetailDialog.vue";
  44. const $q = useQuasar();
  45. const loading = ref(true);
  46. const notifications = ref([]);
  47. const currentPage = ref(1);
  48. const PER_PAGE = 12;
  49. const totalPages = computed(() => Math.max(1, Math.ceil(notifications.value.length / PER_PAGE)));
  50. const pagedItems = computed(() => {
  51. const start = (currentPage.value - 1) * PER_PAGE;
  52. return notifications.value.slice(start, start + PER_PAGE);
  53. });
  54. const openDetail = (item) => {
  55. $q.dialog({
  56. component: NotificationDetailDialog,
  57. componentProps: { item },
  58. }).onOk((markedId) => {
  59. if (!markedId) return;
  60. const found = notifications.value.find((n) => n.id === markedId);
  61. if (found) found.read = true;
  62. });
  63. };
  64. onMounted(async () => {
  65. try {
  66. notifications.value = await getMyNotificationsAssociado();
  67. } catch (e) {
  68. console.error(e);
  69. } finally {
  70. loading.value = false;
  71. }
  72. });
  73. </script>