优化详情页进入购物车页面的逻辑
This commit is contained in:
parent
0cac04e0db
commit
4df3526466
@ -40,7 +40,8 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="GG_rigth" @click="showSizePopup">
|
||||
共{{ info.commodity_goods_info_list ? info.commodity_goods_info_list.length : 0 }}款<u-icon size="26rpx" name="arrow-right"></u-icon>
|
||||
共{{ info.commodity_goods_info_list ? info.commodity_goods_info_list.length : 0 }}款<u-icon size="26rpx"
|
||||
name="arrow-right"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -177,7 +178,7 @@
|
||||
<view class="car_right" v-if="
|
||||
info.commodity_goods_info_list[currentGGIndex].stock_quantity > 0 &&
|
||||
(!info.commodity_goods_info_list[currentGGIndex].cart_count ||
|
||||
info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0)
|
||||
info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0)
|
||||
" @click="addCar">
|
||||
加入购物车
|
||||
</view>
|
||||
@ -188,8 +189,9 @@
|
||||
">
|
||||
加入购物车
|
||||
</view>
|
||||
|
||||
<view class="car_right car_right_disabled" v-if="info.commodity_goods_info_list[currentGGIndex].stock_quantity < 1">
|
||||
|
||||
<view class="car_right car_right_disabled"
|
||||
v-if="info.commodity_goods_info_list[currentGGIndex].stock_quantity < 1">
|
||||
已售罄
|
||||
</view>
|
||||
</view>
|
||||
@ -435,7 +437,6 @@ export default {
|
||||
request(apiArr.getGoodsInfo, "POST", {
|
||||
id: this.id,
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
|
||||
// 分割图片
|
||||
res.commodity_goods_info_list.forEach((item) => {
|
||||
@ -458,7 +459,6 @@ export default {
|
||||
});
|
||||
}
|
||||
this.info = res;
|
||||
console.log("this.info", this.info.commodity_goods_info_list);
|
||||
|
||||
// 检查是否有传入的选中商品信息,如果有则设置为默认选中
|
||||
let selectedIndex = 0;
|
||||
@ -517,14 +517,17 @@ export default {
|
||||
//获取购物车数量
|
||||
getShopCar() {
|
||||
request(apiArr.getCarCount, "POST", {}).then((res) => {
|
||||
this.carNum = res.total;
|
||||
this.prevCarNum = res.total;
|
||||
});
|
||||
},
|
||||
|
||||
getShopCarList() {
|
||||
request(apiArr.getCar, "POST", {}).then((res) => {
|
||||
this.carOrderList = res.commodity_cart_list;
|
||||
return request(apiArr.getCar, "POST", {}).then((res) => {
|
||||
// 合并当日达和普通商品数据
|
||||
this.carOrderList = [].concat(res.same_day_cart_list, res.normal_cart_list)
|
||||
.flatMap(supplier => supplier.commodity_cart_and_goods_model);
|
||||
this.carNum = res.total;
|
||||
return res;
|
||||
});
|
||||
},
|
||||
|
||||
@ -655,20 +658,23 @@ export default {
|
||||
},
|
||||
onReachBottom() { },
|
||||
onShow() {
|
||||
this.getShopCarList();
|
||||
this.getGoodsInfo();
|
||||
this.getShopCar();
|
||||
this.getComment();
|
||||
this.getShopCarList().then(() => {
|
||||
this.getGoodsInfo();
|
||||
this.getShopCar();
|
||||
this.getComment();
|
||||
});
|
||||
},
|
||||
|
||||
//离开页面的时候直接更新购物车数量(目前接口是 传入商品id 数量。如果有当前商品就更新数量。如果没有就增加商品。如果删除某个商品 count 为0 就删除)
|
||||
onHide() {
|
||||
let goods_id_and_count = [];
|
||||
this.info.commodity_goods_info_list.forEach((item) => {
|
||||
goods_id_and_count.push({
|
||||
goods_id: item.id,
|
||||
count: item.cart_count ? item.cart_count.count : 0,
|
||||
});
|
||||
if (item.cart_count) {
|
||||
goods_id_and_count.push({
|
||||
goods_id: item.id,
|
||||
count: item.cart_count.count,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
request(apiArr.updateCar, "POST", {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user