feat:商品信息购物车数量问题
This commit is contained in:
parent
fb7bb4aa9f
commit
b8aacb162f
@ -6,4 +6,5 @@ export const apiArr = {
|
||||
getCarCount:"/api/v2/wechat/commodity/cart/all_count",//购物车数量
|
||||
addCar:"/api/v2/wechat/commodity/cart/add",//添加购物车
|
||||
deleteCar:"/api/v2/wechat/commodity/cart/delete",//删除购物车
|
||||
updateCar:"/api/v2/wechat/commodity/cart/update",
|
||||
}
|
||||
@ -27,6 +27,7 @@
|
||||
</div>
|
||||
|
||||
<!-- 规格 -->
|
||||
<!-- @click="changeGG2(item, index)" :class="index == currentGGIndex ? 'active' : ''"> -->
|
||||
<div class="GGBox">
|
||||
<div class="GG_left">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- 底部购物车 -->
|
||||
<div class="Car">
|
||||
<div class="car_left">
|
||||
@ -80,18 +83,21 @@
|
||||
</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">
|
||||
加入购物车
|
||||
</div>
|
||||
|
||||
<div class="car_right" v-if="info[currentGGIndex].cart_count.count > 0">
|
||||
<u-number-box v-model="info[currentGGIndex].cart_count.count" @change="changeCar">
|
||||
<div class="car_right" v-if="info.commodity_goods_info_list[currentGGIndex].cart_count.count > 0">
|
||||
|
||||
<u-number-box v-model="info.commodity_goods_info_list[currentGGIndex].cart_count.count"
|
||||
@change="changeCar" min="0">
|
||||
<view slot="minus" class="minus">
|
||||
<u-icon name="minus" size="36" bold></u-icon>
|
||||
</view>
|
||||
<text slot="input" style="width: 200rpx;text-align: center;" class="input">{{
|
||||
info[currentGGIndex].cart_count.count }}</text>
|
||||
<text slot="input" style="width: 200rpx;text-align: center;" class="input">
|
||||
{{ info.commodity_goods_info_list[currentGGIndex].cart_count.count }}</text>
|
||||
<view slot="plus" class="plus">
|
||||
<u-icon name="plus" color="#FFFFFF" size="36" bold></u-icon>
|
||||
</view>
|
||||
@ -143,7 +149,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { info } from 'sass';
|
||||
import {
|
||||
apiArr
|
||||
} from '../../../api/shop';
|
||||
@ -171,6 +176,8 @@ export default {
|
||||
|
||||
currentGG: "", //当前选中规格
|
||||
currentGGIndex: "", //当前规格index
|
||||
|
||||
carOrderList: [],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -266,6 +273,7 @@ export default {
|
||||
item.commodity_pic = item.commodity_pic.split(',')
|
||||
});
|
||||
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) {
|
||||
this.currentGG = item
|
||||
this.currentGGIndex = index
|
||||
if (this.currentGG.cart_count) {
|
||||
this.currentNum = this.currentGG.cart_count.count
|
||||
} else {
|
||||
this.currentGG.cart_count = { count: 0 }
|
||||
}
|
||||
},
|
||||
car() {
|
||||
NavgateTo('../shopCar/index')
|
||||
@ -299,14 +319,37 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
//离开页面的时候 判断添加了多少 删除了多少商品
|
||||
getShopCarList() {
|
||||
request(apiArr.getCar, 'POST', {}).then(res => {
|
||||
this.carOrderList = res.commodity_cart_list
|
||||
})
|
||||
},
|
||||
|
||||
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) {
|
||||
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) {
|
||||
const meun = menuButtonInfo();
|
||||
@ -316,30 +359,27 @@ export default {
|
||||
this.id = options.id
|
||||
this.getGoodsInfo()
|
||||
this.getShopCar()
|
||||
this.getShopCarList()
|
||||
},
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
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>
|
||||
|
||||
@ -538,7 +538,7 @@ page {
|
||||
height: 140rpx;
|
||||
position: fixed;
|
||||
right: 33rpx;
|
||||
bottom: 380rpx;
|
||||
bottom: 180rpx;
|
||||
z-index: 10;
|
||||
}
|
||||
.shop_car image{
|
||||
|
||||
@ -191,7 +191,7 @@
|
||||
<nav-footer :current="2" />
|
||||
|
||||
<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_empty.png"></image> -->
|
||||
</div>
|
||||
@ -277,7 +277,8 @@ export default {
|
||||
rightCateList:[], //底部右侧分类
|
||||
currentThirdId:"",
|
||||
|
||||
tagList:[]
|
||||
tagList:[],
|
||||
carNum:"",
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -336,6 +337,13 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
getShopCarList(){
|
||||
request(apiArr.getCar,"POST",).then(res=>{
|
||||
console.log(res);
|
||||
this.carNum = res.total
|
||||
})
|
||||
},
|
||||
|
||||
changeLeftCate(e){
|
||||
this.secondId = e
|
||||
this.getGoodsList()
|
||||
@ -347,6 +355,7 @@ export default {
|
||||
this.top = meun.top;
|
||||
this.localHeight = meun.height;
|
||||
this.getCateList()
|
||||
this.getShopCarList()
|
||||
},
|
||||
onReachBottom() {
|
||||
if (this.flag) {
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
</div>
|
||||
|
||||
<div class="main">
|
||||
<div class="deleteIcon">
|
||||
<div class="deleteIcon" @click="deleteItem">
|
||||
<u-icon name="trash" size="50rpx"></u-icon>
|
||||
</div>
|
||||
|
||||
@ -26,15 +26,15 @@
|
||||
<div class="goodsItem_right">
|
||||
<div class="goodsItem_msg">
|
||||
<div class="goodsItem_msg_img">
|
||||
<image :src="picUrl + item.commodity_pic">
|
||||
<image :src="picUrl + item.commodity_goods_info.commodity_pic">
|
||||
</image>
|
||||
</div>
|
||||
<div class="goodsItem_msg_right">
|
||||
<div class="goodsItem_msg_right_tit">{{ item.goods_name }}</div>
|
||||
<div class="goodsItem_msg_right_subTit">{{ item.goods_intro }}</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_msg">
|
||||
<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 class="goodsItem_msg_right_msg_right">
|
||||
<u-number-box v-model="item.count">
|
||||
@ -114,6 +114,9 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
back() {
|
||||
NavgateTo("1")
|
||||
},
|
||||
submitOrder() {
|
||||
NavgateTo("../submitOrder/index")
|
||||
},
|
||||
@ -156,11 +159,40 @@ export default {
|
||||
let total = 0
|
||||
this.shopCarList.forEach(item => {
|
||||
if (item.checked) {
|
||||
total += item.sales_price * item.count
|
||||
total += item.commodity_goods_info.sales_price * item.count
|
||||
}
|
||||
});
|
||||
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) {
|
||||
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
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
@ -7,12 +7,19 @@
|
||||
"condition": {
|
||||
"miniprogram": {
|
||||
"list": [
|
||||
{
|
||||
"name": "packages/shop/goods/index",
|
||||
"pathName": "packages/shop/goods/index",
|
||||
"query": "id=32",
|
||||
"scene": null,
|
||||
"launchMode": "default"
|
||||
},
|
||||
{
|
||||
"name": "packages/shop/shopCar/index",
|
||||
"pathName": "packages/shop/shopCar/index",
|
||||
"query": "",
|
||||
"scene": null,
|
||||
"launchMode": "default"
|
||||
"launchMode": "default",
|
||||
"scene": null
|
||||
},
|
||||
{
|
||||
"name": "packages/shop/goods/index",
|
||||
@ -20,13 +27,6 @@
|
||||
"query": "id=30",
|
||||
"launchMode": "default",
|
||||
"scene": null
|
||||
},
|
||||
{
|
||||
"name": "packages/shop/index/index",
|
||||
"pathName": "packages/shop/index/index",
|
||||
"query": "",
|
||||
"launchMode": "default",
|
||||
"scene": null
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user