|
|
|
@ -65,14 +65,13 @@ Page({
|
|
|
|
|
let bookList = this.data.bookList;
|
|
|
|
|
|
|
|
|
|
wx.request({
|
|
|
|
|
url: "http://45.76.158.31:8080/web/AddCart.do?action=Delete&BookID=" + that.data.bookList[index].BookID + "&UserID=1",
|
|
|
|
|
url: "https://hunjianghu.xuanjis.com/web/AddCart.do?action=Delete&BookID=" + that.data.bookList[index].BookID + "&UserID=1",
|
|
|
|
|
header: {
|
|
|
|
|
"content-type": "json"
|
|
|
|
|
},
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
|
|
|
|
if (res.statusCode == 200) {
|
|
|
|
|
console.log(res.data)
|
|
|
|
|
that.setData({
|
|
|
|
|
book: res.data,
|
|
|
|
|
})
|
|
|
|
@ -82,7 +81,6 @@ Page({
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
bookList.splice(index, 1);
|
|
|
|
|
console.log(index)
|
|
|
|
|
this.setData({
|
|
|
|
|
bookList: bookList
|
|
|
|
|
});
|
|
|
|
@ -134,14 +132,13 @@ Page({
|
|
|
|
|
this.calculateTotal();
|
|
|
|
|
|
|
|
|
|
wx.request({
|
|
|
|
|
url: "http://45.76.158.31:8080/web/AddCart.do?action=Modify&BookID=" + bookList[index].BookID + "&UserID=1&Count=" + bookList[index].Count,
|
|
|
|
|
url: "https://hunjianghu.xuanjis.com/web/AddCart.do?action=Modify&BookID=" + bookList[index].BookID + "&UserID=1&Count=" + bookList[index].Count,
|
|
|
|
|
header: {
|
|
|
|
|
"content-type": "json"
|
|
|
|
|
},
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
|
|
|
|
if (res.statusCode == 200) {
|
|
|
|
|
console.log(res.data)
|
|
|
|
|
that.setData({
|
|
|
|
|
book: res.data,
|
|
|
|
|
})
|
|
|
|
@ -169,14 +166,13 @@ Page({
|
|
|
|
|
this.calculateTotal();
|
|
|
|
|
|
|
|
|
|
wx.request({
|
|
|
|
|
url: "http://45.76.158.31:8080/web/AddCart.do?action=Modify&BookID=" + bookList[index].BookID + "&UserID=1&Count=" + bookList[index].Count,
|
|
|
|
|
url: "https://hunjianghu.xuanjis.com/web/AddCart.do?action=Modify&BookID=" + bookList[index].BookID + "&UserID=1&Count=" + bookList[index].Count,
|
|
|
|
|
header: {
|
|
|
|
|
"content-type": "json"
|
|
|
|
|
},
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
|
|
|
|
if (res.statusCode == 200) {
|
|
|
|
|
console.log(res.data)
|
|
|
|
|
that.setData({
|
|
|
|
|
book: res.data,
|
|
|
|
|
})
|
|
|
|
@ -190,7 +186,7 @@ Page({
|
|
|
|
|
* 用户选择购物车商品
|
|
|
|
|
*/
|
|
|
|
|
checkboxChange: function(e) {
|
|
|
|
|
console.log('checkbox发生change事件,携带value值为:', e.detail.value);
|
|
|
|
|
//console.log('checkbox发生change事件,携带value值为:', e.detail.value);
|
|
|
|
|
var checkboxItems = this.data.bookList;
|
|
|
|
|
var values = e.detail.value;
|
|
|
|
|
for (var i = 0; i < checkboxItems.length; ++i) {
|
|
|
|
@ -241,7 +237,7 @@ Page({
|
|
|
|
|
|
|
|
|
|
todetail: function(e) {
|
|
|
|
|
var id = e.target.dataset.id
|
|
|
|
|
console.log(id)
|
|
|
|
|
//console.log(id)
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: "/pages/detail/detail?id=" + id
|
|
|
|
|
})
|
|
|
|
@ -267,7 +263,7 @@ Page({
|
|
|
|
|
onShow: function(options) {
|
|
|
|
|
var that = this
|
|
|
|
|
wx.request({
|
|
|
|
|
url: "http://45.76.158.31:8080/web/AddCart.do?action=getinfo&UserID=1",
|
|
|
|
|
url: "https://hunjianghu.xuanjis.com/web/AddCart.do?action=getinfo&UserID=1",
|
|
|
|
|
header: {
|
|
|
|
|
"content-type": "json"
|
|
|
|
|
},
|
|
|
|
@ -275,22 +271,28 @@ Page({
|
|
|
|
|
for (var i = 0; i < res.data.length; i++) {
|
|
|
|
|
res.data[i].checked = false;
|
|
|
|
|
}
|
|
|
|
|
console.log(res.data)
|
|
|
|
|
if (res.statusCode == 200) {
|
|
|
|
|
that.setData({
|
|
|
|
|
bookList: res.data,
|
|
|
|
|
iscart: false
|
|
|
|
|
})
|
|
|
|
|
if (res.data.length == 0) {
|
|
|
|
|
that.setData({
|
|
|
|
|
iscart: true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
//wx.hideNavigationBarLoading()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide: function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -327,50 +329,72 @@ Page({
|
|
|
|
|
newAddress: function() {
|
|
|
|
|
var that = this
|
|
|
|
|
var checkList = [];
|
|
|
|
|
if (!this.data.iscart) {
|
|
|
|
|
var bookList = this.data.bookList
|
|
|
|
|
for (var i = 0; i < bookList.length; i++) {
|
|
|
|
|
if (bookList[i].checked) {
|
|
|
|
|
checkList.push(this.data.bookList[i])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// var checkLists = JSON.stringify(checkList)
|
|
|
|
|
// console.log(checkLists)
|
|
|
|
|
// var flag = false
|
|
|
|
|
|
|
|
|
|
if (this.data.totalCount > 0) {
|
|
|
|
|
if (!this.iscart) { //购物车不空
|
|
|
|
|
var bookLists = this.data.bookList
|
|
|
|
|
for (var i = 0; i < bookLists.length; i++) {
|
|
|
|
|
if (bookLists[i].checked) {
|
|
|
|
|
var bookid = bookLists[i].BookID
|
|
|
|
|
var count = bookLists[i].Count
|
|
|
|
|
wx.request({
|
|
|
|
|
url: 'https://hunjianghu.xuanjis.com/web/Buy.do?UserID=1&BookID=' + bookid + '&Count=' + count + '&MessageID=' + 1,
|
|
|
|
|
header: {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
success: function(res) {
|
|
|
|
|
if (res.statusCode == 200) {
|
|
|
|
|
// that.setData({
|
|
|
|
|
// // book: res.data,
|
|
|
|
|
// flag :true
|
|
|
|
|
// })
|
|
|
|
|
//wx.hideNavigationBarLoading()
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '订单生成成功!',
|
|
|
|
|
icon: 'success',
|
|
|
|
|
duration: 2000
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
wx.request({
|
|
|
|
|
url: "https://hunjianghu.xuanjis.com/web/AddCart.do?action=Delete&BookID=" + bookid + "&UserID=1",
|
|
|
|
|
header: {
|
|
|
|
|
"content-type": "json"
|
|
|
|
|
},
|
|
|
|
|
success: function (res) {
|
|
|
|
|
|
|
|
|
|
if (res.statusCode == 200) {
|
|
|
|
|
// that.setData({
|
|
|
|
|
// book: res.data,
|
|
|
|
|
// })
|
|
|
|
|
//wx.hideNavigationBarLoading()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
//向服务器传用户选中购买的东西生成订单
|
|
|
|
|
for (var i = 0; i < checkList.length; i++) {
|
|
|
|
|
wx.request({
|
|
|
|
|
url: "http://45.76.158.31:8080/web/Buy.do?UserID=1&BookID="+checkList[i].BookID+"&Count="+checkList[i].Count,
|
|
|
|
|
header: {
|
|
|
|
|
"content-type": "json"
|
|
|
|
|
},
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
|
|
|
|
if (res.statusCode == 200) {
|
|
|
|
|
console.log(res.data)
|
|
|
|
|
that.setData({
|
|
|
|
|
book: res.data,
|
|
|
|
|
})
|
|
|
|
|
//wx.hideNavigationBarLoading()
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '订单生成成功!',
|
|
|
|
|
icon: 'success',
|
|
|
|
|
duration: 2000
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
//要延时执行的代码
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: '/pages/order/order?typeId=0'
|
|
|
|
|
})
|
|
|
|
|
}, 3000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (flag) {
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
//要延时执行的代码
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: '/pages/order/order?typeId=0'
|
|
|
|
|
})
|
|
|
|
|
}, 3000)
|
|
|
|
|
// } else {
|
|
|
|
|
// wx.showToast({
|
|
|
|
|
// title: '订单创建失败',
|
|
|
|
|
// icon: 'success',
|
|
|
|
|
// duration: 2000
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
} else {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '没有选择商品',
|
|
|
|
|