search.vue 14 KB

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