Compare commits

...

4 Commits

7 changed files with 215 additions and 56 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
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = {count:1} //
let goods_id_and_count = []
let carNum = 0 this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { count: 1 }
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

@ -132,6 +132,10 @@ page {
padding: 35rpx 0; padding: 35rpx 0;
} }
.CateItem_active {
background-color: #ffffff;
}
.CateItem .hot { .CateItem .hot {
width: 25.82rpx; width: 25.82rpx;
height: 30rpx; height: 30rpx;

View File

@ -90,7 +90,7 @@
<div class="Con"> <div class="Con">
<div class="Con_left"> <div class="Con_left">
<div <div
class="CateItem" class="CateItem" :class="item.id === currentLeftCateId ? 'CateItem_active' : ''"
v-for="item in leftCateList" v-for="item in leftCateList"
:key="item.id" :key="item.id"
@click="changeLeftCate(item.id)" @click="changeLeftCate(item.id)"
@ -176,7 +176,7 @@
<u-number-box <u-number-box
:min="0" :min="0"
v-model="items.quantity" v-model="items.quantity"
@change="handleQuantityChange(items)" @change="(value) => handleQuantityChange(value,items)"
> >
<view slot="minus" class="minus"> <view slot="minus" class="minus">
<u-icon name="minus" size="20"></u-icon> <u-icon name="minus" size="20"></u-icon>
@ -244,7 +244,7 @@
<u-number-box <u-number-box
v-model="ite.quantity" v-model="ite.quantity"
:min="0" :min="0"
@change="handleQuantityChange(ite)" @change="(value) => handleQuantityChange(value,ite)"
> >
<view slot="minus" class="minus"> <view slot="minus" class="minus">
<u-icon name="minus" size="20"></u-icon> <u-icon name="minus" size="20"></u-icon>
@ -356,6 +356,7 @@ export default {
], ],
rightTopActive: 0, rightTopActive: 0,
currentLeftCateId: null,
topShow: false, topShow: false,
GGshow: false, GGshow: false,
@ -416,8 +417,14 @@ export default {
console.log(res); console.log(res);
this.CateList = res.commodity_category_list; this.CateList = res.commodity_category_list;
this.firstId = res.commodity_category_list[0].id; this.firstId = res.commodity_category_list[0].id;
this.leftCateList = res.commodity_category_list[0].level_two_category; this.leftCateList = res.commodity_category_list[0].level_two_category || [];
this.secondId = res.commodity_category_list[0].level_two_category[0].id; if (this.leftCateList.length > 0) {
this.currentLeftCateId = this.leftCateList[0].id;
this.secondId = this.leftCateList[0].id;
} else {
this.currentLeftCateId = null;
this.secondId = null;
}
this.getGoodsList(); this.getGoodsList();
}); });
}, },
@ -448,13 +455,12 @@ export default {
}, },
changeLeftCate(e) { changeLeftCate(e) {
this.currentLeftCateId = e;
this.secondId = e; this.secondId = e;
this.getGoodsList(); this.getGoodsList();
}, },
// //
handleQuantityChange(item) { handleQuantityChange(val,item) {
console.log("🚀 ~ handleQuantityChange ~ value:", item);
const goodsId = "";
if (item.commodity_goods_info_list.length) { if (item.commodity_goods_info_list.length) {
this.goodsId = item.commodity_goods_info_list[0].id; this.goodsId = item.commodity_goods_info_list[0].id;
} else { } else {
@ -465,19 +471,16 @@ export default {
goods_id_and_count: [ goods_id_and_count: [
{ {
goods_id: this.goodsId, goods_id: this.goodsId,
count: item.quantity ? item.quantity + 1 : 1, count: val.value,
}, },
], ],
}; };
console.log("🚀 ~ handleQuantityChange ~ params:", params);
request(apiArr.updateCar, "POST", params).then((res) => { request(apiArr.updateCar, "POST", params).then((res) => {
console.log(res); console.log(res);
this.getShopCarList();
uni.showToast({ uni.showToast({
title: "操作成功!", title: "操作成功!",
success() { success() {
// setTimeout(() => {
// that.getBanlance()
// }, 1500)
}, },
}); });
}); });
@ -488,6 +491,9 @@ export default {
this.top = meun.top; this.top = meun.top;
this.localHeight = meun.height; this.localHeight = meun.height;
this.getCateList(); this.getCateList();
// this.getShopCarList();
},
onShow() {
this.getShopCarList(); this.getShopCarList();
}, },
onReachBottom() { onReachBottom() {

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({
@ -174,18 +205,22 @@ export default {
if (res.confirm) { if (res.confirm) {
let ids = [] let ids = []
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", {
ids ids
}).then(res=>{ }).then(res => {
uni.showToast({ uni.showToast({
title: '删除成功', title: '删除成功',
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

@ -176,4 +176,24 @@
display: flex; display: flex;
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>
<div class="address_Info" @click="choseAddress" v-if="!defAddress">
<div class="address_Info_left noneDef">
<div class="address_Info_btn">添加收货地址</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>
@ -52,10 +59,10 @@
</div> </div>
<div class="line"></div> <div class="line"></div>
</div> </div>
<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() {