diff --git a/frontend/components/entry-exit/bovine-info-form.vue b/frontend/components/entry-exit/bovine-info-form.vue index 068b3c3..8003f95 100644 --- a/frontend/components/entry-exit/bovine-info-form.vue +++ b/frontend/components/entry-exit/bovine-info-form.vue @@ -1,32 +1,32 @@ - - + + @@ -66,15 +66,14 @@ interface FormState { } const form = reactive({ - receivedWeight: props.bovine.receivedWeight, - pricePerKg: props.bovine.pricePerKg, + receivedWeight: props.bovine.receivedWeight ?? null, + pricePerKg: props.bovine.pricePerKg ?? null, buildingId: props.bovine.buildingCase?.building?.id ?? props.bovine.effectiveBuilding?.id ?? null, buildingCaseId: props.bovine.buildingCase?.id ?? null }) -const submitted = ref(false) const isSaving = ref(false) const buildingOptions = computed(() => @@ -101,13 +100,15 @@ watch(() => form.buildingId, (newId) => { }) const submit = async () => { - submitted.value = true - if ( - form.receivedWeight === null - || form.pricePerKg === null - || form.buildingId === null - || form.buildingCaseId === null - ) { + const payload: Record = {} + if (form.receivedWeight != null) payload.receivedWeight = form.receivedWeight + if (form.pricePerKg != null) payload.pricePerKg = form.pricePerKg + if (form.buildingCaseId != null) { + payload.buildingCase = `/api/building_cases/${form.buildingCaseId}` + } + + if (Object.keys(payload).length === 0) { + emit('saved', props.bovine) return } @@ -115,11 +116,8 @@ const submit = async () => { try { const updated = await api.patch( `bovines/${props.bovine.id}`, - { - receivedWeight: form.receivedWeight, - pricePerKg: form.pricePerKg, - buildingCase: `/api/building_cases/${form.buildingCaseId}` - } + payload, + { toastSuccessMessage: `Bovin ${props.bovine.nationalNumber} enregistré.` } ) emit('saved', updated) } finally { diff --git a/frontend/components/ui/UiNumberInput.vue b/frontend/components/ui/UiNumberInput.vue index eaca5c5..542519b 100644 --- a/frontend/components/ui/UiNumberInput.vue +++ b/frontend/components/ui/UiNumberInput.vue @@ -108,7 +108,9 @@ const onInput = (event: Event) => { numeric = Math.min(max, numeric) } - target.value = String(numeric) + if (numeric !== parsed) { + target.value = String(numeric) + } emit('update:modelValue', numeric) } diff --git a/frontend/pages/entry-exit/bovine-info/[id].vue b/frontend/pages/entry-exit/bovine-info/[id].vue index 7a583f3..b876091 100644 --- a/frontend/pages/entry-exit/bovine-info/[id].vue +++ b/frontend/pages/entry-exit/bovine-info/[id].vue @@ -14,36 +14,49 @@ Chargement… - - - - - {{ bovine.nationalNumber }} - - Saisie - - - Attente saisie - - - - + + - + + + + + + + {{ bovine.nationalNumber }} + + Saisie + + + Attente saisie + + + + + + @@ -53,6 +66,7 @@ import type { BovineData } from '~/services/dto/bovine-data' import type { BuildingData } from '~/services/dto/building-data' import type { ReceptionData } from '~/services/dto/reception-data' import { getBuildingList } from '~/services/building' +import BovineInfoForm from '~/components/entry-exit/bovine-info-form.vue' const route = useRoute() const router = useRouter() @@ -65,15 +79,22 @@ const bovines = ref([]) const buildings = ref([]) const loading = ref(true) const openId = ref(null) +const searchQueryRaw = ref('') +const searchQuery = computed({ + get: () => searchQueryRaw.value, + set: (value) => { + searchQueryRaw.value = value.replace(/\D/g, '') + } +}) useHead({ title: () => `Saisie information bovin ${reception.value?.identificationNumber ?? ''}`.trim() }) const isSaisi = (bovine: BovineData) => - bovine.receivedWeight !== null - && bovine.pricePerKg !== null - && bovine.buildingCase !== null + bovine.receivedWeight != null + && bovine.pricePerKg != null + && bovine.buildingCase != null const sortedBovines = computed(() => { const pending = bovines.value.filter(b => !isSaisi(b)) @@ -81,6 +102,14 @@ const sortedBovines = computed(() => { return [...pending, ...done] }) +const filteredBovines = computed(() => { + const query = searchQuery.value.trim().toLowerCase() + if (!query) return sortedBovines.value + return sortedBovines.value.filter(b => + b.nationalNumber.toLowerCase().includes(query) + ) +}) + const onToggle = (bovineId: number, value: boolean) => { openId.value = value ? bovineId : null }