商品如果没有特殊规格则直接可用+和-来调整数量
This commit is contained in:
1 parent
c61283f466
commit
e3c6fe9231
3 files changed
+50
-29
No files matched your search
@@ -207,7 +207,7 @@
|
||||
},
|
||||
"tabBar": {
|
||||
"color": "#919293",
|
||||
"selectedColor": "#09b4f1",
|
||||
"selectedColor": "#ff7417",
|
||||
"backgroundColor": "#fff",
|
||||
"borderStyle": "black",
|
||||
"list": [{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
$color-primary: #09b4f1;
|
||||
$color-primary: #ff7417;
|
||||
$color-success: #4cd964;
|
||||
$color-warning: #FAB714;
|
||||
$color-error: #D12E32;
|
||||
@@ -28,9 +28,9 @@ $text-color-white: #ffffff; //白
|
||||
$text-color-light-muted: #A9A5A0; //浅灰
|
||||
|
||||
/* 背景颜色 */
|
||||
$bg-color: #F1F8FA;
|
||||
$bg-color-grey: #F5F5F5;
|
||||
$bg-color-primary: #dbe7ea;
|
||||
$bg-color: #fff8f1;
|
||||
$bg-color-grey: #fffaf6;
|
||||
$bg-color-primary: #fff0df;
|
||||
|
||||
/* 边框颜色 */
|
||||
$border-color: #e6e6e6;
|
||||
@@ -87,10 +87,10 @@ $uv-border-color: #dadbde;
|
||||
$uv-bg-color: #f3f4f6;
|
||||
$uv-disabled-color: #c8c9cc;
|
||||
|
||||
$uv-primary: #EE6D46;
|
||||
$uv-primary-dark: #EE6D46;
|
||||
$uv-primary-disabled: #FDEDE8;
|
||||
$uv-primary-light: #ecf5ff;
|
||||
$uv-primary: #ff7417;
|
||||
$uv-primary-dark: #e9600b;
|
||||
$uv-primary-disabled: #ffe1c8;
|
||||
$uv-primary-light: #fff1e5;
|
||||
|
||||
$uv-warning: #f9ae3d;
|
||||
$uv-warning-dark: #f1a532;
|
||||
|
||||
Reference in new issue
Block a user