Files
FEDEO/frontend/components/createDocumentFromTemplateModal.vue
root d90499a101
All checks were successful
Build and Push Docker Images / build-frontend (push) Successful in 1m22s
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-backend (push) Successful in 43s
Build and Push Docker Images / build-central-services-admin (push) Successful in 21s
Build and Push Docker Images / build-docs (push) Successful in 21s
Dokumentenvorlagen im Ausgangsbeleg-Editor ergänzen
2026-08-31 18:49:40 +00:00

95 lines
3.4 KiB
Vue

<script setup>
const dataStore = useDataStore()
const modal = useModal()
const router = useRouter()
const templates = ref([])
const selectedType = ref(null)
const loading = ref(true)
const props = defineProps({
queryStringData: { type: String, default: "" },
})
const documentTypes = computed(() => Object.entries(dataStore.documentTypesForCreation || {})
.filter(([key]) => key !== 'serialInvoices')
.map(([key, value]) => ({ key, ...value })))
const visibleTemplates = computed(() => templates.value.filter(template => {
return !selectedType.value || template.documentType === selectedType.value
}))
const loadTemplates = async () => {
try {
templates.value = await useEntities('documenttemplates').select('*')
} finally {
loading.value = false
}
}
const selectTemplate = (template) => {
const query = new URLSearchParams(props.queryStringData)
query.set('templateId', template.id)
query.set('type', template.documentType)
router.push(`/createDocument/edit?${query.toString()}`)
modal.close()
}
loadTemplates()
</script>
<template>
<UModal :ui="{ content: 'sm:max-w-3xl' }">
<template #content>
<UCard>
<template #header>
<div class="flex items-center justify-between">
<div>
<h2 class="text-lg font-semibold">Dokument aus Vorlage erstellen</h2>
<p class="mt-1 text-sm text-muted">Zuerst Dokumenttyp, anschließend die passende Vorlage auswählen.</p>
</div>
<UButton icon="i-heroicons-x-mark" color="gray" variant="ghost" @click="modal.close()" />
</div>
</template>
<UFormField label="Dokumenttyp" required>
<USelectMenu
v-model="selectedType"
:items="documentTypes"
value-key="key"
label-key="labelSingle"
class="w-full"
placeholder="Dokumenttyp auswählen"
/>
</UFormField>
<div class="mt-5 space-y-2">
<p class="text-sm font-medium text-highlighted">Vorlagen</p>
<div v-if="loading" class="py-6 text-center text-sm text-muted">Vorlagen werden geladen </div>
<div v-else-if="visibleTemplates.length === 0" class="rounded-lg border border-dashed border-default p-6 text-center text-sm text-muted">
Keine Vorlagen für diesen Dokumenttyp vorhanden.
</div>
<div v-else class="space-y-2">
<button
v-for="template in visibleTemplates"
:key="template.id"
type="button"
class="flex w-full items-center justify-between rounded-lg border border-default p-3 text-left transition hover:border-primary hover:bg-primary/5"
@click="selectTemplate(template)"
>
<span>
<span class="block font-medium text-highlighted">{{ template.name }}</span>
<span class="text-xs text-muted">{{ dataStore.documentTypesForCreation[template.documentType]?.labelSingle }}</span>
</span>
<UBadge v-if="template.default" color="primary" variant="soft">Standard</UBadge>
</button>
</div>
</div>
<template #footer>
<div class="flex justify-end">
<UButton color="neutral" variant="ghost" @click="modal.close()">Abbrechen</UButton>
</div>
</template>
</UCard>
</template>
</UModal>
</template>