123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- // pages/gasup/index.js
- import {
- getStationList
- } from "../../api/home"
- // import { showIndex } from "../../setting";
- const app = getApp();
- 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" + "@@@@@@@@@@@@@@@@");
- // 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) {
- getStationList({
- stationLongitude: longitude,
- stationLatitude: latitude,
- pageNum: 1,
- pageSize: 4,
- appId:getApp().globalData.appId
- }).then(res => { // handle success
- if (res.retCode == 0) {
- app.globalData.stationList = res.data.stationInfoResponseList; // 暂时没用到
- this.setData({
- list: res.data.stationInfoResponseList
- })
- // if(!showIndex){
- // this.skipIndex()
- // }
- }
- console.log(this.data.list)
- }).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) {
- // 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;
- //
- app.globalData.stationId = app.globalData.stationList[0].stationId
- app.globalData.stationName = app.globalData.stationList[0].stationName
- app.globalData.stationPic = app.globalData.stationList[0].stationPic
- app.globalData.mno = app.globalData.stationList[0].mno
- wx.redirectTo({
- url: "/pages/order/create",
- })
- },
- // skipIndex:function(){
- // app.globalData.stationId = app.globalData.stationList[0].stationId
- // app.globalData.stationName = app.globalData.stationList[0].stationName
- // app.globalData.stationPic = app.globalData.stationList[0].stationPic
- // app.globalData.mno = app.globalData.stationList[0].mno
- // 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
- })
- }
- })
|