import shopApi from '../../../api/shop'; import userApi from '../../../api/user'; import {rpxToPx} from '../../../utils/util' const app = getApp(); Page({ /** * 页面的初始数据 */ data: { isShowConfirm:false, productId:'', detail:{}, productList:[], currentProduct:{}, calculatedPrice:{}, calculating:false, scrollViewHeight:0, windowInfo:{}, markdown:null, productInfoMD:{}, productGuideMD:{}, scrollOverTop:false, navBarHeight:0 }, showConfirm(event){ const currentProduct = event.currentTarget.dataset.item; const orderConfirm = this.selectComponent("#merchantOrderConfirm"); orderConfirm.preOrder(currentProduct); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.data.productId = options.id; // app.getLocation().then((data)=>{ // this.getDetail(data.longitude,data.latitude); // }).catch(()=>{ this.getDetail(); // }) this.createSelectorQuery().select('#navBar').boundingClientRect((res)=>{ this.data.navBarHeight = res.height; }).exec(); }, getDetail(lng,lat){ shopApi.product.detail(this.data.productId,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, productInfoMD:app.towxml('## 详情 \n- 第一项','markdown'), productGuideMD:app.towxml('## 须知 \n- 第一项','markdown') }); }); }, 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.merchant.phone, }) }, scrollViewScroll(event){ if(event.detail.scrollTop+this.data.navBarHeight>rpxToPx(500)){ this.setData({ scrollOverTop:true }) }else{ this.setData({ scrollOverTop:false }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ useCustomShare:true, onShareAppMessage() { return { title:this.data.detail.name, imageUrl:this.data.detail.optimized_image_url, path:`/pages/shop/detail/index?id=${this.data.productId}&shared_user_code=${app.globalData.userInfo.user_code||''}` } } })