DashboardPage.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="dashboard-page bg-page">
  3. <template v-if="loading">
  4. <div class="row items-center justify-center full-width bg-surface" style="height: 80vh">
  5. <q-spinner-dots color="primary" />
  6. </div>
  7. </template>
  8. <template v-else>
  9. <q-pull-to-refresh color="primary" @refresh="onRefresh">
  10. <DashboardHeaderBar
  11. :data="headerBar"
  12. :notifications="notifications"
  13. />
  14. <DashboardRegistrationIncomplete v-if="!registrationComplete" />
  15. <DashboardSummaryInfos v-else :data="summaryInfos" />
  16. <DashboardPaymentIncomplete v-if="!hasPaymentMethods" />
  17. <DashboardPendingSchedules
  18. v-if="pendingServicePackages.length > 0"
  19. :data="pendingServicePackages"
  20. :type="'servicePackage'"
  21. @view-details="openServicePackagePaymentDialog"
  22. />
  23. <DashboardTodaySchedules v-if="todaySchedules.length > 0" :data="todaySchedules" @rate="openRatingDialog" />
  24. <DashboardScrollAreaSchedules />
  25. <DashboardClientProposals v-if="clientProposals.length > 0" :data="clientProposals" @refresh-data="reloadDashboard" />
  26. <DashboardPendingCustomSchedules v-if="customSchedulesNoProposals.length > 0" />
  27. <DashboardNextSchedules v-if="nextSchedules.length > 0" :data="nextSchedules" @view-details="openNextScheduleDialog" />
  28. <DashboardLastDoneSchedules v-if="lastDoneSchedules.length > 0" :data="lastDoneSchedules" />
  29. <DashboardFavoriteProviders v-if="favoriteProviders.length > 0" :data="favoriteProviders" />
  30. <DashboardProvidersClose v-if="providersClose.length > 0" :data="providersClose" />
  31. </q-pull-to-refresh>
  32. </template>
  33. </div>
  34. </template>
  35. <script setup>
  36. import DashboardHeaderBar from 'src/components/dashboard/DashboardHeaderBar.vue';
  37. import DashboardSummaryInfos from 'src/components/dashboard/DashboardSummaryInfos.vue';
  38. import DashboardRegistrationIncomplete from 'src/components/dashboard/DashboardRegistrationIncomplete.vue';
  39. import DashboardPaymentIncomplete from 'src/components/dashboard/DashboardPaymentIncomplete.vue';
  40. import DashboardPendingSchedules from 'src/components/dashboard/DashboardPendingSchedules.vue';
  41. import ScheduleAcceptedDialog from 'src/components/dashboard/ScheduleAcceptedDialog.vue';
  42. import DashboardScrollAreaSchedules from 'src/components/dashboard/DashboardScrollAreaSchedules.vue';
  43. import DashboardNextSchedules from 'src/components/dashboard/DashboardNextSchedules.vue';
  44. import DashboardLastDoneSchedules from 'src/components/dashboard/DashboardLastDoneSchedules.vue';
  45. import DashboardFavoriteProviders from 'src/components/dashboard/DashboardFavoriteProviders.vue';
  46. import DashboardProvidersClose from 'src/components/dashboard/DashboardProvidersClose.vue';
  47. import DashboardTodaySchedules from 'src/components/dashboard/DashboardTodaySchedules.vue';
  48. import FinalSuccesModal from '../schedules/components/FinalSuccesModal.vue';
  49. import DashboardPendingCustomSchedules from 'src/pages/dashboard/components/DashboardPendingCustomSchedules.vue';
  50. import DashboardClientProposals from 'src/pages/dashboard/components/DashboardClientProposals.vue';
  51. import { useRouter } from 'vue-router'
  52. import { onMounted, ref, computed } from 'vue';
  53. import { useQuasar } from 'quasar';
  54. import { dadosDashboard } from 'src/api/dashboard';
  55. import { userStore } from 'src/stores/user';
  56. import NextSchedulesDetailsDialog from 'src/components/dashboard/NextSchedulesDetailsDialog.vue';
  57. import ScheduleRatingDialog from 'src/components/dashboard/ScheduleRatingDialog.vue';
  58. const router = useRouter()
  59. const $q = useQuasar();
  60. const store = userStore();
  61. const hasPaymentMethods = ref(true);
  62. const headerBar = ref({});
  63. const summaryInfos = ref({});
  64. const pendingSchedules = ref([]);
  65. const pendingServicePackages = ref([]);
  66. const nextSchedules = ref([]);
  67. const clientProposals = ref([]);
  68. const customSchedulesNoProposals = ref([]);
  69. const lastDoneSchedules = ref([]);
  70. const favoriteProviders = ref([]);
  71. const providersClose = ref([]);
  72. const todaySchedules = ref([]);
  73. const notifications = ref([]);
  74. const loading = ref(true);
  75. const showSuccessModal = ref(router.currentRoute.value.fullPath.includes('showSuccessModal'));
  76. const registrationComplete = computed(() => store.user?.registration_complete ?? true);
  77. const openServicePackagePaymentDialog = (servicePackage) => {
  78. $q.dialog({
  79. component: ScheduleAcceptedDialog,
  80. componentProps: { servicePackage }
  81. }).onOk(() => {
  82. reloadDashboard();
  83. });
  84. };
  85. const reloadDashboard = async (showLoader = true) => {
  86. if (showLoader) loading.value = true;
  87. const response = await dadosDashboard();
  88. if (response) {
  89. headerBar.value = response.headerBar;
  90. summaryInfos.value = response.summaryInfos;
  91. pendingSchedules.value = response.pendingSchedules ?? [];
  92. pendingServicePackages.value = response.pendingServicePackages ?? [];
  93. nextSchedules.value = response.nextSchedules ?? [];
  94. lastDoneSchedules.value = response.lastDoneSchedules ?? [];
  95. favoriteProviders.value = response.favoriteProviders ?? [];
  96. providersClose.value = response.providersClose ?? [];
  97. clientProposals.value = response.schedulesProposals ?? [];
  98. customSchedulesNoProposals.value = response.customSchedulesNoProposals ?? [];
  99. todaySchedules.value = response.todaySchedules ?? [];
  100. notifications.value = response.notifications ?? [];
  101. hasPaymentMethods.value = response.has_payment_methods ?? true;
  102. }
  103. if( showSuccessModal.value == true) {
  104. $q.dialog({
  105. component: FinalSuccesModal
  106. }).onDismiss(() => {
  107. showSuccessModal.value = false;
  108. router.replace({ path: router.currentRoute.value.path, query: {} });
  109. })
  110. }
  111. loading.value = false;
  112. };
  113. const onRefresh = async (done) => {
  114. try {
  115. await reloadDashboard(false);
  116. } finally {
  117. done();
  118. }
  119. };
  120. const openNextScheduleDialog = (schedule) => {
  121. $q.dialog({
  122. component: NextSchedulesDetailsDialog,
  123. componentProps: { schedule }
  124. }).onOk(() => {
  125. reloadDashboard();
  126. });
  127. };
  128. const openRatingDialog = (schedule) => {
  129. $q.dialog({
  130. component: ScheduleRatingDialog,
  131. componentProps: { schedule }
  132. }).onOk(() => {
  133. reloadDashboard()
  134. })
  135. }
  136. onMounted(async () => {
  137. await reloadDashboard();
  138. });
  139. </script>
  140. <style scoped>
  141. .dashboard-page {
  142. width: 100%;
  143. min-height: 100%;
  144. box-sizing: border-box;
  145. }
  146. </style>