stationDetailsMap.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. <template>
  2. <view >
  3. <u-navbar title="站点详情"></u-navbar>
  4. <view class="content" >
  5. <view>
  6. <Chargermap ref="amap" @onload="mapdown" @clickMap="clickMap"></Chargermap>
  7. <u-image style='position:absolute;z-index:1023;right:20px;bottom:220px;' src="@/static/img/location.png" width="30px" height="30px" @click="setCenter"></u-image>
  8. </view>
  9. <view class="chargerCard" @click="stationDetail(item)">
  10. <view class="card_item font4" style="padding-top: 5rpx;" >
  11. <view style="display: flex;flex-direction: row;">
  12. <view :class="item.type == '快充' ? 'fast-charge':(item.type == '慢充' ? 'trickle-charge':'fast-trickle-charge')"style="margin-right: 5rpx;">
  13. {{item.type}}
  14. </view>
  15. <view>
  16. {{item.name}}
  17. </view>
  18. </view>
  19. </view>
  20. <view class="card_item font3" style="color:#8898A9;">
  21. {{item.address}}
  22. </view>
  23. <view class="card_item2 " >
  24. <view class="font6" style="color:#FF6573;margin-right: 10rpx;">
  25. {{item.costPrice}}
  26. </view>
  27. <view style="display: flex; justify-content: center;align-items: center">
  28. 元/度 起
  29. </view>
  30. </view>
  31. <view class="card_item" style="border-bottom: #F1F4F3; border-bottom-width: 2rpx;border-style: solid;border-top-width: 0rpx;border-left-width: 0rpx;border-right-width:0rpx; padding-bottom:20rpx">
  32. <view style="display: flex;flex-direction: row;">
  33. <view style="background-color: #7DB1FF;padding-left: 10rpx;padding-right: 10rpx;">
  34. P
  35. </view>
  36. <label>{{item.park}}</label>
  37. </view>
  38. <view style="display: flex;flex-direction: row;">
  39. <view style="color: #00B962;">
  40. 空闲{{item.availableNum}}
  41. </view>
  42. <view>
  43. /总数{{item.totalNum}}
  44. </view>
  45. </view>
  46. </view>
  47. <view class="card_item" style="padding-bottom: 20rpx;">
  48. <u-button shape='circle' style="color: #00B962;" @click="getScanCode">
  49. <u-icon name="scan" size="26" color="#00B962" style="margin-right: 20rpx;"></u-icon>
  50. <label>扫码充电</label></u-button>
  51. <view class="round">
  52. <text class="iconfont distance-font">&#xe615;</text>
  53. <view style="margin-right: 10rpx;">
  54. {{item.distance!=null?item.distance.toFixed(2):''}}公里
  55. </view>
  56. <view style="margin-right: 10rpx;">
  57. {{item.time!=null?item.time.toFixed(0):''}}分钟
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. let _self;
  68. import * as api from '@/apis/site.js';
  69. import * as indexAPI from '@/apis/index.js'
  70. import Chargermap from '@/components/Chargermap.vue';
  71. import * as WxJsApi from '@/utils/wxJsApi.js'
  72. import MapLoader from '@/utils/AMap'
  73. export default {
  74. components: {
  75. Chargermap
  76. },
  77. data() {
  78. return {
  79. elderMode:false,
  80. userId:'',
  81. id: '',
  82. longitude: 112.28468,
  83. latitude: 30.307094,
  84. // longitude: '',
  85. // latitude: '',
  86. area: '荆州市',
  87. action: '筛选',
  88. item:{
  89. name:'',
  90. position:'',
  91. price:1,idleNum:0,total:0,distance:0,time:0,type:'慢充',id: 0,
  92. park: '以实际费用为准',
  93. longitude: 112.28541,
  94. latitude: 30.308354 },
  95. stations:[]
  96. }
  97. },
  98. methods:{
  99. theme(type) {
  100. if(type == 'elder')
  101. {
  102. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  103. }
  104. else
  105. {
  106. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  107. }
  108. },
  109. getPoint() {
  110. console.log('getPoint')
  111. WxJsApi.getLocation().then((res) => {
  112. if(res==null)
  113. return;
  114. console.log('站点地图当前位置'+JSON.stringify(res))
  115. _self.latitude = parseFloat(res.latitude);
  116. _self.longitude = parseFloat(res.longitude);
  117. var startLngLat = {longitude: _self.longitude ,latitude: _self.latitude };
  118. var endLngLat = {longitude: _self.item.longitude, latitude: _self.item.latitude};
  119. console.log('start'+JSON.stringify(startLngLat));
  120. console.log('end'+JSON.stringify(endLngLat));
  121. //_self.calculateDistance(startLngLat,endLngLat);
  122. //let posCenter= {longitude: _self.longitude,latitude: _self.latitude};
  123. var obj = {
  124. longitude: _self.longitude,
  125. latitude: _self.latitude
  126. };
  127. _self.$refs.amap.setPerson(obj);
  128. var lnglat = new AMap.LngLat(startLngLat.longitude,startLngLat.latitude);
  129. var myDistance = lnglat.distance([endLngLat.longitude, endLngLat.latitude]);
  130. _self.item.distance = myDistance/1000;
  131. _self.item.time = myDistance/500;
  132. /*
  133. _self.$refs.amap.calculateDistance(startLngLat,endLngLat).then(function(res){
  134. _self.item.distance = res.distance/1000;
  135. _self.item.time = res.time/60;
  136. //console.log(result)
  137. //console.log(result.routes[0].time)//秒
  138. //console.log(result.routes[0].distance)//米
  139. console.log('距离'+JSON.stringify(res))
  140. })*/
  141. console.log('当前位置' +JSON.stringify(data))
  142. //this.latitude2 = latitude;
  143. //this.longitude2 = longitude;
  144. /*uni.showToast({
  145. title:JSON.stringify(res)
  146. })*/
  147. //this.message=JSON.stringify(res)
  148. }).catch(error => {
  149. uni.showToast({
  150. title:error//JSON.stringify(error)
  151. })
  152. })
  153. },
  154. stationDetail(item){
  155. console.log('item'+JSON.stringify(item))
  156. uni.navigateTo({
  157. url:'stationDetails?id='+this.item.id
  158. //url:'stationDetails?station='+encodeURIComponent(JSON.stringify(this.item))
  159. })
  160. },
  161. setCenter(){
  162. console.log('getPoint')
  163. WxJsApi.getLocation().then((res) => {
  164. _self.latitude = parseFloat(res.latitude);
  165. _self.longitude = parseFloat(res.longitude);
  166. //let data = {position:{latitude:latitude,longitude:longitude}};
  167. let posCenter= {longitude: _self.longitude,latitude: _self.latitude};
  168. this.$refs.amap.setCenter(posCenter);
  169. }).catch(error => {
  170. uni.showToast({
  171. title:error//JSON.stringify(error)
  172. })
  173. })
  174. // console.log('setCenter')
  175. },
  176. getScanCode() {
  177. if (this.userId) {
  178. WxJsApi.scanQRCode(1).then(res => {
  179. if(res) {
  180. indexAPI.scanCode(res).then((response) => {
  181. }).catch(error => {
  182. uni.showToast({
  183. title: error,
  184. icon: "none"
  185. })
  186. })
  187. }
  188. }).catch(error => {
  189. })
  190. } else {
  191. uni.navigateTo({
  192. url: '/pages/login/login'
  193. })
  194. }
  195. },
  196. mapdown() {
  197. let data = {stationId:this.id};
  198. api.getChargingStationDetail(data).then(function(res){
  199. // console.log('站点详情'+JSON.stringify(res))
  200. //this.info.st
  201. if(res && res.result)
  202. {
  203. if(res.data){
  204. let data = res.data;
  205. data.station.time = 0;
  206. _self.item = data.station;
  207. if(_self.item.park == null)
  208. _self.item.park = '以实际费用为准'
  209. if(_self.item.type == '2')
  210. _self.item.type = '慢充'
  211. else if(_self.item.type == '1')
  212. _self.item.type = '快充'
  213. else {
  214. _self.item.type = '快/慢'
  215. }
  216. if(_self.item.costPrice == null){
  217. if(data.fastPrice != null){
  218. _self.item.costPrice = data.fastPrice.costPrice;
  219. if(data.slowPrice != null){
  220. if(_self.item.costPrice> data.slowPrice.costPrice){
  221. _self.item.costPrice = data.slowPrice.costPrice;
  222. }
  223. }
  224. }else if(data.slowPrice != null){
  225. _self.item.costPrice = data.slowPrice.costPrice;
  226. }
  227. }
  228. if(_self.item.distance == null){
  229. _self.getPoint();
  230. }
  231. var obj = {
  232. longitude: _self.item.longitude,
  233. latitude: _self.item.latitude
  234. };
  235. _self.$refs.amap.setCenter(obj)
  236. _self.stations = [];
  237. _self.stations.push(_self.item);
  238. // console.log('stations1'+JSON.stringify(this.stations[0]))
  239. // console.log('stations2'+JSON.stringify(this.item))
  240. _self.$refs.amap.setChargerList(_self.stations);
  241. console.log('站点项目'+JSON.stringify(_self.item))
  242. _self.$refs.amap.updateCharger(_self.item)
  243. //_self.stationDetail = data;
  244. //_self.processStationsInfo();
  245. console.log('data'+JSON.stringify(_self.item ));
  246. }
  247. }
  248. })
  249. }
  250. },
  251. onLoad(op) {
  252. _self = this;
  253. // console.log('longitude0 ' + _self.longitude);
  254. if (op != null) {
  255. if(op.stationId != null){
  256. //_self.item = this.carhelp.get(op.stationId);
  257. //return;
  258. this.id = op.stationId;
  259. return;
  260. }
  261. if(op.station!=null){
  262. console.log('op.station ' + op.station);
  263. this.item = JSON.parse(decodeURIComponent(op.station));
  264. console.log('item '+JSON.stringify(this.item));
  265. this.longitude = this.item.longitude;
  266. this.latitude = this.item.latitude;
  267. //this.mapdown();
  268. }
  269. if (op.longitude != null) this.longitude = op.longitude;
  270. if (op.latitude != null) this.latitude = op.latitude;
  271. if (op.id != null) this.id = op.id;
  272. }
  273. this.item.longitude = this.longitude;
  274. this.item.latitude = this.latitude;
  275. },
  276. onReady() {
  277. this.elderMode = this.carhelp.get('getElderModeClass');
  278. if(this.elderMode)
  279. this.theme('elder')
  280. else
  281. this.theme('standard')
  282. // console.log('longitude2 '+this.longitude)
  283. // console.log('latitude2 '+this.latitude)
  284. if (this.carhelp.getPersonInfo()) {
  285. this.userId = this.carhelp.getPersonInfo().id;
  286. }
  287. WxJsApi.getWxConfig(['getLocation', 'addEventListener', 'scanQRCode']).then((res) => {
  288. // console.log(res)
  289. }).catch(error => {
  290. console.log(res)
  291. })
  292. this.isReady = true;
  293. this.$refs.amap.init();
  294. //let state = {};
  295. uni.getSystemInfo({
  296. success: (res) => {
  297. // #ifndef MP
  298. let navbarH = 0
  299. // #endif
  300. // #ifdef MP
  301. let navbarH = uni.upx2px(90)
  302. // #endif
  303. /*state.status_width = res.windowWidth;
  304. console.log('window width'+state.status_width);*/
  305. let scrollH = res.windowHeight;// - uni.upx2px(88) - navbarH
  306. // console.log('布局结果'+ JSON.stringify(res));
  307. // console.log('scrollH'+scrollH)
  308. //#ifdef MP-WEIXIN
  309. const {
  310. statusBarHeight,
  311. windowWidth,
  312. } = uni.getSystemInfoSync();
  313. console.log('height ' + statusBarHeight);
  314. //this.status_height = uni.getStatusbarHeight();
  315. let res1 = uni.getMenuButtonBoundingClientRect()
  316. console.log('layout selectHeight '+JSON.stringify(res1))
  317. //state.selectHeight = (res1.top-res.statusBarHeight)*2+ res1.height;
  318. //#endif
  319. //console.log('status height'+state.status_height)
  320. _self.$refs.amap.setMyStyle("height:"+(scrollH-44)+ "px;width:100%;");
  321. }
  322. })
  323. },
  324. onShow() {
  325. },
  326. }
  327. </script>
  328. <style lang="scss" scoped>
  329. @import "@/_theme.scss";
  330. .preference_group_item {
  331. padding: 15rpx;
  332. }
  333. .preference_group {
  334. padding-bottom: 20rpx;
  335. }
  336. .preference {
  337. background-color: #ffffff;
  338. left: 0rpx;
  339. position: absolute;
  340. }
  341. .preference_item {
  342. margin-bottom: 10rpx;
  343. margin-left: 20rpx;
  344. text-align: center;
  345. border-style: none;
  346. width: 20%;
  347. }
  348. .preference_item_plus {
  349. margin-bottom: 10rpx;
  350. margin-left: 20rpx;
  351. align-items: center;
  352. justify-content: center;
  353. text-align: center;
  354. width: 25%;
  355. border-style: none;
  356. }
  357. .preference_label {
  358. color: #9f9c99;
  359. margin-left: 20rpx;
  360. margin-bottom: 100rpx;
  361. }
  362. .map{
  363. background-color: #ffffff;
  364. left: 0rpx;
  365. position: absolute;
  366. }
  367. .chargerCard{
  368. /* background-color: #fff;
  369. margin: 0 12px;
  370. border-radius: 8px;
  371. padding: 10px 12px 0px;
  372. position: absolute;
  373. bottom: 68px;
  374. left: 0;
  375. right: 0;
  376. z-index:1021
  377. */
  378. background-color: #fff;
  379. margin: 0 12px;
  380. border-radius: 8px;
  381. padding: 10px 12px 0px;
  382. bottom: 28px;
  383. left: 0;
  384. right: 0;
  385. position: fixed;
  386. height:360rpx;
  387. /*
  388. z-index: 1021;
  389. width: 80%;
  390. margin-left: 10%;
  391. bottom: 50rpx;
  392. */
  393. }
  394. .arrow{
  395. margin-right: 15rpx;
  396. }
  397. .card_item{
  398. display: flex;
  399. flex-direction: row;
  400. justify-content: space-between;
  401. margin-left: 20rpx;
  402. margin-right: 20rpx;
  403. margin-bottom: 10rpx;
  404. @include themeify{
  405. font-size: themed('font-size2');
  406. }
  407. }
  408. .card_item2{
  409. display: flex;
  410. flex-direction: row;
  411. margin-left: 20rpx;
  412. margin-right: 20rpx;
  413. margin-bottom: 10rpx;
  414. @include themeify{
  415. font-size: themed('font-size2');
  416. }
  417. }
  418. .round{
  419. border-radius:50rpx;
  420. background-color: #00B962;
  421. color: #ffffff;
  422. text-align: center;
  423. justify-content: center;
  424. align-items: center;
  425. width: 250rpx;
  426. display: flex;
  427. flex-direction: row;
  428. }
  429. .round2{
  430. border-radius:50rpx;
  431. background-color: #00B962;
  432. color: #ffffff;
  433. text-align: center;
  434. justify-content: center;
  435. align-items: center;
  436. width:125rpx;
  437. }
  438. .swiper-item{
  439. }
  440. .list {
  441. margin-left: 2px;
  442. }
  443. .charing-slow {
  444. background-color: #fff;
  445. margin: 20rpx;
  446. border-radius: 8px;
  447. padding: 10px 12px 0px;
  448. position: relative;
  449. left: 0;
  450. right: 0;
  451. }
  452. .fast-charge {
  453. display: inline-block;
  454. width: 44px;
  455. height: 20px;
  456. line-height: 20px;
  457. border-radius: 50px;
  458. background-color: #9d9fff;
  459. color: rgba(255, 255, 255, 100);
  460. @include themeify{
  461. font-size: themed('font-size1');
  462. line-height: themed('font-size5');
  463. height: themed('font-size5');
  464. }
  465. /* font-size: 12px;*/
  466. text-align: center;
  467. }
  468. .fast-trickle-charge {
  469. display: inline-block;
  470. width: 66px;
  471. /* height: 20px;
  472. line-height: 20px;*/
  473. border-radius: 50px;
  474. background-color: #00BAC8;
  475. color: rgba(255, 255, 255, 100);
  476. @include themeify{
  477. font-size: themed('font-size1');
  478. line-height: themed('font-size5');
  479. height: themed('font-size5');
  480. }
  481. /* font-size: 12px;*/
  482. text-align: center;
  483. }
  484. .trickle-charge {
  485. display: inline-block;
  486. width: 44px;
  487. /* height: 20px;
  488. line-height: 20px;*/
  489. border-radius: 50px;
  490. background-color: rgba(0, 185, 98, 100);
  491. color: rgba(255, 255, 255, 100);
  492. /* font-size: 12px;*/
  493. @include themeify{
  494. font-size: themed('font-size1');
  495. line-height: themed('font-size5');
  496. height: themed('font-size5');
  497. }
  498. text-align: center;
  499. }
  500. .station-items {
  501. display: inline-block;
  502. /* height: 16px;
  503. line-height: 16px;
  504. font-size: 16px;*/
  505. @include themeify{
  506. font-size: themed('font-size3');
  507. line-height: themed('font-size3');
  508. height: themed('font-size3');
  509. }
  510. margin-left: 4px;
  511. color: #101010;
  512. }
  513. .fast-charge {
  514. display: inline-block;
  515. width: 44px;
  516. /* height: 20px;
  517. line-height: 20px;*/
  518. border-radius: 50px;
  519. background-color: #9d9fff;
  520. color: rgba(255, 255, 255, 100);
  521. /* font-size: 12px;*/
  522. @include themeify{
  523. font-size: themed('font-size1');
  524. line-height: themed('font-size5');
  525. height: themed('font-size5');
  526. }
  527. text-align: center;
  528. }
  529. .address {
  530. margin-top: 8px;
  531. @include themeify{
  532. font-size: themed('font-size1');
  533. line-height: themed('font-size3');
  534. }
  535. /* line-height: 16px;
  536. font-size: 11px;*/
  537. color: rgba(119, 119, 119, 100);
  538. }
  539. .price {
  540. display: flex;
  541. height: 20px;
  542. }
  543. .num {
  544. height: 20px;
  545. color: rgba(255, 98, 0, 100);
  546. @include themeify{
  547. font-size: themed('font-size5');
  548. }
  549. /* font-size: 20px;*/
  550. text-align: left;
  551. font-family: Roboto-medium;
  552. }
  553. .unit {
  554. /* height: 14px;
  555. line-height: 14px;*/
  556. color: rgba(102, 102, 102, 100);
  557. @include themeify{
  558. font-size: themed('font-size2');
  559. line-height: themed('font-size2');
  560. height: themed('font-size2');
  561. }
  562. /* font-size: 14px;*/
  563. text-align: left;
  564. font-family: AlibabaPuHui-regular;
  565. margin-top: 6px;
  566. margin-left: 4px;
  567. }
  568. .park {
  569. margin-top: 8px;
  570. display: flex;
  571. }
  572. .park-p {
  573. display: inline-block;
  574. width: 20px;
  575. @include themeify{
  576. /* font-size: themed('font-size1'); */
  577. line-height: themed('font-size1');
  578. height: themed('font-size4');
  579. }
  580. /* height: 18px;
  581. line-height: 12px;*/
  582. text-align: center;
  583. background-color: rgba(125, 177, 255, 100);
  584. color: #fff;
  585. }
  586. .park-text {
  587. display: inline-block;
  588. width: 300px;
  589. /* height: 17px;*/
  590. color: rgba(102, 102, 102, 100);
  591. /* font-size: 12px;*/
  592. @include themeify{
  593. font-size: themed('font-size1');
  594. height: themed('font-size4');
  595. }
  596. text-align: left;
  597. margin-left: 4px;
  598. margin-top: 2px;
  599. }
  600. .map {
  601. width: 100%;
  602. height: 100%;
  603. position: relative;
  604. }
  605. #container {
  606. width: 100%;
  607. height: 100%;
  608. }
  609. .free {
  610. display: flex;
  611. justify-content: space-between;
  612. height: 52px;
  613. border-top: 1px solid rgba(238, 242, 240, 100);
  614. margin-top: 10px;
  615. }
  616. .free-num {
  617. line-height: 52px;
  618. /* font-size: 16px*/
  619. @include themeify{
  620. font-size: themed('font-size3');
  621. }
  622. }
  623. .distance {
  624. width: 130px;
  625. /* height: 28px;
  626. line-height: 28px;*/
  627. color: rgba(255, 255, 255, 100);
  628. /* font-size: 14px;*/
  629. @include themeify{
  630. font-size: themed('font-size2');
  631. height: themed('font-size9');
  632. line-height: themed('font-size9');
  633. }
  634. background-color: #00b962;
  635. border-radius: 50px;
  636. margin: 12px;
  637. text-align: center;
  638. }
  639. .distance-font {
  640. font-size: 16px
  641. }
  642. </style>