map.vue 6.7 KB

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