diff --git a/src/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile2Addons.vue b/src/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile2Addons.vue index c49988c1..f6ec56fb 100644 --- a/src/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile2Addons.vue +++ b/src/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile2Addons.vue @@ -42,6 +42,55 @@ const getLabel = (addon: Addon) => { //return `${addon.name} / ${SessionUser.functions.currency.toLocal(addon.price)}`; } +/** + * When double-clicking on the product, it will add 1 to the quantity + */ +const doubleClickTimeout = 500; // milliseconds +const doubleClickTimers = ref<{ [key: string]: number | null }>({}); + +/** + * Function to add a product to the add-ons list + * @param addon + */ +const onAddProduct = (addon: Addon) => { + // Check if the product was just added + if (doubleClickTimers.value[addon.id]) { + console.warn("Double-click detected for product " + addon.id, addon); + clearTimeout(doubleClickTimers.value[addon.id]); + doubleClickTimers.value[addon.id] = null; + // Check if the product can have more quantity + if (addon.quantity >= addon.max && addon.max !== -1) { + console.warn("Max quantity reached for product " + addon.id, addon); + return; + } + addon.quantity = addon.quantity + 1; + emit('update:addons', [...props.addons]) + // Set the timeout again to allow for the next double-click + doubleClickTimers.value[addon.id] = window.setTimeout(() => { + doubleClickTimers.value[addon.id] = null; + }, doubleClickTimeout); + return; + } + console.warn("Single click detected for product " + addon.id, addon); + // If the product is already has a quantity, set it to 0 + if (addon.quantity > 0) { + addon.quantity = 0; + emit('update:addons', [...props.addons]) + return; + } + addon.quantity = (addon.min > 0 ? addon.min : 1); + // Set a timeout to handle double-clicks. + // If the product max is reached, it will not be added. + if (addon.quantity >= addon.max && addon.max !== -1) { + console.warn("Max quantity reached for product " + addon.id, addon); + emit('update:addons', [...props.addons]) + return; + } + doubleClickTimers.value[addon.id] = window.setTimeout(() => { + doubleClickTimers.value[addon.id] = null; + }, doubleClickTimeout); + emit('update:addons', [...props.addons]) +} @@ -55,7 +104,7 @@ const getLabel = (addon: Addon) => { :price="addon.price" :label="getLabel(addon)" :piktogram="addon.product.piktogram" - @addProduct="addon.quantity = (addon.min > 0 ? addon.min : 1); emit('update:addons', [...props.addons])" + @addProduct="onAddProduct(addon)" :customButton="addon.quantity > 0"> { } .custom-label { /* Add-ons */ - + padding-bottom: 24px; width: 60px; height: 16px; diff --git a/src/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile2CategoryProduct.vue b/src/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile2CategoryProduct.vue index 812b7259..24f35a0d 100644 --- a/src/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile2CategoryProduct.vue +++ b/src/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile2CategoryProduct.vue @@ -61,14 +61,14 @@ const imageStyleCompact = {