Inline manager order editing
This commit is contained in:
@@ -20,12 +20,16 @@ const props = defineProps<{
|
||||
mode?: 'readonly' | 'manager-pricing' | 'cart';
|
||||
editable?: boolean;
|
||||
unitPriceDrafts?: Record<string, string>;
|
||||
editablePriceItemIds?: string[];
|
||||
disabled?: boolean;
|
||||
framed?: boolean;
|
||||
pricePlaceholder?: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:unit-price': [payload: { itemId: string; value: string }];
|
||||
'activate:unit-price': [itemId: string];
|
||||
'finish:unit-price': [itemId: string];
|
||||
increment: [itemId: string];
|
||||
decrement: [itemId: string];
|
||||
remove: [itemId: string];
|
||||
@@ -86,6 +90,18 @@ function updateUnitPrice(itemId: string, event: Event) {
|
||||
});
|
||||
}
|
||||
|
||||
function activateUnitPrice(itemId: string) {
|
||||
if (!isPricingMode.value || props.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit('activate:unit-price', itemId);
|
||||
}
|
||||
|
||||
function finishUnitPrice(itemId: string) {
|
||||
emit('finish:unit-price', itemId);
|
||||
}
|
||||
|
||||
function incrementItem(itemId: string) {
|
||||
emit('increment', itemId);
|
||||
}
|
||||
@@ -110,6 +126,8 @@ const mode = computed(() => props.mode ?? (props.editable ? 'manager-pricing' :
|
||||
const isPricingMode = computed(() => mode.value === 'manager-pricing');
|
||||
const isCartMode = computed(() => mode.value === 'cart');
|
||||
const isFramed = computed(() => props.framed ?? true);
|
||||
const editablePriceItemIds = computed(() => new Set(props.editablePriceItemIds ?? []));
|
||||
const displayPricePlaceholder = computed(() => props.pricePlaceholder ?? '—');
|
||||
|
||||
function mapParameterEntries(source: Record<string, unknown> | null | undefined): ItemParameter[] {
|
||||
if (!source || typeof source !== 'object') {
|
||||
@@ -187,18 +205,26 @@ function itemParameters(item: OrderItemView) {
|
||||
<div class="mt-4 md:mt-0">
|
||||
<p class="mb-1 text-[11px] font-semibold uppercase tracking-[0.18em] text-[#6a8a76] md:hidden">Цена</p>
|
||||
<input
|
||||
v-if="isPricingMode"
|
||||
v-if="isPricingMode && editablePriceItemIds.has(item.id)"
|
||||
:value="unitPriceDrafts?.[item.id] ?? ''"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder="Например, 125.50"
|
||||
:data-unit-price-input="item.id"
|
||||
class="w-full rounded-2xl bg-[#f3f5f4] px-4 py-3 text-sm text-[#123824] outline-none transition focus:shadow-[0_0_0_3px_rgba(19,153,87,0.12)] disabled:cursor-not-allowed disabled:bg-[#f4f8f5]"
|
||||
:disabled="disabled"
|
||||
@input="updateUnitPrice(item.id, $event)"
|
||||
@blur="finishUnitPrice(item.id)"
|
||||
@keydown.enter="finishUnitPrice(item.id)"
|
||||
>
|
||||
<p v-else class="text-sm font-semibold text-[#123824]">
|
||||
{{ formatPrice(currentUnitPrice(item)) || '—' }}
|
||||
<p
|
||||
v-else
|
||||
class="text-sm font-semibold text-[#123824]"
|
||||
:class="isPricingMode && !disabled ? 'cursor-pointer transition hover:text-[#0d854a]' : ''"
|
||||
@dblclick="activateUnitPrice(item.id)"
|
||||
>
|
||||
{{ formatPrice(currentUnitPrice(item)) || displayPricePlaceholder }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user