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, buying:false, qty:0 }, showConfirm(event){ const currentProduct = event.currentTarget.dataset.item; const orderConfirm = this.selectComponent("#merchantOrderConfirm"); orderConfirm.preOrder(currentProduct); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.data.productId = options.id; 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(data.product_detail,'markdown'), productGuideMD:app.towxml(data.purchase_note,'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 }) } }, updateDefaultAddress(address){ this.setData({ "detail.default_address":address }) }, buy(){ const valid = app.validateForm({ qty:{min:1,shake:true} },this) if(valid.length==0){ this.selectComponent('#merchantOrder').getOrder(this.data.detail.id,this.data.qty,this.data.detail.default_address.id) }else{ wx.showToast({ icon:'none', title: '请选择数量', }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ 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||''}` } } })