Added Keyboard Controls for Tab Nav and Back to List Added Select On Enter for First Entry in Search for Customers and Vendors
149 lines
3.4 KiB
Vue
149 lines
3.4 KiB
Vue
<template>
|
|
<UDashboardNavbar title="Kunden" :badge="filteredRows.length">
|
|
<template #right>
|
|
<UInput
|
|
id="searchinput"
|
|
name="searchinput"
|
|
v-model="searchString"
|
|
icon="i-heroicons-funnel"
|
|
autocomplete="off"
|
|
placeholder="Suche..."
|
|
class="hidden lg:block"
|
|
@keydown.esc="$event.target.blur()"
|
|
>
|
|
<template #trailing>
|
|
<UKbd value="/" />
|
|
</template>
|
|
</UInput>
|
|
|
|
<UButton @click="router.push(`/customers/create/`)">+ Kunde</UButton>
|
|
|
|
</template>
|
|
</UDashboardNavbar>
|
|
|
|
<UDashboardToolbar>
|
|
<template #right>
|
|
<USelectMenu
|
|
v-model="selectedColumns"
|
|
icon="i-heroicons-adjustments-horizontal-solid"
|
|
:options="templateColumns"
|
|
multiple
|
|
class="hidden lg:block"
|
|
by="key"
|
|
>
|
|
<template #label>
|
|
Spalten
|
|
</template>
|
|
</USelectMenu>
|
|
</template>
|
|
</UDashboardToolbar>
|
|
|
|
<UTable
|
|
:rows="filteredRows"
|
|
:columns="columns"
|
|
class="w-full"
|
|
:ui="{ divide: 'divide-gray-200 dark:divide-gray-800' }"
|
|
@select="(i) => router.push(`/customers/show/${i.id}`) "
|
|
:empty-state="{ icon: 'i-heroicons-circle-stack-20-solid', label: 'Keine Kunden anzuzeigen' }"
|
|
>
|
|
<template #isCompany-data="{row}">
|
|
<span v-if="row.isCompany">Firmenkunden</span>
|
|
<span v-else>Privatkunde</span>
|
|
</template>
|
|
<template #active-data="{row}">
|
|
<span v-if="row.active" class="text-primary-500">Aktiv</span>
|
|
<span v-else class="text-rose-500">Gesperrt</span>
|
|
</template>
|
|
<template #address-data="{row}">
|
|
{{row.infoData.street ? `${row.infoData.street}, ` : ''}}{{row.infoData.special ? `${row.infoData.special},` : ''}} {{row.infoData.zip ? row.infoData.zip : ""}} {{row.infoData.city ? `${row.infoData.city}, ` : ''}} {{row.infoData.country}}
|
|
</template>
|
|
</UTable>
|
|
</template>
|
|
|
|
<script setup>
|
|
definePageMeta({
|
|
middleware: "auth"
|
|
})
|
|
|
|
defineShortcuts({
|
|
'/': () => {
|
|
//console.log(searchinput)
|
|
//searchinput.value.focus()
|
|
document.getElementById("searchinput").focus()
|
|
},
|
|
'+': () => {
|
|
router.push("/customers/create")
|
|
},
|
|
'enter': {
|
|
usingInput: "searchinput",
|
|
handler: () => {
|
|
router.push(`/customers/show/${selectedEntry.value}`)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
const dataStore = useDataStore()
|
|
const router = useRouter()
|
|
|
|
const templateColumns = [
|
|
{
|
|
key: 'customerNumber',
|
|
label: "Kundennr.",
|
|
sortable: true
|
|
},
|
|
{
|
|
key: "name",
|
|
label: "Name",
|
|
sortable: true
|
|
},
|
|
{
|
|
key: "isCompany",
|
|
label: "Typ",
|
|
sortable: true
|
|
},
|
|
{
|
|
key: "notes",
|
|
label: "Notizen",
|
|
sortable: true
|
|
},
|
|
{
|
|
key: "active",
|
|
label: "Aktiv",
|
|
sortable: true
|
|
},
|
|
{
|
|
key: "address",
|
|
label: "Adresse",
|
|
sortable: true
|
|
}
|
|
]
|
|
const selectedColumns = ref(templateColumns)
|
|
const columns = computed(() => templateColumns.filter((column) => selectedColumns.value.includes(column)))
|
|
|
|
|
|
const searchString = ref('')
|
|
const selectedEntry = ref(null)
|
|
|
|
const filteredRows = computed(() => {
|
|
if(!searchString.value) {
|
|
return dataStore.customers
|
|
}
|
|
|
|
let results = dataStore.customers.filter(item => {
|
|
return Object.values(item).some((value) => {
|
|
return String(value).toLowerCase().includes(searchString.value.toLowerCase())
|
|
})
|
|
})
|
|
|
|
selectedEntry.value = results[0].id
|
|
|
|
return results
|
|
})
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
</style> |