fondMap.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view>
  3. <view class="map-container">
  4. <map style="width: 100%; height: 100vh;" :show-location='true' ref="map" id="map" :latitude="latitude"
  5. :longitude="longitude" :markers="marker" :scale="scale" @callouttap='callouttap' v-if="mapShow">
  6. <view class="cover-view">
  7. <view @click="onControltap">
  8. <image class="cover-image" src="@/static/image/food/dw.png"></image>
  9. </view>
  10. </view>
  11. </map>
  12. </view>
  13. <!-- <view class="search" :style="{top:topHeight+'px'}">
  14. <searchBar @click="search" :city="city"></searchBar>
  15. </view> -->
  16. <cardList :stationList="markerIdClick" v-if="tag" style="position: fixed;top: 70%;"></cardList>
  17. <tabbar :current="current"></tabbar>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. authorizedLocation
  23. } from '@/util/util.js'
  24. export default {
  25. data() {
  26. return {
  27. mapShow: false,
  28. topHeight: 20,
  29. tag: false,
  30. latitude: '', //纬度
  31. longitude: '', //经度
  32. scale: 12, //缩放级别
  33. current: 1,
  34. marker: [],
  35. pageSize: 10,
  36. pageNum: 1,
  37. total: 0, // 总数据量
  38. markerIdClick: [],
  39. mapList: [],
  40. }
  41. },
  42. async onLoad() {
  43. this.isdingwei()
  44. this.getStationList()
  45. const {
  46. height,
  47. top
  48. } = uni.getMenuButtonBoundingClientRect();
  49. this.topHeight = height + top + 13
  50. },
  51. methods: {
  52. isdingwei() {
  53. authorizedLocation().then(res => {
  54. let _obj = {}
  55. if (res == '取消授权') {
  56. //获取上一次,无上一次山海广场
  57. let _place = uni.getStorageSync("LocationPlace")
  58. if (_place && _place.latitude) {
  59. _obj = {
  60. latitude: _place.latitude,
  61. longitude: _place.longitude
  62. }
  63. } else {
  64. _obj = {
  65. latitude: 40.22086204872,
  66. longitude: 122.08338497727
  67. }
  68. }
  69. } else {
  70. _obj = {
  71. latitude: res.latitude,
  72. longitude: res.longitude
  73. }
  74. }
  75. this.longitude = _obj.longitude
  76. this.latitude = _obj.latitude
  77. })
  78. },
  79. search(searchInp) {
  80. console.log('search页面子向父传值', searchInp);
  81. },
  82. regionChange() {
  83. this.tag = false
  84. if (this.pageNum * this.pageSize >= this.total) return
  85. this.pageNum++
  86. this.getStationList()
  87. },
  88. //移动到当前位置
  89. onControltap() {
  90. uni.createMapContext("map", this).moveToLocation();
  91. },
  92. //气泡点击事件
  93. callouttap(e) {
  94. let id = String(e.detail.markerId)
  95. let arr = this.mapList.find(item => {
  96. return item.stationId === id
  97. })
  98. this.markerIdClick = [arr]
  99. this.tag = true
  100. },
  101. getList() {
  102. return new Promise((resolve, reject) => {
  103. this.$request.baseRequest('admin.tourism.foodInfo', 'foodList', {
  104. page: 1,
  105. limit: 9999,
  106. }, failres => {
  107. uni.showToast({
  108. icon: "none",
  109. title: failres.errmsg,
  110. duration: 3000
  111. });
  112. }).then(res => {
  113. uni.hideLoading()
  114. resolve(res)
  115. })
  116. })
  117. },
  118. async getStationList() {
  119. console.log('发送请求前 打印用户经纬度', this.latitude, this.longitude);
  120. const data = await this.getList()
  121. console.log('queryStationInfos,信息列表显示总数据', data);
  122. this.total = data.total
  123. data.data.items.forEach(item => {
  124. item.latitude = item.location.split(',')[0]
  125. item.longitude = item.location.split(',')[1]
  126. this.marker.push({
  127. id: Number(item.id),
  128. iconPath: '/static/image/food/location.png', //显示的图标
  129. latitude: Number(item.latitude),
  130. longitude: Number(item.longitude),
  131. label:{
  132. content:item.shopNames,
  133. textAlign:"left",
  134. padding:-20
  135. },
  136. width: 30,
  137. height: 30,
  138. // callout: { //气泡窗口
  139. // content: '空闲', //文本
  140. // color: '#ffffff',
  141. // fontSize: 15,
  142. // borderRadius: 15,
  143. // padding: '10',
  144. // bgColor: '#406390',
  145. // display: 'ALWAYS', //常显
  146. // }
  147. })
  148. })
  149. this.mapShow = true
  150. this.mapList = this.mapList.concat(data.data.items)
  151. console.log(this.marker);
  152. // for (let index in obj.list) {
  153. // let stationMarker = {
  154. // iconPath: '/static/images/mapStation.png', //显示的图标
  155. // id: Number(index) || 0,
  156. // title: this.mapList[index].stationName || '',
  157. // latitude: Number(this.mapList[index].stationLat),
  158. // longitude: Number(this.mapList[index].stationLng),
  159. // width: 30,
  160. // height: 30,
  161. // callout: { //气泡窗口
  162. // content: '空闲' + this.mapList[index].totalFree, //文本
  163. // color: '#ffffff', //文字颜色
  164. // fontSize: 15, //文本大小
  165. // borderRadius: 15, //边框圆角
  166. // padding: '10',
  167. // bgColor: '#406390', //背景颜色
  168. // display: 'ALWAYS', //常显
  169. // }
  170. // }
  171. // // console.log(stationMarker, 'stationMarker');
  172. // this.marker.push(stationMarker)
  173. // }
  174. }
  175. }
  176. }
  177. </script>
  178. <style scoped lang="scss">
  179. /deep/ .uni-searchbar__box-search-input {
  180. color: #fff !important;
  181. }
  182. .search {
  183. position: fixed;
  184. width: 80%;
  185. }
  186. .map-container {
  187. margin-top: -40rpx;
  188. position: relative;
  189. overflow: hidden;
  190. border-radius: 50rpx 50rpx 0 0;
  191. .cover-view {
  192. display: flex;
  193. flex-direction: column;
  194. align-items: center;
  195. justify-content: center;
  196. /* width: 80rpx;
  197. height: 160rpx; */
  198. padding: 10rpx 15rpx;
  199. color: #4F575F;
  200. font-weight: 400;
  201. background-color: #fff;
  202. background-position: center center;
  203. position: absolute;
  204. bottom: 300rpx;
  205. right: 30rpx;
  206. border-radius: 20rpx;
  207. }
  208. .cover-image {
  209. display: inline-block;
  210. width: 40rpx;
  211. height: 40rpx;
  212. }
  213. }
  214. </style>