search.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <ax-body blank="0">
  3. <view class="page-background"><image src="@/static/img/my-bg.svg" mode="widthFix"></image></view>
  4. <view class="body">
  5. <view class="search-box">
  6. <icon class="ax-iconline i-search icon"></icon>
  7. <input v-model="search" placeholder="输入目的地/电站名" placeholder-class="app-placeholder" class="input"/>
  8. <view v-if="search.length" @click="search=''" class="clear"><icon class="ax-iconblock i-cuowu"></icon></view>
  9. <text @click="query()" class="txt">搜索</text>
  10. </view>
  11. <!-- 搜索历史 -->
  12. <view v-if="histories.length" class="history">
  13. <view class="title">
  14. <text class="txt">搜索历史</text>
  15. <icon @click="clean()" class="ax-iconline i-delete icon"></icon>
  16. </view>
  17. <view class="list app-hide-scrollbar">
  18. <view class="wrap"><view v-for="(item,index) in histories" :key="index" @click="setSearch(item)" class="item">{{item}}</view></view>
  19. </view>
  20. </view>
  21. <!-- 搜索结果 -->
  22. <view class="result">
  23. <view class="title">
  24. <text class="txt">搜索结果</text>
  25. <text class="total">共计 {{result.length}} 条</text>
  26. </view>
  27. <view class="list">
  28. <view class="wrap app-hide-scrollbar">
  29. <view v-for="(item,index) in result" :key="index" class="site" @click="gotoSiteDetail(item)" >
  30. <view class="name">{{item.name}}</view>
  31. <!-- <view class="aux" v-html="item.parkTips"></view> -->
  32. <view class="aux">充电减免2小时停车费,超出时长部分计时收费</view>
  33. <view class="info">
  34. <view class="sta"><text class="txt green">快</text><text class="val">{{item.params.emptyFast}}</text><text class="unit">/{{item.params.totalFast}}</text></view>
  35. <view class="sta"><text class="txt blue">慢</text><text class="val">{{item.params.emptySlow}}</text><text class="unit">/{{item.params.totalSlow}}</text></view>
  36. <view class="sta"><text class="txt orange">距离</text><text class="val">{{item.params.rangeShow}}</text></view>
  37. </view>
  38. </view>
  39. <view v-if="!result.length" class="empty">
  40. <icon class="ax-iconblock i-meiyou icon"></icon>
  41. <text class="txt">暂无数据展示</text>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </ax-body>
  48. </template>
  49. <script>
  50. export default {
  51. onLoad() {
  52. this.histories = this.$app.storage.get('history-search') || [];
  53. },
  54. data() {
  55. return {
  56. search: "",
  57. histories:[],
  58. result:[]
  59. }
  60. },
  61. methods: {
  62. convertBdToTx(lng, lat) {
  63. // 百度坐标系(BD09)转火星坐标系(GCJ-02,即腾讯地图使用的坐标系)
  64. // 这里的转换公式是基于经验公式,可能存在一定的误差
  65. let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  66. let x = lng - 0.0065;
  67. let y = lat - 0.006;
  68. let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  69. let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  70. let lngs = z * Math.cos(theta);
  71. let lats = z * Math.sin(theta);
  72. return { lng: lngs, lat: lats };
  73. },
  74. gotoSiteDetail(item){
  75. this.$app.url.goto('/pages/site/site?item='+JSON.stringify(item));
  76. },
  77. query(){
  78. const history = Array.from(new Set([this.search].concat(this.histories)));
  79. this.histories = history;
  80. this.$app.storage.set('history-search',history);
  81. this.result = [{},{},{},{},{}];
  82. let location = this.$app.storage.get('USER_LOCATION')
  83. let lng = ""
  84. let lat = ""
  85. if(location&&location.split(",").length==2){
  86. lng = location.split(",")[0]
  87. lat = location.split(",")[1]
  88. }
  89. var key = this.search
  90. this.$api.base("post","/chargeApi/getStations",{order:"0",lng,lat,key},{}).then(res=>{
  91. res.stationList.forEach(i=>{
  92. var txPoint = this.convertBdToTx(i.lng,i.lat)
  93. i.lng = txPoint.lng
  94. i.lat = txPoint.lat
  95. })
  96. this.result = res.stationList
  97. })
  98. },
  99. setSearch(item){
  100. this.search = item;
  101. this.query();
  102. },
  103. clean(){
  104. this.$app.popup.confirm('确定是否删除所有历史搜索纪录?','清空历史').then(confirm=>{
  105. if(confirm){
  106. this.histories = [];
  107. this.$app.storage.remove('history-search');
  108. }
  109. });
  110. }
  111. }
  112. }
  113. </script>
  114. <style scoped>
  115. @import url("search.css");
  116. </style>