map_search.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view style="height: 100%;">
  3. <map style="width: 100%;height: 100%;" :latitude="latitude" :longitude="longitude" :markers="covers" @markertap="markertap">
  4. </map>
  5. <cover-view class="map-pop-box" v-show="isShowPop" @click="goParkDetail()">
  6. <cover-view class="display-between">
  7. <cover-view class="pop-title">{{popInfo.name}}</cover-view>
  8. <cover-image src="/static/park/location2.png" style='width:50rpx;height:50rpx;'></cover-image>
  9. </cover-view>
  10. <cover-view class="display-flex-start" style="margin-bottom: 10rpx;">
  11. <cover-view class="pop-subtitle">入驻企业:</cover-view>
  12. <cover-view class="pop-value">{{popInfo.company_count}}</cover-view>
  13. </cover-view>
  14. <cover-view class="display-flex-start">
  15. <cover-view class="pop-subtitle">园区地址:</cover-view>
  16. <cover-view class="pop-value">{{popInfo.address}}</cover-view>
  17. </cover-view>
  18. </cover-view>
  19. </view>
  20. </template>
  21. <script>
  22. import md5 from '@/common/md5.js';
  23. export default {
  24. data() {
  25. return {
  26. id:0, // 使用 marker点击事件 需要填写id
  27. title: 'map',
  28. latitude: 34.438387,
  29. longitude: 108.762834,
  30. isShowPop:false,
  31. startList:[],
  32. nowId:'',
  33. popInfo:{
  34. // title:"新鸿辉工业园测试数据",
  35. // enterprise:'484',
  36. // address:'渭城区底张镇88号',
  37. // id:1
  38. },
  39. covers: [
  40. // {
  41. // id:1,
  42. // latitude: 39.909,
  43. // longitude: 116.39742,
  44. // name:'天安门',
  45. // iconPath: '/static/park/location.svg',
  46. // }, {
  47. // id:2,
  48. // name:'XX12221',
  49. // latitude: 39.90,
  50. // longitude: 116.39,
  51. // iconPath: '/static/park/location.svg'
  52. // },
  53. ]
  54. }
  55. },
  56. onLoad() {
  57. this.init()
  58. },
  59. methods: {
  60. init(){
  61. this.getPark();
  62. },
  63. mapRender(data){
  64. let arrayData = [];
  65. for (var i = 0; i < data.length; i++) {
  66. arrayData.push({
  67. id: Number(data[i].id), //marker点击事件回调会返回此id。建议为每个marker设置上Number类型id,保证更新marker时有更好的性能。
  68. latitude: data[i].latitude, //纬度
  69. longitude: data[i].longitude, //经度
  70. title: data[i].name, //点击时显示,callout存在时将被忽略
  71. iconPath: '/static/park/location.svg', //项目目录下的图片路径,支持相对路径写法,以'/'开头则表示相对小程序根目录;也支持临时路径
  72. width: 20,
  73. height: 30,
  74. callout: {
  75. content: data[i].name, //文本
  76. color: '#000', //文本颜色
  77. borderRadius: 3, //边框圆角
  78. borderWidth: 0, //边框宽度
  79. borderColor: '#FF0202', //边框颜色
  80. bgColor: '#fff', //背景色
  81. padding: 10, //文本边缘留白
  82. display:'ALWAYS',
  83. textAlign: 'center' //文本对齐方式 left, right, center
  84. },
  85. });
  86. }
  87. // this.covers = arrayData;
  88. this.covers = arrayData.slice(0,1);
  89. console.log(this.covers);
  90. },
  91. //地图点击事件
  92. markertap(e) {
  93. this.nowId = e.detail.markerId;
  94. this.startList.forEach((item)=>{
  95. if(item.id == e.detail.markerId){
  96. this.popInfo = item;
  97. }
  98. })
  99. this.isShowPop = true;
  100. },
  101. goParkDetail(){
  102. uni.navigateTo({
  103. url:'park_deatil?id=' + this.nowId
  104. })
  105. },
  106. getPark(){
  107. let md5Sign = md5("method="+'park'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
  108. let url = getApp().globalData.shareUrl+'api/api.php'+'?method=park&source=park&action=list&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
  109. let postData = {
  110. order_by:"weight desc",
  111. }
  112. uni.request({
  113. url:url,
  114. method: 'POST',
  115. header: {
  116. 'content-type': 'application/x-www-form-urlencoded'
  117. },
  118. data:postData,
  119. success: (res) => {
  120. console.log(res)
  121. if(res.data.code === 200){
  122. this.startList =res.data.data.list;
  123. res.data.data.list.forEach((item)=>{
  124. item.location = item.location.split(',')
  125. let coverObj = {
  126. id:item.id,
  127. latitude: item.location[0],
  128. longitude: item.location[1],
  129. name:item.name,
  130. }
  131. this.covers.push(coverObj)
  132. })
  133. this.mapRender(this.covers)
  134. }
  135. },
  136. fail: () => {
  137. console.log("连接失败");
  138. }
  139. });
  140. },
  141. },
  142. }
  143. </script>
  144. <style>
  145. page {
  146. height: 100%;
  147. }
  148. .map-pop-box {
  149. width: 92%;
  150. padding: 30rpx;
  151. background-color: #fff;
  152. position: fixed;
  153. bottom: 0;
  154. }
  155. .pop-title {
  156. font-size: 28rpx;
  157. font-weight: 600;
  158. line-height: 36rpx;
  159. letter-spacing: 0.02em;
  160. color: #0D1937;
  161. }
  162. .pop-subtitle{
  163. font-size: 20rpx;
  164. color: #CFCFCF;
  165. margin-right: 10rpx;
  166. }
  167. .pop-value {
  168. font-size: 20rpx;
  169. color: #0D1937;
  170. }
  171. </style>