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

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

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

Loading…
Cancel
Save