index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // pages/gasup/index.js
  2. import {
  3. getStationList
  4. } from "../../api/home"
  5. // import { showIndex } from "../../setting";
  6. const app = getApp();
  7. Page({
  8. data: {
  9. list: [], // 列表数据
  10. page: 1, //页数
  11. limit: 4, //每页几条记录
  12. latitude: null,//用户当前纬度坐标
  13. longitude: null,//用户当前经度坐标
  14. latitudeStation: null,//油站纬度坐标
  15. longitudeStaion: null,//油站经度坐标
  16. isShowLocationLayer: false, //是否显示自定义授权位置弹框
  17. iconSize: [20, 30, 40, 50, 60, 70],
  18. iconColor: [
  19. 'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
  20. ],
  21. iconType: [
  22. 'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'
  23. ]
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. // console.log("@@@@@@@@@@@@@@@@" + "onLoad" + "@@@@@@@@@@@@@@@@");
  30. // console.log("openId:"+app.MpOpenId);
  31. let that = this; //将this赋值给that,以区别js本身的this
  32. that.bindAuthLocation(); //授权位置
  33. },
  34. //获取当前位置信息
  35. getLocationInfo: function (e) {
  36. var that = this;
  37. //获取当前位置信息
  38. wx.getLocation({
  39. type: 'gcj02',
  40. success(res) {
  41. that.setData({
  42. latitude: res.latitude,
  43. longitude: res.longitude
  44. });
  45. that.getStations(res.longitude, res.latitude);
  46. }
  47. })
  48. },
  49. //授权位置按钮
  50. bindAuthLocation: function (e) {
  51. var that = this;
  52. //获取授权结果查看是否已授权位置
  53. wx.getSetting({
  54. success: (res) => {
  55. if (res.authSetting['scope.userLocation'] == undefined && !res.authSetting['scope.userLocation']) //未授权位置(首次进来页面)
  56. that.getLocationInfo(); //获取当前位置信息
  57. else if (res.authSetting['scope.userLocation'] === false) //未授权位置(点击官方授权弹框取消按钮后)
  58. that.setData({ //显示自定义授权框
  59. isShowLocationLayer: true
  60. })
  61. else //已授权
  62. that.getLocationInfo(); //获取当前位置信息
  63. }
  64. })
  65. },
  66. //定位授权框确认按钮
  67. bindConfirmLocation: function (e) {
  68. var that = this;
  69. //打开设置页面进行授权设置
  70. wx.openSetting({
  71. success: function (res) {
  72. if (res.authSetting['scope.userLocation']) {
  73. //获取当前位置信息
  74. that.getLocationInfo();
  75. that.setData({
  76. isShowLocationLayer: false,
  77. })
  78. }
  79. }
  80. });
  81. },
  82. //定位授权框取消按钮
  83. bindCancelLocation: function (e) {
  84. let that = this;
  85. that.setData({
  86. isShowLocationLayer: false
  87. })
  88. wx.showModal({
  89. title: '拒绝授权提示',
  90. content: '您未授权使用当前地理位置信息,油站列表将无法展示!是否拒绝授权?',
  91. showCancel: true, //是否显示取消按钮
  92. cancelText: "否", //默认是“取消”
  93. cancelColor: 'skyblue', //取消文字的颜色
  94. confirmText: "是", //默认是“确定”
  95. confirmColor: 'skyblue', //确定文字的颜色
  96. success: function (res) {
  97. if (res.cancel) { //点击否
  98. that.setData({
  99. isShowLocationLayer: true
  100. })
  101. } else { //点击是
  102. that.setData({
  103. isShowLocationLayer: false
  104. })
  105. }
  106. },
  107. fail: function (res) {}, //接口调用失败的回调函数
  108. complete: function (res) {}, //接口调用结束的回调函数(调用成功、失败都会执行)
  109. })
  110. },
  111. getStations: function (longitude, latitude) {
  112. getStationList({
  113. stationLongitude: longitude,
  114. stationLatitude: latitude,
  115. pageNum: 1,
  116. pageSize: 4,
  117. appId:getApp().globalData.appId
  118. }).then(res => { // handle success
  119. if (res.retCode == 0) {
  120. app.globalData.stationList = res.data.stationInfoResponseList; // 暂时没用到
  121. this.setData({
  122. list: res.data.stationInfoResponseList
  123. })
  124. // if(!showIndex){
  125. // this.skipIndex()
  126. // }
  127. }
  128. console.log(this.data.list)
  129. }).catch(error => { // handle error
  130. console.log(error);
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面初次渲染完成
  135. */
  136. onReady: function () {
  137. // console.log("@@@@@@@@@@@@@@@@" + "onReady"+ "@@@@@@@@@@@@@@@@");
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function (options) {
  143. let app = getApp()
  144. // console.log("@@@@@@@@@@@@@@@@" + "onShow" + "@@@@@@@@@@@@@@@@");
  145. let that = this; //将this赋值给that,以区别js本身的this
  146. that.bindAuthLocation(); //授权位置
  147. },
  148. /**
  149. * 生命周期函数--监听页面隐藏
  150. */
  151. onHide: function () {
  152. // console.log("@@@@@@@@@@@@@@@@" + "onHide"+ "@@@@@@@@@@@@@@@@");
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function () {
  158. // console.log("@@@@@@@@@@@@@@@@" + "onUnload"+ "@@@@@@@@@@@@@@@@");
  159. },
  160. /**
  161. * 页面相关事件处理函数--监听用户下拉动作
  162. */
  163. onPullDownRefresh: function () {
  164. //在当前页面显示导航条加载动画
  165. wx.showNavigationBarLoading();
  166. // console.log("@@@@@@@@@@@@@@@@" + "onPullDownRefresh"+ "@@@@@@@@@@@@@@@@");
  167. //回弹页面
  168. wx.stopPullDownRefresh();
  169. //隐藏导航条加载动画
  170. wx.hideNavigationBarLoading();
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. onReachBottom: function () {
  176. // console.log("@@@@@@@@@@@@@@@@" + "onReachBottom"+ "@@@@@@@@@@@@@@@@");
  177. },
  178. /**
  179. * 用户点击右上角分享
  180. */
  181. onShareAppMessage: function () {
  182. // console.log("@@@@@@@@@@@@@@@@" + "onShareAppMessage"+ "@@@@@@@@@@@@@@@@");
  183. },
  184. toAddOil: function (e) {
  185. // let stationId = e.currentTarget.dataset.sid;
  186. // let stationName = e.currentTarget.dataset.sname;
  187. // let mno = e.currentTarget.dataset.mno;
  188. // let thumb = e.currentTarget.dataset.pic;
  189. // 待删除
  190. // app.stationId = stationId;
  191. // app.stationName = stationName;
  192. // app.picUrl = thumb;
  193. // app.mno = mno;
  194. //
  195. app.globalData.stationId = app.globalData.stationList[0].stationId
  196. app.globalData.stationName = app.globalData.stationList[0].stationName
  197. app.globalData.stationPic = app.globalData.stationList[0].stationPic
  198. app.globalData.mno = app.globalData.stationList[0].mno
  199. wx.redirectTo({
  200. url: "/pages/order/create",
  201. })
  202. },
  203. // skipIndex:function(){
  204. // app.globalData.stationId = app.globalData.stationList[0].stationId
  205. // app.globalData.stationName = app.globalData.stationList[0].stationName
  206. // app.globalData.stationPic = app.globalData.stationList[0].stationPic
  207. // app.globalData.mno = app.globalData.stationList[0].mno
  208. // wx.navigateTo({
  209. // url: "/pages/order/create"
  210. // });
  211. // },
  212. //到这里去,调用地图
  213. goMap: function (e) {
  214. let latitude = Number(e.target.dataset.latitude);
  215. let longitude = Number(e.target.dataset.longitude);
  216. let name=e.target.dataset.stationname;
  217. wx.openLocation({
  218. latitude,
  219. longitude,
  220. scale: 18,
  221. name:name
  222. })
  223. }
  224. })