Skip to content

Commit

Permalink
实现点击提交订单按钮,进行结算的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
TeanLee committed Dec 18, 2021
1 parent 0677cd9 commit eb2efa4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
35 changes: 33 additions & 2 deletions pages/shopping/shopping.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,38 @@ Page({
}
})
},
onClickButton() {
console.log(this.data.goodsList);
submitOrder() {
const { goodsList } = this.data;
const orders = [];
goodsList.forEach(item => {
if(item.selected) {
orders.push({
"productId": item.productId,
"count": item.count
})
}
})
console.log(orders);

wx.request({
url: "http://localhost:8080/order/add",
method: "POST",
header: {
'content-type': 'application/json' // 说明向后端传递的是 json 数据
},
data: {
"orderItem": orders
},
success: (res) => {
wx.showToast({
title: '订单提交成功!', // 标题
icon: 'success',
duration: 1500 // 提示窗停留时间,默认1500ms
})
// 订单提交成功后,要在购物车表中删除已经购买的数据
this.getShoppingCartProducts();
}
})
},
// 增加商品数量
addCount:function (e) {
Expand Down Expand Up @@ -191,6 +221,7 @@ Page({
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
this.getShoppingCartProducts();
this.clearSelected();
},

Expand Down
2 changes: 1 addition & 1 deletion pages/shopping/shopping.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<van-submit-bar
price="{{sum*100}}"
button-text="提交订单"
bind:submit="onClickButton"
bind:submit="submitOrder"
label="合计 "
>
</van-submit-bar>
Expand Down

0 comments on commit eb2efa4

Please sign in to comment.