From b752fba69a26943042410dae99560448d450aa0a Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 28 Oct 2025 16:37:10 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20g=C3=A9rer=20les=20constructeurs=20mult?= =?UTF-8?q?iples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/ComponentItem.vue | 77 ++++- app/components/ConstructeurSelect.vue | 279 ++++++++++++------ app/components/PieceItem.vue | 76 ++++- app/composables/useComposants.js | 5 +- app/composables/useMachines.js | 7 +- app/composables/usePieces.js | 5 +- app/pages/component/[id]/edit.vue | 15 +- app/pages/component/create.vue | 13 +- app/pages/machine/[id].vue | 335 ++++++++++++++++++---- app/pages/pieces/[id]/edit.vue | 15 +- app/pages/pieces/create.vue | 9 +- app/shared/constructeurUtils.ts | 115 ++++++++ app/shared/modelUtils.ts | 13 +- app/utils/printTemplates/machineReport.js | 159 +++++++--- 14 files changed, 901 insertions(+), 222 deletions(-) create mode 100644 app/shared/constructeurUtils.ts 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 @@