Added Automatic ZIP Completion

This commit is contained in:
2024-04-10 11:14:57 +02:00
parent bf04b9c563
commit bb158c1353
3 changed files with 29 additions and 19 deletions

View File

@@ -0,0 +1,11 @@
export const useZipCheck = async (zip) => {
const supabase = useSupabaseClient()
console.log((await supabase.from("citys").select().eq("zip",Number(zip)).maybeSingle()).data)
const result = (await supabase.from("citys").select().eq("zip",Number(zip)).maybeSingle()).data
return result ? result.short : null
}

View File

@@ -1,4 +1,5 @@
<script setup> <script setup>
definePageMeta({ definePageMeta({
middleware: "auth" middleware: "auth"
}) })
@@ -48,6 +49,10 @@ const cancelEditorCreate = () => {
} }
const setCityByZip = async () => {
itemInfo.value.infoData.city = await useZipCheck(itemInfo.value.infoData.zip)
}
setupPage() setupPage()
</script> </script>
@@ -301,6 +306,7 @@ setupPage()
> >
<UInput <UInput
v-model="itemInfo.infoData.zip" v-model="itemInfo.infoData.zip"
@focusout="setCityByZip"
/> />
</UFormGroup> </UFormGroup>
<UFormGroup <UFormGroup

View File

@@ -32,16 +32,8 @@ const setupPage = () => {
} }
const editItem = async () => { const setCityByZip = async () => {
router.push(`/vendors/edit/${currentItem.value.id}`) itemInfo.value.infoData.city = await useZipCheck(itemInfo.value.infoData.zip)
}
const cancelEditorCreate = () => {
if(currentItem.value) {
router.push(`/vendors/show/${currentItem.value.id}`)
} else {
router.push(`/vendors`)
}
} }
setupPage() setupPage()
@@ -63,7 +55,7 @@ setupPage()
Erstellen Erstellen
</UButton> </UButton>
<UButton <UButton
@click="cancelEditorCreate" @click="router.push(currentItem.id ? `/vendors/show/${currentItem.id}` : '/vendors/show')"
color="red" color="red"
class="ml-2" class="ml-2"
v-if="mode === 'edit' || mode === 'create'" v-if="mode === 'edit' || mode === 'create'"
@@ -72,7 +64,7 @@ setupPage()
</UButton> </UButton>
<UButton <UButton
v-if="mode === 'show'" v-if="mode === 'show'"
@click="editItem" @click="router.push(`/vendors/edit/${currentItem.id}`)"
> >
Bearbeiten Bearbeiten
</UButton> </UButton>
@@ -88,13 +80,13 @@ setupPage()
<div class="w-1/2 mr-5"> <div class="w-1/2 mr-5">
<UCard> <UCard>
<div v-if="currentItem.infoData" class="text-wrap"> <div v-if="currentItem.infoData" class="text-wrap">
<p v-if="currentItem.infoData.street">Straße + Hausnummer: {{currentItem.infoData.street}}</p> <p>Straße + Hausnummer: {{currentItem.infoData.street ? currentItem.infoData.street : ""}}</p>
<p v-if="currentItem.infoData.zip && currentItem.infoData.city">PLZ + Ort: {{currentItem.infoData.zip}} {{currentItem.infoData.city}}</p> <p>PLZ + Ort: {{currentItem.infoData.zip}} {{currentItem.infoData.city}}</p>
<p v-if="currentItem.infoData.tel">Telefon: {{currentItem.infoData.tel}}</p> <p>Telefon: {{currentItem.infoData.tel}}</p>
<p v-if="currentItem.infoData.email">E-Mail: {{currentItem.infoData.email}}</p> <p>E-Mail: {{currentItem.infoData.email}}</p>
<p v-if="currentItem.infoData.web">Web: {{currentItem.infoData.web}}</p> <p>Web: {{currentItem.infoData.web}}</p>
<p v-if="currentItem.infoData.ustid">USt-Id: {{currentItem.infoData.ustid}}</p> <p>USt-Id: {{currentItem.infoData.ustid}}</p>
<p v-if="currentItem.notes">Notizen:<br> {{currentItem.notes}}</p> <p>Notizen:<br> {{currentItem.notes}}</p>
</div> </div>
</UCard> </UCard>
<UCard class="mt-5"> <UCard class="mt-5">
@@ -176,6 +168,7 @@ setupPage()
> >
<UInput <UInput
v-model="itemInfo.infoData.zip" v-model="itemInfo.infoData.zip"
@focusout="setCityByZip"
/> />
</UFormGroup> </UFormGroup>
<UFormGroup <UFormGroup