map.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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].stationName }}</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].distance }}km</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].fastCharging }}</text></view>
  58. </view>
  59. <view class="charge purple">
  60. <view class="icon">慢充</view>
  61. <view><text class="value">{{ list.data[list.index].slowCharging }}</text></view>
  62. </view>
  63. <view class="charge blue">
  64. <view class="icon">停车</view>
  65. <view><text class="value">{{ list.data[list.index].parkingFee || '0' }}</text><text
  66. class="max">h</text></view>
  67. </view>
  68. </view>
  69. <view class="price">
  70. <view class="app-flex middle" style="color: #FF5D50;">
  71. <text class="value">{{ list.data[list.index].platformPrice }}</text>
  72. <text class="unit">元/度</text>
  73. </view>
  74. <view>{{ list.data[list.index].peakValue }}{{ list.data[list.index].peakTime }}</view>
  75. </view>
  76. <view class="parkade">
  77. <view class="icon">
  78. <image src="@/static/img/parkade.svg" mode="widthFix"></image>
  79. </view>
  80. <!-- <view class="txt" v-html="list.data[list.index].parkTips"></view> -->
  81. <view class="txt">{{ list.data[list.index].tips }}</view>
  82. </view>
  83. </view>
  84. <view :style="{ height: `${footPad}px` }"></view>
  85. </view>
  86. </ax-popup>
  87. <app-navigation id="app-navigation" active="home"></app-navigation>
  88. </ax-body>
  89. </template>
  90. <script>
  91. export default {
  92. onLoad() {
  93. this.loadData();
  94. },
  95. mounted() {
  96. this.$nextTick(() => {
  97. this.$app.act.selectorQuery(this, '#app-navigation').then(res => {
  98. this.footPad = res.height + 20;
  99. });
  100. });
  101. var mapCtx = wx.createMapContext('map');
  102. let location = this.$app.storage.get('USER_LOCATION')
  103. if (location && location.split(",").length == 2) {
  104. mapCtx.moveToLocation({
  105. longitude: location.split(",")[0],
  106. latitude: location.split(",")[1]
  107. });
  108. } else {
  109. mapCtx.moveToLocation()
  110. }
  111. this.mapCtx = mapCtx
  112. },
  113. data() {
  114. return {
  115. mapCtx: {},
  116. footPad: 0,
  117. map: {
  118. latitude: 26.646694,
  119. longitude: 106.628201,
  120. },
  121. list: {
  122. index: -1,
  123. data: []
  124. },
  125. }
  126. },
  127. computed: {
  128. markersData() {
  129. const markers = this.list.data.map((i, index) => {
  130. const marker = {
  131. ...i,
  132. id: parseInt(i.stationId) || index,
  133. width: index == this.list.index ? 32 : 28,
  134. height: index == this.list.index ? 32 : 28,
  135. iconPath: '/static/img/marker-icon.png',
  136. };
  137. return marker;
  138. });
  139. return markers;
  140. }
  141. },
  142. onShareAppMessage(res) {
  143. if (res.from === 'button') {
  144. // 来自页面内分享按钮
  145. console.log(res.target);
  146. }
  147. return {
  148. title: "用券充天天都享会员价", // 标题
  149. path: "/pages/index/index", // 分享路径
  150. imageUrl: '../../static/img/share.jpg', // 分享图
  151. desc: '用券充天天都享会员价'
  152. };
  153. },
  154. onShareTimeline() {
  155. return {
  156. title: "用券充天天都享会员价", // 标题
  157. path: "/pages/index/index", // 分享路径
  158. imageUrl: '../../static/img/share.jpg' // 分享图
  159. };
  160. },
  161. methods: {
  162. convertBdToTx(lng, lat) {
  163. // 百度坐标系(BD09)转火星坐标系(GCJ-02,即腾讯地图使用的坐标系)
  164. // 这里的转换公式是基于经验公式,可能存在一定的误差
  165. let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  166. let x = lng - 0.0065;
  167. let y = lat - 0.006;
  168. let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  169. let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  170. let lngs = z * Math.cos(theta);
  171. let lats = z * Math.sin(theta);
  172. return {
  173. lng: lngs,
  174. lat: lats
  175. };
  176. },
  177. // 载入数据
  178. loadData() {
  179. let location = this.$app.storage.get('USER_LOCATION')
  180. let lng = ""
  181. let lat = ""
  182. if (location && location.split(",").length == 2) {
  183. lng = location.split(",")[0]
  184. lat = location.split(",")[1]
  185. }
  186. this.$api.base("get", "/applet/v1/homePage/getStationInfoMapList", {
  187. longitude: lng,
  188. latitude: lat
  189. }, {}).then(res => {
  190. res.data.forEach(i => {
  191. var txPoint = this.convertBdToTx(i.longitude, i.latitude)
  192. i.longitude = txPoint.lng
  193. i.latitude = txPoint.lat
  194. })
  195. this.list.data = res.data
  196. })
  197. },
  198. // 点击标记
  199. markertap(e) {
  200. console.log(e.detail.markerId, '点击的标记事件');
  201. const selectedItem = this.list.data.find(i => parseInt(i.stationId) === e.detail.markerId);
  202. if (selectedItem) {
  203. this.list.index = this.list.data.indexOf(selectedItem);
  204. console.log(this.list.data[this.list.index], '点击的标记');
  205. this.$refs.site.open();
  206. } else {
  207. console.log('未找到匹配的标记点');
  208. }
  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>