超V课程
This commit is contained in:
@@ -7,11 +7,7 @@
|
||||
<u-alert
|
||||
v-if=""
|
||||
style="
|
||||
|
||||
position: fixed;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
z-index: 10;
|
||||
"
|
||||
:title="goBuyTitle"
|
||||
type="warning"
|
||||
@@ -105,7 +101,8 @@
|
||||
},
|
||||
proPriceList:[],
|
||||
pricespop:false,
|
||||
userMsg:{},
|
||||
userMsg:{},
|
||||
cartList:[]
|
||||
};
|
||||
},
|
||||
//第一次加载
|
||||
@@ -137,14 +134,111 @@
|
||||
},
|
||||
//方法
|
||||
methods: {
|
||||
// 获取购物车数据
|
||||
addCart(val){
|
||||
console.log(val)
|
||||
if (val.productStock == 0) {
|
||||
uni.showToast({
|
||||
title: '商品库存不足',
|
||||
icon: "none"
|
||||
});
|
||||
} else {
|
||||
console.log(this.userInfo, '222')
|
||||
this.$http
|
||||
.post(`book/ordercart/getCartList?userId=${this.userInfo.id}`)
|
||||
.then(res => {
|
||||
// console.log(
|
||||
this.cartList = res.cartList
|
||||
this.isAddLink(val)
|
||||
})
|
||||
}
|
||||
},
|
||||
// 加入到购物车
|
||||
isAddLink(item) {
|
||||
// 统计商品信息
|
||||
let data = {
|
||||
"userId": this.userInfo.id,
|
||||
"productId": item.productId,
|
||||
"productAmount": this.productAmount,
|
||||
"price": item.price
|
||||
}
|
||||
// 判断列表是否为空
|
||||
if (this.cartList.length > 0) {
|
||||
let flag = ''
|
||||
let shagnpin = {}
|
||||
// 循环购物车列表
|
||||
flag = this.cartList.some((item, index) => {
|
||||
if (item.productId == data.productId) {
|
||||
shagnpin = item
|
||||
shagnpin.productAmount += 1
|
||||
return true
|
||||
}
|
||||
})
|
||||
if (flag) {
|
||||
// 已在购物车中添加
|
||||
$http.request({
|
||||
url: "book/ordercart/update",
|
||||
method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档
|
||||
data: shagnpin,
|
||||
header: { //默认 无 说明:请求头
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
}).then(res => {
|
||||
if (res.code == 0) {
|
||||
this.upoShow = false
|
||||
uni.showToast({
|
||||
title: '加入购物车成功',
|
||||
duration: 1000,
|
||||
});
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// 加入购物车
|
||||
$http.request({
|
||||
url: "book/ordercart/save",
|
||||
method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档
|
||||
data,
|
||||
header: { //默认 无 说明:请求头
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
}).then(res => {
|
||||
if (res.code == 0) {
|
||||
this.upoShow = false
|
||||
uni.showToast({
|
||||
title: '加入购物车成功',
|
||||
duration: 1000,
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
} else {
|
||||
// 购物车列表为空时直接加入购物车
|
||||
$http.request({
|
||||
url: "book/ordercart/save",
|
||||
method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档
|
||||
data,
|
||||
header: { //默认 无 说明:请求头
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
}).then(res => {
|
||||
if (res.code == 0) {
|
||||
uni.showToast({
|
||||
title: '加入购物车成功',
|
||||
duration: 1000,
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
oprate(data){
|
||||
console.log(data,'得到的内容')
|
||||
if(data.name == 'buy'){
|
||||
this.buy(data.item)
|
||||
}
|
||||
// else if(data.name == 'gouwuche'){
|
||||
// this.addCart(data.item)
|
||||
// }
|
||||
else if(data.name == 'gouwuche'){
|
||||
this.addCart(data.item)
|
||||
}
|
||||
},
|
||||
buy(val){
|
||||
var mynavData = JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user