// pages/pbService/library/getpoint/index.js import commonApi from "../../../../utils/https/common" Page({ /** * 页面的初始数据 */ data: { card_no:null, now:null, other:[], from:null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.from){ this.setData({ from:options.from }) } let that = this; commonApi.user_post("pbservice/Booking/loginNeedAuth").then(res=>{ console.log(res) if(res.code==1 && res.data && res.data.card_no){ let card_no = res.data.card_no; this.setData({ card_no:card_no }) commonApi.user_post("pbservice/Booking/deliveryCurrent",{ card_no:card_no }).then(res=>{ if(res.code==1 && res.data){ this.setData({ now:res.data }) } }) // 获取当前地区的经纬度 wx.getLocation({ type: 'gcj02', success: function (res) { commonApi.user_post("pbservice/Booking/deliveryList",{ longitude:res.longitude, latitude:res.latitude }).then(res=>{ if(res.code==1 && res.data){ res.data.map(item=>{ if(item.distance>=1000){ item.distance = (item.distance/1000)+"km" } else { item.distance = item.distance +"m"; } }) that.setData({ other:res.data }) } }) }, fail:function(){ wx.showToast({ title: '请开启定位授权后重试', icon:'none' }) } }) } }) }, setDefault:function(e){ let item = e.currentTarget.dataset.item,index = e.currentTarget.dataset.index; commonApi.user_post("pbservice/Booking/setDefaultDelivery",{ card_no:this.data.card_no, appartment_code:item.appartmentCode, district:item.districtCode }).then(res=>{ if(res.code==1){ wx.showToast({ title: '设置成功', icon: 'success' }) this.setData({ now:item }) if(this.data.from=='orderbook'){ setTimeout(()=>{ wx.navigateBack() },500) } } }) }, gotoLocation:function(e){ let info = e.currentTarget.dataset.info; wx.openLocation({ latitude:info.latitude, longitude:info.longitude, scale: 18 }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })