import shopApi from '../../../api/shop'; import userApi from '../../../api/user'; const app = getApp(); Page({ /** * 页面的初始数据 */ data: { isShowConfirm:false, detail:{}, productList:[], currentProduct:{}, calculatedPrice:{}, calculating:false, scrollViewHeight:0, windowInfo:{} }, showConfirm(event){ const currentProduct = event.currentTarget.dataset.item; const orderConfirm = this.selectComponent("#merchantOrderConfirm"); orderConfirm.preOrder(currentProduct); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const windowInfo = wx.getWindowInfo(); console.log(windowInfo); this.setData({ windowInfo:windowInfo, scrollViewHeight:windowInfo.screenHeight-251-windowInfo.statusBarHeight-53 }) const shopId = options.id; app.getLocation().then((data)=>{ this.getOrderDetail(shopId,data.longitude,data.latitude); }).catch(()=>{ this.getOrderDetail(shopId); }) shopApi.productList(shopId).then((data)=>{ data.items.map((item)=>{ item.tags = item.tags.split(',') }) this.setData({ productList:data.items }); }) }, getOrderDetail(id,lng,lat){ shopApi.detail(id,lng,lat).then((data)=>{ if(data.distance){ if(data.distance>=1000){ data.distance = parseFloat(data.distance/1000).toFixed(1)+'km'; }else{ data.distance+='m'; } } this.setData({ detail:data }); }); }, navToMap(){ wx.openLocation({ name:this.data.detail.name, address:this.data.detail.address, latitude: this.data.detail.latitude, longitude: this.data.detail.longitude, }) }, makePhoneCall(){ wx.makePhoneCall({ phoneNumber:this.data.detail.phone, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })