DashboardPage.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <div class="dashboard-page bg-page">
  3. <template v-if="loading">
  4. <div
  5. class="bg-surface full-width items-center justify-center row"
  6. style="height: 80vh"
  7. >
  8. <q-spinner-dots color="primary" />
  9. </div>
  10. </template>
  11. <template v-else>
  12. <q-pull-to-refresh color="primary" @refresh="onRefresh">
  13. <DashboardHeaderBar :data="headerBar" :notifications="notifications" />
  14. <DashboardSummaryInfos :data="summaryInfos" />
  15. <DashboardPriceSuggest :data="priceSuggestion" />
  16. <DashboardTodayServices
  17. v-if="todayServices?.length > 0"
  18. :data="todayServices"
  19. @refresh="loadDashboard"
  20. @rate="openRatingDialog"
  21. />
  22. <DashboardScrollAreaSchedules />
  23. <DashboardSolicitations
  24. v-if="solicitations?.length > 0"
  25. :data="solicitations"
  26. @accept="(item) => openDetailsDialog(item)"
  27. @reject="(item) => openDetailsDialog(item, 'confirm-reject')"
  28. @view-details="(item) => openDetailsDialog(item)"
  29. />
  30. <DashboardPendingConfirmation
  31. v-if="pendingConfirmation.length > 0"
  32. :data="pendingConfirmation"
  33. @view-details="(item) => openNextScheduleDialog(item)"
  34. />
  35. <DashboardNextSchedules
  36. :data="nextSchedules"
  37. @view-details="(item) => openNextScheduleDialog(item)"
  38. />
  39. <DashboardOpportunities :data="opportunities" />
  40. </q-pull-to-refresh>
  41. </template>
  42. </div>
  43. </template>
  44. <script setup>
  45. import { dadosDashboard } from "src/api/dashboard";
  46. import { onMounted, ref, watch } from "vue";
  47. import { acceptServicePackage, rejectServicePackage, updateScheduleStatus } from "src/api/schedule";
  48. import { useQuasar } from "quasar";
  49. import { useRoute, useRouter } from "vue-router";
  50. import DashboardHeaderBar from "src/components/dashboard/DashboardHeaderBar.vue";
  51. import DashboardNextSchedules from "src/components/dashboard/DashboardNextSchedules.vue";
  52. import DashboardOpportunities from "src/components/dashboard/DashboardOpportunities.vue";
  53. import DashboardPriceSuggest from "src/components/dashboard/DashboardPriceSuggest.vue";
  54. import DashboardScrollAreaSchedules from "src/components/dashboard/DashboardScrollAreaSchedules.vue";
  55. import DashboardSolicitations from "src/components/dashboard/DashboardSolicitations.vue";
  56. import DashboardSummaryInfos from "src/components/dashboard/DashboardSummaryInfos.vue";
  57. import DashboardTodayServices from "src/components/dashboard/DashboardTodayServices.vue";
  58. import NextSchedulesDetailsDialog from "src/components/dashboard/NextSchedulesDetailsDialog.vue";
  59. import ScheduleRatingDialog from "src/components/dashboard/ScheduleRatingDialog.vue";
  60. import SolicitationDetailsDialog from "src/components/dashboard/SolicitationDetailsDialog.vue";
  61. import OpportunityDialog from "src/pages/opportunities/components/OpportunityDialog.vue";
  62. import DashboardPendingConfirmation from "src/components/dashboard/DashboardPendingConfirmation.vue";
  63. const $q = useQuasar();
  64. const router = useRouter();
  65. const route = useRoute();
  66. const headerBar = ref({});
  67. const loading = ref(true);
  68. const nextSchedules = ref([]);
  69. const notifications = ref([]);
  70. const opportunities = ref([]);
  71. const priceSuggestion = ref({});
  72. const solicitations = ref([]);
  73. const summaryInfos = ref({});
  74. const todayServices = ref([]);
  75. const pendingConfirmation = ref([]);
  76. const handleScheduleAction = async (id, status, ids = [], servicePackageId = null) => {
  77. try {
  78. if (servicePackageId && status === "accepted") {
  79. await acceptServicePackage(servicePackageId);
  80. } else if (servicePackageId && status === "rejected") {
  81. await rejectServicePackage(servicePackageId);
  82. } else {
  83. const scheduleIds = ids.length ? ids : [id];
  84. await Promise.all(
  85. scheduleIds.map((scheduleId) => updateScheduleStatus(scheduleId, status)),
  86. );
  87. }
  88. } catch (e) {
  89. console.log(e);
  90. } finally {
  91. await loadDashboard();
  92. }
  93. };
  94. const loadDashboard = async () => {
  95. const response = await dadosDashboard();
  96. console.log(response);
  97. console.log(response.solicitations);
  98. if (response) {
  99. headerBar.value = response.headerBar;
  100. nextSchedules.value = response.nextSchedules ?? [];
  101. notifications.value = response.notifications ?? [];
  102. opportunities.value = response.opportunities ?? [];
  103. priceSuggestion.value = response.priceSuggested;
  104. solicitations.value = response.solicitations ?? [];
  105. summaryInfos.value = response.summaryInfos;
  106. pendingConfirmation.value = response.pendingConfirmation ?? [];
  107. todayServices.value = response.todayServices ?? [];
  108. }
  109. };
  110. const onRefresh = async (done) => {
  111. try {
  112. await loadDashboard();
  113. } finally {
  114. done();
  115. }
  116. };
  117. const openDetailsDialog = (solicitation, initialView = "details") => {
  118. $q.dialog({
  119. component: SolicitationDetailsDialog,
  120. componentProps: { initialView, solicitation },
  121. }).onOk(async ({ action, id, ids, service_package_id }) => {
  122. await handleScheduleAction(
  123. id,
  124. action === "accept" ? "accepted" : "rejected",
  125. ids,
  126. service_package_id,
  127. );
  128. });
  129. };
  130. const openNextScheduleDialog = (schedule) => {
  131. $q.dialog({
  132. component: NextSchedulesDetailsDialog,
  133. componentProps: { schedule },
  134. }).onOk(async ({ action }) => {
  135. if (action === "cancelled") {
  136. await loadDashboard();
  137. }
  138. });
  139. };
  140. const openRatingDialog = (schedule) => {
  141. $q.dialog({
  142. component: ScheduleRatingDialog,
  143. componentProps: { schedule },
  144. }).onOk(() => {
  145. loadDashboard();
  146. });
  147. };
  148. watch(
  149. () => route.query.showSuccessModal,
  150. (val) => {
  151. if (val === "true") {
  152. $q.dialog({ component: OpportunityDialog }).onDismiss(() => {
  153. router.replace({ path: route.path, query: {} });
  154. });
  155. }
  156. },
  157. { immediate: true },
  158. );
  159. onMounted(async () => {
  160. await loadDashboard();
  161. loading.value = false;
  162. });
  163. </script>
  164. <style scoped>
  165. .dashboard-page {
  166. box-sizing: border-box;
  167. min-height: 100%;
  168. width: 100%;
  169. }
  170. </style>