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.

This commit is contained in:
burakovec
2026-03-31 09:46:43 +03:00
parent 5557ecf52b
commit a5b604a265
2 changed files with 36 additions and 21 deletions

View File

@ -446,14 +446,26 @@
const OnKeyup = () => { const OnKeyup = () => {
uyeBilgileriStore.formChanged = true uyeBilgileriStore.formChanged = true
} }
const ChangeIl = (e: Event, v: string | number, d: Record<string, any>) => { const ChangeIl = async (e: Event, v: string | number, d: Record<string, any>) => {
uyeBilgileriStore.formData.ilceId = '' 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 uyeBilgileriStore.formChanged = true
} }
const ChangeIlce = (e: Event, v: string | number, d: Record<string, any>) => { const ChangeIlce = async (e: Event, v: string | number, d: Record<string, any>) => {
uyeBilgileriStore.formData.mahalleId = '' 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 uyeBilgileriStore.formChanged = true
} }
@ -511,7 +523,7 @@
Object.assign(uyeBilgileriStore.formData, data) Object.assign(uyeBilgileriStore.formData, data)
globalStore.selCustomerType = uyeBilgileriStore.formData.basvuruTipId globalStore.selCustomerType = uyeBilgileriStore.formData.basvuruTipId
usersStore.userMail = data.email usersStore.userMail = data.email
uyeBilgileriStore.SetIlIlce() await uyeBilgileriStore.SetIlIlce()
uyeBilgileriStore.SetbasvuruTip() uyeBilgileriStore.SetbasvuruTip()
Object.assign(uyeBilgileriStore.safeData, uyeBilgileriStore.formData) Object.assign(uyeBilgileriStore.safeData, uyeBilgileriStore.formData)
@ -545,14 +557,11 @@
}) })
watch( watch(
() => route, () => route.params.altUyeId,
(to) => { async () => {
if(to.name === 'UyeYetkiliDetay'){ if (route.name === 'UyeYetkiliDetay') {
GetData() await GetData()
} }
},
{
deep: true
} }
) )
</script> </script>

View File

@ -2,11 +2,13 @@ import { defineStore } from 'pinia'
import { ref, reactive } from 'vue' import { ref, reactive } from 'vue'
import { useValidationStore } from '@/stores/validationStore' import { useValidationStore } from '@/stores/validationStore'
import { useGlobalDataStore } from '@/stores/globalDataStore' import { useGlobalDataStore } from '@/stores/globalDataStore'
import { useDataStore } from '@/stores/dataStore'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
export const useUyeBilgileriStore = defineStore('uyeBilgileriStore', () => { export const useUyeBilgileriStore = defineStore('uyeBilgileriStore', () => {
const validationStore = useValidationStore() const validationStore = useValidationStore()
const globalDataStore = useGlobalDataStore() const globalDataStore = useGlobalDataStore()
const dataStore = useDataStore()
const route = useRoute() const route = useRoute()
const formChanged = ref<boolean>(false) const formChanged = ref<boolean>(false)
@ -227,30 +229,34 @@ export const useUyeBilgileriStore = defineStore('uyeBilgileriStore', () => {
(formData.sirketMersis = '') (formData.sirketMersis = '')
} }
} }
const SetIlIlce = () => { const SetIlIlce = async () => {
if ( if (
formData.ilId !== undefined &&
formData.ilId !== null &&
formData.ilId !== '' &&
formData.ilceId !== undefined && formData.ilceId !== undefined &&
formData.ilceId !== null && formData.ilceId !== null &&
formData.ilceId !== '' formData.ilceId !== ''
) { ) {
let ilO = globalDataStore.ilList.filter((v: Record<string, any>) => { const ilceler = await dataStore.GetIlcelerByIlId(formData.ilId)
return v.id === formData.ilId ilceList.value.splice(0, ilceList.value.length, ...ilceler)
})
ilceList.value.splice(0, ilceList.value.length, ...(ilO[0]['ilceler'] as Record<string,any>[]))
} else { } else {
ilceList.value = []
formData.ilceId = '' formData.ilceId = ''
} }
if ( if (
formData.ilceId !== undefined &&
formData.ilceId !== null &&
formData.ilceId !== '' &&
formData.mahalleId !== undefined && formData.mahalleId !== undefined &&
formData.mahalleId !== null && formData.mahalleId !== null &&
formData.mahalleId !== '' formData.mahalleId !== ''
) { ) {
let mahalleO = ilceList.value.filter((v: Record<string, any>) => { const mahalleler = await dataStore.GetMahallelerByIlceId(formData.ilceId)
return v.id === formData.ilceId mahalleList.value.splice(0, mahalleList.value.length, ...mahalleler)
})
mahalleList.value.splice(0, mahalleList.value.length, ...mahalleO[0]['mahalleler'])
} else { } else {
mahalleList.value = []
formData.mahalleId = '' formData.mahalleId = ''
} }
} }