// pages/gasup/index.js import { getStationList } from "../../api/home" Page({ data: { list: [], // 列表数据 page: 1, //页数 limit: 4, //每页几条记录 latitude: null,//用户当前纬度坐标 longitude: null,//用户当前经度坐标 latitudeStation: null,//油站纬度坐标 longitudeStaion: null,//油站经度坐标 isShowLocationLayer: false, //是否显示自定义授权位置弹框 iconSize: [20, 30, 40, 50, 60, 70], iconColor: [ 'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple' ], iconType: [ 'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear' ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // console.log("@@@@@@@@@@@@@@@@" + "onLoad" + "@@@@@@@@@@@@@@@@"); var app = getApp() // console.log("openId:"+app.MpOpenId); let that = this; //将this赋值给that,以区别js本身的this that.bindAuthLocation(); //授权位置 }, //获取当前位置信息 getLocationInfo: function (e) { var that = this; //获取当前位置信息 wx.getLocation({ type: 'gcj02', success(res) { that.setData({ latitude: res.latitude, longitude: res.longitude }); that.getStations(res.longitude, res.latitude); } }) }, //授权位置按钮 bindAuthLocation: function (e) { var that = this; //获取授权结果查看是否已授权位置 wx.getSetting({ success: (res) => { if (res.authSetting['scope.userLocation'] == undefined && !res.authSetting['scope.userLocation']) //未授权位置(首次进来页面) that.getLocationInfo(); //获取当前位置信息 else if (res.authSetting['scope.userLocation'] === false) //未授权位置(点击官方授权弹框取消按钮后) that.setData({ //显示自定义授权框 isShowLocationLayer: true }) else //已授权 that.getLocationInfo(); //获取当前位置信息 } }) }, //定位授权框确认按钮 bindConfirmLocation: function (e) { var that = this; //打开设置页面进行授权设置 wx.openSetting({ success: function (res) { if (res.authSetting['scope.userLocation']) { //获取当前位置信息 that.getLocationInfo(); that.setData({ isShowLocationLayer: false, }) } } }); }, //定位授权框取消按钮 bindCancelLocation: function (e) { let that = this; that.setData({ isShowLocationLayer: false }) wx.showModal({ title: '拒绝授权提示', content: '您未授权使用当前地理位置信息,油站列表将无法展示!是否拒绝授权?', showCancel: true, //是否显示取消按钮 cancelText: "否", //默认是“取消” cancelColor: 'skyblue', //取消文字的颜色 confirmText: "是", //默认是“确定” confirmColor: 'skyblue', //确定文字的颜色 success: function (res) { if (res.cancel) { //点击否 that.setData({ isShowLocationLayer: true }) } else { //点击是 that.setData({ isShowLocationLayer: false }) } }, fail: function (res) {}, //接口调用失败的回调函数 complete: function (res) {}, //接口调用结束的回调函数(调用成功、失败都会执行) }) }, getStations: function (longitude, latitude) { // console.log("longitude:"+longitude); // console.log("latitude:"+latitude); getStationList({ stationLongitude: longitude, stationLatitude: latitude, pageNum: 1, pageSize: 4, appId:getApp().globalData.appId }).then(res => { // handle success // console.log(res.data); if (res.retCode == 0) { this.setData({ list: res.data.stationInfoResponseList }) } }).catch(error => { // handle error console.log(error); }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { // console.log("@@@@@@@@@@@@@@@@" + "onReady"+ "@@@@@@@@@@@@@@@@"); }, /** * 生命周期函数--监听页面显示 */ onShow: function (options) { let app = getApp() // console.log("@@@@@@@@@@@@@@@@" + "onShow" + "@@@@@@@@@@@@@@@@"); let that = this; //将this赋值给that,以区别js本身的this that.bindAuthLocation(); //授权位置 }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { // console.log("@@@@@@@@@@@@@@@@" + "onHide"+ "@@@@@@@@@@@@@@@@"); }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { // console.log("@@@@@@@@@@@@@@@@" + "onUnload"+ "@@@@@@@@@@@@@@@@"); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { //在当前页面显示导航条加载动画 wx.showNavigationBarLoading(); // console.log("@@@@@@@@@@@@@@@@" + "onPullDownRefresh"+ "@@@@@@@@@@@@@@@@"); //回弹页面 wx.stopPullDownRefresh(); //隐藏导航条加载动画 wx.hideNavigationBarLoading(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { // console.log("@@@@@@@@@@@@@@@@" + "onReachBottom"+ "@@@@@@@@@@@@@@@@"); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { // console.log("@@@@@@@@@@@@@@@@" + "onShareAppMessage"+ "@@@@@@@@@@@@@@@@"); }, toAddOil: function (e) { // console.log("@@@@@@@@@@@@@@@@" + " 去加油"+ "@@@@@@@@@@@@@@@@"); var app = getApp() // if (app.globalData.userInfo == null) { // console.log("app.globalData中的userInfo:" + app.globalData.userInfo); // this.showDialogLogin(); //调用登录弹窗 // } else { //获取到绑定的数据 // console.log("stationId:"+e.currentTarget.dataset.sid); // console.log("stationName:"+e.currentTarget.dataset.sname); console.log(e) let stationId = e.currentTarget.dataset.sid; let stationName = e.currentTarget.dataset.sname; let mno = e.currentTarget.dataset.mno; let thumb = e.currentTarget.dataset.pic; app.stationId = stationId; app.stationName = stationName; app.picUrl = thumb; app.mno = mno; // console.log("picUrl:"+app.picUrl); wx.navigateTo({ url: "/pages/order/create" }); // } }, //到这里去,调用地图 goMap: function (e) { let latitude = Number(e.target.dataset.latitude); let longitude = Number(e.target.dataset.longitude); let name=e.target.dataset.stationname; wx.openLocation({ latitude, longitude, scale: 18, name:name }) } })