Compare commits

..

2 Commits

1 changed files with 45 additions and 4 deletions

View File

@ -42,10 +42,15 @@
<!-- 中间菜单列表可滑动 --> <!-- 中间菜单列表可滑动 -->
<scroll-view class="menu-list" scroll-y="true"> <scroll-view class="menu-list" scroll-y="true">
<view class="menu-item" v-for="(item, index) in menuList" :key="index"> <view
class="menu-item"
v-for="(item, index) in menuList"
:key="index"
:class="{ 'out-of-stock': item.stock === 0 }"
>
<view <view
class="checkbox" class="checkbox"
:class="{ checked: item.selected }" :class="{ checked: item.selected, disabled: item.stock === 0 }"
@click="toggleMenuItem(index)" @click="toggleMenuItem(index)"
> >
<text v-if="item.selected" class="checkmark"></text> <text v-if="item.selected" class="checkmark"></text>
@ -75,17 +80,21 @@
<view <view
class="quantity-btn minus" class="quantity-btn minus"
:class="{ :class="{
disabled: (item.quantity || 0) <= 0, disabled: (item.quantity || 0) <= 0 || item.stock === 0,
}" }"
@click="decreaseQuantity(index)" @click="decreaseQuantity(index)"
>-</view >-</view
> >
<text class="quantity-number">{{ item.quantity || 0 }}</text> <text class="quantity-number">{{ item.quantity || 0 }}</text>
<view class="quantity-btn plus" @click="increaseQuantity(index)" <view
class="quantity-btn plus"
:class="{ disabled: item.stock === 0 }"
@click="increaseQuantity(index)"
>+</view >+</view
> >
</view> </view>
</view> </view>
<view v-if="item.stock === 0" class="stock-tip"></view>
</view> </view>
</view> </view>
</scroll-view> </scroll-view>
@ -275,6 +284,10 @@ export default {
// //
toggleMenuItem(index) { toggleMenuItem(index) {
const item = this.menuList[index]; const item = this.menuList[index];
//
if (item && item.stock === 0) {
return;
}
item.selected = !item.selected; item.selected = !item.selected;
if (!item.selected) { if (!item.selected) {
item.quantity = 0; item.quantity = 0;
@ -287,6 +300,10 @@ export default {
// //
increaseQuantity(index) { increaseQuantity(index) {
const item = this.menuList[index]; const item = this.menuList[index];
//
if (item && item.stock === 0) {
return;
}
// //
if (!item.selected) { if (!item.selected) {
item.selected = true; item.selected = true;
@ -298,6 +315,10 @@ export default {
// //
decreaseQuantity(index) { decreaseQuantity(index) {
const item = this.menuList[index]; const item = this.menuList[index];
//
if (item && item.stock === 0) {
return;
}
const currentQuantity = item.quantity || 0; const currentQuantity = item.quantity || 0;
// 0 // 0
if (currentQuantity > 0) { if (currentQuantity > 0) {
@ -579,6 +600,10 @@ export default {
align-items: center; align-items: center;
position: relative; position: relative;
&.out-of-stock {
opacity: 0.6;
}
.checkbox { .checkbox {
width: 30rpx; width: 30rpx;
height: 30rpx; height: 30rpx;
@ -590,6 +615,11 @@ export default {
margin-right: 19rpx; margin-right: 19rpx;
flex-shrink: 0; flex-shrink: 0;
&.disabled {
border-color: #dddddd;
background-color: #f5f5f5;
}
&.checked { &.checked {
background-color: #004294; background-color: #004294;
border-color: #004294; border-color: #004294;
@ -694,6 +724,12 @@ export default {
font-weight: 500; font-weight: 500;
background-color: #ffffff; background-color: #ffffff;
border-radius: 4rpx; border-radius: 4rpx;
&.disabled {
color: #bbbbbb;
border-color: #dddddd;
background-color: #f5f5f5;
}
} }
.quantity-number { .quantity-number {
@ -706,6 +742,11 @@ export default {
} }
} }
} }
.stock-tip {
margin-top: 10rpx;
font-size: 20rpx;
color: #999999;
}
} }
} }
} }