app-area-sel-bak.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="app-area-sel">
  3. <bottom-popup class="popup-wrap" :show="show" @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 placeholder="请输入你的收货地址" />
  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. export default {
  43. name: 'app-area-sel',
  44. components: {
  45. BottomPopup,
  46. AppClose,
  47. AppSearchModule
  48. },
  49. props: {
  50. show: {
  51. type: Boolean,
  52. default: false
  53. }
  54. },
  55. data() {
  56. return {
  57. // 地图
  58. latitude: 24.44579,
  59. longitude: 118.08243,
  60. // 列表
  61. currentSelectAddress: 0,
  62. nearListData: [
  63. {
  64. title: '中国共产党厦门市思明区纪律检查委员会',
  65. address: '福建省厦门市思明区民族路33号'
  66. },
  67. {
  68. title: '厦门市思明区人民政府',
  69. address: '福建省厦门市思明区民族路33号'
  70. },
  71. {
  72. title: '海滨商厦',
  73. address: '福建省厦门市思明区民族路42~44'
  74. },
  75. {
  76. title: '卢卡国际青年旅舍',
  77. address: '福建省厦门市思明区民族路35号(思明区政府对面)'
  78. },
  79. {
  80. title: '中国共产党厦门市思明区纪律检查委员会',
  81. address: '福建省厦门市思明区民族路33号'
  82. },
  83. {
  84. title: '厦门市思明区人民政府',
  85. address: '福建省厦门市思明区民族路33号'
  86. },
  87. {
  88. title: '海滨商厦',
  89. address: '福建省厦门市思明区民族路42~44'
  90. }
  91. ]
  92. }
  93. },
  94. onLoad(val) {
  95. this.mapCtx = uni.createMapContext('myMap')
  96. this.query = val
  97. this.reload()
  98. },
  99. methods: {
  100. hidePopup() {
  101. this.$emit('hide')
  102. },
  103. // 地图操作
  104. reload() {
  105. uni.getLocation({
  106. type: 'wgs84',
  107. success: res => {
  108. this.latitude = res.latitude
  109. this.longitude = res.longitude
  110. // this.nearList()
  111. },
  112. // eslint-disable-next-line handle-callback-err
  113. fail: err => {
  114. this.$msg('定位失败')
  115. // setTimeout(function() {
  116. // uni.navigateBack({
  117. // delta: 1
  118. // })
  119. // }, 1500)
  120. }
  121. })
  122. },
  123. mapChange(e) {
  124. if (e.type == 'end' && (e.causedBy == 'scale' || e.causedBy == 'drag')) {
  125. this.mapCtx.getCenterLocation({
  126. success: res => {
  127. this.longitude = res.longitude
  128. this.latitude = res.latitude
  129. // this.nearList()
  130. }
  131. })
  132. }
  133. },
  134. // 获取列表
  135. nearList() {
  136. geocoder({
  137. latitude: this.latitude,
  138. longitude: this.longitude
  139. }).then(res => {
  140. console.log(res)
  141. let data = res.result
  142. this.currentSelectAddress = 0
  143. this.nearListData = data.pois
  144. // this.currentRegion = [data.address_component.province, data.address_component.city, data.address_component.district]
  145. })
  146. },
  147. switchAddress(item, index) {
  148. // this.currentSelectAddress = index
  149. // this.latitude = item.location.lat
  150. // this.longitude = item.location.lng
  151. // if (!this.$util.isEmpty(item.province) && !this.$util.isEmpty(item.city)) {
  152. // this.currentRegion = [item.province, item.city, item.district]
  153. // }
  154. this.$emit('change', item)
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. // 弹窗
  161. /deep/.popup-wrap {
  162. .tui-popup-class {
  163. border-top-left-radius: 20px;
  164. border-top-right-radius: 20px;
  165. }
  166. }
  167. .map-wrap {
  168. .map-top-tit-wrap {
  169. padding: 30px 0;
  170. text-align: center;
  171. font-size: 34px;
  172. }
  173. .map-search {
  174. padding: 0 30px;
  175. margin-bottom: 20px;
  176. }
  177. .map-box {
  178. .current-site-icon {
  179. width: 63px;
  180. height: 90px;
  181. position: absolute;
  182. top: 50%;
  183. left: 50%;
  184. transform: translate(-50%, -50%);
  185. }
  186. }
  187. // 列表
  188. .near-list {
  189. height: 620rpx;
  190. // padding-bottom: 110rpx;
  191. box-sizing: border-box;
  192. .near-item {
  193. line-height: 40rpx;
  194. padding: 18rpx 50rpx 18rpx 0;
  195. margin-left: 90px;
  196. text-align: left;
  197. border-bottom: 1px solid #eee;
  198. position: relative;
  199. }
  200. .current-site {
  201. width: 16px;
  202. height: 16px;
  203. background-color: #dedede;
  204. border-radius: 50%;
  205. position: absolute;
  206. top: 60rpx;
  207. left: -60rpx;
  208. &.active {
  209. background-color: $mainColor;
  210. }
  211. }
  212. .near-item .title {
  213. color: #282828;
  214. font-size: 28rpx;
  215. white-space: nowrap;
  216. overflow: hidden;
  217. text-overflow: ellipsis;
  218. }
  219. .near-item .add {
  220. color: $fontColor3;
  221. font-size: 22rpx;
  222. white-space: nowrap;
  223. overflow: hidden;
  224. text-overflow: ellipsis;
  225. }
  226. .near-item .title1 {
  227. color: $mainColor;
  228. }
  229. .near-item .add1 {
  230. color: $mainColor;
  231. }
  232. }
  233. }
  234. </style>