app-area-sel.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="app-area-sel">
  3. <bottom-popup class="popup-wrap" :show="showPopup" @close="hidePopup">
  4. <div class="map-wrap">
  5. <div class="map-top-tit-wrap">
  6. <div class="map-top-tit">地址</div>
  7. <app-close icon="iconguanbi" @close="hidePopup" />
  8. </div>
  9. <!-- 搜索 -->
  10. <div class="map-search">
  11. <app-search-module ref="aaaaa" placeholder="请输入你的地址" :focus="false" @input="searchFn" />
  12. </div>
  13. <!-- 地图 -->
  14. <!-- <div class="map-box">
  15. <map id="myMap" style="width: 100%; height: 140upx;" :latitude="latitude" :longitude="longitude" @regionchange="mapChange">
  16. <cover-image class="current-site-icon" src="../../static/images/common/localposition.png"></cover-image>
  17. <cover-view class="reload" @click="reload">
  18. <cover-view class="center1">
  19. <cover-view class="center2"></cover-view>
  20. </cover-view>
  21. </cover-view>
  22. </map>
  23. </div>-->
  24. <!-- 列表 -->
  25. <scroll-view class="near-list" scroll-y>
  26. <view v-for="(item,index) in nearListData" :key="index" @click="switchAddress(item,index)" class="near-item">
  27. <div class="current-site" :class="{'active' : currentSelectAddress === index}"></div>
  28. <view>
  29. <view :class="['title',currentSelectAddress === index? 'title1':'']">{{item.title}}</view>
  30. <view class="add">{{item.address}}</view>
  31. </view>
  32. </view>
  33. </scroll-view>
  34. </div>
  35. </bottom-popup>
  36. </div>
  37. </template>
  38. <script>
  39. import BottomPopup from '@/components/plugin/bottom-popup'
  40. import AppClose from '@/components/module/app-close'
  41. import AppSearchModule from '@/components/module/app-search'
  42. // api
  43. import { suggestion } from '@/api/common'
  44. export default {
  45. name: 'app-area-sel',
  46. components: {
  47. BottomPopup,
  48. AppClose,
  49. AppSearchModule
  50. },
  51. props: {
  52. show: {
  53. type: Boolean,
  54. default: false
  55. },
  56. city: {
  57. type: String,
  58. default: ''
  59. }
  60. },
  61. data() {
  62. return {
  63. showPopup: false,
  64. keyword: '',
  65. // 地图
  66. // latitude: 24.44579,
  67. // longitude: 118.08243,
  68. // 列表
  69. currentSelectAddress: null,
  70. nearListData: []
  71. }
  72. },
  73. // onLoad(val) {
  74. // this.mapCtx = uni.createMapContext('myMap')
  75. // this.query = val
  76. // this.reload()
  77. // },
  78. watch: {
  79. show(val) {
  80. this.showPopup = val
  81. // #ifdef H5
  82. this.$nextTick(function() {
  83. setTimeout(() => {
  84. this.$refs.aaaaa.$refs.searchInput._focusInput()
  85. }, 1000)
  86. })
  87. // #endif
  88. },
  89. city() {
  90. this.nearListData = []
  91. this.$refs.aaaaa.search = ''
  92. }
  93. },
  94. methods: {
  95. getAreaList() {
  96. if (!this.keyword) {
  97. return false
  98. }
  99. suggestion({ region: this.city, keyword: this.keyword }).then(res => {
  100. this.nearListData = res.data.data
  101. })
  102. },
  103. // 搜索
  104. searchFn(e) {
  105. this.keyword = e
  106. this.getAreaList()
  107. // this.$emit('search', e)
  108. // uni.reverseGeocode({
  109. // latitude: 25.661333498914413,
  110. // longitude: 117.5537109375
  111. // }, (e) => {
  112. // console.log(e)
  113. // })
  114. },
  115. hidePopup() {
  116. this.$emit('update:show', false)
  117. this.$emit('hide')
  118. },
  119. switchAddress(item, index) {
  120. this.currentSelectAddress = index
  121. // this.latitude = item.location.lat
  122. // this.longitude = item.location.lng
  123. // if (!this.$util.isEmpty(item.province) && !this.$util.isEmpty(item.city)) {
  124. // this.currentRegion = [item.province, item.city, item.district]
  125. // }
  126. this.$emit('change', item)
  127. this.hidePopup()
  128. }
  129. // 地图操作
  130. // reload() {
  131. // uni.getLocation({
  132. // type: 'wgs84',
  133. // success: res => {
  134. // this.latitude = res.latitude
  135. // this.longitude = res.longitude
  136. // // this.nearList()
  137. // },
  138. // // eslint-disable-next-line handle-callback-err
  139. // fail: err => {
  140. // this.$msg('定位失败')
  141. // // setTimeout(function() {
  142. // // uni.navigateBack({
  143. // // delta: 1
  144. // // })
  145. // // }, 1500)
  146. // }
  147. // })
  148. // },
  149. // mapChange(e) {
  150. // if (e.type == 'end' && (e.causedBy == 'scale' || e.causedBy == 'drag')) {
  151. // this.mapCtx.getCenterLocation({
  152. // success: res => {
  153. // this.longitude = res.longitude
  154. // this.latitude = res.latitude
  155. // // this.nearList()
  156. // }
  157. // })
  158. // }
  159. // },
  160. // 获取列表
  161. // nearList() {
  162. // geocoder({
  163. // latitude: this.latitude,
  164. // longitude: this.longitude
  165. // }).then(res => {
  166. // console.log(res)
  167. // let data = res.result
  168. // this.currentSelectAddress = 0
  169. // this.nearListData = data.pois
  170. // // this.currentRegion = [data.address_component.province, data.address_component.city, data.address_component.district]
  171. // })
  172. // },
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. // 弹窗
  178. /deep/.popup-wrap {
  179. .tui-popup-class {
  180. border-top-left-radius: 20upx;
  181. border-top-right-radius: 20upx;
  182. }
  183. }
  184. .map-wrap {
  185. .map-top-tit-wrap {
  186. padding: 30upx 0;
  187. text-align: center;
  188. font-size: 34upx;
  189. }
  190. .map-search {
  191. padding: 0 30upx;
  192. margin-bottom: 20upx;
  193. }
  194. .map-box {
  195. .current-site-icon {
  196. width: 63upx;
  197. height: 90upx;
  198. position: absolute;
  199. top: 50%;
  200. left: 50%;
  201. transform: translate(-50%, -50%);
  202. }
  203. }
  204. // 列表
  205. .near-list {
  206. height: 820upx;
  207. // padding-bottom: 110upx;
  208. box-sizing: border-box;
  209. .near-item {
  210. line-height: 40upx;
  211. padding: 18upx 50upx 18upx 0;
  212. margin-left: 90upx;
  213. text-align: left;
  214. border-bottom: 1upx solid #eee;
  215. position: relative;
  216. }
  217. .current-site {
  218. width: 16upx;
  219. height: 16upx;
  220. background-color: #dedede;
  221. border-radius: 50%;
  222. position: absolute;
  223. top: 60upx;
  224. left: -60upx;
  225. &.active {
  226. background-color: $mainColor;
  227. }
  228. }
  229. .near-item .title {
  230. color: #282828;
  231. font-size: 28upx;
  232. white-space: nowrap;
  233. overflow: hidden;
  234. text-overflow: ellipsis;
  235. }
  236. .near-item .add {
  237. color: $fontColor3;
  238. font-size: 22upx;
  239. white-space: nowrap;
  240. overflow: hidden;
  241. text-overflow: ellipsis;
  242. }
  243. .near-item .title1 {
  244. color: $mainColor;
  245. }
  246. .near-item .add1 {
  247. color: $mainColor;
  248. }
  249. }
  250. }
  251. </style>