// pages/shop/goodDetail.js const goodService = require("../../services/good") const orderService = require("../../services/order") Page({ /** * 页面的初始数据 */ data: { goodId: -1, goodinfo: {} }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log("goodDetail ->options", options) let goodId = options.id this.setData({ goodId: goodId }) this.loadPageData() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, // 立即下单 btnBuyTap() { (async () => { // 创建订单 let orderList = [{ goodId: this.data.goodId, count: 1, }] let orderId = await orderService.createOrder(orderList) console.log("orderId", orderId) // 跳转订单查看页面(携带订单号) wx.navigateTo({ // url: "/pages/scan/entrance?a=1" url: "/pages/shop/orderDetail?orderId=" + orderId }) })(); }, loadPageData() { (async () => { let goodDetail = await goodService.getGoodDetail(this.data.goodId) console.log("goodDetail", goodDetail) this.setData({ goodinfo: goodDetail }) })(); } })