DashboardPage.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. <DashboardSummaryInfos :data="summaryInfos" />
  15. <DashboardPriceSuggest :data="priceSuggestion"/>
  16. <DashboardTodayServices v-if="todayServices?.length > 0" :data="todayServices" @refresh="loadDashboard" @rate="openRatingDialog" />
  17. <DashboardScrollAreaSchedules />
  18. <DashboardSolicitations
  19. v-if="solicitations?.length > 0"
  20. :data="solicitations"
  21. @accept="(item) => openDetailsDialog(item, 'confirm-accept')"
  22. @reject="(item) => openDetailsDialog(item, 'confirm-reject')"
  23. @view-details="(item) => openDetailsDialog(item)"
  24. />
  25. <DashboardNextSchedules v-if="nextSchedules?.length > 0" :data="nextSchedules" @view-details="(item) => openNextScheduleDialog(item)" />
  26. <DashboardOpportunities v-if="opportunities?.length > 0" :data="opportunities"/>
  27. </q-pull-to-refresh>
  28. </template>
  29. </div>
  30. </template>
  31. <script setup>
  32. import DashboardHeaderBar from 'src/components/dashboard/DashboardHeaderBar.vue';
  33. import DashboardSummaryInfos from 'src/components/dashboard/DashboardSummaryInfos.vue';
  34. import DashboardPriceSuggest from 'src/components/dashboard/DashboardPriceSuggest.vue';
  35. import DashboardScrollAreaSchedules from 'src/components/dashboard/DashboardScrollAreaSchedules.vue';
  36. import DashboardSolicitations from 'src/components/dashboard/DashboardSolicitations.vue';
  37. import DashboardTodayServices from 'src/components/dashboard/DashboardTodayServices.vue';
  38. import DashboardNextSchedules from 'src/components/dashboard/DashboardNextSchedules.vue';
  39. import DashboardOpportunities from 'src/components/dashboard/DashboardOpportunities.vue';
  40. import SolicitationDetailsDialog from 'src/components/dashboard/SolicitationDetailsDialog.vue';
  41. import NextSchedulesDetailsDialog from 'src/components/dashboard/NextSchedulesDetailsDialog.vue';
  42. import ScheduleRatingDialog from 'src/components/dashboard/ScheduleRatingDialog.vue';
  43. import OpportunityDialog from 'src/pages/opportunities/components/OpportunityDialog.vue';
  44. import { onMounted, ref, watch } from 'vue';
  45. import { useQuasar } from 'quasar';
  46. import { dadosDashboard } from 'src/api/dashboard';
  47. import { updateScheduleStatus } from 'src/api/schedule';
  48. import { useRouter, useRoute } from 'vue-router';
  49. const router = useRouter();
  50. const route = useRoute();
  51. const headerBar = ref({});
  52. const summaryInfos = ref({});
  53. const priceSuggestion = ref({});
  54. const solicitations = ref([]);
  55. const todayServices = ref([]);
  56. const nextSchedules = ref([]);
  57. const opportunities = ref([]);
  58. const notifications = ref([]);
  59. const $q = useQuasar();
  60. watch(() => route.query.showSuccessModal, (val) => {
  61. if (val === 'true') {
  62. $q.dialog({ component: OpportunityDialog })
  63. .onDismiss(() => {
  64. router.replace({ path: route.path, query: {} });
  65. });
  66. }
  67. }, { immediate: true });
  68. const loading = ref(true);
  69. const loadDashboard = async () => {
  70. const response = await dadosDashboard();
  71. if (response) {
  72. headerBar.value = response.headerBar;
  73. summaryInfos.value = response.summaryInfos;
  74. priceSuggestion.value = response.priceSuggested;
  75. solicitations.value = response.solicitations ?? [];
  76. todayServices.value = response.todayServices ?? [];
  77. nextSchedules.value = response.nextSchedules ?? [];
  78. opportunities.value = response.opportunities ?? [];
  79. notifications.value = response.notifications ?? [];
  80. }
  81. }
  82. const onRefresh = async (done) => {
  83. try {
  84. await loadDashboard();
  85. } finally {
  86. done();
  87. }
  88. };
  89. const handleScheduleAction = async (id, status) => {
  90. try {
  91. await updateScheduleStatus(id, status);
  92. await loadDashboard();
  93. } catch (e) {
  94. console.log(e);
  95. }
  96. };
  97. const openDetailsDialog = (solicitation, initialView = 'details') => {
  98. $q.dialog({
  99. component: SolicitationDetailsDialog,
  100. componentProps: { solicitation, initialView }
  101. }).onOk(async ({ action, id }) => {
  102. await handleScheduleAction(id, action === 'accept' ? 'accepted' : 'rejected');
  103. });
  104. };
  105. const openNextScheduleDialog = (schedule) => {
  106. $q.dialog({
  107. component: NextSchedulesDetailsDialog,
  108. componentProps: { schedule }
  109. }).onOk(async ({ action }) => {
  110. if (action === 'cancelled') {
  111. await loadDashboard();
  112. }
  113. });
  114. };
  115. const openRatingDialog = (schedule) => {
  116. $q.dialog({
  117. component: ScheduleRatingDialog,
  118. componentProps: { schedule }
  119. }).onOk(() => {
  120. loadDashboard()
  121. })
  122. };
  123. onMounted(async () => {
  124. await loadDashboard();
  125. loading.value = false;
  126. });
  127. </script>
  128. <style scoped>
  129. .dashboard-page {
  130. width: 100%;
  131. min-height: 100%;
  132. box-sizing: border-box;
  133. }
  134. </style>