商品如果没有特殊规格则直接可用+和-来调整数量

This commit is contained in:
Kroytz committed 2026-07-10 18:11:15 +08:00
1 parent c61283f466
commit e3c6fe9231
3 files changed
+50 -29

No files matched your search

+41 -20
View File
@@ -90,8 +90,9 @@
<text class="name">{{ good.storeName }}</text>
<text v-if="good.storeInfo" class="tips">{{ good.storeInfo }}</text>
<view class="price_and_action">
<text class="price">¥{{ good.price }}</text>
<view class="btn-group" v-if="good.stock > 0">
<text class="price">¥{{ good.price }}</text>
<view class="btn-group" v-if="good.stock > 0">
<template v-if="hasSpecialSpecs(good)">
<button type="primary" class="btn property_btn"
hover-class="none" size="mini"
@tap="showGoodDetailModal(item, good)">
@@ -99,6 +100,12 @@
</button>
<view class="dot" v-show="goodCartNum(good.id)">
{{ goodCartNum(good.id) }}</view>
</template>
<template v-else>
<button v-if="goodCartNum(good.id)" type="default" plain class="btn quantity-btn" size="mini" hover-class="none" @tap.stop="adjustSimpleGood(item, good, -1)"><text class="iconfont iconsami-select"></text></button>
<text v-if="goodCartNum(good.id)" class="number">{{ goodCartNum(good.id) }}</text>
<button type="primary" class="btn quantity-btn" size="mini" hover-class="none" @tap.stop="adjustSimpleGood(item, good, 1)"><text class="iconfont iconadd-select"></text></button>
</template>
</view>
@@ -313,6 +320,8 @@ const spread = computed(() => { //差多少元起送
})
const isGoodVisible = (good) => !keyword.value || [good.storeName, good.storeInfo]
.filter(Boolean).join(' ').toLowerCase().includes(keyword.value.trim().toLowerCase())
const hasSpecialSpecs = (good) => (good.productAttr || []).some(attr => (attr.attrValueArr || []).length > 1)
const defaultSpec = (good) => (good.productAttr || []).map(attr => attr.attrValueArr?.[0]).filter(Boolean).join(',')
// 监听自定义事件
uni.$on('refreshMenu', () => {
@@ -545,13 +554,8 @@ const calcSize = () => {
sizeCalcState.value = true
}
const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车
const index = cart.value.findIndex(item => {
if (newGood) {
return (item.id === newGood.id) && (item.valueStr === good.value.valueStr)
} else {
return item.id === newGood.id
}
})
const valueStr = newGood.valueStr || ''
const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr)
if (index > -1) {
cart.value[index].number += num
} else {
@@ -562,20 +566,25 @@ const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车
price: newGood.price,
number: num,
image: newGood.image,
valueStr: good.value.valueStr
valueStr
})
}
uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
}
const handleReduceFromCart = (item, good) => {
const index = cart.value.findIndex(item => item.id === good.id)
cart.value[index].number -= 1
if (cart.value[index].number <= 0) {
cart.value.splice(index, 1)
const adjustSimpleGood = (cate, newGood, num) => {
const valueStr = defaultSpec(newGood)
const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr)
if (num > 0) {
handleAddToCart(cate, { ...newGood, valueStr }, num)
return
}
if (index < 0) return
cart.value[index].number += num
if (cart.value[index].number <= 0) cart.value.splice(index, 1)
uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
}
const showGoodDetailModal = (item, newGood) => {
if (!hasSpecialSpecs(newGood)) return adjustSimpleGood(item, newGood, 1)
isCartShow.value = true
good.value = JSON.parse(JSON.stringify({
...newGood,
@@ -752,7 +761,7 @@ $menu-divider-height: 2rpx;
text-align: center;
}
.btn {
.btn {
//padding: 0;
border-radius: $border-radius-circle;
}
@@ -1071,9 +1080,15 @@ page {
font-size: $font-size-sm;
line-height: var(--menu-control-size-sm);
&.property_btn {
border-radius: 24rpx;
}
&.property_btn {
border-radius: 24rpx;
}
&.quantity-btn {
width: var(--menu-control-size-sm);
padding: 0;
border-radius: 50%;
}
&.add_btn,
&.reduce_btn {
@@ -1098,7 +1113,13 @@ page {
border-radius: $border-radius-circle;
}
@include quantity-control(var(--menu-control-size-sm));
@include quantity-control(var(--menu-control-size-sm));
.number {
min-width: 38rpx;
padding: 0 8rpx;
font-size: $font-size-sm;
}
}
}
}