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 = () => {
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.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<string, any>) => {
const ChangeIlce = async (e: Event, v: string | number, d: Record<string, any>) => {
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
}
)
</script>

View File

@ -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<boolean>(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<string, any>) => {
return v.id === formData.ilId
})
ilceList.value.splice(0, ilceList.value.length, ...(ilO[0]['ilceler'] as Record<string,any>[]))
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<string, any>) => {
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 = ''
}
}