Denis 1 жил өмнө
parent
commit
d1dec3e6c2

+ 12 - 2
src/components/regions/CountrySelect.vue

@@ -9,7 +9,9 @@
     :options="countryOptions"
     :label="label"
     :loading="loading"
-    :placeholder="$t('common.actions.search') + ' ' + $t('ui.navigation.country')"
+    :placeholder="
+      $t('common.actions.search') + ' ' + $t('ui.navigation.country')
+    "
     :rules="rules"
     @filter="filterFn"
   >
@@ -28,7 +30,7 @@ import { getCountries } from "src/api/country";
 import { ref, onMounted } from "vue";
 import { useI18n } from "vue-i18n";
 
-const { label, rules } = defineProps({
+const { label, rules, initialId } = defineProps({
   label: {
     type: String,
     default: () => useI18n().t("ui.navigation.country"),
@@ -37,6 +39,11 @@ const { label, rules } = defineProps({
     type: Array,
     default: () => [],
   },
+  initialId: {
+    type: Number,
+    required: false,
+    default: null,
+  },
 });
 
 const selectedCountry = defineModel();
@@ -83,6 +90,9 @@ onMounted(async () => {
       label: country.name,
       value: country.id,
     }));
+    if (initialId) {
+      selectCountryById(initialId);
+    }
   } catch (e) {
     console.log(e);
   } finally {

+ 5 - 4
src/pages/city/components/AddEditCityDialog.vue

@@ -20,6 +20,7 @@
           <StateSelect
             v-model="selectedState"
             :country="selectedCountry"
+            :initial-id="form.state_id"
             :label="$t('ui.navigation.state')"
             :rules="[inputRules.required]"
             class="col-md-6 col-12"
@@ -87,10 +88,10 @@ const formRef = useTemplateRef("formRef");
 const countrySelectRef = useTemplateRef("countrySelectRef");
 
 const { form, getUpdatedFields, hasUpdatedFields } = useFormUpdateTracker({
-  name: city ? city.name : "",
-  country_id: city ? city.country_id : null,
-  state_id: city ? city.state_id : null,
-  status: city ? city.status : "ACTIVE",
+  name: city ? city?.name : "",
+  country_id: city ? city?.country_id : null,
+  state_id: city ? city?.state_id : null,
+  status: city ? city?.status : "ACTIVE",
 });
 
 const loading = ref(false);

+ 3 - 3
src/pages/country/components/AddEditCountryDialog.vue

@@ -75,9 +75,9 @@ const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } =
 const formRef = useTemplateRef("formRef");
 
 const { form, getUpdatedFields, hasUpdatedFields } = useFormUpdateTracker({
-  name: country ? country.name : "",
-  code: country ? country.code : "",
-  status: country ? country.status : "ACTIVE",
+  name: country ? country?.name : "",
+  code: country ? country?.code : "",
+  status: country ? country?.status : "ACTIVE",
 });
 
 const loading = ref(false);

+ 5 - 4
src/pages/state/components/AddEditStateDialog.vue

@@ -20,6 +20,7 @@
             v-model="selectedCountry"
             :label="$t('ui.navigation.country')"
             :rules="[inputRules.required]"
+            :initial-id="form.country_id"
             class="col-md-6 col-12"
           />
           <q-select
@@ -82,10 +83,10 @@ const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } =
 const formRef = useTemplateRef("formRef");
 
 const { form, getUpdatedFields, hasUpdatedFields } = useFormUpdateTracker({
-  name: state ? state.name : "",
-  code: state ? state.code : "",
-  country_id: state ? state.country_id : null,
-  status: state ? state.status : "ACTIVE",
+  name: state ? state?.name : "",
+  code: state ? state?.code : "",
+  country_id: state ? state?.country_id : null,
+  status: state ? state?.status : "ACTIVE",
 });
 
 const loading = ref(false);