[fix]首页加入购入车

main
huyuanxiang 1 year ago
parent 2ad63130e8
commit 0bd3284165

@ -31,13 +31,13 @@
<!-- <text v-if="item.skuItem.dashPrice" class="text2 text-xs"> {{item.skuItem.dashPrice.text}}</text> -->
</view>
<view class="g_left price" v-else>
<view class="g_left price" v-if="!item.price">
<text class="text1 text-bold text-sm">客服询价 </text>
</view>
<!-- <view class="g_right" @tap="addCart(item)">
<image src="/static/images/new/jiagou.png" style=" width: 28px;height: 28px;" mode="aspectFill"></image>
</view> -->
<view class="g_right" v-if="item.price" @tap="addCart(item)">
<image src="/static/images/new/jiagou.png" style=" width: 24px;height: 24px;" mode="aspectFill"></image>
</view>
</view>
</view>
@ -116,90 +116,57 @@
url: '/pages/views/goods/goodsDetails?id=' + item.id
});
},
addCart(e) {
console.log(e)
//
addCart(item) {
if(!getToken()){
uni.navigateTo({ //
url:'/pages/login/index1'
})
return
uni.navigateTo({ //
url:'/pages/login/index1'
})
return
}
setCartDetails(e.skuItem)
setGoodsDetails(e.skuItem)
var data = this.good_data
data.status= 0;
data.img = e.skuItem.picUrl;
data.title = e.skuItem.skuTitle.text;
data.money = parseFloat(e.skuItem.sellPrice.text.substr(1));
data.imgList.push(e.skuItem.picUrl);
data.imgList.push(e.skuItem.detailPagePic);
data.xiaoliang = e.skuItem.skuId;
data.goods_id = e.skuItem.skuId;
if(data.skuArr){
let sku = data.skuArr
for(let i=0;i<sku.length;i++){
sku[i].img = data.img
sku[i].goods_sku_text = data.title+"测试规格"+i;
sku[i].money = data.money
}
}
if(data.sku){
let sku = data.sku[0].child
for(let i=0;i<sku.length;i++){
sku[i].imgs = data.img
sku[i].tagname = data.title+"测试规格"+i;
sku[i].money = data.money
}
if (!item.ifSale) {
this.$toast('该商品已下架')
return
}
data.selectSku.goods_sku_text = data.skuArr[0].goods_sku_text
data.selectSku.img = data.skuArr[0].img
data.selectSku.money = data.skuArr[0].money
let colCart = getCart();
if(colCart.length){
const hasItem = colCart.some(v => v.goods_id === data.goods_id)
if (!hasItem) {
colCart.push(data)
} else {
for(let y = 0;y < colCart.length; y++){
const item = colCart[y]
if (data.goods_id === item.goods_id) {
item.number ++
break
const cartList = getCart()
item.imgList = item.url.split(',')
item.number = 1
item._selectedSku = [{
id: item.id,
imgs: '',
money: item.price,
number: 1,
tagname: item.goodsName
}]
item._skus = [
{
sku_id: item.id,
skuname: '规格',
child: [
{
id: 1,
imgs: '',
money: item.price,
number: 1,
tagname: item.goodsName
}
}
]
}
]
const goodsItem = item
let hasItem = false
const cartHasGoodsList = cartList.map(v => {
if (v.id === (goodsItem.id +'')) {
hasItem = true
v.number = v.number >= 99999 ? 99999 : v.number + 1
}
} else {
colCart = [data]
return v
})
if (!hasItem) {
cartHasGoodsList.push(item)
}
resetCart(colCart)
/**
* 模拟获取购物车的数量 getCart
*/
// let cartNum = getCart()
setTabBarBadge(colCart.length)
//
uni.showToast({
title: '加入购物车成功 !',
icon: 'none'
});
resetCart(cartHasGoodsList)
setTabBarBadge(cartHasGoodsList.length)
this.$toast('加入购物车成功')
},
},
}

@ -142,7 +142,7 @@
this.bottomShow = 0
// #endif
// #ifdef H5
this.bottomShow = '100upx'
this.bottomShow = '50px'
// #endif
// #ifdef APP-PLUS
this.showHeader = true //APP

@ -35,8 +35,6 @@
<view class="type_good">
<goodList :has-token="hasToken" style="width: 100%; background-color: #FFFFFF;" :propsList = "cateGood" ></goodList>
</view>
</scroll-view>
</view>
</view>

Loading…
Cancel
Save