search.vue 4.2 KB

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