mychargestation.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // pages/ucenter/mychargestation/mychargestation.js
  2. let Util = require('../../../utils/util');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. markers: []
  9. },
  10. goIndex(e) {
  11. //console.log(e);
  12. let markerId = e.currentTarget.id;
  13. let pages = getCurrentPages();
  14. let prevPage = pages[pages.length - 3]; //上一个页面
  15. this.data.markers.forEach((item, index) => {
  16. if (markerId && markerId == item.id) {
  17. let {
  18. latitude,
  19. longitude
  20. } = item;
  21. prevPage.setData({
  22. markerId,
  23. latitude,
  24. longitude,
  25. textData: item
  26. });
  27. wx.navigateBack({
  28. delta: 3
  29. });
  30. }
  31. });
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function(options) {
  37. let userInfo = wx.getStorageSync('userInfo');
  38. let isLogin = wx.getStorageSync('isLogin');
  39. let that = this;
  40. //console.log(12345);
  41. if (userInfo && isLogin) {
  42. wx.getLocation({
  43. success: function(res) {
  44. //console.log(res);
  45. let {
  46. latitude,
  47. longitude,
  48. } = res;
  49. wx.request({
  50. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/userChargStations',
  51. data: {
  52. userId: userInfo.userId,
  53. lat: latitude,
  54. lon: longitude
  55. },
  56. method: 'POST',
  57. success(res) {
  58. console.log(res);
  59. let {
  60. data
  61. } = res;
  62. let markers = [];
  63. data.forEach((item, index) => {
  64. //item.callout = {
  65. // content: item.name, //文本 String 1.2.0
  66. // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
  67. // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
  68. // };
  69. //console.log(Util.distance(latitude, longitude, item.lat, item.lon));
  70. var marker = {
  71. name: item.chargStationName,
  72. address: item.address,
  73. width: "46rpx",
  74. height: "67rpx",
  75. iconPath: "/images/marker.png",
  76. id: item.id,
  77. callout: {},
  78. latitude: item.lat,
  79. longitude: item.lon,
  80. distance: Math.round(item.distance) / 1000,
  81. //distance: Util.distance(latitude, longitude, item.lat, item.lon),
  82. chargPileNum: item.fastCharg + item.slowCharg,
  83. fastCharg: item.fastCharg,
  84. slowCharg: item.slowCharg,
  85. freenum: item.freenum,
  86. fastfreenum: item.fastfreenum,
  87. slowfreenum: item.slowfreenum,
  88. breaknum: item.breaknum,
  89. /** 电费 */
  90. chargprice: item.chargprice,
  91. /** 服务费 */
  92. serviceprice: item.serviceprice,
  93. /** 停车费 */
  94. stopprice: item.stopprice,
  95. operationState: item.operationState
  96. };
  97. markers[index] = marker;
  98. });
  99. that.setData({
  100. markers
  101. });
  102. }
  103. });
  104. }
  105. });
  106. }
  107. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady: function() {
  112. },
  113. /**
  114. * 生命周期函数--监听页面显示
  115. */
  116. onShow: function() {
  117. },
  118. /**
  119. * 生命周期函数--监听页面隐藏
  120. */
  121. onHide: function() {
  122. },
  123. /**
  124. * 生命周期函数--监听页面卸载
  125. */
  126. onUnload: function() {
  127. },
  128. /**
  129. * 页面相关事件处理函数--监听用户下拉动作
  130. */
  131. onPullDownRefresh: function() {
  132. },
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom: function() {
  137. },
  138. /**
  139. * 用户点击右上角分享
  140. */
  141. onShareAppMessage: function() {
  142. }
  143. })