74 lines
2.6 KiB
Vue
74 lines
2.6 KiB
Vue
<template>
|
|
<div class="flex items-center justify-between">
|
|
<h1 class="text-4xl font-bold uppercase text-primary-500">Liste des fournisseurs</h1>
|
|
</div>
|
|
|
|
<div v-if="auth.isAdmin" class="mt-7 border border-slate-200 mb-11">
|
|
<div class="max-h-96 overflow-y-auto">
|
|
<div
|
|
class="sticky text-primary-700 top-0 z-10 grid grid-cols-4 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide"
|
|
>
|
|
<div>Nom</div>
|
|
<div>Téléphone</div>
|
|
<div>Mail</div>
|
|
<div>Créé par</div>
|
|
</div>
|
|
|
|
<div v-if="supplierList.length === 0" class="px-4 py-6 text-slate-400">
|
|
Aucun fournisseur.
|
|
</div>
|
|
|
|
<div
|
|
v-for="supplier in supplierList"
|
|
:key="supplier.id"
|
|
class="grid grid-cols-4 text-primary-700 hover:bg-slate-50 border-t gap-4 px-4 py-2 cursor-pointer"
|
|
@click="goToSupplier(supplier.id)"
|
|
>
|
|
<div class="truncate">{{ supplier.name || "—" }}</div>
|
|
<div class="truncate">{{ supplier.phone || "—" }}</div>
|
|
<div class="truncate">{{ supplier.email || "—" }}</div>
|
|
<div class="truncate">{{ supplier.createdBy?.username || "—" }}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div v-else class="mt-7 border border-slate-200 mb-11 px-4 py-6 text-slate-400">
|
|
Accès réservé aux administrateurs.
|
|
</div>
|
|
<div class="flex justify-center items-center">
|
|
<NuxtLink
|
|
to="/admin/supplier"
|
|
class="inline-flex items-center mb-16 justify-center text-xl text-white uppercase bg-primary-500 h-[50px] px-8 rounded hover:opacity-80 gap-2"
|
|
:class="auth.isAdmin ? '' : 'cursor-not-allowed opacity-60'"
|
|
@click="handleAddClick"
|
|
>
|
|
<Icon name="mdi:plus" size="28" />
|
|
Ajouter
|
|
</NuxtLink>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { getSupplierList } from "~/services/supplier"
|
|
import type { SupplierData } from "~/services/dto/supplier-data"
|
|
import { useAuthStore } from "~/stores/auth"
|
|
|
|
const supplierList = ref<SupplierData[]>([])
|
|
const router = useRouter()
|
|
const auth = useAuthStore()
|
|
|
|
const goToSupplier = (id: number) => {
|
|
if (!auth.isAdmin) return
|
|
router.push(`/admin/supplier/${id}`)
|
|
}
|
|
|
|
const handleAddClick = (event: Event) => {
|
|
if (auth.isAdmin) return
|
|
event.preventDefault()
|
|
}
|
|
|
|
onMounted(async () => {
|
|
if (!auth.isAdmin) return
|
|
supplierList.value = await getSupplierList()
|
|
})
|
|
</script>
|