feat:商品信息购物车数量问题

This commit is contained in:
qiaojiale 2025-07-17 15:34:49 +08:00
parent fb7bb4aa9f
commit b8aacb162f
18 changed files with 139 additions and 57 deletions

View File

@ -6,4 +6,5 @@ export const apiArr = {
getCarCount:"/api/v2/wechat/commodity/cart/all_count",//购物车数量 getCarCount:"/api/v2/wechat/commodity/cart/all_count",//购物车数量
addCar:"/api/v2/wechat/commodity/cart/add",//添加购物车 addCar:"/api/v2/wechat/commodity/cart/add",//添加购物车
deleteCar:"/api/v2/wechat/commodity/cart/delete",//删除购物车 deleteCar:"/api/v2/wechat/commodity/cart/delete",//删除购物车
updateCar:"/api/v2/wechat/commodity/cart/update",
} }

View File

@ -27,6 +27,7 @@
</div> </div>
<!-- 规格 --> <!-- 规格 -->
<!-- @click="changeGG2(item, index)" :class="index == currentGGIndex ? 'active' : ''"> -->
<div class="GGBox"> <div class="GGBox">
<div class="GG_left"> <div class="GG_left">
<div class="GG_Item" v-for="(item, index) in info.commodity_goods_info_list" :key="item.id" <div class="GG_Item" v-for="(item, index) in info.commodity_goods_info_list" :key="item.id"
@ -63,6 +64,8 @@
<image v-for="item in currentGG.goods_detail_pic" :src="picUrl + item" mode="widthFix"></image> <image v-for="item in currentGG.goods_detail_pic" :src="picUrl + item" mode="widthFix"></image>
</div> </div>
<!-- 底部购物车 --> <!-- 底部购物车 -->
<div class="Car"> <div class="Car">
<div class="car_left"> <div class="car_left">
@ -80,18 +83,21 @@
</div> </div>
</div> </div>
<div class="car_right" v-if="!info[currentGGIndex].cart_count || info[currentGGIndex].cart_count.count == 0" <div class="car_right"
v-if="!info.commodity_goods_info_list[currentGGIndex].cart_count || info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0"
@click="addCar"> @click="addCar">
加入购物车 加入购物车
</div> </div>
<div class="car_right" v-if="info[currentGGIndex].cart_count.count > 0"> <div class="car_right" v-if="info.commodity_goods_info_list[currentGGIndex].cart_count.count > 0">
<u-number-box v-model="info[currentGGIndex].cart_count.count" @change="changeCar">
<u-number-box v-model="info.commodity_goods_info_list[currentGGIndex].cart_count.count"
@change="changeCar" min="0">
<view slot="minus" class="minus"> <view slot="minus" class="minus">
<u-icon name="minus" size="36" bold></u-icon> <u-icon name="minus" size="36" bold></u-icon>
</view> </view>
<text slot="input" style="width: 200rpx;text-align: center;" class="input">{{ <text slot="input" style="width: 200rpx;text-align: center;" class="input">
info[currentGGIndex].cart_count.count }}</text> {{ info.commodity_goods_info_list[currentGGIndex].cart_count.count }}</text>
<view slot="plus" class="plus"> <view slot="plus" class="plus">
<u-icon name="plus" color="#FFFFFF" size="36" bold></u-icon> <u-icon name="plus" color="#FFFFFF" size="36" bold></u-icon>
</view> </view>
@ -143,7 +149,6 @@
</template> </template>
<script> <script>
import { info } from 'sass';
import { import {
apiArr apiArr
} from '../../../api/shop'; } from '../../../api/shop';
@ -171,6 +176,8 @@ export default {
currentGG: "", // currentGG: "", //
currentGGIndex: "", //index currentGGIndex: "", //index
carOrderList: [],
} }
}, },
methods: { methods: {
@ -266,6 +273,7 @@ export default {
item.commodity_pic = item.commodity_pic.split(',') item.commodity_pic = item.commodity_pic.split(',')
}); });
this.currentGG = res.commodity_goods_info_list[0] this.currentGG = res.commodity_goods_info_list[0]
this.currentGGIndex = 0
}) })
}, },
@ -282,10 +290,22 @@ export default {
}); });
}, },
// changeGG2(item, index) {
// request(apiArr.addCar,"POST",{
// goods_id:item.id,
// count:1
// })
// },
changeGG(item, index) { changeGG(item, index) {
this.currentGG = item this.currentGG = item
this.currentGGIndex = index this.currentGGIndex = index
this.currentGG.cart_count = { count: 0 } if (this.currentGG.cart_count) {
this.currentNum = this.currentGG.cart_count.count
} else {
this.currentGG.cart_count = { count: 0 }
}
}, },
car() { car() {
NavgateTo('../shopCar/index') NavgateTo('../shopCar/index')
@ -299,14 +319,37 @@ export default {
}) })
}, },
//
getShopCarList() {
request(apiArr.getCar, 'POST', {}).then(res => {
this.carOrderList = res.commodity_cart_list
})
},
addCar() { addCar() {
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = 1 console.log(this.info);
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = {count:1}
let carNum = 0
this.info.commodity_goods_info_list.forEach(item => {
carNum += item.cart_count.count
})
this.carNum = carNum
}, },
changeCar(newValue) { changeCar(newValue) {
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value
let carNum = 0
this.info.commodity_goods_info_list.forEach(item => {
if (item.cart_count) {
carNum += item.cart_count.count
}
})
this.carNum = carNum
}, },
}, },
onLoad(options) { onLoad(options) {
const meun = menuButtonInfo(); const meun = menuButtonInfo();
@ -316,30 +359,27 @@ export default {
this.id = options.id this.id = options.id
this.getGoodsInfo() this.getGoodsInfo()
this.getShopCar() this.getShopCar()
this.getShopCarList()
}, },
onReachBottom() { onReachBottom() {
}, },
onHide() { 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.count
})
})
request(apiArr.updateCar, "POST", {
goods_id_and_count
})
return
}, },
// watch() {
// return {
// 'info.commodity_goods_info_list': {
// handler(newList) {
// //
// this.carNum = newList.reduce((total, item) => {
// if (item.cart_count && item.cart_count.count) {
// return total + item.cart_count.count;
// }
// return total;
// }, 0);
// },
// deep: true,
// immediate: true
// }
// }
// }
} }
</script> </script>

View File

@ -538,7 +538,7 @@ page {
height: 140rpx; height: 140rpx;
position: fixed; position: fixed;
right: 33rpx; right: 33rpx;
bottom: 380rpx; bottom: 180rpx;
z-index: 10; z-index: 10;
} }
.shop_car image{ .shop_car image{

View File

@ -191,7 +191,7 @@
<nav-footer :current="2" /> <nav-footer :current="2" />
<div class="shop_car" @click="shopCar"> <div class="shop_car" @click="shopCar">
<u-badge numberType="limit" type="error" max="99" :value="value"></u-badge> <u-badge numberType="limit" type="error" max="99" :value="carNum"></u-badge>
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_car_num.png"></image> <image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_car_num.png"></image>
<!-- <image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_car_empty.png"></image> --> <!-- <image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_car_empty.png"></image> -->
</div> </div>
@ -277,7 +277,8 @@ export default {
rightCateList:[], // rightCateList:[], //
currentThirdId:"", currentThirdId:"",
tagList:[] tagList:[],
carNum:"",
} }
}, },
methods: { methods: {
@ -336,6 +337,13 @@ export default {
}) })
}, },
getShopCarList(){
request(apiArr.getCar,"POST",).then(res=>{
console.log(res);
this.carNum = res.total
})
},
changeLeftCate(e){ changeLeftCate(e){
this.secondId = e this.secondId = e
this.getGoodsList() this.getGoodsList()
@ -347,6 +355,7 @@ export default {
this.top = meun.top; this.top = meun.top;
this.localHeight = meun.height; this.localHeight = meun.height;
this.getCateList() this.getCateList()
this.getShopCarList()
}, },
onReachBottom() { onReachBottom() {
if (this.flag) { if (this.flag) {

View File

@ -13,28 +13,28 @@
</div> </div>
<div class="main"> <div class="main">
<div class="deleteIcon"> <div class="deleteIcon" @click="deleteItem">
<u-icon name="trash" size="50rpx"></u-icon> <u-icon name="trash" size="50rpx"></u-icon>
</div> </div>
<div class="goodsList"> <div class="goodsList">
<div class="goodsItem" v-for="item, index in shopCarList" :key="item.id"> <div class="goodsItem" v-for="item, index in shopCarList" :key="item.id">
<div class="goodsItem_left" @click="changeChecked(item,index)"> <div class="goodsItem_left" @click="changeChecked(item, index)">
<image v-if="!item.checked" src="http://192.168.0.172:5500/7.15/shop_checked1.png"></image> <image v-if="!item.checked" src="http://192.168.0.172:5500/7.15/shop_checked1.png"></image>
<image v-if="item.checked" src="http://192.168.0.172:5500/7.15/shop_checked2.png"></image> <image v-if="item.checked" src="http://192.168.0.172:5500/7.15/shop_checked2.png"></image>
</div> </div>
<div class="goodsItem_right"> <div class="goodsItem_right">
<div class="goodsItem_msg"> <div class="goodsItem_msg">
<div class="goodsItem_msg_img"> <div class="goodsItem_msg_img">
<image :src="picUrl + item.commodity_pic"> <image :src="picUrl + item.commodity_goods_info.commodity_pic">
</image> </image>
</div> </div>
<div class="goodsItem_msg_right"> <div class="goodsItem_msg_right">
<div class="goodsItem_msg_right_tit">{{ item.goods_name }}</div> <div class="goodsItem_msg_right_tit">{{ item.commodity_goods_info.goods_name }}</div>
<div class="goodsItem_msg_right_subTit">{{ item.goods_intro }}</div> <div class="goodsItem_msg_right_subTit">{{ item.commodity_goods_info.goods_intro }}</div>
<div class="goodsItem_msg_right_msg"> <div class="goodsItem_msg_right_msg">
<div class="goodsItem_msg_right_msg_left"> <div class="goodsItem_msg_right_msg_left">
<span></span>{{ item.sales_price }} <span>/{{ item.goods_unit }}</span> <span></span>{{ item.commodity_goods_info.sales_price }} <span>/{{ item.commodity_goods_info.goods_unit }}</span>
</div> </div>
<div class="goodsItem_msg_right_msg_right"> <div class="goodsItem_msg_right_msg_right">
<u-number-box v-model="item.count"> <u-number-box v-model="item.count">
@ -114,6 +114,9 @@ export default {
} }
}, },
methods: { methods: {
back() {
NavgateTo("1")
},
submitOrder() { submitOrder() {
NavgateTo("../submitOrder/index") NavgateTo("../submitOrder/index")
}, },
@ -129,7 +132,7 @@ export default {
}) })
}, },
// //
changeChecked(item, index) { changeChecked(item, index) {
this.shopCarList[index].checked = !this.shopCarList[index].checked this.shopCarList[index].checked = !this.shopCarList[index].checked
this.calcTotal() this.calcTotal()
@ -156,11 +159,40 @@ export default {
let total = 0 let total = 0
this.shopCarList.forEach(item => { this.shopCarList.forEach(item => {
if (item.checked) { if (item.checked) {
total += item.sales_price * item.count total += item.commodity_goods_info.sales_price * item.count
} }
}); });
this.shopMoney = total this.shopMoney = total
}, },
deleteItem() {
let that = this
uni.showModal({
title: '提示',
content: '确定删除所选商品吗',
success: function (res) {
if (res.confirm) {
let ids = []
that.shopCarList.forEach(item => {
if(item.checked){
ids.push(item.id)
}
})
request(apiArr.deleteCar, "POST", {
ids
}).then(res=>{
uni.showToast({
title: '删除成功',
duration: 2000
});
that.getShopCar()
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
},
}, },
onLoad(options) { onLoad(options) {
const meun = menuButtonInfo(); const meun = menuButtonInfo();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -7,12 +7,19 @@
"condition": { "condition": {
"miniprogram": { "miniprogram": {
"list": [ "list": [
{
"name": "packages/shop/goods/index",
"pathName": "packages/shop/goods/index",
"query": "id=32",
"scene": null,
"launchMode": "default"
},
{ {
"name": "packages/shop/shopCar/index", "name": "packages/shop/shopCar/index",
"pathName": "packages/shop/shopCar/index", "pathName": "packages/shop/shopCar/index",
"query": "", "query": "",
"scene": null, "launchMode": "default",
"launchMode": "default" "scene": null
}, },
{ {
"name": "packages/shop/goods/index", "name": "packages/shop/goods/index",
@ -20,13 +27,6 @@
"query": "id=30", "query": "id=30",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
},
{
"name": "packages/shop/index/index",
"pathName": "packages/shop/index/index",
"query": "",
"launchMode": "default",
"scene": null
} }
] ]
} }