DashboardPage.vue 4.6 KB

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