Pārlūkot izejas kodu

feat(students): enhance payer logic and add copy data button

alvesantos 1 nedēļu atpakaļ
vecāks
revīzija
9209ee624a

+ 66 - 6
src/pages/students/components/AddEditStudentDialog.vue

@@ -175,7 +175,7 @@
                 <DefaultInput
                 <DefaultInput
                   v-model="form.payer"
                   v-model="form.payer"
                   class="col-6"
                   class="col-6"
-                  label="Pagador"
+                  label="Responsável Financeiro"
                   :error="!!validationErrors.payer_name"
                   :error="!!validationErrors.payer_name"
                   :error-message="validationErrors.payer_name"
                   :error-message="validationErrors.payer_name"
                 />
                 />
@@ -219,6 +219,17 @@
                 concluir.
                 concluir.
               </q-banner>
               </q-banner>
 
 
+              <div class="row q-mb-md justify-end">
+                <q-btn
+                  outline
+                  color="primary"
+                  icon="content_copy"
+                  label="Copiar Dados do Aluno"
+                  size="sm"
+                  @click="copyStudentDataToResponsible"
+                />
+              </div>
+
               <div class="row q-col-gutter-sm">
               <div class="row q-col-gutter-sm">
                 <DefaultInput
                 <DefaultInput
                   v-model="responsibleForm.name"
                   v-model="responsibleForm.name"
@@ -1001,12 +1012,61 @@ watch(responsibleSelectedCity, (city) => {
     city?.value ?? null;
     city?.value ?? null;
 });
 });
 
 
+const copyStudentDataToResponsible = () => {
+  responsibleForm.value.name = form.value.name;
+  responsibleForm.value.cpf = form.value.cpf;
+  responsibleForm.value.birth_date = form.value.birthdate;
+  responsibleForm.value.gender = form.value.gender;
+  responsibleForm.value.email = form.value.email;
+  responsibleForm.value.phone = form.value.phone;
+  responsibleForm.value.postal_code = form.value.cep;
+  responsibleForm.value.street = form.value.address;
+  responsibleForm.value.address_number = form.value.address_number;
+  responsibleForm.value.neighborhood = form.value.neighborhood;
+  responsibleForm.value.complement = form.value.complement;
+  
+  responsibleSelectedState.value = selectedState.value;
+  responsibleSelectedCity.value = selectedCity.value;
+  
+  // The watchers below will sync the actual IDs in the form
+};
+
+watch(
+  () => form.value.name,
+  (newName) => {
+    if (!isStudentUnderage.value) {
+      form.value.payer = newName;
+    }
+  }
+);
+
+watch(
+  () => responsibleForm.value.name,
+  (newName) => {
+    if (isStudentUnderage.value) {
+      form.value.payer = newName;
+    }
+  }
+);
+
+watch(
+  () => form.value.payer,
+  (newPayer) => {
+    if (isStudentUnderage.value) {
+      responsibleForm.value.name = newPayer;
+    }
+  }
+);
+
 watch(isStudentUnderage, (underage) => {
 watch(isStudentUnderage, (underage) => {
-  if (
-    !underage &&
-    activeTab.value === "responsible"
-  ) {
-    activeTab.value = "student";
+  if (underage) {
+    form.value.payer = responsibleForm.value.name;
+  } else {
+    form.value.payer = form.value.name;
+    
+    if (activeTab.value === "responsible") {
+      activeTab.value = "student";
+    }
   }
   }
 });
 });
 
 

+ 1 - 1
src/pages/students/tabs/StudentDataTab.vue

@@ -130,7 +130,7 @@
         v-model="form.payer"
         v-model="form.payer"
         :error="!!validationErrors.payer_name"
         :error="!!validationErrors.payer_name"
         :error-message="validationErrors.payer_name"
         :error-message="validationErrors.payer_name"
-        label="Pagador"
+        label="Responsável Financeiro"
         class="col-6"
         class="col-6"
       />
       />