修改搜索商品的详情页加入购物车按钮的显示逻辑
This commit is contained in:
parent
56e0d60f34
commit
a139ec38c9
@ -284,6 +284,11 @@ image {
|
|||||||
margin-top: 26rpx;
|
margin-top: 26rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.car_right_disabled {
|
||||||
|
background: #CCCCCC;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
.cars {
|
.cars {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@ -175,30 +175,22 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="car_right" v-if="
|
<view class="car_right" v-if="
|
||||||
!info.commodity_goods_info_list[currentGGIndex].cart_count ||
|
info.commodity_goods_info_list[currentGGIndex].stock_quantity > 0 &&
|
||||||
info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0
|
(!info.commodity_goods_info_list[currentGGIndex].cart_count ||
|
||||||
|
info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0)
|
||||||
" @click="addCar">
|
" @click="addCar">
|
||||||
加入购物车
|
加入购物车
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="car_right" v-if="info.commodity_goods_info_list[currentGGIndex].cart_count.count > 0">
|
<view class="car_right" @click="changeCar" v-if="
|
||||||
<!-- <view class="car_right"> -->
|
info.commodity_goods_info_list[currentGGIndex].cart_count.count > 0
|
||||||
<u-number-box v-model="info.commodity_goods_info_list[currentGGIndex].cart_count.count"
|
&& info.commodity_goods_info_list[currentGGIndex].stock_quantity > 0
|
||||||
@change="changeCar" min="0">
|
">
|
||||||
<!-- <u-number-box > -->
|
加入购物车
|
||||||
<view slot="minus" class="minus">
|
</view>
|
||||||
<u-icon name="minus" size="36" bold></u-icon>
|
|
||||||
</view>
|
<view class="car_right car_right_disabled" v-if="info.commodity_goods_info_list[currentGGIndex].stock_quantity < 1">
|
||||||
<text slot="input" style="width: 200rpx; text-align: center" class="input">
|
已售罄
|
||||||
{{ info.commodity_goods_info_list[currentGGIndex].cart_count.count }}
|
|
||||||
</text>
|
|
||||||
<!-- text slot="input" style="width: 200rpx; text-align: center" class="input">
|
|
||||||
{{info.commodity_goods_info_list[currentGGIndex]}}
|
|
||||||
</text> -->
|
|
||||||
<view slot="plus" class="plus">
|
|
||||||
<u-icon name="plus" color="#FFFFFF" size="36" bold></u-icon>
|
|
||||||
</view>
|
|
||||||
</u-number-box>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -576,32 +568,39 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 购物车更改
|
// 购物车更改
|
||||||
changeCar(newValue) {
|
changeCar() {
|
||||||
// // 修改当前商品在购物车中的数量
|
// 直接增加商品数量,与addCar逻辑类似
|
||||||
// this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value
|
const currentGoods = this.info.commodity_goods_info_list[this.currentGGIndex];
|
||||||
// // 修改购物车列表中的数量
|
const currentQuantity = currentGoods.cart_count ? currentGoods.cart_count.count : 0;
|
||||||
// this.carOrderList.forEach(item => {
|
const stockQuantity = currentGoods.stock_quantity || 0;
|
||||||
// if (item.commodity_goods_info.id == this.info.commodity_goods_info_list[this.currentGGIndex].id) {
|
|
||||||
// item.count = newValue.value
|
// 检查库存是否充足
|
||||||
// }
|
if (currentQuantity >= stockQuantity) {
|
||||||
// })
|
uni.showToast({
|
||||||
// // 计算购物车数量
|
title: "库存不足",
|
||||||
// let carNum = 0
|
icon: "none",
|
||||||
// this.carOrderList.forEach(item => {
|
duration: 2000
|
||||||
// carNum += item.count
|
});
|
||||||
// })
|
return;
|
||||||
// this.carNum = carNum
|
}
|
||||||
//商品数量变化
|
|
||||||
|
// 增加商品数量
|
||||||
|
currentGoods.cart_count = {
|
||||||
|
count: currentQuantity + 1,
|
||||||
|
};
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
user_id: uni.getStorageSync("userId"),
|
user_id: uni.getStorageSync("userId"),
|
||||||
goods_id_and_count: [{
|
goods_id_and_count: [{
|
||||||
goods_id: this.info.commodity_goods_info_list[this.currentGGIndex].id,
|
goods_id: currentGoods.id,
|
||||||
count: newValue.value,
|
count: currentGoods.cart_count.count,
|
||||||
},],
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
request(apiArr.updateCar, "POST", params).then((res) => {
|
request(apiArr.updateCar, "POST", params).then((res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
this.getShopCarList();
|
this.getShopCarList();
|
||||||
|
this.getShopCar();
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "操作成功!",
|
title: "操作成功!",
|
||||||
success() { },
|
success() { },
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user