优化详情页进入购物车页面的逻辑

This commit is contained in:
赵毅 2025-10-27 09:43:53 +08:00
parent 0cac04e0db
commit 4df3526466

View File

@ -40,7 +40,8 @@
</view> </view>
</view> </view>
<view class="GG_rigth" @click="showSizePopup"> <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>
</view> </view>
@ -177,7 +178,7 @@
<view class="car_right" v-if=" <view class="car_right" v-if="
info.commodity_goods_info_list[currentGGIndex].stock_quantity > 0 && 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 ||
info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0) info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0)
" @click="addCar"> " @click="addCar">
加入购物车 加入购物车
</view> </view>
@ -189,7 +190,8 @@
加入购物车 加入购物车
</view> </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>
</view> </view>
@ -435,7 +437,6 @@ export default {
request(apiArr.getGoodsInfo, "POST", { request(apiArr.getGoodsInfo, "POST", {
id: this.id, id: this.id,
}).then((res) => { }).then((res) => {
console.log(res);
// //
res.commodity_goods_info_list.forEach((item) => { res.commodity_goods_info_list.forEach((item) => {
@ -458,7 +459,6 @@ export default {
}); });
} }
this.info = res; this.info = res;
console.log("this.info", this.info.commodity_goods_info_list);
// //
let selectedIndex = 0; let selectedIndex = 0;
@ -517,14 +517,17 @@ export default {
// //
getShopCar() { getShopCar() {
request(apiArr.getCarCount, "POST", {}).then((res) => { request(apiArr.getCarCount, "POST", {}).then((res) => {
this.carNum = res.total;
this.prevCarNum = res.total; this.prevCarNum = res.total;
}); });
}, },
getShopCarList() { getShopCarList() {
request(apiArr.getCar, "POST", {}).then((res) => { return request(apiArr.getCar, "POST", {}).then((res) => {
this.carOrderList = res.commodity_cart_list; //
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() { }, onReachBottom() { },
onShow() { onShow() {
this.getShopCarList(); this.getShopCarList().then(() => {
this.getGoodsInfo(); this.getGoodsInfo();
this.getShopCar(); this.getShopCar();
this.getComment(); this.getComment();
});
}, },
//( id count 0 ) //( id count 0 )
onHide() { onHide() {
let goods_id_and_count = []; let goods_id_and_count = [];
this.info.commodity_goods_info_list.forEach((item) => { this.info.commodity_goods_info_list.forEach((item) => {
goods_id_and_count.push({ if (item.cart_count) {
goods_id: item.id, goods_id_and_count.push({
count: item.cart_count ? item.cart_count.count : 0, goods_id: item.id,
}); count: item.cart_count.count,
});
}
}); });
request(apiArr.updateCar, "POST", { request(apiArr.updateCar, "POST", {