doum
2026-04-28 6d5807a11995300bef0fc37a7fd0ed1d3834e031
small-program/shop/pages/order-details/order-details.vue
@@ -18,7 +18,16 @@
            <view class="nr-status-type1"  v-if="info.type === 1 && info.isUrgent === 1">极速达</view>
         </view>
         <view class="item" style="padding: 10rpx;" v-if="info.type ===1 && info.status===4">
            <map name="mapAddr"></map>
            <map
               name="mapAddr"
               :latitude="mapLat"
               :longitude="mapLng"
               :scale="mapScale"
               :markers="markers"
               :polyline="polyline"
               show-location
               style="width: 100%; height: 362rpx;"
            ></map>
         </view>
         <view class="item">
            <view class="addr">
@@ -249,6 +258,7 @@
<script>
   import { mapState } from 'vuex'
   import drawQrcode from 'weapp-qrcode'
   var amapFile = require('@/utils/amap-wx.130.js')
   export default {
      computed: {
@@ -259,7 +269,12 @@
            id:null,
            qrcodeImage:null,
            showCancel:false,
            info:{}
            info:{},
            mapLat: 0,
            mapLng: 0,
            mapScale: 12,
            markers: [],
            polyline: []
         }
      },
      onShow() {
@@ -351,7 +366,152 @@
            if (res.code === 200) { 
               this.info = res.data 
               uni.$emit('updateOrder',{info:this.info,delete:0})
               if (this.info.type === 1 && this.info.status === 4) {
                  this.getRoutePlanning()
               }
            } 
         },
         getRoutePlanning() {
            var that = this
            var driverLat = this.info.driverLat
            var driverLng = this.info.driverLng
            var depositShopLat = this.info.depositShopLat
            var depositShopLng = this.info.depositShopLng
            console.log('getRoutePlanning called', driverLat, driverLng, depositShopLat, depositShopLng)
            if (!driverLat || !driverLng || !depositShopLat || !depositShopLng) {
               console.log('坐标缺失')
               return
            }
            this.mapLat = driverLat
            this.mapLng = driverLng
            var myAmapFun = new amapFile.AMapWX({ key: this.$gaodeMapKey })
            myAmapFun.getDrivingRoute({
               origin: driverLng + ',' + driverLat,
               destination: depositShopLng + ',' + depositShopLat,
               success: function(data) {
                  console.log('获取路径规划成功 data:', data)
                  console.log('data keys:', Object.keys(data))
                  console.log('data.paths:', data.paths)
                  console.log('driverLng:', driverLng, 'driverLat:', driverLat, 'depositShopLng:', depositShopLng, 'depositShopLat:', depositShopLat)
                  var points = []
                  if (data.paths && data.paths.length > 0) {
                     var path = data.paths[0]
                     console.log('path:', path)
                     console.log('path keys:', Object.keys(path))
                     var steps = path.steps || path.routs || path.roads || []
                     if (steps.length === 0 && path.distance) {
                        steps = [path]
                     }
                     console.log('steps:', steps)
                     if (steps && steps.length > 0) {
                        for (var i = 0; i < steps.length; i++) {
                           var step = steps[i]
                           console.log('step:', step)
                           console.log('step keys:', step ? Object.keys(step) : 'null')
                           var polylineStr = step.polyline || step.Polyline || step.path || step.line || step.road || ''
                           console.log('polylineStr:', polylineStr)
                           if (!step || !polylineStr) continue
                           var stepPoints = polylineStr.split(';')
                           if (!stepPoints || stepPoints.length === 0) continue
                           for (var j = 0; j < stepPoints.length; j++) {
                              if (!stepPoints[j]) continue
                              var point = stepPoints[j].split(',')
                              if (!point || point.length < 2) continue
                              points.push({
                                 latitude: parseFloat(point[1]),
                                 longitude: parseFloat(point[0])
                              })
                           }
                        }
                     }
                  }
                  console.log('points:', points)
                  that.polyline = [{
                     points: points,
                     color: '#00c47c',
                     width: 10,
                     arrowLine: true
                  }]
                  console.log('polyline set:', that.polyline)
                  that.markers = [
                     {
                        id: 1,
                        latitude: parseFloat(driverLat),
                        longitude: parseFloat(driverLng),
                        iconPath: '/static/icon/start.png',
                        width: 30,
                        height: 40,
                        anchor: { x: 0.5, y: 1 }
                     },
                     {
                        id: 2,
                        latitude: parseFloat(depositShopLat),
                        longitude: parseFloat(depositShopLng),
                        iconPath: '/static/icon/end.png',
                        width: 30,
                        height: 40,
                        anchor: { x: 0.5, y: 1 }
                     },
                     {
                        id: 3,
                        latitude: parseFloat(driverLat),
                        longitude: parseFloat(driverLng),
                        iconPath: '/static/icon/dizhi.png',
                        width: 24,
                        height: 30,
                        anchor: { x: 0.5, y: 0.5 },
                        callout: {
                           content: '预计到店时间\n' + (that.info.expectedDepositTime || ''),
                           color: '#222222',
                           fontSize: 14,
                           borderRadius: 4,
                           padding: 8,
                           display: 'ALWAYS',
                           bgColor: 'rgba(255, 255, 255, 0.95)'
                        }
                     }
                  ]
                  if (points.length > 0) {
                     that.mapLat = points[Math.floor(points.length / 2)].latitude
                     that.mapLng = points[Math.floor(points.length / 2)].longitude
                  }
               },
               fail: function(err) {
                  console.error('获取路径规划失败', err)
                  that.markers = [
                     {
                        id: 1,
                        latitude: parseFloat(driverLat),
                        longitude: parseFloat(driverLng),
                        iconPath: '/static/icon/start.png',
                        width: 30,
                        height: 40,
                        anchor: { x: 0.5, y: 1 }
                     },
                     {
                        id: 2,
                        latitude: parseFloat(depositShopLat),
                        longitude: parseFloat(depositShopLng),
                        iconPath: '/static/icon/end.png',
                        width: 30,
                        height: 40,
                        anchor: { x: 0.5, y: 1 }
                     }
                  ]
               }
            })
         }
         
      }