商品详情页和云函数 js 代码
商品详情页代码
/** 商品详情页 js 代码 **/
const productTableId = 12345678
const orderTableId = 123456789
Page({
data: {
product: {}
},
onLoad(options) {
// 设置默认的商品 id,方便调试
const productId = options.id || '5ade97135acfb521865bf766'
this.getProductDetail(productId)
},
/**
* 获取商品详情信息
* @param {String} id
*/
getProductDetail(id) {
const tableObject = new wx.BaaS.TableObject(productTableId)
const query = new wx.BaaS.Query()
query.compare('id', '=', id)
tableObject.setQuery(query).find().then(res => {
const objects = res.data.objects || []
const product = objects[0] || {}
this.setData({ product })
})
},
/**
* 点击立即购买按钮事件
*/
createOrder(e) {
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
this.createOrderHandle()
} else {
wx.BaaS.login()
}
}
})