map.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <ax-body hide-indicator-area>
  3. <!-- 标题栏 -->
  4. <template #title>
  5. <view class="titlebar event-off">
  6. <image src="@/static/img/title.png" class="page-title"></image>
  7. <!-- <text class="page-subtitle">“新能源充电新能源”</text> -->
  8. </view>
  9. </template>
  10. <view class="map-box">
  11. <map id="map" class="map" @markertap.stop="markertap" :latitude="map.latitude" :show-location="true"
  12. :longitude="map.longitude" :markers="markersData"></map>
  13. </view>
  14. <view class="contet event-off">
  15. <!-- 搜索块 -->
  16. <view id="search" class="app-flex search-view event-on">
  17. <label class="search-bar" @click="$app.url.goto('/pages/search/search')">
  18. <view class="locate-city">
  19. <image src="@/static/img/locate.svg" class="_icon"></image>
  20. <text class="__name">贵阳</text>
  21. </view>
  22. <input placeholder-class="app-placeholder" placeholder="| 输入目的地/电站名" />
  23. <image src="@/static/img/search.svg" class="_icon-search"></image>
  24. </label>
  25. <view style="width: 20rpx;"></view>
  26. <!-- 列表模式 -->
  27. <view class="top-subinfo">
  28. <view @click="$app.url.goto('/pages/index/index', false)" class="list-model event-on">
  29. <image src="@/static/img/switch.svg" class="icon"></image>
  30. <view>列表模式</view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 电站信息 -->
  36. <ax-popup @closed="onClosed" ref="site" position="bottom" maskType="" maskClose>
  37. <view class="popup-body">
  38. <view @click="gotoSiteDetail()" class="site event-on">
  39. <view class="name-wrap">
  40. <view class="name">
  41. <view class="icon">
  42. <image src="@/static/img/plug.svg" mode="widthFix"></image>
  43. </view>
  44. <view class="txt">{{ list.data[list.index].name }}</view>
  45. </view>
  46. <view class="distance">
  47. <view class="icon">
  48. <image src="@/static/img/distance.svg" mode="widthFix"></image>
  49. </view>
  50. <text>{{ list.data[list.index].params.rangeShow }}</text>
  51. </view>
  52. </view>
  53. <view class="ec-name">{{ list.data[list.index].equipmentOwnerName }}</view>
  54. <view class="app-flex c-between info">
  55. <view class="charge">
  56. <view class="icon">快充</view>
  57. <view><text class="value">{{ list.data[list.index].params.emptyFast }}</text><text
  58. class="max">{{
  59. list.data[list.index].params.totalFast }}</text></view>
  60. </view>
  61. <view class="charge purple">
  62. <view class="icon">慢充</view>
  63. <view><text class="value">{{ list.data[list.index].params.emptySlow }}</text><text
  64. class="max">{{
  65. list.data[list.index].params.totalSlow }}</text></view>
  66. </view>
  67. <view class="charge blue">
  68. <view class="icon">停车</view>
  69. <view><text class="value">3</text><text class="max">h</text></view>
  70. </view>
  71. </view>
  72. <view class="price">
  73. <view class="app-flex middle" style="color: #FF5D50;">
  74. <text class="value">{{ (list.data[list.index] && list.data[list.index].params.nowPrice) ?
  75. list.data[list.index].params.nowPrice.toFixed(4) : '0.0000' }}</text>
  76. <text class="unit">元/度</text>
  77. </view>
  78. <view>{{ list.data[list.index].params.priceShow }}</view>
  79. </view>
  80. <view class="parkade">
  81. <view class="icon">
  82. <image src="@/static/img/parkade.svg" mode="widthFix"></image>
  83. </view>
  84. <!-- <view class="txt" v-html="list.data[list.index].parkTips"></view> -->
  85. <view class="txt">充电减免2小时停车费,超出时长部分计时收费</view>
  86. </view>
  87. </view>
  88. <view :style="{ height: `${footPad}px` }"></view>
  89. </view>
  90. </ax-popup>
  91. <app-navigation id="app-navigation" active="home"></app-navigation>
  92. </ax-body>
  93. </template>
  94. <script>
  95. export default {
  96. onLoad() {
  97. this.loadData();
  98. },
  99. mounted() {
  100. this.$nextTick(() => {
  101. this.$app.act.selectorQuery(this, '#app-navigation').then(res => {
  102. this.footPad = res.height + 20;
  103. });
  104. });
  105. var mapCtx = wx.createMapContext('map');
  106. let location = this.$app.storage.get('USER_LOCATION')
  107. if (location && location.split(",").length == 2) {
  108. mapCtx.moveToLocation({
  109. longitude: location.split(",")[0],
  110. latitude: location.split(",")[1]
  111. });
  112. } else {
  113. mapCtx.moveToLocation()
  114. }
  115. this.mapCtx = mapCtx
  116. },
  117. data() {
  118. return {
  119. mapCtx: {},
  120. footPad: 0,
  121. map: {
  122. latitude: 26.646694,
  123. longitude: 106.628201,
  124. },
  125. list: {
  126. index: -1,
  127. data: []
  128. },
  129. }
  130. },
  131. computed: {
  132. markersData() {
  133. const markers = this.list.data.map((i, index) => {
  134. const marker = {
  135. ...i,
  136. width: index == this.list.index ? 32 : 28,
  137. height: index == this.list.index ? 32 : 28,
  138. iconPath: '/static/img/marker-icon.png',
  139. };
  140. return marker;
  141. });
  142. return markers;
  143. }
  144. },
  145. onShareAppMessage(res) {
  146. if (res.from === 'button') {
  147. // 来自页面内分享按钮
  148. console.log(res.target);
  149. }
  150. return {
  151. title: "用券充天天都享会员价", // 标题
  152. path: "/pages/index/index", // 分享路径
  153. imageUrl: '../../static/img/share.jpg', // 分享图
  154. desc: '用券充天天都享会员价'
  155. };
  156. },
  157. onShareTimeline() {
  158. return {
  159. title: "用券充天天都享会员价", // 标题
  160. path: "/pages/index/index", // 分享路径
  161. imageUrl: '../../static/img/share.jpg' // 分享图
  162. };
  163. },
  164. methods: {
  165. convertBdToTx(lng, lat) {
  166. // 百度坐标系(BD09)转火星坐标系(GCJ-02,即腾讯地图使用的坐标系)
  167. // 这里的转换公式是基于经验公式,可能存在一定的误差
  168. let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  169. let x = lng - 0.0065;
  170. let y = lat - 0.006;
  171. let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  172. let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  173. let lngs = z * Math.cos(theta);
  174. let lats = z * Math.sin(theta);
  175. return {
  176. lng: lngs,
  177. lat: lats
  178. };
  179. },
  180. // 载入数据
  181. loadData() {
  182. let location = this.$app.storage.get('USER_LOCATION')
  183. let lng = ""
  184. let lat = ""
  185. if (location && location.split(",").length == 2) {
  186. lng = location.split(",")[0]
  187. lat = location.split(",")[1]
  188. }
  189. this.$api.base("get", "/applet/v1/homePage/getStationInfoMap", {
  190. longitude: lng,
  191. latitude: lat
  192. }, {}).then(res => {
  193. res.stationList.forEach(i => {
  194. var txPoint = this.convertBdToTx(i.lng, i.lat)
  195. i.lng = txPoint.lng
  196. i.lat = txPoint.lat
  197. })
  198. res.stationList.forEach(i => {
  199. i.latitude = i.lat
  200. i.longitude = i.lng
  201. })
  202. this.list.data = res.stationList
  203. })
  204. },
  205. // 点击标记
  206. markertap(e) {
  207. this.list.index = this.list.data.findIndex(i => i.id == e.detail.markerId);
  208. this.$refs.site.open();
  209. },
  210. // 关闭站点信息
  211. onClosed() {
  212. this.list.index = -1;
  213. },
  214. gotoSiteDetail() {
  215. this.$app.url.goto('/pages/site/site?item=' + JSON.stringify(this.list.data[this.list.index]));
  216. }
  217. }
  218. }
  219. </script>
  220. <style>
  221. @import url("map.css");
  222. </style>