feat(front) : logique Ajouter un bovin sur écran de saisie
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -181,8 +181,48 @@ const loadReception = async () => {
|
||||
resetForm()
|
||||
}
|
||||
|
||||
const loadSavedBovines = async () => {
|
||||
const response = await api.get<{ 'hydra:member'?: BovineData[] } | BovineData[]>(
|
||||
`bovines?reception=${receptionId.value}`,
|
||||
{},
|
||||
{ toast: false }
|
||||
)
|
||||
savedBovines.value = Array.isArray(response)
|
||||
? response
|
||||
: (response['hydra:member'] ?? [])
|
||||
}
|
||||
|
||||
const focusFirstField = () => {
|
||||
const el = document.querySelector<HTMLInputElement>('form input[type="text"]')
|
||||
el?.focus()
|
||||
}
|
||||
|
||||
const addBovine = async () => {
|
||||
// implémenté en Task 9
|
||||
if (!isFormValid.value || isAdding.value) return
|
||||
|
||||
isAdding.value = true
|
||||
try {
|
||||
const payload = {
|
||||
nationalNumber: form.nationalNumber.trim(),
|
||||
receivedWeight: form.receivedWeight,
|
||||
pricePerKg: form.pricePerKg,
|
||||
arrivalDate: form.arrivalDate,
|
||||
supplier: `/api/suppliers/${form.supplierId}`,
|
||||
buildingCase: `/api/building_cases/${form.caseId}`,
|
||||
reception: `/api/receptions/${receptionId.value}`
|
||||
}
|
||||
|
||||
await api.post<BovineData>('bovines', payload, {
|
||||
headers: { 'Content-Type': 'application/ld+json' }
|
||||
})
|
||||
|
||||
await loadSavedBovines()
|
||||
resetForm()
|
||||
await nextTick()
|
||||
focusFirstField()
|
||||
} finally {
|
||||
isAdding.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -191,5 +231,6 @@ onMounted(async () => {
|
||||
getBuildingList()
|
||||
])
|
||||
await loadReception()
|
||||
await loadSavedBovines()
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user