EditStudentDialog.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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-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 :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 { ref, 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. const StudentDataTab = defineAsyncComponent(
  56. () => import("src/pages/students/tabs/StudentDataTab.vue"),
  57. );
  58. const ResponsibleTab = defineAsyncComponent(
  59. () => import("src/pages/students/tabs/ResponsibleTab.vue"),
  60. );
  61. const ContractTab = defineAsyncComponent(
  62. () => import("src/pages/students/tabs/ContractTab.vue"),
  63. );
  64. const HistoryTab = defineAsyncComponent(
  65. () => import("src/pages/students/tabs/HistoryTab.vue"),
  66. );
  67. const MediaTab = defineAsyncComponent(
  68. () => import("src/pages/students/tabs/MediaTab.vue"),
  69. );
  70. const props = defineProps({
  71. student: {
  72. type: Object,
  73. required: true,
  74. },
  75. });
  76. defineEmits([...useDialogPluginComponent.emits]);
  77. const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } =
  78. useDialogPluginComponent();
  79. const studentDataTabRef = useTemplateRef("studentDataTabRef");
  80. const currentTab = ref("profile");
  81. const { loading: saving, execute } = useSubmitHandler({
  82. onSuccess: () => onDialogOK(true),
  83. });
  84. const tabs = [
  85. { name: "profile", label: "Perfil do Aluno" },
  86. { name: "responsible", label: "Responsáveis" },
  87. { name: "contracts", label: "Contratos" },
  88. { name: "history", label: "Frequência" },
  89. { name: "media", label: "Mídias" },
  90. ];
  91. async function handleSave() {
  92. const valid = await (studentDataTabRef.value?.validate() ?? true);
  93. if (!valid) return;
  94. const studentPayload = studentDataTabRef.value.buildPayload();
  95. await execute(() => updateStudent(studentPayload, props.student.id));
  96. }
  97. </script>