feat(bovine-type) : piloter l'affichage en réception via un champ display [#FER-30]
Ajoute un champ display (défaut false) sur BovineType : seuls les types activés par un admin apparaissent à la sélection des races en réception. Les types créés par la synchro inventaire restent masqués par défaut. - Affichage des races en grille 4 colonnes (création réception) - Édition réception : conserve les types déjà saisis même masqués - Admin : badge "Affiché en réception" + checkbox dans le formulaire Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,12 +5,10 @@
|
||||
@submit.prevent="goNext"
|
||||
>
|
||||
<h1 class="text-4xl uppercase font-bold text-primary-500">Sélection des races réceptionnées</h1>
|
||||
<div
|
||||
class="flex flex-row gap-8 items-center w-full">
|
||||
<div class="grid grid-cols-4 gap-x-8 gap-y-6">
|
||||
<div
|
||||
v-for="type in bovineType"
|
||||
:key="type.id"
|
||||
class="mt-8 flex flex-row mb-2 w-full">
|
||||
:key="type.id">
|
||||
<UiNumberInput
|
||||
:id="type.id"
|
||||
:label="type.label"
|
||||
@@ -23,12 +21,11 @@
|
||||
wrapper-class="gap-3"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="mt-8 flex flex-row mb-2 gap-6">
|
||||
<div>
|
||||
<UiNumberInput
|
||||
label="Autres"
|
||||
v-model="otherQuantity"
|
||||
class="max-w-[80px]"
|
||||
class="max-w-[150px]"
|
||||
wrapper-class="gap-3"
|
||||
/>
|
||||
</div>
|
||||
@@ -79,7 +76,7 @@ const totalBovines = computed(() => {
|
||||
const loadBovineType = async () => {
|
||||
isLoadingBovineType.value = true
|
||||
try {
|
||||
bovineType.value = await getBovineTypeList()
|
||||
bovineType.value = await getBovineTypeList({ display: true })
|
||||
} finally {
|
||||
isLoadingBovineType.value = false
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref, watch } from 'vue'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { getBovineTypeList } from '~/services/bovine-type'
|
||||
import type { BovineTypeData } from '~/services/dto/bovine-type-data'
|
||||
import type { ReceptionBovineTypeData } from '~/services/dto/reception-bovine-data'
|
||||
@@ -45,7 +45,18 @@ const emit = defineEmits<{
|
||||
(event: 'update:otherQuantity', value: number | null): void
|
||||
}>()
|
||||
|
||||
const bovineTypes = ref<BovineTypeData[]>([])
|
||||
// Types activés par l'admin (display=true), chargés depuis l'API.
|
||||
const displayedTypes = ref<BovineTypeData[]>([])
|
||||
// On affiche les types activés ET ceux déjà saisis sur la réception (même masqués),
|
||||
// pour ne pas faire disparaître/perdre une quantité existante.
|
||||
const bovineTypes = computed<BovineTypeData[]>(() => {
|
||||
const seen = new Set(displayedTypes.value.map((type) => type.id))
|
||||
const fromExisting = props.modelValue
|
||||
.map((entry) => entry.bovineType)
|
||||
.filter((type): type is BovineTypeData => Boolean(type) && !seen.has(type.id))
|
||||
|
||||
return [...displayedTypes.value, ...fromExisting]
|
||||
})
|
||||
const localQuantities = reactive<Record<string, number | null>>({})
|
||||
const localOtherQuantity = ref<number | null>(props.otherQuantity ?? 0)
|
||||
// Verrou pour éviter les boucles props -> local -> emit -> props.
|
||||
@@ -154,8 +165,13 @@ watch(
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
// Re-synchronise dès que la liste fusionnée change (chargement async des types).
|
||||
watch(bovineTypes, () => {
|
||||
syncLocalFromProps()
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
bovineTypes.value = await getBovineTypeList()
|
||||
displayedTypes.value = await getBovineTypeList({ display: true })
|
||||
syncLocalFromProps()
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user