Refactor location selection methods in various components to use async data fetching. Update ChangeIl and ChangeIlce functions to clear dependent fields and handle empty selections, ensuring accurate form data management. Enhance error handling in data retrieval with skipErrorForStatuses option for improved user experience.

This commit is contained in:
burakovec
2026-03-31 10:03:24 +03:00
parent 2615e9b3ee
commit 2bbeea8c6f
5 changed files with 43 additions and 26 deletions

View File

@ -383,13 +383,23 @@
return uyeBilgileriStore.mahalleList.length === 0 return uyeBilgileriStore.mahalleList.length === 0
}) })
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
}
const ChangeIlce = (e: Event, v: string | number, d: Record<string, any>) => {
uyeBilgileriStore.formData.mahalleId = '' uyeBilgileriStore.formData.mahalleId = ''
uyeBilgileriStore.mahalleList = d.mahalleler uyeBilgileriStore.mahalleList = []
if (Object.keys(d).length === 0) {
uyeBilgileriStore.ilceList = []
return
}
uyeBilgileriStore.ilceList = await dataStore.GetIlcelerByIlId(v)
}
const ChangeIlce = async (e: Event, v: string | number, d: Record<string, any>) => {
uyeBilgileriStore.formData.mahalleId = ''
if (Object.keys(d).length === 0) {
uyeBilgileriStore.mahalleList = []
return
}
uyeBilgileriStore.mahalleList = await dataStore.GetMahallelerByIlceId(v)
} }
const PasswordCheck = (e: KeyboardEvent) => { const PasswordCheck = (e: KeyboardEvent) => {
if ( if (

View File

@ -38,10 +38,13 @@
const GetData = async () => { const GetData = async () => {
loaded.value = false loaded.value = false
let dt = await dataStore.dataGet( let dt = await dataStore.dataGet(
'IrtibatBilgi/GetIrtibatBilgiCekilis/' + piyangoStore.selectedLottery 'IrtibatBilgi/GetIrtibatBilgiCekilis/' + piyangoStore.selectedLottery,
{
skipErrorForStatuses: [404]
}
) )
if (dt !== 'errorfalse') { if (dt !== 'errorfalse' && !dt?._error) {
Object.assign(piyangoContactStore.contactData, dt) Object.assign(piyangoContactStore.contactData, dt)
} }
setTimeout(()=>{ setTimeout(()=>{

View File

@ -443,9 +443,14 @@
return piyangoStore.lotteryData.ilId === null || ilceList.value.length === 0 return piyangoStore.lotteryData.ilId === null || ilceList.value.length === 0
}) })
const ChangeIl = (e: Event, v: string | number, d: Record<string, any>) => { const ChangeIl = async (e: Event, v: string | number, d: Record<string, any>) => {
piyangoStore.lotteryData.ilceId = '' piyangoStore.lotteryData.ilceId = ''
ilceList.value = d.ilceler if (Object.keys(d).length === 0) {
ilceList.value = []
formChanged.value = true
return
}
ilceList.value = await dataStore.GetIlcelerByIlId(v)
formChanged.value = true formChanged.value = true
} }
const OnKeyup = () => { const OnKeyup = () => {
@ -474,11 +479,8 @@
piyangoStore.lotteryData.ilceId !== null && piyangoStore.lotteryData.ilceId !== null &&
piyangoStore.lotteryData.ilceId !== '' piyangoStore.lotteryData.ilceId !== ''
) { ) {
let ilO = globalDataStore.ilList.filter((v: Record<string, any>) => { const ilceler = await dataStore.GetIlcelerByIlId(piyangoStore.lotteryData.ilId)
return v.id === piyangoStore.lotteryData.ilId ilceList.value.splice(0, ilceList.value.length, ...(ilceler as IIl[]))
})
if (ilO.length !== 0)
ilceList.value.splice(0, ilceList.value.length, ...(ilO[0]['ilceler'] as IIl[]))
} }
if (piyangoStore.lotteryData.amacpiyangoId === 2) { if (piyangoStore.lotteryData.amacpiyangoId === 2) {

View File

@ -87,11 +87,14 @@
const GetData = async () => { const GetData = async () => {
loaded.value = false loaded.value = false
let dt = await dataStore.dataGet( let dt = await dataStore.dataGet(
'IrtibatBilgi/GetIrtibatBilgiCekilis/' + piyangoStore.selectedLottery 'IrtibatBilgi/GetIrtibatBilgiCekilis/' + piyangoStore.selectedLottery,
{
skipErrorForStatuses: [404]
}
) )
piyangoContactStore.ResetFormData() piyangoContactStore.ResetFormData()
if (dt !== 'errorfalse') { if (dt !== 'errorfalse' && !dt?._error) {
Object.assign(piyangoContactStore.contactData, dt) Object.assign(piyangoContactStore.contactData, dt)
Object.assign(piyangoContactStore.safeContactData, dt) Object.assign(piyangoContactStore.safeContactData, dt)
} else { } else {

View File

@ -255,7 +255,7 @@
label="İlçe" label="İlçe"
:listData="ilceList" :listData="ilceList"
listText="ad" listText="ad"
listVal="id" listVal="ad"
modelKey="ilce" modelKey="ilce"
v-model="piyangoKatilimciStore.piyangoKatilimciUserFormData.ilce" v-model="piyangoKatilimciStore.piyangoKatilimciUserFormData.ilce"
:invalidText="piyangoKatilimciValidationStore.userFormInvalidTexts.ilce" :invalidText="piyangoKatilimciValidationStore.userFormInvalidTexts.ilce"
@ -391,13 +391,14 @@
piyangoKatilimciValidationStore.userFormChanged = true piyangoKatilimciValidationStore.userFormChanged = true
} }
const ChangeIl = (e: Event, v: string | number, d: Record<string, any>) => { const ChangeIl = async (e: Event, v: string | number, d: Record<string, any>) => {
piyangoKatilimciStore.piyangoKatilimciUserFormData.ilce = '' piyangoKatilimciStore.piyangoKatilimciUserFormData.ilce = ''
if (Object.keys(d).length === 0) { if (Object.keys(d).length === 0) {
ilceList.value = [] ilceList.value = []
return return
} }
ilceList.value.splice(0, ilceList.value.length, ...d.ilceler) const ilceler = await dataStore.GetIlcelerByIlId(d.id)
ilceList.value.splice(0, ilceList.value.length, ...ilceler)
piyangoKatilimciValidationStore.userFormChanged = true piyangoKatilimciValidationStore.userFormChanged = true
} }
const ilceDisabled = computed<boolean>(() => { const ilceDisabled = computed<boolean>(() => {
@ -417,13 +418,11 @@
piyangoKatilimciStore.piyangoKatilimciUserFormData.ilce !== null && piyangoKatilimciStore.piyangoKatilimciUserFormData.ilce !== null &&
piyangoKatilimciStore.piyangoKatilimciUserFormData.ilce !== '' piyangoKatilimciStore.piyangoKatilimciUserFormData.ilce !== ''
) { ) {
let ilO: Record<string, any>[] = globalDataStore.ilList.filter( const selectedIl = dataStore.GetIlByName(piyangoKatilimciStore.piyangoKatilimciUserFormData.il)
(v: Record<string, any>) => { if (selectedIl !== undefined) {
return v.ad === piyangoKatilimciStore.piyangoKatilimciUserFormData.il const ilceler = await dataStore.GetIlcelerByIlId(selectedIl.id)
ilceList.value.splice(0, ilceList.value.length, ...ilceler)
} }
)
if (ilO.length !== 0)
ilceList.value.splice(0, ilceList.value.length, ...ilO[0]['ilceler'])
} }
}) })
</script> </script>