lijj 2 лет назад
Родитель
Сommit
2cbf5be2af
1 измененных файлов с 73 добавлено и 4 удалено
  1. 73 4
      miniapp/pages/yuecai/restaurant/detail/index.vue

+ 73 - 4
miniapp/pages/yuecai/restaurant/detail/index.vue

@@ -8,9 +8,14 @@
     <view class="col-info-d t-c m-b-30">
     <view class="col-info-d t-c m-b-30">
       <u-parse :content="detailVO.content"></u-parse>
       <u-parse :content="detailVO.content"></u-parse>
     </view>
     </view>
-    <detailBottom type="restaurant" :articleId.sync="detailVO.id" :liked.sync="detailVO.liked" :collected.sync="detailVO.collected"
-      :views.sync="detailVO.views" :likeNum.sync="detailVO.likeNum" :collectNum.sync="detailVO.collectNum"
-      @doRefresh="getDetail"></detailBottom>
+    <view v-if="detailVO && detailVO.id && detailVO.latitude && detailVO.longitude" class="width-100 m-b-20"
+      style="height: 250px;">
+      <map id="map" class="width-100 height-100" :show-location="true" :latitude="detailVO.latitude"
+        :longitude="detailVO.longitude"></map>
+    </view>
+    <detailBottom type="restaurant" :articleId.sync="detailVO.id" :liked.sync="detailVO.liked"
+      :collected.sync="detailVO.collected" :views.sync="detailVO.views" :likeNum.sync="detailVO.likeNum"
+      :collectNum.sync="detailVO.collectNum" @doRefresh="getDetail"></detailBottom>
   </view>
   </view>
 </template>
 </template>
 
 
@@ -23,15 +28,79 @@
     data() {
     data() {
       return {
       return {
         detailVO: {},
         detailVO: {},
+        //
+        mapDom: null,
       }
       }
     },
     },
+    onReady() {},
+
     methods: {
     methods: {
+      createMap() {
+        this.mapDom = uni.createMapContext("map", this);
+
+        // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
+        this.mapDom.initMarkerCluster({
+          enableDefaultStyle: false,
+          zoomOnClick: true,
+          gridSize: 60,
+          complete(res) {
+            console.log('initMarkerCluster', res)
+          }
+        });
+
+        this.mapDom.on("markerClusterCreate", (e) => {
+          console.log("markerClusterCreate", e);
+        });
+      },
+      addMarkers(name, latitude, longitude) {
+        const positions = [{
+          latitude: latitude,
+          longitude: longitude,
+          name: name
+        }]
+
+        const markers = []
+
+        positions.forEach((p, i) => {
+          console.log(i)
+          markers.push(
+            Object.assign({}, {
+              id: i + 1,
+              // iconPath: img,
+              // width: 50,
+              // height: 50,
+              joinCluster: true, // 指定了该参数才会参与聚合
+              // label: {
+              //   // width: 50,
+              //   // height: 30,
+              //   borderWidth: 1,
+              //   borderRadius: 10,
+              //   padding: 5,
+              //   bgColor: '#ffffff',
+              //   content: p.name
+              // }
+            }, p)
+          )
+        })
+        this.mapDom.addMarkers({
+          markers,
+          clear: false,
+          complete(res) {
+            console.log('addMarkers', res)
+          }
+        })
+      },
       getDetail() {
       getDetail() {
         this.$u.api.getRestaurantDetail(this.detailVO.id).then(res => {
         this.$u.api.getRestaurantDetail(this.detailVO.id).then(res => {
           if (res.data.content) {
           if (res.data.content) {
             res.data.content = decodeURIComponent(res.data.content);
             res.data.content = decodeURIComponent(res.data.content);
           }
           }
           this.detailVO = res.data || {}
           this.detailVO = res.data || {}
+          if (this.detailVO && this.detailVO.id && this.detailVO.latitude && this.detailVO.longitude) {
+            this.createMap();
+            this.addMarkers(this.detailVO.name, res.data.latitude, res.data.longitude)
+          }
+
           //
           //
           uni.setNavigationBarTitle({
           uni.setNavigationBarTitle({
             title: res.data.name || ''
             title: res.data.name || ''
@@ -54,11 +123,11 @@
     color: #65371b;
     color: #65371b;
     margin-bottom: 20px;
     margin-bottom: 20px;
   }
   }
+
   .time {
   .time {
     font-size: 14px;
     font-size: 14px;
     color: #787878;
     color: #787878;
     font-weight: 300;
     font-weight: 300;
     padding-bottom: 10px;
     padding-bottom: 10px;
   }
   }
-  
 </style>
 </style>