feat:调用购物车 默认地址接口 修改商品详情bug

This commit is contained in:
qiaojiale 2025-07-17 18:31:40 +08:00
parent b8aacb162f
commit 53d506c084
7 changed files with 202 additions and 46 deletions

View File

@ -6,5 +6,6 @@ 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", updateCar:"/api/v2/wechat/commodity/cart/update",//更新购物车信息
getUserDefAddress:"/api/v2/wechat/commodity/receiving_address/get_default",//获取用户默认地址
} }

View File

@ -327,25 +327,67 @@ export default {
}, },
addCar() { addCar() {
console.log(this.info);
let that = this
//
let goods_id_and_count = []
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { count: 1 } this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { count: 1 }
let carNum = 0
this.info.commodity_goods_info_list.forEach(item => { this.info.commodity_goods_info_list.forEach(item => {
carNum += item.cart_count.count console.log(item);
goods_id_and_count.push({
goods_id: item.id,
count: item.cart_count.count
}) })
this.carNum = carNum })
request(apiArr.updateCar, "POST", {
goods_id_and_count
}).then(res => {
that.getShopCar()
that.getShopCarList()
})
// let flag = false
// this.carOrderList.forEach(item => {
// if (item.goods_id == this.info.commodity_goods_info_list[this.currentGGIndex].id) {
// flag = true
// }
// })
// console.log(flag);
// if (flag) {
// 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
// } else {
// }
}, },
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 => { this.carOrderList.forEach(item=>{
if (item.cart_count) { if(item.commodity_goods_info.id == this.info.commodity_goods_info_list[this.currentGGIndex].id){
carNum += item.cart_count.count console.log(item,'item');
item.count = newValue.value
} }
}) })
let carNum = 0
this.carOrderList.forEach(item=>{
carNum += item.count
})
// let carNum = 0
// this.info.commodity_goods_info_list.forEach(item => {
// if (item.cart_count) {
// carNum += item.cart_count.count
// }
// })
this.carNum = carNum this.carNum = carNum
}, },
@ -357,12 +399,15 @@ export default {
this.localHeight = meun.height; this.localHeight = meun.height;
this.id = options.id this.id = options.id
this.getGoodsInfo()
this.getShopCar()
this.getShopCarList()
}, },
onReachBottom() { onReachBottom() {
},
onShow() {
this.getGoodsInfo()
this.getShopCar()
this.getShopCarList()
}, },
onHide() { onHide() {

View File

@ -31,19 +31,21 @@
</div> </div>
<div class="goodsItem_msg_right"> <div class="goodsItem_msg_right">
<div class="goodsItem_msg_right_tit">{{ item.commodity_goods_info.goods_name }}</div> <div class="goodsItem_msg_right_tit">{{ item.commodity_goods_info.goods_name }}</div>
<div class="goodsItem_msg_right_subTit">{{ item.commodity_goods_info.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.commodity_goods_info.sales_price }} <span>/{{ item.commodity_goods_info.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" :asyncChange="true" min="0">
<view slot="minus" class="minus"> <view slot="minus" class="minus" @click="minus(item, index)">
<u-icon name="minus" size="32" bold></u-icon> <u-icon name="minus" size="32" bold></u-icon>
</view> </view>
<text slot="input" style="width: 80rpx;text-align: center;" class="input">{{ <text slot="input" style="width: 80rpx;text-align: center;" class="input">{{
item.count }}</text> item.count }}</text>
<view slot="plus" class="plus"> <view slot="plus" class="plus" @click="add(item, index)">
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon> <u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon>
</view> </view>
</u-number-box> </u-number-box>
@ -118,7 +120,15 @@ export default {
NavgateTo("1") NavgateTo("1")
}, },
submitOrder() { submitOrder() {
NavgateTo("../submitOrder/index")
let arr = []
this.shopCarList.forEach(item => {
if (item.checked) {
arr.push(item)
}
})
NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`)
}, },
getShopCar() { getShopCar() {
@ -126,7 +136,6 @@ export default {
res.commodity_cart_list.forEach(item => { res.commodity_cart_list.forEach(item => {
item.checked = false item.checked = false
}); });
console.log(res.commodity_cart_list);
this.shopCarTotal = res.total this.shopCarTotal = res.total
this.shopCarList = res.commodity_cart_list this.shopCarList = res.commodity_cart_list
}) })
@ -156,8 +165,11 @@ export default {
}, },
// //
calcTotal() { calcTotal() {
let total = 0 let total = 0
this.shopCarList.forEach(item => { this.shopCarList.forEach(item => {
console.log(item);
if (item.checked) { if (item.checked) {
total += item.commodity_goods_info.sales_price * item.count total += item.commodity_goods_info.sales_price * item.count
} }
@ -165,6 +177,25 @@ export default {
this.shopMoney = total this.shopMoney = total
}, },
minus(item, index) {
let that = this
if (item.count === 1) {
request(apiArr.deleteCar, "POST", {
ids: [item.id]
}).then(res => {
that.shopCarList.splice(index, 1)
that.calcTotal()
})
}
this.shopCarList[index].count = this.shopCarList[index].count - 1
this.calcTotal()
},
add(item, index) {
this.shopCarList[index].count = this.shopCarList[index].count + 1
this.calcTotal()
},
deleteItem() { deleteItem() {
let that = this let that = this
uni.showModal({ uni.showModal({
@ -176,6 +207,7 @@ export default {
that.shopCarList.forEach(item => { that.shopCarList.forEach(item => {
if (item.checked) { if (item.checked) {
ids.push(item.id) ids.push(item.id)
item.checked = false
} }
}) })
request(apiArr.deleteCar, "POST", { request(apiArr.deleteCar, "POST", {
@ -186,6 +218,9 @@ export default {
duration: 2000 duration: 2000
}); });
that.getShopCar() that.getShopCar()
that.calcTotal()
}).catch(err => {
console.log(err);
}) })
} else if (res.cancel) { } else if (res.cancel) {
console.log('用户点击取消'); console.log('用户点击取消');

View File

@ -177,3 +177,23 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.address_Info_btn {
background: linear-gradient(91deg, #FF7658 0%, #FF370B 100%);
border-radius: 100rpx 100rpx 100rpx 100rpx;
height: 90rpx;
width: 600rpx;
font-size: 36rpx;
color: #FFFFFF;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
}
.noneDef{
display: flex;
align-items: center;
justify-content: center;
width: 100%;
}

View File

@ -4,42 +4,49 @@
<div class="border"> <div class="border">
<image src="http://192.168.0.172:5500/7.15/shop_border.png" mode="widthFix"></image> <image src="http://192.168.0.172:5500/7.15/shop_border.png" mode="widthFix"></image>
</div> </div>
<div class="address_Info" @click="choseAddress"> <div class="address_Info" @click="choseAddress" v-if="defAddress">
<div class="address_Info_left"> <div class="address_Info_left">
<div class="address_Info_left_tit">收货地址</div> <div class="address_Info_left_tit">收货地址</div>
<div class="address_Info_left_name">李佳 15901518415</div> <div class="address_Info_left_name">李佳 15901518415</div>
<div class="address_Info_left_addr">北京北京市朝阳区珠江绿洲文化广场</div> <div class="address_Info_left_addr">北京北京市朝阳区珠江绿洲文化广场</div>
</div> </div>
<div class="address_Info_right">
<u-icon name="arrow-right" size="40rpx"></u-icon>
</div> </div>
<div class="address_Info" @click="choseAddress" v-if="!defAddress">
<div class="address_Info_left noneDef">
<div class="address_Info_btn">添加收货地址</div>
</div> </div>
</div>
<div class="border"> <div class="border">
<image src="http://192.168.0.172:5500/7.15/shop_border.png" mode="widthFix"></image> <image src="http://192.168.0.172:5500/7.15/shop_border.png" mode="widthFix"></image>
</div> </div>
</div> </div>
<div class="goodsCate" v-for="items, indexs in 2" :key="indexs"> <div class="goodsCate" v-for="items, indexs in carList" :key="indexs">
<div class="goodsItem" v-for="item, index in 3" :key="index"> <div class="goodsItem">
<div class="goodsItem_msg_img"> <div class="goodsItem_msg_img">
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_MsgImg1.png"> <image :src="picUrl + items.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">泰国金枕榴莲</div> <div class="goodsItem_msg_right_tit">{{ items.commodity_goods_info.goods_name }}</div>
<div class="goodsItem_msg_right_subTit">商品介绍商品介绍</div> <div class="goodsItem_msg_right_subTit">{{ items.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>125.9 <span>/</span> <span></span>{{ items.commodity_goods_info.sales_price }}
<span>/{{ items.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="value"> <u-number-box v-model="value">
<view slot="minus" class="minus"> <view slot="minus" class="minus" @click="minus(items, indexs)">
<u-icon name="minus" size="32" bold></u-icon> <u-icon name="minus" size="32" bold></u-icon>
</view> </view>
<text slot="input" style="width: 80rpx;text-align: center;" class="input">{{ <text slot="input" style="width: 80rpx;text-align: center;" class="input">
value }}</text> {{ items.count }}
<view slot="plus" class="plus"> </text>
<view slot="plus" class="plus" @click="add(items, indexs)">
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon> <u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon>
</view> </view>
</u-number-box> </u-number-box>
@ -55,7 +62,7 @@
<div class="footer"> <div class="footer">
<div class="btn">立即支付4500.00</div> <div class="btn">立即支付{{ totalMony }}</div>
</div> </div>
</view> </view>
@ -64,7 +71,7 @@
<script> <script>
import { import {
apiArr apiArr
} from '../../../api/doorToDoor'; } from '../../../api/shop';
import { import {
picUrl, picUrl,
menuButtonInfo, menuButtonInfo,
@ -74,22 +81,63 @@ import {
export default { export default {
data() { data() {
return { return {
picUrl,
top: "", top: "",
localHeight: "", localHeight: "",
value: 3, value: 3,
type: "error", type: "error",
carList: [],
totalMony: 0,
defAddress:{},
} }
}, },
methods: { methods: {
choseAddress() { choseAddress() {
NavgateTo('../address/index') NavgateTo('../address/index')
}, },
calcTotal() {
let total = 0
this.carList.forEach(item => {
total += item.commodity_goods_info.sales_price * item.count
})
this.totalMony = total
},
minus(item, index) {
let that = this
if (item.count === 1) {
request(apiArr.deleteCar, "POST", {
ids: [item.id]
}).then(res => {
that.carList.splice(index, 1)
that.calcTotal()
})
}
this.carList[index].count = this.carList[index].count - 1
this.calcTotal()
},
add(item, index) {
this.carList[index].count = this.carList[index].count + 1
this.calcTotal()
},
//
getUserAddress() {
request(apiArr.getUserDefAddress, "POST", {}).then(res => {
this.defAddress = res.default_address
})
},
},
onShow() {
this.getUserAddress()
}, },
onLoad(options) { onLoad(options) {
const meun = menuButtonInfo(); const meun = menuButtonInfo();
this.top = meun.top; this.top = meun.top;
this.localHeight = meun.height; this.localHeight = meun.height;
this.carList = JSON.parse(options.shopCarList)
this.calcTotal()
}, },
onReachBottom() { onReachBottom() {

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/shopCar/index",
"pathName": "packages/shop/shopCar/index",
"query": "",
"launchMode": "default",
"scene": null
},
{ {
"name": "packages/shop/goods/index", "name": "packages/shop/goods/index",
"pathName": "packages/shop/goods/index", "pathName": "packages/shop/goods/index",
"query": "id=32", "query": "id=32",
"scene": null, "launchMode": "default",
"launchMode": "default" "scene": null
}, },
{ {
"name": "packages/shop/shopCar/index", "name": "packages/shop/shopCar/index",