102 lines
3.6 KiB
Vue
102 lines
3.6 KiB
Vue
<template>
|
|
<div class="flex justify-center">
|
|
<div class="flex flex-col items-center w-[660px]">
|
|
<h1 class="font-bold text-5xl uppercase text-primary-500">{{ title }}</h1>
|
|
<!--@TODO Voir comment faire pour savoir si le pont-bascule et bien connecté + ajouter un icon comme sur la maquette-->
|
|
<p class="text-primary-500 uppercase text-2xl text-primary-500 mt-2">Pont-bascule connecté</p>
|
|
<div
|
|
v-if="showLoadingBox"
|
|
class="w-full flex flex-col items-center justify-center border border-black h-[90px] mt-12 mb-[86px]">
|
|
<UiLoadingDots />
|
|
</div>
|
|
<div v-else-if="displayWeight !== null" class="w-full">
|
|
<div
|
|
class="w-full flex flex-col items-center justify-center border border-black h-[90px] mt-12 mb-[25px] text-4xl text-primary-500">
|
|
{{ displayWeight }} kg
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="flex justify-center mt-[54px]">
|
|
<UiButton
|
|
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
@click="fetchWeight"
|
|
>{{ displayWeight !== null ? 'refaire une pesée' : 'peser' }}</UiButton>
|
|
<UiButton
|
|
v-if="displayWeight !== null && !showGenerateReceipt"
|
|
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px] ml-4"
|
|
@click="saveWeight"
|
|
>Valider la pesée</UiButton>
|
|
<UiButton
|
|
v-if="showGenerateReceipt"
|
|
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px] ml-4"
|
|
@click="printReceipt"
|
|
>Générer le bon</UiButton>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import {computed, onMounted} from 'vue'
|
|
import { storeToRefs } from 'pinia'
|
|
import { useWeighing } from '~/composables/useWeighing'
|
|
import { usePdfPrinter } from '~/composables/usePdfPrinter'
|
|
import { useReceptionStore } from '~/stores/reception'
|
|
|
|
const props = defineProps<{
|
|
mode: 'gross' | 'tare'
|
|
}>()
|
|
|
|
const router = useRouter()
|
|
const receptionStore = useReceptionStore()
|
|
const { current: storeReception } = storeToRefs(receptionStore)
|
|
const { printPdf } = usePdfPrinter()
|
|
const {
|
|
displayWeight,
|
|
title,
|
|
showLoadingBox,
|
|
fetchWeight,
|
|
saveWeight
|
|
} = useWeighing({
|
|
mode: props.mode,
|
|
reception: storeReception,
|
|
updateReception: receptionStore.updateReception,
|
|
loadReception: receptionStore.loadReception
|
|
})
|
|
// Affiche le bouton de génération du bon à l'étape tare
|
|
const showGenerateReceipt = computed(
|
|
() => props.mode === 'tare' && displayWeight.value !== null
|
|
)
|
|
|
|
// Génère le bon de réception, puis clôture la réception
|
|
const printReceipt = async () => {
|
|
if (!import.meta.client || !receptionStore.current) {
|
|
return
|
|
}
|
|
|
|
await saveWeight()
|
|
const reception = receptionStore.current
|
|
const filename = `${reception.identificationNumber ?? reception.id}_${reception.supplier?.name ?? 'fournisseur'}_${reception.licensePlate ?? 'immat'}.pdf`
|
|
await printPdf(`/receptions/${reception.id}/receipt`, filename)
|
|
|
|
// Laisse le temps a la boite de dialogue d'impression de s'ouvrir.
|
|
await new Promise((resolve) => setTimeout(resolve, 600))
|
|
|
|
const result = await receptionStore.updateReception(receptionStore.current.id, {
|
|
isValid: true
|
|
})
|
|
if (!result) {
|
|
return
|
|
}
|
|
|
|
receptionStore.clearCurrent()
|
|
await router.push('/')
|
|
}
|
|
|
|
// Récupère le poids dès l'arrivée sur l'écran
|
|
onMounted(() => {
|
|
if (displayWeight.value === null) {
|
|
fetchWeight()
|
|
}
|
|
})
|
|
</script>
|