search.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <template>
  2. <view>
  3. <ujp-navbar title="" ref='navbar' id='navbar' :height='nav_height'>
  4. <u-search id='search' ref='search' :input-style='inputStyle' placeholder="搜索站点名称" @change="search()" v-model="keyword" color="#c8c8c8" @search="search" @click="search" @clickicon='back' @custom='search'></u-search>
  5. </ujp-navbar>
  6. <view class="recommend">推荐充电站</view>
  7. <view class="charing-slow" v-for="(item,index) in stations_filter" :key="item.id" @click="stationDetail(item)">
  8. <text :class="item.type == '快充' ? 'fast-charge':(item.type == '慢充' ? 'trickle-charge':'fast-trickle-charge')">{{item.type}}</text> <text class="station-items">{{item.name}}</text>
  9. <view class="address">
  10. {{item.position}}
  11. </view>
  12. <view class="price">
  13. <view class="num">{{item.price}}</view> <view class="unit">
  14. 元/度 起
  15. </view>
  16. </view>
  17. <view class="park">
  18. <text class="park-p">p</text>
  19. <text class="park-text">{{item.park}}</text>
  20. </view>
  21. <view class="free">
  22. <view class="free-num">
  23. <text style="color:#009143;">空闲{{item.idleNum}}</text>/总数{{item.total}}
  24. </view>
  25. <view class="distance" @click="navigateTo(item)">
  26. <text class="iconfont distance-font">&#xe615;</text>
  27. {{item.distance!=null&&item.distance>0.1 ? item.distance.toFixed(1)+'公里':'小于100米'}} {{item.time.toFixed(0)}}分钟
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. let _self;
  35. import * as api from '@/apis/site.js';
  36. import * as WxJsApi from '@/utils/wxJsApi.js'
  37. import MapLoader from '@/utils/AMap'
  38. export default {
  39. data() {
  40. return {
  41. elderMode:false,
  42. inputStyle:{
  43. backgroundColor: 'transparent',
  44. "font-size":'36rpx',
  45. "font-weight":"normal"
  46. },
  47. nav_height:54,
  48. userId:'',
  49. keyword:'',
  50. stations_filter:[],
  51. stations:[
  52. /* {name:'荆鹏软件园充电站',position:'湖北省荆州市沙市区江津东路附155号',price:1.2,idleNum:10,total:10,distance:0.1,time:1,type:'慢充',park:'2小时免费停车'},
  53. {name:'荆鹏软件园充电站2',position:'湖北省荆州市沙市区江津东路附156号',price:1.2,idleNum:10,total:10,distance:0.15,time:12,type:'快充',park:'3小时免费停车'},
  54. {name:'荆鹏软件园充电站3',position:'湖北省荆州市沙市区江津东路附157号',price:1.2,idleNum:10,total:10,distance:0.2,time:13,type:'慢充',park:'4小时免费停车'},
  55. {name:'荆鹏大道求助站充电站',position:'湖北省荆州市沙市区江津东路附158号',price:1.2,idleNum:10,total:10,distance:0.3,time:14,type:'快充',park:'5小时免费停车'},
  56. */
  57. ],
  58. }
  59. },
  60. onLoad(op){
  61. _self = this;
  62. //var px1 = uni.upx2px(88);
  63. //var rpx = 40/(uni.upx2px(100)/100);
  64. // 验证上面rpx的值
  65. var px = uni.upx2px(88);
  66. this.nav_height = px;
  67. // //('搜索框高度'+JSON.stringify(rpx))
  68. // //('搜索框高度'+JSON.stringify(px))
  69. /*
  70. if(op!= null && op.stationlist != null){
  71. this.stations = decodeURIComponent(op.stationlist)
  72. //('stations'+JSON.stringify(this.stations))
  73. }
  74. //('op'+JSON.stringify(op))*/
  75. },
  76. onReady() {
  77. this.elderMode = this.carhelp.get('getElderModeClass') == '长辈模式';
  78. if(this.elderMode)
  79. this.theme('elder')
  80. else
  81. this.theme('standard')
  82. if (this.carhelp.getPersonInfo()) {
  83. this.userId = this.carhelp.getPersonInfo().id;
  84. }
  85. WxJsApi.getWxConfig(['getLocation','addEventListener']).then((res)=>{
  86. // this.message=JSON.stringify(res)
  87. // uni.showToast({
  88. // title:JSON.stringify(res)
  89. // })
  90. //(res)
  91. }).catch(error => {
  92. //(res)
  93. })
  94. this.getPoint();
  95. },
  96. // conponents:{charingSlows},
  97. methods: {
  98. theme(type) {
  99. if(type == 'elder')
  100. {
  101. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  102. let data = {
  103. backgroundColor: 'transparent',
  104. "font-size":'32rpx',
  105. "font-weight":"bold!important"
  106. };
  107. this.inputStyle = data;
  108. }
  109. else
  110. {
  111. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  112. let data ={
  113. backgroundColor: 'transparent',
  114. "font-size":'32rpx',
  115. "font-weight":"normal"
  116. };
  117. this.inputStyle = data;
  118. }
  119. },
  120. navigateTo(item){
  121. window.location.href="https://uri.amap.com/marker?position="+ item.longitude+","+item.latitude+"&name="+item.name;
  122. },
  123. stationDetail(item){
  124. //('stationDetail item'+JSON.stringify(item))
  125. uni.navigateTo({
  126. url:'../searchPile/stationAndPile/stationDetails?id='+item.id
  127. })
  128. /*
  129. uni.navigateTo({
  130. url:'stationAndPile/stationDetails?station='+encodeURIComponent(JSON.stringify(item))
  131. })
  132. */
  133. // //('stationDetail'+JSON.stringify(item))
  134. },
  135. calculateDistance(startLngLat,obj){
  136. var _this = this;
  137. var endLngLat = [obj.longitude,obj.latitude];
  138. MapLoader().then(AMap1 => {
  139. this.AMap=AMap;
  140. var lnglat = new AMap.LngLat(startLngLat.longitude,startLngLat.latitude);
  141. var myDistance = lnglat.distance([obj.longitude, obj.latitude]);
  142. obj.distance = myDistance/1000;
  143. obj.time = myDistance/500;
  144. /*
  145. var map=new AMap.Map("container", {
  146. center: [116.397559, 39.89621],
  147. zoom: 14
  148. });
  149. AMap.plugin('AMap.Driving', function() {
  150. var driving = new AMap.Driving({
  151. // 驾车路线规划策略,AMap.DrivingPolicy.LEAST_TIME是最快捷模式
  152. policy: AMap.DrivingPolicy.LEAST_TIME
  153. })
  154. //var startLngLat = [116.379028, 39.865042]
  155. //var endLngLat = [116.427281, 39.903719]
  156. driving.search(startLngLat, endLngLat, function (status, result) {
  157. //(result)
  158. //(result.routes[0].time)//秒
  159. //(result.routes[0].distance)//米
  160. obj.distance = result.routes[0].distance/1000;
  161. obj.time = result.routes[0].time/60;
  162. })
  163. })
  164. */
  165. }, e => {
  166. //_this.mui.toast('地图加载失败');
  167. //('地图加载失败', e)
  168. })
  169. },
  170. getPoint() {
  171. var _this = this;
  172. //('getPoint')
  173. WxJsApi.getLocation().then((res) => {
  174. var latitude = parseFloat(res.latitude);
  175. var longitude = parseFloat(res.longitude);
  176. _this.latitude = latitude;
  177. _this.longitude = longitude;
  178. let data = {latitude:_this.latitude,longtitude:_this.longitude};
  179. this.getChargingStationData(data);
  180. //('当前位置' +JSON.stringify(data))
  181. //this.latitude2 = latitude;
  182. //this.longitude2 = longitude;
  183. /*uni.showToast({
  184. title:JSON.stringify(res)
  185. })*/
  186. //this.message=JSON.stringify(res)
  187. }).catch(error => {
  188. uni.showToast({
  189. title:JSON.stringify(error)
  190. })
  191. })
  192. },
  193. getChargingStationData(pos){
  194. //('getChargingStationData')
  195. //return;
  196. if(pos == null)
  197. return ;
  198. let data1 = { pageIndex:0,pageSize:20};
  199. if(pos.longtitude != null)
  200. data1.longitude = pos.longtitude.toString();
  201. if(pos.latitude != null)
  202. data1.latitude = pos.latitude.toString();
  203. //data1.findType = "0";
  204. //data1.type = "1";
  205. //data1.online = "0";
  206. /* if(this.info.obc_type[this.preference.obc_type_index].text.indexOf('直流快充')>=0)
  207. data1.type = "1";
  208. else if(this.info.obc_type[this.preference.obc_type_index].text.indexOf('交流慢充')>=0)
  209. data1.type = "2";
  210. if(this.info.miles_type[this.preference.miles_index].distance!=null)
  211. data1.radius = this.info.miles_type[this.preference.miles_index].distance.toString();
  212. data1.online = "0";//在线
  213. if(pos.findType != null)
  214. data1.findType = pos.findType;
  215. else
  216. data1.findType = "0";
  217. if(this.preference.obc_power.minValue!=null)
  218. data1.powerStart = this.preference.obc_power.minValue.toString();
  219. if(this.preference.obc_power.maxValue!=null)
  220. data1.powerEnd = this.preference.obc_power.maxValue.toString();
  221. */
  222. //('data1'+JSON.stringify(data1))
  223. api.searchStationData(data1).then(function(res){
  224. //('getChargingStationData'+JSON.stringify(res))
  225. if(!res.result || !res.data || !res.data.data)
  226. {
  227. //('getChargingStationData res nulll')
  228. return;
  229. }
  230. let items = res.data.data;
  231. _self.stations_filter = [];
  232. for(let i = 0;i<items.length;i++)
  233. {
  234. let obj = {
  235. name:'',
  236. position:'',
  237. price:1.2,
  238. idleNum:10,
  239. total:10,
  240. type: data1.type == "2" ? '慢充':'快充',
  241. id: i,
  242. distance:0.9,
  243. time:9,
  244. park: '2小时免费停车',
  245. // longitude: 112.28541 + i * 0.001,
  246. // latitude: 30.308354 + i * 0.01
  247. };
  248. if(items[i].id != null)
  249. obj.id = items[i].id;
  250. else
  251. continue;
  252. if(items[i].type.indexOf("1")>=0 && items[i].type.indexOf("2")>=0)
  253. {
  254. obj.type = '快/慢'
  255. }
  256. if(items[i].costPrice!=null)
  257. obj.price = items[i].costPrice;
  258. if(items[i].name!=null)
  259. obj.name = items[i].name;
  260. if(items[i].address!=null)
  261. obj.position = items[i].address;
  262. if(items[i].coostPrice!=null)
  263. obj.price = items[i].coostPrice;
  264. if(items[i].availableNum!=null)
  265. obj.idleNum = items[i].availableNum;
  266. if(items[i].totalNum!=null)
  267. obj.total = items[i].totalNum;
  268. if(items[i].longitude!=null)
  269. obj.longitude = items[i].longitude;
  270. if(items[i].latitude!=null)
  271. obj.latitude = items[i].latitude;
  272. if(items[i].distance!=null)
  273. obj.distance = items[i].distance;
  274. if(items[i].time != null){
  275. obj.time = items[i].time;
  276. }
  277. if(items[i].park != null)
  278. obj.park = items[i].park;
  279. var startLngLat = {longitude: _self.longitude,latitude: _self.latitude};
  280. //var endLngLat = [obj.longitude,obj.latitude];
  281. _self.calculateDistance(startLngLat,obj);
  282. /*
  283. _self.item.distance = myDistance/1000;
  284. _self.item.time = myDistance/500;
  285. let obj = {name:items[i].name,
  286. position:items[i].address,
  287. price:items[i].coostPrice,
  288. idleNum:items[i].availableNum,
  289. total:items[i].totalNum,
  290. distance:0.1,
  291. time:1,
  292. type:'慢充',
  293. id: items[i].id,
  294. park: i%2 == 0? '以实际费用为准':'2小时免费停车',
  295. longitude: items[i].longitude,
  296. latitude: items[i].latitude
  297. };*/
  298. _self.stations.push(obj);
  299. }
  300. _self.stations_filter = _self.stations;
  301. //_self.$refs.amap.searchBtn([_self.longitude, _self.latitude],_self.stationsmap)
  302. //_self.$refs.amap.setChargerList(_self.stationsmap);
  303. //if(_self.stationsmap.length>0)
  304. // _self.$refs.amap.updateCharger(_self.stationsmap[0]);
  305. },function(err){
  306. //('getChargingStationData err'+JSON.stringify(err))
  307. }
  308. )
  309. //('getChargingStationData end')
  310. },
  311. back(){
  312. //('back');
  313. uni.navigateBack({
  314. delta:1
  315. })
  316. },
  317. search(){
  318. //('search keyword'+this.keyword + ' '+JSON.stringify(this.stations))
  319. this.stations_filter = []
  320. if(this.keyword.length<=0){
  321. this.stations_filter = this.stations
  322. return;
  323. }
  324. for(let i = 0;i< this.stations.length;i++){
  325. if(this.stations[i].name.indexOf(this.keyword)>=0){
  326. this.stations_filter.push(this.stations[i]);
  327. }
  328. }
  329. //('search ' + this.keyword);
  330. }
  331. }
  332. }
  333. </script>
  334. <style lang="scss" scoped>
  335. @import "@/_theme.scss";
  336. /deep/.u-content[data-v-1a326067] {
  337. flex: 0.95;
  338. color: #bdbdbd;
  339. }
  340. /deep/.u-action {
  341. margin-right: 0rpx;
  342. color: #c8c8c8;
  343. }
  344. .recommend {
  345. width: 100%;
  346. height: 88rpx;
  347. line-height: 88rpx;
  348. color: #101010;
  349. padding: 0 32rpx;
  350. background-color: #fff;
  351. font-weight: 600;
  352. }
  353. .charing-slow {
  354. width: 91%;
  355. background-color: #fff;
  356. margin: 24rpx auto 0;
  357. border-radius: 16rpx;
  358. padding: 20rpx 24rpx 0rpx;
  359. .trickle-charge {
  360. display: inline-block;
  361. width: 88rpx;
  362. /* height: 40rpx;
  363. line-height: 40rpx;*/
  364. border-radius: 100rpx;
  365. background-color: rgba(0, 185, 98, 100);
  366. color: rgba(255, 255, 255, 100);
  367. @include themeify{
  368. font-size:themed('font-size1');
  369. line-height: themed('font-size5');
  370. height:themed('font-size5')
  371. }
  372. /* font-size: 24rpx;*/
  373. text-align: center;
  374. }
  375. .fast-trickle-charge{
  376. display: inline-block;
  377. width: 132rpx;
  378. /* height: 40rpx;
  379. line-height: 40rpx;*/
  380. border-radius: 100rpx;
  381. background-color: #00BAC8;
  382. color: rgba(255, 255, 255, 100);
  383. @include themeify{
  384. font-size:themed('font-size1');
  385. line-height: themed('font-size5');
  386. height:themed('font-size5')
  387. }
  388. /* font-size: 24rpx;*/
  389. text-align: center;
  390. }
  391. .fast-charge {
  392. display: inline-block;
  393. width: 88rpx;
  394. /* height: 40rpx;
  395. line-height: 40rpx;*/
  396. border-radius: 100rpx;
  397. background-color: #9d9fff;
  398. color: rgba(255, 255, 255, 100);
  399. /* font-size: 24rpx;*/
  400. @include themeify{
  401. font-size:themed('font-size1');
  402. line-height: themed('font-size5');
  403. height:themed('font-size5')
  404. }
  405. text-align: center;
  406. }
  407. .station-items {
  408. display: inline-block;
  409. /* height: 32rpx;
  410. line-height: 32rpx;
  411. font-size: 32rpx;
  412. */
  413. @include themeify{
  414. font-size:themed('font-size3');
  415. line-height: themed('font-size3');
  416. height:themed('font-size3');
  417. font-weight: themed('fontWeight');
  418. letter-spacing: themed('letterSpacing');
  419. }
  420. margin-left: 8rpx;
  421. color: #101010;
  422. }
  423. .address {
  424. margin-top: 16rpx;
  425. @include themeify{
  426. font-size:themed('font-size1');
  427. line-height: themed('font-size3');
  428. /* height:themed('font-size11')*/
  429. }
  430. /*
  431. line-height: 32rpx;
  432. font-size: 22rpx;*/
  433. color: rgba(119, 119, 119, 100);
  434. }
  435. .price{
  436. display: flex;
  437. @include themeify{
  438. height:themed('font-size5');
  439. }
  440. /* height: 40rpx;*/
  441. .num{
  442. height: 40rpx;
  443. color: rgba(255, 98, 0, 100);
  444. @include themeify{
  445. font-size:themed('font-size5');
  446. }
  447. /* font-size: 40rpx;*/
  448. text-align: left;
  449. font-family: Roboto-medium;
  450. }
  451. .unit{
  452. /* height: 28rpx;
  453. line-height: 28rpx;*/
  454. color: rgba(102, 102, 102, 100);
  455. @include themeify{
  456. font-size:themed('font-size2');
  457. line-height: themed('font-size2');
  458. height:themed('font-size2')
  459. }
  460. /* font-size: 28rpx;*/
  461. text-align: left;
  462. font-family: AlibabaPuHui-regular;
  463. margin-top: 12rpx;
  464. margin-left: 8rpx;
  465. }
  466. }
  467. .park {
  468. margin-top: 16rpx;
  469. display: flex;
  470. .park-p {
  471. display: inline-block;
  472. width: 40rpx;
  473. /* height: 36rpx;
  474. line-height: 24rpx;*/
  475. @include themeify{
  476. line-height: themed('font-size1');
  477. height:themed('font-size3')
  478. }
  479. text-align: center;
  480. background-color: rgba(125, 177, 255, 100);
  481. color: #fff;
  482. }
  483. .park-text {
  484. display: inline-block;
  485. width: 600rpx;
  486. /*height: 34rpx;*/
  487. color: rgba(102, 102, 102, 100);
  488. @include themeify{
  489. font-size: themed('font-size1');
  490. height:themed('font-size4')
  491. }
  492. /* font-size: 24rpx;*/
  493. text-align: left;
  494. margin-left: 8rpx;
  495. margin-top: 4rpx;
  496. }
  497. }
  498. .free{
  499. display: flex;
  500. justify-content: space-between;
  501. height: 104rpx;
  502. border-top: 2rpx solid rgba(238, 242, 240, 100);
  503. margin-top: 20rpx;
  504. .free-num{
  505. line-height: 104rpx;
  506. @include themeify{
  507. font-size: themed('font-size3');
  508. font-weight: themed('fontWeight');
  509. letter-spacing: themed('letterSpacing');
  510. }
  511. /* font-size: 32rpx*/
  512. }
  513. .distance{
  514. /* width: 260rpx;*/
  515. height: 56rpx;
  516. line-height: 56rpx;
  517. color: rgba(255, 255, 255, 100);
  518. @include themeify{
  519. font-size: themed('font-size2');
  520. width: themed('buttonWidth');
  521. }
  522. /* font-size: 28rpx;*/
  523. background-color: #00b962;
  524. border-radius: 100rpx;
  525. margin: 24rpx;
  526. text-align: center;
  527. .distance-font{
  528. @include themeify{
  529. font-size: themed('font-size3');
  530. }
  531. /* font-size: 32rpx*/
  532. }
  533. }
  534. }
  535. }
  536. </style>