DashboardPage.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 ProposalAcceptedDialog from "src/components/dashboard/ProposalAcceptedDialog.vue";
  62. import OpportunityDialog from "src/pages/opportunities/components/OpportunityDialog.vue";
  63. import DashboardPendingConfirmation from "src/components/dashboard/DashboardPendingConfirmation.vue";
  64. const $q = useQuasar();
  65. const router = useRouter();
  66. const route = useRoute();
  67. const headerBar = ref({});
  68. const loading = ref(true);
  69. const nextSchedules = ref([]);
  70. const notifications = ref([]);
  71. const opportunities = ref([]);
  72. const priceSuggestion = ref({});
  73. const solicitations = ref([]);
  74. const summaryInfos = ref({});
  75. const todayServices = ref([]);
  76. const pendingConfirmation = ref([]);
  77. const handleScheduleAction = async (id, status, ids = [], servicePackageId = null) => {
  78. try {
  79. if (servicePackageId && status === "accepted") {
  80. await acceptServicePackage(servicePackageId);
  81. } else if (servicePackageId && status === "rejected") {
  82. await rejectServicePackage(servicePackageId);
  83. } else {
  84. const scheduleIds = ids.length ? ids : [id];
  85. await Promise.all(
  86. scheduleIds.map((scheduleId) => updateScheduleStatus(scheduleId, status)),
  87. );
  88. }
  89. } catch (e) {
  90. console.log(e);
  91. } finally {
  92. await loadDashboard();
  93. }
  94. };
  95. const loadDashboard = async () => {
  96. const response = await dadosDashboard();
  97. if (response) {
  98. headerBar.value = response.headerBar;
  99. nextSchedules.value = response.nextSchedules ?? [];
  100. notifications.value = response.notifications ?? [];
  101. opportunities.value = response.opportunities ?? [];
  102. priceSuggestion.value = response.priceSuggested;
  103. solicitations.value = response.solicitations ?? [];
  104. summaryInfos.value = response.summaryInfos;
  105. pendingConfirmation.value = response.pendingConfirmation ?? [];
  106. todayServices.value = response.todayServices ?? [];
  107. }
  108. };
  109. const onRefresh = async (done) => {
  110. try {
  111. await loadDashboard();
  112. } finally {
  113. done();
  114. }
  115. };
  116. const openDetailsDialog = (solicitation, initialView = "details") => {
  117. $q.dialog({
  118. component: SolicitationDetailsDialog,
  119. componentProps: { initialView, solicitation },
  120. }).onOk(async ({ action, id, ids, service_package_id }) => {
  121. await handleScheduleAction(
  122. id,
  123. action === "accept" ? "accepted" : "rejected",
  124. ids,
  125. service_package_id,
  126. );
  127. if (action === "accept") {
  128. $q.dialog({
  129. component: ProposalAcceptedDialog,
  130. });
  131. }
  132. });
  133. };
  134. const openNextScheduleDialog = (schedule) => {
  135. $q.dialog({
  136. component: NextSchedulesDetailsDialog,
  137. componentProps: { schedule },
  138. }).onOk(async ({ action }) => {
  139. if (action === "cancelled") {
  140. await loadDashboard();
  141. }
  142. });
  143. };
  144. const openRatingDialog = (schedule) => {
  145. $q.dialog({
  146. component: ScheduleRatingDialog,
  147. componentProps: { schedule },
  148. }).onOk(() => {
  149. loadDashboard();
  150. });
  151. };
  152. watch(
  153. () => route.query.showSuccessModal,
  154. (val) => {
  155. if (val === "true") {
  156. $q.dialog({ component: OpportunityDialog }).onDismiss(() => {
  157. router.replace({ path: route.path, query: {} });
  158. });
  159. }
  160. },
  161. { immediate: true },
  162. );
  163. onMounted(async () => {
  164. await loadDashboard();
  165. loading.value = false;
  166. });
  167. </script>
  168. <style scoped>
  169. .dashboard-page {
  170. box-sizing: border-box;
  171. min-height: 100%;
  172. width: 100%;
  173. }
  174. </style>