index.js 6.8 KB

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