EditStudentDialog.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <q-dialog ref="dialogRef" @hide="onDialogHide">
  3. <q-card
  4. class="q-dialog-plugin overflow-hidden"
  5. style="width: 100%; max-width: 1400px"
  6. >
  7. <DefaultDialogHeader title="Dados do Aluno" @close="onDialogCancel" />
  8. <q-card-section class="q-pt-sm" style="height: 65vh; overflow-y: auto">
  9. <CustomTabComponent
  10. v-model:active-tab="currentTab"
  11. :tabs="tabs"
  12. class="q-mb-md"
  13. />
  14. <div v-show="currentTab === 'profile'">
  15. <StudentDataTab ref="studentDataTabRef" :student="props.student" />
  16. </div>
  17. <div v-show="currentTab === 'responsible'">
  18. <ResponsibleTab :student-id="props.student.id" />
  19. </div>
  20. <div v-if="canViewContracts" v-show="currentTab === 'contracts'">
  21. <ContractTab :student="props.student" />
  22. </div>
  23. <div v-show="currentTab === 'history'">
  24. <HistoryTab />
  25. </div>
  26. <div v-show="currentTab === 'media'">
  27. <MediaTab ref="mediaTabRef" :student-id="props.student.id" />
  28. </div>
  29. </q-card-section>
  30. <q-separator />
  31. <q-card-actions align="right">
  32. <q-btn
  33. outline
  34. color="primary"
  35. label="CANCELAR"
  36. @click="onDialogCancel"
  37. />
  38. <q-btn
  39. color="primary"
  40. label="SALVAR"
  41. :loading="saving"
  42. @click="handleSave"
  43. />
  44. </q-card-actions>
  45. </q-card>
  46. </q-dialog>
  47. </template>
  48. <script setup>
  49. import { computed, ref, watch, useTemplateRef, defineAsyncComponent } from "vue";
  50. import { useDialogPluginComponent } from "quasar";
  51. import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
  52. import CustomTabComponent from "src/components/shared/CustomTabComponent.vue";
  53. import { useSubmitHandler } from "src/composables/useSubmitHandler";
  54. import { updateStudent } from "src/api/student";
  55. import { permissionStore } from "src/stores/permission";
  56. const StudentDataTab = defineAsyncComponent(
  57. () => import("src/pages/students/tabs/StudentDataTab.vue"),
  58. );
  59. const ResponsibleTab = defineAsyncComponent(
  60. () => import("src/pages/students/tabs/ResponsibleTab.vue"),
  61. );
  62. const ContractTab = defineAsyncComponent(
  63. () => import("src/pages/students/tabs/ContractTab.vue"),
  64. );
  65. const HistoryTab = defineAsyncComponent(
  66. () => import("src/pages/students/tabs/HistoryTab.vue"),
  67. );
  68. const MediaTab = defineAsyncComponent(
  69. () => import("src/pages/students/tabs/MediaTab.vue"),
  70. );
  71. const props = defineProps({
  72. student: {
  73. type: Object,
  74. required: true,
  75. },
  76. });
  77. defineEmits([...useDialogPluginComponent.emits]);
  78. const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } =
  79. useDialogPluginComponent();
  80. const studentDataTabRef = useTemplateRef("studentDataTabRef");
  81. const mediaTabRef = useTemplateRef("mediaTabRef");
  82. const currentTab = ref("profile");
  83. const permissions = permissionStore();
  84. const canViewContracts = computed(() =>
  85. permissions.getAccess("franchisee_contracts", "view"),
  86. );
  87. watch(currentTab, (tab) => {
  88. if (tab === "media") mediaTabRef.value?.refresh();
  89. });
  90. const { loading: saving, execute } = useSubmitHandler({
  91. onSuccess: () => onDialogOK(true),
  92. });
  93. const tabs = computed(() => [
  94. { name: "profile", label: "Perfil do Aluno" },
  95. { name: "responsible", label: "Responsáveis" },
  96. ...(canViewContracts.value
  97. ? [{ name: "contracts", label: "Contratos" }]
  98. : []),
  99. { name: "history", label: "Frequência" },
  100. { name: "media", label: "Mídias" },
  101. ]);
  102. async function handleSave() {
  103. const valid = await (studentDataTabRef.value?.validate() ?? true);
  104. if (!valid) return;
  105. const studentPayload = studentDataTabRef.value.buildPayload();
  106. await execute(() => updateStudent(studentPayload, props.student.id));
  107. }
  108. </script>