fix(menu): 购物车莫名其妙消失
This commit is contained in:
1 parent
b9246f3e97
commit
140afd88a1
1 file changed
+9
-4
@@ -137,7 +137,7 @@
|
||||
<image src="/static/images/menu/cart.png" class="cart-img" @tap="openCartPopup"></image>
|
||||
<view class="tag" v-show="getCartGoodsNumber">{{ getCartGoodsNumber }}</view>
|
||||
</view>
|
||||
<view class="price" @tap="openCartShow">
|
||||
<view class="price" @tap="openCartPopup">
|
||||
<view class="price__amount">¥{{ getCartGoodsPrice }}</view>
|
||||
<view v-if="deliveryTipText" class="price__tip">{{ deliveryTipText }}</view>
|
||||
</view>
|
||||
@@ -462,14 +462,12 @@ onHide(() => {
|
||||
})
|
||||
onShow(() => {
|
||||
//init();
|
||||
isCartShow.value = true
|
||||
refreshCart()
|
||||
shopAd.value = uni.getStorageSync('shopAd')
|
||||
loadAddressesForDelivery()
|
||||
})
|
||||
|
||||
const openCartShow = () =>{
|
||||
isCartShow.value = false
|
||||
}
|
||||
const in_array = (search, array) => {
|
||||
for (var i in array) {
|
||||
if (array[i] == search) {
|
||||
@@ -751,6 +749,7 @@ const calcSize = () => {
|
||||
sizeCalcState.value = true
|
||||
}
|
||||
const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车
|
||||
isCartShow.value = true
|
||||
const valueStr = newGood.valueStr || ''
|
||||
const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr)
|
||||
if (index > -1) {
|
||||
@@ -769,6 +768,7 @@ const handleAddToCart = (cate, newGood, num) =>{ //添加到购物车
|
||||
uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
|
||||
}
|
||||
const adjustSimpleGood = (cate, newGood, num) => {
|
||||
isCartShow.value = true
|
||||
const valueStr = defaultSpec(newGood)
|
||||
const index = cart.value.findIndex(item => item.id === newGood.id && item.valueStr === valueStr)
|
||||
if (num > 0) {
|
||||
@@ -848,6 +848,8 @@ const handleAddToCartInModal = () => {
|
||||
closeGoodDetailModal()
|
||||
}
|
||||
const openCartPopup = () => { //打开/关闭购物车列表popup
|
||||
isCartShow.value = true
|
||||
if (!cart.value.length) return
|
||||
popup.value.open()
|
||||
}
|
||||
const handleCartClear = () => { //清空购物车
|
||||
@@ -866,10 +868,12 @@ const handleCartClear = () => { //清空购物车
|
||||
})
|
||||
}
|
||||
const handleCartItemAdd = (index) => {
|
||||
isCartShow.value = true
|
||||
cart.value[index].number += 1
|
||||
uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
|
||||
}
|
||||
const handleCartItemReduce = (index) => {
|
||||
isCartShow.value = true
|
||||
if (cart.value[index].number === 1) {
|
||||
cart.value.splice(index, 1)
|
||||
} else {
|
||||
@@ -877,6 +881,7 @@ const handleCartItemReduce = (index) => {
|
||||
}
|
||||
if (!cart.value.length) {
|
||||
cartPopupVisible.value = false
|
||||
popup.value?.close?.()
|
||||
}
|
||||
uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user