diff --git a/app/components/ComponentItem.vue b/app/components/ComponentItem.vue index af727e9..8624d41 100644 --- a/app/components/ComponentItem.vue +++ b/app/components/ComponentItem.vue @@ -32,7 +32,15 @@ Défini dans le catalogue {{ component.reference }} - {{ component.constructeur?.name }} + {{ component.prix }}€
-
- {{ component.constructeur?.name || 'Non défini' }} - - {{ [component.constructeur?.email, component.constructeur?.phone].filter(Boolean).join(' • ') }} - +
+
+ {{ constructeur.name }} + + {{ formatConstructeurContact(constructeur) }} + +
+ Non défini
@@ -331,6 +349,12 @@ import DocumentPreviewModal from '~/components/DocumentPreviewModal.vue' import IconLucideChevronRight from '~icons/lucide/chevron-right' import { useCustomFields } from '~/composables/useCustomFields' import { useToast } from '~/composables/useToast' +import { useConstructeurs } from '~/composables/useConstructeurs' +import { + formatConstructeurContact as formatConstructeurContactSummary, + resolveConstructeurs, + uniqueConstructeurIds, +} from '~/shared/constructeurUtils' const props = defineProps({ component: { @@ -406,6 +430,28 @@ const childComponents = computed(() => { return Array.isArray(list) ? list : [] }) +const { constructeurs } = useConstructeurs() + +const componentConstructeurIds = computed(() => + uniqueConstructeurIds( + props.component, + Array.isArray(props.component.constructeurs) ? props.component.constructeurs : [], + props.component.constructeur ? [props.component.constructeur] : [], + ), +) + +const componentConstructeursDisplay = computed(() => + resolveConstructeurs( + componentConstructeurIds.value, + Array.isArray(props.component.constructeurs) ? props.component.constructeurs : [], + props.component.constructeur ? [props.component.constructeur] : [], + constructeurs.value, + ), +) + +const formatConstructeurContact = (constructeur) => + formatConstructeurContactSummary(constructeur) + const extractStructureCustomFields = (structure) => { if (!structure || typeof structure !== 'object') { return [] @@ -686,7 +732,17 @@ watch( ) const handleConstructeurChange = async (value) => { - props.component.constructeurId = value + const ids = uniqueConstructeurIds(value) + + props.component.constructeurIds = [...ids] + props.component.constructeurId = null + props.component.constructeur = null + props.component.constructeurs = resolveConstructeurs( + ids, + constructeurs.value, + Array.isArray(props.component.constructeurs) ? props.component.constructeurs : [], + ) + await updateComponent() } @@ -723,7 +779,10 @@ const toggleCollapse = () => { } const updateComponent = () => { - emit('update', props.component) + emit('update', { + ...props.component, + constructeurIds: componentConstructeurIds.value, + }) } function resolveFieldKey(field, index) { diff --git a/app/components/ConstructeurSelect.vue b/app/components/ConstructeurSelect.vue index c9ea3dc..6bdaa13 100644 --- a/app/components/ConstructeurSelect.vue +++ b/app/components/ConstructeurSelect.vue @@ -1,7 +1,7 @@ - diff --git a/app/components/PieceItem.vue b/app/components/PieceItem.vue index 9c709f5..85d439b 100644 --- a/app/components/PieceItem.vue +++ b/app/components/PieceItem.vue @@ -68,22 +68,33 @@
Constructeur: - - {{ - piece.constructeur?.name || "Non défini" - }} - - {{ - [piece.constructeur?.email, piece.constructeur?.phone] - .filter(Boolean) - .join(" • ") - }} +
+
+
+ + {{ constructeur.name }} + + + {{ formatConstructeurContact(constructeur) }} + +
+
+ + Non défini - +
@@ -353,6 +364,7 @@