app-area-sel.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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: 140px;" :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. // if (val) {
  89. // this.getAreaList()
  90. // }
  91. }
  92. },
  93. methods: {
  94. getAreaList() {
  95. if (!this.keyword) {
  96. return false
  97. }
  98. suggestion({ region: this.city, keyword: this.keyword }).then(res => {
  99. this.nearListData = res.data.data
  100. })
  101. },
  102. // 搜索
  103. searchFn(e) {
  104. this.keyword = e
  105. this.getAreaList()
  106. // this.$emit('search', e)
  107. // uni.reverseGeocode({
  108. // latitude: 25.661333498914413,
  109. // longitude: 117.5537109375
  110. // }, (e) => {
  111. // console.log(e)
  112. // })
  113. },
  114. hidePopup() {
  115. this.$emit('update:show', false)
  116. this.$emit('hide')
  117. },
  118. switchAddress(item, index) {
  119. this.currentSelectAddress = index
  120. // this.latitude = item.location.lat
  121. // this.longitude = item.location.lng
  122. // if (!this.$util.isEmpty(item.province) && !this.$util.isEmpty(item.city)) {
  123. // this.currentRegion = [item.province, item.city, item.district]
  124. // }
  125. this.$emit('change', item)
  126. this.hidePopup()
  127. }
  128. // 地图操作
  129. // reload() {
  130. // uni.getLocation({
  131. // type: 'wgs84',
  132. // success: res => {
  133. // this.latitude = res.latitude
  134. // this.longitude = res.longitude
  135. // // this.nearList()
  136. // },
  137. // // eslint-disable-next-line handle-callback-err
  138. // fail: err => {
  139. // this.$msg('定位失败')
  140. // // setTimeout(function() {
  141. // // uni.navigateBack({
  142. // // delta: 1
  143. // // })
  144. // // }, 1500)
  145. // }
  146. // })
  147. // },
  148. // mapChange(e) {
  149. // if (e.type == 'end' && (e.causedBy == 'scale' || e.causedBy == 'drag')) {
  150. // this.mapCtx.getCenterLocation({
  151. // success: res => {
  152. // this.longitude = res.longitude
  153. // this.latitude = res.latitude
  154. // // this.nearList()
  155. // }
  156. // })
  157. // }
  158. // },
  159. // 获取列表
  160. // nearList() {
  161. // geocoder({
  162. // latitude: this.latitude,
  163. // longitude: this.longitude
  164. // }).then(res => {
  165. // console.log(res)
  166. // let data = res.result
  167. // this.currentSelectAddress = 0
  168. // this.nearListData = data.pois
  169. // // this.currentRegion = [data.address_component.province, data.address_component.city, data.address_component.district]
  170. // })
  171. // },
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. // 弹窗
  177. /deep/.popup-wrap {
  178. .tui-popup-class {
  179. border-top-left-radius: 20px;
  180. border-top-right-radius: 20px;
  181. }
  182. }
  183. .map-wrap {
  184. .map-top-tit-wrap {
  185. padding: 30px 0;
  186. text-align: center;
  187. font-size: 34px;
  188. }
  189. .map-search {
  190. padding: 0 30px;
  191. margin-bottom: 20px;
  192. }
  193. .map-box {
  194. .current-site-icon {
  195. width: 63px;
  196. height: 90px;
  197. position: absolute;
  198. top: 50%;
  199. left: 50%;
  200. transform: translate(-50%, -50%);
  201. }
  202. }
  203. // 列表
  204. .near-list {
  205. height: 820rpx;
  206. // padding-bottom: 110rpx;
  207. box-sizing: border-box;
  208. .near-item {
  209. line-height: 40rpx;
  210. padding: 18rpx 50rpx 18rpx 0;
  211. margin-left: 90px;
  212. text-align: left;
  213. border-bottom: 1px solid #eee;
  214. position: relative;
  215. }
  216. .current-site {
  217. width: 16px;
  218. height: 16px;
  219. background-color: #dedede;
  220. border-radius: 50%;
  221. position: absolute;
  222. top: 60rpx;
  223. left: -60rpx;
  224. &.active {
  225. background-color: $mainColor;
  226. }
  227. }
  228. .near-item .title {
  229. color: #282828;
  230. font-size: 28rpx;
  231. white-space: nowrap;
  232. overflow: hidden;
  233. text-overflow: ellipsis;
  234. }
  235. .near-item .add {
  236. color: $fontColor3;
  237. font-size: 22rpx;
  238. white-space: nowrap;
  239. overflow: hidden;
  240. text-overflow: ellipsis;
  241. }
  242. .near-item .title1 {
  243. color: $mainColor;
  244. }
  245. .near-item .add1 {
  246. color: $mainColor;
  247. }
  248. }
  249. }
  250. </style>