index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="chooseAddress">
  3. <view class="search-box">
  4. <view class="input-box">
  5. <view class="city">
  6. {{city}}
  7. </view>
  8. <input class="address-input" focus :placeholder="type == 'start'?'您从哪里上车':'您想去哪里'" type="text" v-model="address" />
  9. </view>
  10. </view>
  11. <view class="search-content">
  12. <view class="item" v-for="(item,index) in list" :key="index" @click="chooseAddress(item)">
  13. <view class="info">
  14. <view class="address">
  15. {{item.title}}
  16. </view>
  17. <view class="desc">
  18. {{item.address}}
  19. </view>
  20. </view>
  21. <view class="distance">
  22. {{item._distance | filterDistance}}
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import {debounce} from '@/utils/tool.js'
  30. // 腾讯地图
  31. var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
  32. var qqmapsdk = new QQMapWX({
  33. key: 'KX5BZ-B64RC-RO62W-AMWAZ-VVTC3-YAFXF'})
  34. export default {
  35. data() {
  36. return {
  37. longitude: 0,
  38. latitude: 0,
  39. city: '定位中',
  40. address:'',
  41. type:'',
  42. list:[]
  43. }
  44. },
  45. watch: {
  46. address:debounce(function(keyword) {
  47. let that = this
  48. qqmapsdk.getSuggestion({
  49. keyword,
  50. region_fix:1,
  51. policy:1,
  52. location: `${that.latitude},${that.longitude}`,
  53. success(res){
  54. console.log(res);
  55. that.list = res.data
  56. }
  57. })
  58. })
  59. },
  60. methods: {
  61. chooseAddress(item) {
  62. uni.navigateTo({
  63. url:`../index/index?type=${this.type}`,
  64. success: function(res) {
  65. // 通过eventChannel向被打开页面传送数据
  66. res.eventChannel.emit('address', {
  67. latitude:item.location.lat,
  68. longitude:item.location.lng,
  69. address:item.title
  70. })
  71. }
  72. })
  73. }
  74. },
  75. filters: {
  76. filterDistance: function(val) {
  77. return (val/1000).toFixed(1)+'km'
  78. }
  79. },
  80. onLoad(val) {
  81. this.type = val.type
  82. },
  83. created() {
  84. this.city = uni.getStorageSync('city')
  85. let that = this
  86. uni.getLocation({
  87. type: 'gcj02',
  88. success(res) {
  89. that.longitude = res.longitude
  90. that.latitude = res.latitude
  91. }
  92. })
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. .chooseAddress{
  98. .search-box{
  99. position: fixed;
  100. top: 0%;
  101. left: 0%;
  102. width: 100%;
  103. height: 72rpx;
  104. padding: 20rpx 32rpx;
  105. background: #fff;
  106. .input-box{
  107. height: 72rpx;
  108. padding: 16rpx 0;
  109. box-sizing: border-box;
  110. border-radius: 36rpx;
  111. background: #F9F9F9;
  112. display: flex;
  113. font-size: 28rpx;
  114. .city{
  115. flex: 0 0 154rpx;
  116. text-align: center;
  117. color: #222222;
  118. border-right: 2rpx solid #F0F0F0;;
  119. }
  120. .address-input{
  121. flex: 1;
  122. color: #AAAAAA;
  123. padding-left: 20rpx;
  124. }
  125. }
  126. }
  127. .search-content{
  128. padding-top: 112rpx;
  129. .item{
  130. display: flex;
  131. align-items: center;
  132. justify-content: space-between;
  133. padding: 36rpx 32rpx;
  134. border-bottom: 1rpx solid #F0F0F0;
  135. .info{
  136. .address{
  137. font-weight: bold;
  138. color: #222222;
  139. font-size: 28rpx;
  140. }
  141. .desc{
  142. font-size: 24rpx;
  143. color: #AAAAAA;
  144. margin-top: 14rpx;
  145. }
  146. }
  147. .distance{
  148. font-size: 28rpx;
  149. color: #AAAAAA;
  150. }
  151. }
  152. }
  153. }
  154. </style>