226 lines
5.7 KiB
Vue
226 lines
5.7 KiB
Vue
<script setup>
|
|
definePageMeta({
|
|
middleware: "auth"
|
|
})
|
|
|
|
const dataStore = useDataStore()
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
const toast = useToast()
|
|
const id = ref(route.params.id ? route.params.id : null )
|
|
|
|
|
|
let currentItem = ref(null)
|
|
|
|
//Working
|
|
const mode = ref(route.params.mode || "show")
|
|
const itemInfo = ref({
|
|
active: true
|
|
})
|
|
|
|
//Functions
|
|
const setupPage = () => {
|
|
if(mode.value === "show" || mode.value === "edit"){
|
|
currentItem = dataStore.getContactById(Number(useRoute().params.id))
|
|
}
|
|
|
|
if(mode.value === "edit") itemInfo.value = currentItem
|
|
|
|
if(mode.value === "create") {
|
|
let query = route.query
|
|
|
|
if(query.customer) itemInfo.value.customer = Number(query.customer)
|
|
if(query.vendor) itemInfo.value.vendor = Number(query.vendor)
|
|
}
|
|
}
|
|
|
|
const cancelEditorCreate = () => {
|
|
if(currentItem.value) {
|
|
router.push(`/contacts/show/${currentItem.value.id}`)
|
|
} else {
|
|
router.push(`/contacts`)
|
|
}
|
|
|
|
}
|
|
|
|
setupPage()
|
|
</script>
|
|
|
|
<template>
|
|
<UDashboardNavbar :title="currentItem ? currentItem.fullName : (mode === 'create' ? 'Ansprechpartner erstellen' : 'Ansprechpartner bearbeiten')">
|
|
<template #right>
|
|
<UButton
|
|
v-if="mode === 'edit'"
|
|
@click="dataStore.updateItem('contacts',{...itemInfo, fullName: itemInfo.firstName + ' ' + itemInfo.lastName})"
|
|
>
|
|
Speichern
|
|
</UButton>
|
|
<UButton
|
|
v-else-if="mode === 'create'"
|
|
@click="dataStore.createNewItem('contacts',{...itemInfo, fullName: itemInfo.firstName + ' ' + itemInfo.lastName})"
|
|
>
|
|
Erstellen
|
|
</UButton>
|
|
<UButton
|
|
@click="cancelEditorCreate"
|
|
color="red"
|
|
class="ml-2"
|
|
v-if="mode === 'edit' || mode === 'create'"
|
|
>
|
|
Abbrechen
|
|
</UButton>
|
|
<UButton
|
|
v-if="mode === 'show'"
|
|
@click="router.push(`/contacts/edit/${currentItem.id}`)"
|
|
>
|
|
Bearbeiten
|
|
</UButton>
|
|
</template>
|
|
<template #badge v-if="currentItem">
|
|
<UBadge
|
|
v-if="currentItem.active"
|
|
>
|
|
Kontakt aktiv
|
|
</UBadge>
|
|
<UBadge
|
|
v-else
|
|
color="red"
|
|
>
|
|
Kontakt inaktiv
|
|
</UBadge>
|
|
</template>
|
|
</UDashboardNavbar>
|
|
<UTabs
|
|
:items="[{label: 'Informationen'}, {label: 'Logbuch'}]"
|
|
v-if="currentItem && mode == 'show'"
|
|
class="p-5"
|
|
>
|
|
<template #item="{item}">
|
|
<UCard class="mt-5">
|
|
<div v-if="item.label === 'Informationen'">
|
|
|
|
|
|
<div class="text-wrap mt-3">
|
|
<p v-if="currentItem.customer">Kunde: <nuxt-link :to="`/customers/show/${currentItem.customer}`">{{dataStore.customers.find(customer => customer.id === currentItem.customer) ? dataStore.customers.find(customer => customer.id === currentItem.customer).name : "" }}</nuxt-link></p>
|
|
<p v-if="currentItem.vendor">Lieferant: <nuxt-link :to="`/vendors/show/${currentItem.vendor}`">{{dataStore.vendors.find(vendor => vendor.id === currentItem.vendor) ? dataStore.vendors.find(vendor => vendor.id === currentItem.vendor).name : ""}}</nuxt-link></p>
|
|
|
|
|
|
<p>E-Mail: {{currentItem.email}}</p>
|
|
<p>Mobil: {{currentItem.phoneMobile}}</p>
|
|
<p>Festnetz: {{currentItem.phoneHome}}</p>
|
|
<p>Rolle: {{currentItem.role}}</p>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
<div v-else-if="item.label === 'Logbuch'">
|
|
<HistoryDisplay
|
|
type="contact"
|
|
v-if="currentItem"
|
|
:element-id="currentItem.id"
|
|
/>
|
|
</div>
|
|
</UCard>
|
|
</template>
|
|
</UTabs>
|
|
<UForm
|
|
v-else-if="mode == 'edit' || mode == 'create'"
|
|
class="p-5"
|
|
>
|
|
<UFormGroup
|
|
label="Anrede:"
|
|
>
|
|
<UInput
|
|
v-model="itemInfo.salutation"
|
|
/>
|
|
</UFormGroup>
|
|
<UFormGroup
|
|
label="Vorname:"
|
|
>
|
|
<UInput
|
|
v-model="itemInfo.firstName"
|
|
/>
|
|
</UFormGroup>
|
|
<UFormGroup
|
|
label="Nachname:"
|
|
>
|
|
<UInput
|
|
v-model="itemInfo.lastName"
|
|
/>
|
|
</UFormGroup>
|
|
|
|
<UFormGroup
|
|
label="Kunde:"
|
|
>
|
|
<USelectMenu
|
|
v-model="itemInfo.customer"
|
|
option-attribute="name"
|
|
value-attribute="id"
|
|
:options="dataStore.customers"
|
|
searchable
|
|
:search-attributes="['name']"
|
|
>
|
|
<template #label>
|
|
{{dataStore.customers.find(customer => customer.id === itemInfo.customer) ? dataStore.customers.find(customer => customer.id === itemInfo.customer).name : "Kunde auswählen"}}
|
|
</template>
|
|
</USelectMenu>
|
|
</UFormGroup>
|
|
<UFormGroup
|
|
label="Lieferant:"
|
|
>
|
|
<USelectMenu
|
|
v-model="itemInfo.vendor"
|
|
option-attribute="name"
|
|
value-attribute="id"
|
|
:options="dataStore.vendors"
|
|
searchable
|
|
:search-attributes="['name']"
|
|
>
|
|
<template #label>
|
|
{{dataStore.vendors.find(vendor => vendor.id === itemInfo.vendor) ? dataStore.vendors.find(vendor => vendor.id === itemInfo.vendor).name : "Lieferant auswählen"}}
|
|
</template>
|
|
</USelectMenu>
|
|
</UFormGroup>
|
|
|
|
<UFormGroup
|
|
label="Kontakt aktiv:"
|
|
>
|
|
<UCheckbox
|
|
v-model="itemInfo.active"
|
|
/>
|
|
</UFormGroup>
|
|
|
|
<UFormGroup
|
|
label="E-Mail:"
|
|
>
|
|
<UInput
|
|
v-model="itemInfo.email"
|
|
/>
|
|
</UFormGroup>
|
|
<UFormGroup
|
|
label="Mobil:"
|
|
>
|
|
<UInput
|
|
v-model="itemInfo.phoneMobile"
|
|
/>
|
|
</UFormGroup>
|
|
<UFormGroup
|
|
label="Festnetz:"
|
|
>
|
|
<UInput
|
|
v-model="itemInfo.phoneHome"
|
|
/>
|
|
</UFormGroup>
|
|
<UFormGroup
|
|
label="Rolle:"
|
|
>
|
|
<UInput
|
|
v-model="itemInfo.role"
|
|
/>
|
|
</UFormGroup>
|
|
</UForm>
|
|
</template>
|
|
|
|
<style scoped>
|
|
|
|
</style> |