Browse Source

餐具费为0时不允许更改数量

sunshibo 3 weeks ago
parent
commit
5e75342dad
2 changed files with 25 additions and 6 deletions
  1. 20 5
      pages/orderFood/components/CartModal.vue
  2. 5 1
      pages/orderFood/index.vue

+ 20 - 5
pages/orderFood/components/CartModal.vue

@@ -31,8 +31,8 @@
                         </view>
                     </view>
 
-                    <!-- 数量选择器 -->
-                    <view class="cart-item__actions">
+                    <!-- 数量选择器(餐具费 0 元时不可修改) -->
+                    <view class="cart-item__actions" :class="{ 'cart-item__actions--disabled': !canEditItemQuantity(item) }">
                         <view class="action-btn minus" :class="{ disabled: item.quantity === 0 }"
                             @click="handleDecrease(item)" hover-class="hover-active">
                             <image :src="getFileUrl('img/icon/reduce1.png')" mode="aspectFit" class="action-icon"
@@ -119,27 +119,37 @@ const getItemLinePrice = (item) => {
     return qty * unitPrice;
 };
 
-// 餐具(cuisineId 或 id 为 -1)可修改数量(含减至 0)
+// 餐具(cuisineId 或 id 为 -1)可修改数量(含减至 0);餐具费为 0 元时不允许修改数量
 const isTablewareItem = (item) => {
     if (!item) return false;
     const id = item.cuisineId ?? item.id;
     return Number(id) === -1;
 };
 
+// 该项是否允许修改数量:非餐具允许;餐具仅当单价>0 时允许
+const canEditItemQuantity = (item) => {
+    if (!item) return false;
+    if (!isTablewareItem(item)) return true;
+    const price = getItemPrice(item);
+    return Number(price) > 0;
+};
+
 // 处理关闭
 const handleClose = () => {
     getOpen.value = false;
     emit('close');
 };
 
-// 增加数量
+// 增加数量(餐具费 0 元时不触发)
 const handleIncrease = (item) => {
+    if (!canEditItemQuantity(item)) return;
     if (item.quantity >= 99) return;
     emit('increase', item);
 };
 
-// 减少数量
+// 减少数量(餐具费 0 元时不触发)
 const handleDecrease = (item) => {
+    if (!canEditItemQuantity(item)) return;
     if (item && item.quantity > 0) {
         emit('decrease', item);
     }
@@ -309,6 +319,11 @@ const handleClear = () => {
         box-sizing: border-box;
         padding: 0 3rpx;
         margin-left: 20rpx;
+
+        &--disabled {
+            opacity: 0.6;
+            pointer-events: none;
+        }
     }
 }
 

+ 5 - 1
pages/orderFood/index.vue

@@ -482,10 +482,14 @@ const isTableware = (item) => {
 };
 
 // 更新菜品数量:菜品 id 一致则全部同步为同一数量,触发响应式;新增加入购物车时调接口;并同步 cartData
-// Update 接口返回 400 时不改页面数量和金额(会回滚本地状态)
+// Update 接口返回 400 时不改页面数量和金额(会回滚本地状态);餐具费为 0 元时不允许修改餐具数量
 const updateFoodQuantity = (food, delta) => {
   if (!food) return;
   const id = food.id ?? food.cuisineId;
+  if (Number(id) === -1) {
+    const unitPrice = Number(food?.unitPrice ?? food?.price ?? 0) || 0;
+    if (unitPrice <= 0) return;
+  }
   const prevQty = food.quantity || 0;
   const nextQty = Math.max(0, prevQty + delta);
   const sameId = (item) =>