From a5b604a265a3a138dd97f852f53dbc98af6fd07e Mon Sep 17 00:00:00 2001 From: burakovec Date: Tue, 31 Mar 2026 09:46:43 +0300 Subject: [PATCH] Refactor form handling in FormUyeBilgileri.vue and UyeBilgileriStore.ts to use async functions for data fetching. Update ChangeIl and ChangeIlce methods to clear dependent fields and handle empty selections, improving data integrity and user experience. Enhance SetIlIlce method to fetch ilce and mahalle lists based on selected values, ensuring accurate form data management. --- .../components/form/FormUyeBilgileri.vue | 33 ++++++++++++------- src/module/uyeler/stores/UyeBilgileriStore.ts | 24 +++++++++----- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/module/uyeler/components/form/FormUyeBilgileri.vue b/src/module/uyeler/components/form/FormUyeBilgileri.vue index b31b6ca..aa01d8c 100644 --- a/src/module/uyeler/components/form/FormUyeBilgileri.vue +++ b/src/module/uyeler/components/form/FormUyeBilgileri.vue @@ -446,14 +446,26 @@ const OnKeyup = () => { uyeBilgileriStore.formChanged = true } - const ChangeIl = (e: Event, v: string | number, d: Record) => { + const ChangeIl = async (e: Event, v: string | number, d: Record) => { uyeBilgileriStore.formData.ilceId = '' - uyeBilgileriStore.ilceList = d.ilceler + uyeBilgileriStore.formData.mahalleId = '' + uyeBilgileriStore.mahalleList = [] + if (Object.keys(d).length === 0) { + uyeBilgileriStore.ilceList = [] + uyeBilgileriStore.formChanged = true + return + } + uyeBilgileriStore.ilceList = await dataStore.GetIlcelerByIlId(v) uyeBilgileriStore.formChanged = true } - const ChangeIlce = (e: Event, v: string | number, d: Record) => { + const ChangeIlce = async (e: Event, v: string | number, d: Record) => { uyeBilgileriStore.formData.mahalleId = '' - uyeBilgileriStore.mahalleList = d.mahalleler + if (Object.keys(d).length === 0) { + uyeBilgileriStore.mahalleList = [] + uyeBilgileriStore.formChanged = true + return + } + uyeBilgileriStore.mahalleList = await dataStore.GetMahallelerByIlceId(v) uyeBilgileriStore.formChanged = true } @@ -511,7 +523,7 @@ Object.assign(uyeBilgileriStore.formData, data) globalStore.selCustomerType = uyeBilgileriStore.formData.basvuruTipId usersStore.userMail = data.email - uyeBilgileriStore.SetIlIlce() + await uyeBilgileriStore.SetIlIlce() uyeBilgileriStore.SetbasvuruTip() Object.assign(uyeBilgileriStore.safeData, uyeBilgileriStore.formData) @@ -545,14 +557,11 @@ }) watch( - () => route, - (to) => { - if(to.name === 'UyeYetkiliDetay'){ - GetData() + () => route.params.altUyeId, + async () => { + if (route.name === 'UyeYetkiliDetay') { + await GetData() } - }, - { - deep: true } ) diff --git a/src/module/uyeler/stores/UyeBilgileriStore.ts b/src/module/uyeler/stores/UyeBilgileriStore.ts index 77054d5..cf2e0d7 100644 --- a/src/module/uyeler/stores/UyeBilgileriStore.ts +++ b/src/module/uyeler/stores/UyeBilgileriStore.ts @@ -2,11 +2,13 @@ import { defineStore } from 'pinia' import { ref, reactive } from 'vue' import { useValidationStore } from '@/stores/validationStore' import { useGlobalDataStore } from '@/stores/globalDataStore' +import { useDataStore } from '@/stores/dataStore' import { useRoute } from 'vue-router' export const useUyeBilgileriStore = defineStore('uyeBilgileriStore', () => { const validationStore = useValidationStore() const globalDataStore = useGlobalDataStore() + const dataStore = useDataStore() const route = useRoute() const formChanged = ref(false) @@ -227,30 +229,34 @@ export const useUyeBilgileriStore = defineStore('uyeBilgileriStore', () => { (formData.sirketMersis = '') } } - const SetIlIlce = () => { + const SetIlIlce = async () => { if ( + formData.ilId !== undefined && + formData.ilId !== null && + formData.ilId !== '' && formData.ilceId !== undefined && formData.ilceId !== null && formData.ilceId !== '' ) { - let ilO = globalDataStore.ilList.filter((v: Record) => { - return v.id === formData.ilId - }) - ilceList.value.splice(0, ilceList.value.length, ...(ilO[0]['ilceler'] as Record[])) + const ilceler = await dataStore.GetIlcelerByIlId(formData.ilId) + ilceList.value.splice(0, ilceList.value.length, ...ilceler) } else { + ilceList.value = [] formData.ilceId = '' } if ( + formData.ilceId !== undefined && + formData.ilceId !== null && + formData.ilceId !== '' && formData.mahalleId !== undefined && formData.mahalleId !== null && formData.mahalleId !== '' ) { - let mahalleO = ilceList.value.filter((v: Record) => { - return v.id === formData.ilceId - }) - mahalleList.value.splice(0, mahalleList.value.length, ...mahalleO[0]['mahalleler']) + const mahalleler = await dataStore.GetMahallelerByIlceId(formData.ilceId) + mahalleList.value.splice(0, mahalleList.value.length, ...mahalleler) } else { + mahalleList.value = [] formData.mahalleId = '' } }