MrShi
2026-06-09 3f9032e92fdd383bfefc87a0bec9b242e1223851
small-program/shop/pages/order-details/order-details.vue
@@ -16,9 +16,19 @@
            <view class="nr-status-type"  v-if="info.type === 1">同城寄送</view>
            <view class="nr-status-type1"  v-if="info.type === 1 && info.isUrgent === 0">标速达</view>
            <view class="nr-status-type1"  v-if="info.type === 1 && info.isUrgent === 1">极速达</view>
            <view class="nr-status-type2" v-if="info.type === 0 && info.exceptionStatus === 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">
@@ -28,9 +38,9 @@
                  <view class="addr-item-top">
                     <text>{{info.depositShopName || ''}}</text>
                  </view>
                  <text>{{info.depositShopAddress || ''}}  </text>
                  <view class='addr-link' style="top: 50rpx;">
                     <image style="margin-right: 10rpx;" @click="contactPhoneDo(info.takePhone)" src="/static/icon/ic_call@2x.png" mode="widthFix"  ></image>
                  <text style="width: 70%;">{{info.depositShopAddress || ''}}  </text>
                  <view class='addr-link' style="top: 0;" @click="contactPhoneDo(info.takePhone)">
                     <image style="margin-right: 10rpx;" src="/static/icon/ic_call@2x.png" mode="widthFix"  ></image>
                     <text class=" txt-d1">联系客户</text>
                  </view>
               </view>
@@ -53,7 +63,7 @@
                  <view class="item-form-val">{{info.takePhone || ''}}</view>
               </view>
               <view class="item-list-row">
                  <view class="item-form-label">预计到店时间</view>
                  <view class="item-form-label">到店寄存时间</view>
                  <view class="item-form-val">{{info.expectedDepositTime || ''}}</view>
               </view>
               <view class="item-list-row">
@@ -79,8 +89,8 @@
                  <view class="addr-item-top">
                        <text class=" txt-d">司机:{{info.driverName || '战神'}} </text>
                  </view>
                  <view class='addr-link'>
                     <image style="margin-right: 10rpx;" @click="contactPhoneDo(info.driverPhone)" src="/static/icon/ic_call@2x.png" mode="widthFix"  ></image>
                  <view class='addr-link' style="top: 0;" @click="contactPhoneDo(info.driverPhone)">
                     <image style="margin-right: 10rpx;" src="/static/icon/ic_call@2x.png" mode="widthFix"  ></image>
                     <text class=" txt-d1">联系司机</text>
                  </view>
                  
@@ -159,6 +169,10 @@
                  <view class="item-form-val" style="color: #333333; font-size: 24rpx;">¥{{((info.declaredFee || 0)/100).toFixed(2)}}</view>
               </view>
               <view class="item-list-row">
                  <view class="item-form-label" style="color: #333333; font-size: 28rpx;">优惠金额</view>
                  <view class="item-form-val" style="color: #333333; font-size: 24rpx;">¥{{((info.deductionAmount || 0)/100).toFixed(2)}}</view>
               </view>
               <view class="item-list-row">
                  <view class="item-form-label" style="color: #222222; font-size: 30rpx; font-weight: 600;">实付款</view>
                  <view class="item-form-val price" style="color: #FE2C2E; font-size: 36rpx;">{{((info.actualPayAmount || 0)/100).toFixed(2)}}</view>
               </view>
@@ -214,7 +228,7 @@
         </view>
         <view style="width: 100%; height: calc(210rpx + env(safe-area-inset-bottom));"></view>
      </view>
      <view class="tips" v-if="info.overdueStatus !==0">
      <view class="tips" v-if="info.overdueStatus !==0 &&info.overdueStatus !==2">
         <image src="/static/icon/ic_waring@2x.png" mode="widthFix"></image>
         <text  v-if="info.overdueStatus ===1">已超过取件时间,已产生超时费用:¥{{((info.overdueFee || 0)/100).toFixed(2)}}元</text> 
         <text  v-if="info.overdueStatus ===3">已超过取件时间,等待客户支付超时费用:¥{{((info.overdueFee || 0)/100).toFixed(2)}}元</text>
@@ -223,9 +237,14 @@
      <view class="footer" >
         <view class="footer-btns">
            <view class="btn kong" @click="contactPhoneDo(info.takePhone)" v-if="info.status === 1 || info.status === 5" >联系客户</view>
            <view class="btn kong" @click="openTrackPopup">订单轨迹</view>
            <view class="btn kong" @click="contactPhoneDo(info.driverPhone)" v-if="info.type ===1&&(info.status === 4 || info.status === 3)">联系骑手</view>
            <view class="btn you"  v-if="info.status ===1  || info.status ===4 "   @click="hexiaoOrder(info)" >收件核销</view>
            <view class="btn you" v-if="info.status ===5 &&(info.overdueStatus ==0 || info.overdueStatus == 1)" @click="hexiaoOrder(info)" >确认到店</view>
            <!-- <view class="btn you"  v-if="[1,4].includes(info.status) && info.takeShopId" @click="hexiaoOrder(info)" >收件核销</view> -->
            <view class="btn you" v-if="(info.status === 1 && (shopInfo.id == info.depositShopId)) || (info.status === 4 && (shopInfo.id == info.takeShopId))" @click="hexiaoOrder(info)" >收件核销</view>
            <view class="btn you"  v-if="info.status>0||info.status<=7  "   @click="printerOrder(info)" >打印标签</view>
            <view class="btn you" v-if="info.status ===5 &&(info.overdueStatus ==0 || info.overdueStatus == 1) && info.takeShopId" @click="hexiaoOrder(info)" >确认到店</view>
            <view class="btn you" v-if="info.status ===5 && (info.overdueStatus == 4 || info.overdueStatus == 2)" @click="hexiaoOrder(info)" >取件核销</view>
         </view>
      </view>
@@ -243,38 +262,148 @@
            </view>
         </view>
      </u-popup>
      <u-popup :show="showTrackPopup" mode="bottom" round="24" :safeAreaInsetBottom="true" :closeOnClickOverlay="true" @close="closeTrackPopup">
         <view class="track-popup">
            <view class="track-popup__header">
               <text class="track-popup__title">订单轨迹</text>
               <view class="track-popup__close" @click="closeTrackPopup">×</view>
            </view>
            <scroll-view scroll-y class="track-popup__body">
               <view class="track-empty" v-if="!trackList.length">暂无轨迹信息</view>
               <view class="track-list" v-else>
                  <view class="track-item" v-for="(track, index) in trackList" :key="track.key || index">
                     <view class="track-item__content">
                        <view class="track-item__rail">
                           <image v-if="index === 0" class="track-item__dot track-item__dot--active" src="/static/icon/dian.png" mode="aspectFit"></image>
                           <view v-else class="track-item__dot"></view>
                           <view class="track-item__line" v-if="index !== trackList.length - 1"></view>
                        </view>
                        <view class="track-item__body">
                           <text class="track-item__time">{{ track.time }}</text>
                           <text class="track-item__desc">{{ track.title }}</text>
                           <view class="track-item__images" v-if="track.images && track.images.length">
                              <image
                                 v-for="(img, imgIndex) in track.images"
                                 :key="track.key + '-' + imgIndex"
                                 :src="img"
                                 mode="aspectFill"
                                 @click="previewImage(trackList[index].images, imgIndex)"
                              ></image>
                           </view>
                        </view>
                     </view>
                  </view>
               </view>
            </scroll-view>
         </view>
      </u-popup>
   </view>
</template>
<script>
   import { mapState } from 'vuex'
   import drawQrcode from 'weapp-qrcode'
   var amapFile = require('@/utils/amap-wx.130.js')
   export default {
      computed: {
         ...mapState(['navHeight', 'statusbarHeight'])
         ...mapState(['navHeight', 'statusbarHeight', 'shopInfo'])
      },
      data() {
         return {
            loading:false,
            id:null,
            qrcodeImage:null,
            showCancel:false,
            info:{}
            showTrackPopup:false,
            trackList: [],
            info:{},
            mapLat: 0,
            mapLng: 0,
            mapScale: 12,
            markers: [],
            polyline: []
         }
      },
      onShow() {
      // onShow() {
      //    this.showCancel=false
      //    this.trackList = []
      //    this.info={}
      //    this.getOrderDetail()
      // },
      onLoad(options) {
         this.id = options.id
         this.showCancel=false
         this.trackList = []
         this.info={} 
         this.getOrderDetail() 
      },
      onLoad(options) {
         this.id = options.id
      },
      methods:{
         async openTrackPopup() {
            uni.showLoading({
               title: '加载中...',
               mask: true
            })
            let success = false
            try {
               success = await this.getOrderTimeline()
            } finally {
               uni.hideLoading()
            }
            if (success) {
               this.showTrackPopup = true
            }
         },
         closeTrackPopup() {
            this.showTrackPopup = false
         },
         async getOrderTimeline() {
            if (!this.id) {
               this.trackList = []
               return false
            }
            try {
               let res = await this.$u.api.shopTimeline(this.id)
               if (res.code === 200) {
                  let list = Array.isArray(res.data) ? res.data : []
                  this.trackList = list.map((item, index) => ({
                     key: item.id || item.time || index,
                     title: item.title || '',
                     time: item.time || '--',
                     images: this.normalizeTrackImages(item.images)
                  }))
                  return true
               }
               this.trackList = []
               uni.showToast({
                  title: res.msg || '获取轨迹失败',
                  icon: 'none'
               })
               return false
            } catch (e) {
               this.trackList = []
               uni.showToast({
                  title: '获取轨迹失败',
                  icon: 'none'
               })
               return false
            }
         },
         normalizeTrackImages(images) {
            if (!Array.isArray(images)) {
               return []
            }
            return images.filter(item => !!item)
         },
         previewImage(images,index = 0) {
            console.log(images)
            console.log(index)
            uni.previewImage({
               current: index, 
               urls: images
               urls: images,
               fail(err) {
                  console.log(err)
               }
            });
         },
         hexiaoOrder(item){
@@ -292,6 +421,27 @@
         cancelOrder(item){
            this.showCancel = !this.showCancel
         }, 
         async printerOrder(){
            if(this.loading){
               return
            }
            this.loading =true
            try{
               var that =this
                that.$u.api.printOrderLabel({ orderId: this.id }).then(res=>{
                   if (res.code === 200 ) {
                      uni.showToast({
                         title:'发起打印请求成功',
                        icon:'none'
                      })
                   }
                   that.loading =false
                })
            }catch(e){
               this.loading =false
            }
         },
         async cancelOrderDo(){
            var that =this
            let res = await that.$u.api.cancelOrder({ orderId: this.id });
@@ -316,14 +466,22 @@
                   height: 180,
                   correctLevel: 2
                })
                setTimeout(() => {
                   uni.canvasToTempFilePath({
                      canvasId: 'qrcodeCanvas',
                      success: (res) => {
                         that.qrcodeImage = res.tempFilePath
                      }
                   }, this)
                }, 100)
               this.$nextTick(() => {
                  uni.canvasToTempFilePath({
                     canvasId: 'qrcodeCanvas',
                     success: (res) => {
                        that.qrcodeImage = res.tempFilePath
                     }
                  }, this)
               })
                // setTimeout(() => {
                //    uni.canvasToTempFilePath({
                //       canvasId: 'qrcodeCanvas',
                //       success: (res) => {
                //          that.qrcodeImage = res.tempFilePath
                //       }
                //    }, this)
                // }, 100)
             }
              
          },
@@ -351,7 +509,165 @@
            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 = []
                  var duration = 0
                  if (data.paths && data.paths.length > 0) {
                     var path = data.paths[0]
                     duration = path.duration || 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)
                  var expectedTime = ''
                  if (duration > 0) {
                     var now = new Date()
                     var arrivalTime = new Date(now.getTime() + duration * 1000)
                     var month = arrivalTime.getMonth() + 1
                     var day = arrivalTime.getDate()
                     var hours = arrivalTime.getHours()
                     var minutes = arrivalTime.getMinutes()
                     expectedTime = month + '.' + (day < 10 ? '0' + day : day) + ' ' + (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes)
                  }
                  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' + expectedTime,
                           color: '#222222',
                           fontSize: 14,
                           borderRadius: 4,
                           padding: 8,
                           display: 'ALWAYS',
                           bgColor: '#ffffff'
                        }
                     }
                  ]
                  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 }
                     }
                  ]
               }
            })
         }
         
      }
@@ -433,6 +749,127 @@
      .head1{
         background: #E4730B;
      }
      .track-popup {
         background: #FFFFFF;
         border-radius: 24rpx 24rpx 0 0;
         padding: 24rpx 24rpx calc(24rpx + env(safe-area-inset-bottom));
         box-sizing: border-box;
         .track-popup__header {
            height: 88rpx;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
         }
         .track-popup__title {
            font-size: 40rpx;
            font-weight: 600;
            color: #222222;
         }
         .track-popup__close {
            position: absolute;
            right: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 56rpx;
            height: 56rpx;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 56rpx;
            line-height: 1;
            color: #A5A7AD;
         }
         .track-popup__body {
            height: 50vh;
         }
         .track-empty {
            line-height: 50vh;
            text-align: center;
            font-size: 28rpx;
            color: #999999;
         }
         .track-list {
            padding: 12rpx 0 0;
         }
         .track-item {
            position: relative;
         }
         .track-item__rail {
            width: 34rpx;
            flex-shrink: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            align-self: stretch;
            position: relative;
         }
         .track-item__dot {
            width: 16rpx;
            height: 16rpx;
            flex-shrink: 0;
            position: relative;
            z-index: 1;
            border-radius: 50%;
            background: #CCCCCC;
            margin-top: 12rpx;
         }
         .track-item__dot--active {
            width: 32rpx;
            height: 32rpx;
            flex-shrink: 0;
            display: block;
            position: relative;
            z-index: 1;
            margin-top: 4rpx;
            background: transparent;
         }
         .track-item__line {
            width: 2rpx;
            position: absolute;
            left: 50%;
            top: 28rpx;
            bottom: -30rpx;
            transform: translateX(-50%);
            background: #E6EAF0;
         }
         .track-item__content {
            display: flex;
            align-items: flex-start;
            column-gap: 22rpx;
            padding: 0 0 20rpx;
         }
         .track-item__body {
            flex: 1;
            min-width: 0;
         }
         .track-item__time {
            display: block;
            font-size: 28rpx;
            font-weight: 400;
            color: #8A8F99;
            line-height: 1.4;
         }
         .track-item__desc {
            display: block;
            margin-top: 22rpx;
            font-weight: 500;
            font-size: 30rpx;
            color: #666666;
         }
         .track-item__images {
            display: flex;
            flex-wrap: wrap;
            gap: 18rpx;
            margin-top: 24rpx;
            image {
               width: 130rpx;
               height: 130rpx;
               border-radius: 12rpx;
               background: #F3F5F8;
            }
         }
      }
      .head {
         width: 100%;
         padding: 0 30rpx;
@@ -483,6 +920,19 @@
               font-weight: 400;
               font-size: 24rpx;
               color: #FA8010;
            }
            .nr-status-type2 {
               width: 158rpx;
               height: 38rpx;
               display: flex;
               align-items: center;
               justify-content: center;
               background: #FFFFFF;
               border-radius: 8rpx;
               font-weight: 400;
               font-size: 24rpx;
               color: #FF0000;
               margin-left: 16rpx;
            }
            .nr-status-type1 {
               width: 158rpx;
@@ -840,6 +1290,7 @@
                     flex-wrap: wrap;
                     align-items: center;
                     justify-content: space-between;
                     gap: 20rpx;
                     .item-form-list-row {
                        width: 88rpx;
                        height: 88rpx;