map_search.vue 5.0 KB

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