|
|
|
@ -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('加入购物车成功')
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|