小程序商品列表页优化;添加我的订单页面
This commit is contained in:
153
weixin-miniprogram/pages/shop/orderDetail.js
Normal file
153
weixin-miniprogram/pages/shop/orderDetail.js
Normal file
@@ -0,0 +1,153 @@
|
||||
// pages/shop/orderDetail.js
|
||||
|
||||
const orderService = require("../../services/order")
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
orderId: '',
|
||||
order: {},
|
||||
// goods: [],
|
||||
// orderItem: [],
|
||||
orderGoodList: [],
|
||||
|
||||
orderTime: '',
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
console.log(options)
|
||||
if (!options || !options.orderId) {
|
||||
wx.showModal({
|
||||
title: '订单查询失败',
|
||||
content: '请刷新页面后重试',
|
||||
showCancel: false,
|
||||
complete: (res) => {
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
this.setData({
|
||||
orderId: options.orderId,
|
||||
})
|
||||
this.loadPageData()
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
},
|
||||
|
||||
confirmPayment() {
|
||||
// 点击确认支付按钮
|
||||
wx.showModal({
|
||||
title: '拉起支付',
|
||||
content: '点击确认完成支付,点击取消放弃支付',
|
||||
complete: (res) => {
|
||||
if (res.cancel) {
|
||||
wx.showToast({
|
||||
title: '用户取消支付',
|
||||
icon: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
if (res.confirm) {
|
||||
wx.showToast({
|
||||
title: '支付成功',
|
||||
icon: 'success',
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
loadPageData() {
|
||||
(async () => {
|
||||
console.log("orderId", this.data.orderId)
|
||||
let orderDetail = await orderService.getOrderDetail(this.data.orderId)
|
||||
console.log("orderDetail", orderDetail)
|
||||
|
||||
if (!orderDetail) {
|
||||
wx.showModal({
|
||||
title: '订单查询失败',
|
||||
content: '',
|
||||
showCancel: false,
|
||||
complete: (res) => {
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let orderGoodList = []
|
||||
for (let item of orderDetail.orderItem) {
|
||||
orderGoodList.push({
|
||||
wxid: item.goodId, // 用于列表渲染
|
||||
good: orderDetail.goods.find(good => good.id == item.goodId),
|
||||
goodCount: item.goodCount,
|
||||
unitPrice: item.unitPrice,
|
||||
})
|
||||
}
|
||||
console.log("orderGoodList", orderGoodList)
|
||||
|
||||
this.setData({
|
||||
order: orderDetail.order,
|
||||
// goods: orderDetail.goods,
|
||||
// orderItem: orderDetail.orderItem,
|
||||
orderGoodList: orderGoodList,
|
||||
|
||||
orderTime: orderDetail.order.orderDate.replace("T", " ")
|
||||
})
|
||||
})();
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user