fix:商品库存不足置灰+提示
parent
6a8b1e4f10
commit
dfd2fc52b2
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue