"Refine DepartmentDashboardOrderBooking.vue to handle item removal when quantity decreases to zero, ensuring accurate item management and persistence."
This commit is contained in:
+8
-3
@@ -80,9 +80,14 @@ const onChangeQty = async (index: number, delta: number) => {
|
||||
if (!booking.value) return;
|
||||
const newItems = [...(booking.value.items || [])];
|
||||
const item = { ...(newItems[index] || {}) };
|
||||
const qty = Math.max(1, parseInt(item.quantity || 1) + delta);
|
||||
item.quantity = qty;
|
||||
newItems[index] = item;
|
||||
const nextQty = parseInt(item.quantity || 1) + delta;
|
||||
if (nextQty <= 0) {
|
||||
// When decrementing from 1 to 0, remove the item entirely
|
||||
newItems.splice(index, 1);
|
||||
} else {
|
||||
item.quantity = nextQty;
|
||||
newItems[index] = item;
|
||||
}
|
||||
await persistItems(newItems);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user