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

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

No files matched your search

+1 -1
View File
@@ -207,7 +207,7 @@
}, },
"tabBar": { "tabBar": {
"color": "#919293", "color": "#919293",
"selectedColor": "#09b4f1", "selectedColor": "#ff7417",
"backgroundColor": "#fff", "backgroundColor": "#fff",
"borderStyle": "black", "borderStyle": "black",
"list": [{ "list": [{
+34 -13
View File
@@ -92,6 +92,7 @@
<view class="price_and_action"> <view class="price_and_action">
<text class="price">¥{{ good.price }}</text> <text class="price">¥{{ good.price }}</text>
<view class="btn-group" v-if="good.stock > 0"> <view class="btn-group" v-if="good.stock > 0">
<template v-if="hasSpecialSpecs(good)">
<button type="primary" class="btn property_btn" <button type="primary" class="btn property_btn"
hover-class="none" size="mini" hover-class="none" size="mini"
@tap="showGoodDetailModal(item, good)"> @tap="showGoodDetailModal(item, good)">
@@ -99,6 +100,12 @@
</button> </button>
<view class="dot" v-show="goodCartNum(good.id)"> <view class="dot" v-show="goodCartNum(good.id)">
{{ goodCartNum(good.id) }}</view> {{ 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> </view>
@@ -313,6 +320,8 @@ const spread = computed(() => { //差多少元起送
}) })
const isGoodVisible = (good) => !keyword.value || [good.storeName, good.storeInfo] const isGoodVisible = (good) => !keyword.value || [good.storeName, good.storeInfo]
.filter(Boolean).join(' ').toLowerCase().includes(keyword.value.trim().toLowerCase()) .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', () => { uni.$on('refreshMenu', () => {
@@ -545,13 +554,8 @@ const calcSize = () => {
sizeCalcState.value = true sizeCalcState.value = true
} }
const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车 const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车
const index = cart.value.findIndex(item => { const valueStr = newGood.valueStr || ''
if (newGood) { const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr)
return (item.id === newGood.id) && (item.valueStr === good.value.valueStr)
} else {
return item.id === newGood.id
}
})
if (index > -1) { if (index > -1) {
cart.value[index].number += num cart.value[index].number += num
} else { } else {
@@ -562,20 +566,25 @@ const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车
price: newGood.price, price: newGood.price,
number: num, number: num,
image: newGood.image, image: newGood.image,
valueStr: good.value.valueStr valueStr
}) })
} }
uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value))) uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
} }
const handleReduceFromCart = (item, good) => { const adjustSimpleGood = (cate, newGood, num) => {
const index = cart.value.findIndex(item => item.id === good.id) const valueStr = defaultSpec(newGood)
cart.value[index].number -= 1 const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr)
if (cart.value[index].number <= 0) { if (num > 0) {
cart.value.splice(index, 1) 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))) uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
} }
const showGoodDetailModal = (item, newGood) => { const showGoodDetailModal = (item, newGood) => {
if (!hasSpecialSpecs(newGood)) return adjustSimpleGood(item, newGood, 1)
isCartShow.value = true isCartShow.value = true
good.value = JSON.parse(JSON.stringify({ good.value = JSON.parse(JSON.stringify({
...newGood, ...newGood,
@@ -1075,6 +1084,12 @@ page {
border-radius: 24rpx; border-radius: 24rpx;
} }
&.quantity-btn {
width: var(--menu-control-size-sm);
padding: 0;
border-radius: 50%;
}
&.add_btn, &.add_btn,
&.reduce_btn { &.reduce_btn {
width: var(--menu-control-size-sm); width: var(--menu-control-size-sm);
@@ -1099,6 +1114,12 @@ page {
} }
@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;
}
} }
} }
} }
+8 -8
View File
@@ -14,7 +14,7 @@
/* 颜色变量 */ /* 颜色变量 */
/* 行为相关颜色 */ /* 行为相关颜色 */
$color-primary: #09b4f1; $color-primary: #ff7417;
$color-success: #4cd964; $color-success: #4cd964;
$color-warning: #FAB714; $color-warning: #FAB714;
$color-error: #D12E32; $color-error: #D12E32;
@@ -28,9 +28,9 @@ $text-color-white: #ffffff; //白
$text-color-light-muted: #A9A5A0; //浅灰 $text-color-light-muted: #A9A5A0; //浅灰
/* 背景颜色 */ /* 背景颜色 */
$bg-color: #F1F8FA; $bg-color: #fff8f1;
$bg-color-grey: #F5F5F5; $bg-color-grey: #fffaf6;
$bg-color-primary: #dbe7ea; $bg-color-primary: #fff0df;
/* 边框颜色 */ /* 边框颜色 */
$border-color: #e6e6e6; $border-color: #e6e6e6;
@@ -87,10 +87,10 @@ $uv-border-color: #dadbde;
$uv-bg-color: #f3f4f6; $uv-bg-color: #f3f4f6;
$uv-disabled-color: #c8c9cc; $uv-disabled-color: #c8c9cc;
$uv-primary: #EE6D46; $uv-primary: #ff7417;
$uv-primary-dark: #EE6D46; $uv-primary-dark: #e9600b;
$uv-primary-disabled: #FDEDE8; $uv-primary-disabled: #ffe1c8;
$uv-primary-light: #ecf5ff; $uv-primary-light: #fff1e5;
$uv-warning: #f9ae3d; $uv-warning: #f9ae3d;
$uv-warning-dark: #f1a532; $uv-warning-dark: #f1a532;