ソースを参照

fix: corrige select de status

ebagabee 2 週間 前
コミット
4a874ba647

+ 10 - 1
src/components/selects/StateSelect.vue

@@ -24,7 +24,7 @@
 
 <script setup>
 import { getStates } from "src/api/state";
-import { ref, onMounted, watch } from "vue";
+import { ref, onMounted, watch, computed } from "vue";
 import { normalizeString } from "src/helpers/utils";
 import { useI18n } from "vue-i18n";
 import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
@@ -123,6 +123,15 @@ watch(selectedState, () => {
   }
 });
 
+watch(
+  () => initialId,
+  (newId) => {
+    if (newId && baseOptions.value.length > 0) {
+      selectStateById(newId);
+    }
+  },
+);
+
 onMounted(async () => {
   try {
     const baseStates = await getStates();

+ 10 - 1
src/components/selects/UnitSelect.vue

@@ -23,7 +23,7 @@
 </template>
 
 <script setup>
-import { onMounted, ref } from "vue";
+import { onMounted, ref, watch } from "vue";
 import { getUnitsForSelect } from "src/api/unit";
 import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
 
@@ -71,5 +71,14 @@ onMounted(async () => {
   }
 });
 
+watch(
+  () => initialId,
+  (newId) => {
+    if (newId && unitOptions.value.length > 0) {
+      selectUnitById(newId);
+    }
+  },
+);
+
 defineExpose({ selectUnitById });
 </script>

+ 10 - 1
src/components/selects/UserTypeSelect.vue

@@ -15,7 +15,7 @@
 </template>
 
 <script setup>
-import { onMounted, ref } from "vue";
+import { onMounted, ref, watch } from "vue";
 import { userTypes } from "src/api/user";
 import { useI18n } from "vue-i18n";
 import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
@@ -82,6 +82,15 @@ onMounted(async () => {
   }
 });
 
+watch(
+  () => type,
+  (newType) => {
+    if (newType && userTypeOptions.value.length > 0) {
+      selectUserByValue(newType);
+    }
+  },
+);
+
 defineExpose({
   selectUserByValue,
 });

+ 3 - 0
src/pages/users/UserActionPage.vue

@@ -26,6 +26,7 @@
               class="col-6"
               outlined
               label="Unidade"
+              :initial-id="editUnitId"
             />
 
             <UserTypeSelect
@@ -170,6 +171,7 @@ const showPasswordConfirm = ref(false);
 
 const editUserTypeValue = ref(null);
 const editStateId = ref(null);
+const editUnitId = ref(null);
 
 const isEdit = computed(() => !!route.params.id);
 
@@ -200,6 +202,7 @@ onMounted(async () => {
     form.value.cpf = user.cpf;
     editUserTypeValue.value = user.user_type;
     editStateId.value = user.state_id ?? null;
+    editUnitId.value = user.unit_id ?? null;
     if (user.avatar_url) {
       avatarRef.value?.setImageUrl(user.avatar_url);
     }