feat(component-edit) : add inline quantity input for piece slots
Quantity can now be edited directly on the component edit page next to each piece selector, instead of only being defined in the category. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,6 @@ import { useProductTypes } from '~/composables/useProductTypes'
|
|||||||
import { usePieces } from '~/composables/usePieces'
|
import { usePieces } from '~/composables/usePieces'
|
||||||
import { useProducts } from '~/composables/useProducts'
|
import { useProducts } from '~/composables/useProducts'
|
||||||
import { useCustomFields } from '~/composables/useCustomFields'
|
import { useCustomFields } from '~/composables/useCustomFields'
|
||||||
import type { SelectionEntry } from '~/shared/utils/structureSelectionUtils'
|
|
||||||
import { useApi } from '~/composables/useApi'
|
import { useApi } from '~/composables/useApi'
|
||||||
import { useToast } from '~/composables/useToast'
|
import { useToast } from '~/composables/useToast'
|
||||||
import { extractRelationId } from '~/shared/apiRelations'
|
import { extractRelationId } from '~/shared/apiRelations'
|
||||||
@@ -348,19 +347,17 @@ export function useComponentEdit(componentId: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveSlotQuantity = async (entry: SelectionEntry) => {
|
const saveSlotQuantity = async (slotId: string, quantity: number) => {
|
||||||
const slotId = entry.slotId
|
if (!slotId || quantity < 1) return
|
||||||
const quantity = typeof entry._definition?.quantity === 'number'
|
const result = await patch(`/composant-piece-slots/${slotId}`, { quantity: Math.max(1, quantity) })
|
||||||
? Math.max(1, entry._definition.quantity)
|
if (result.success) {
|
||||||
: null
|
const structure = component.value?.structure
|
||||||
if (!slotId || quantity === null) return
|
if (structure?.pieces) {
|
||||||
try {
|
const slot = (structure.pieces as any[]).find((s: any) => s.slotId === slotId)
|
||||||
await patch(`/composant-piece-slots/${slotId}`, { quantity })
|
if (slot) slot.quantity = quantity
|
||||||
|
}
|
||||||
toast.showSuccess('Quantité mise à jour')
|
toast.showSuccess('Quantité mise à jour')
|
||||||
}
|
}
|
||||||
catch (error: any) {
|
|
||||||
toast.showError(error?.message || 'Erreur lors de la mise à jour de la quantité')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const submitEdition = async () => {
|
const submitEdition = async () => {
|
||||||
|
|||||||
@@ -186,12 +186,27 @@
|
|||||||
<label class="label">
|
<label class="label">
|
||||||
<span class="label-text text-xs font-medium">{{ slot.label }}</span>
|
<span class="label-text text-xs font-medium">{{ slot.label }}</span>
|
||||||
</label>
|
</label>
|
||||||
<PieceSelect
|
<div class="flex items-start gap-2">
|
||||||
:model-value="slot.selectedPieceId"
|
<div class="flex-1">
|
||||||
:disabled="!canEdit || saving"
|
<PieceSelect
|
||||||
:type-piece-id="slot.typePieceId"
|
:model-value="slot.selectedPieceId"
|
||||||
@update:model-value="(value) => savePieceSlotSelection(slot.slotId, value)"
|
:disabled="!canEdit || saving"
|
||||||
/>
|
:type-piece-id="slot.typePieceId"
|
||||||
|
@update:model-value="(value) => savePieceSlotSelection(slot.slotId, value)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="w-20 shrink-0">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
:value="slot.quantity"
|
||||||
|
min="1"
|
||||||
|
class="input input-bordered input-sm w-full text-center"
|
||||||
|
:disabled="!canEdit || saving"
|
||||||
|
title="Quantité"
|
||||||
|
@change="(e) => saveSlotQuantity(slot.slotId, Number((e.target as HTMLInputElement).value))"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user