wlzboy
2025-11-16 f67945d53b20f6a45ae50b27d74c966eb1355bb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<template>
  <div class="task-mileage-detail">
    <el-card class="box-card" shadow="hover">
      <div slot="header" class="clearfix">
        <span class="card-title">
          <i class="el-icon-location-information"></i>
          任务GPS里程统计
        </span>
        <el-button 
          style="float: right; padding: 3px 10px" 
          type="text" 
          size="small"
          @click="refreshData"
          :loading="loading"
        >
          <i class="el-icon-refresh"></i> 刷新
        </el-button>
      </div>
      
      <!-- 统计概览 -->
      <div class="mileage-summary">
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="stat-item total-mileage">
              <div class="stat-label">总里程</div>
              <div class="stat-value">{{ totalMileage }} <span class="unit">km</span></div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="stat-item segment-count">
              <div class="stat-label">分段数</div>
              <div class="stat-value">{{ segmentCount }} <span class="unit">段</span></div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="stat-item gps-count">
              <div class="stat-label">GPS点数</div>
              <div class="stat-value">{{ totalGpsPoints }} <span class="unit">个</span></div>
            </div>
          </el-col>
        </el-row>
      </div>
 
      <!-- 分段明细 -->
      <div class="segment-detail" v-if="segmentList.length > 0">
        <el-divider content-position="left">
          <i class="el-icon-tickets"></i> 里程分段明细
        </el-divider>
        
        <el-table 
          :data="segmentList" 
          size="small"
          :max-height="400"
          stripe
          border
        >
          <el-table-column type="index" label="序号" width="50" align="center" />
          <el-table-column label="时间段开始" prop="segmentStartTime" width="160" align="center">
            <template slot-scope="scope">
              {{ parseTime(scope.row.segmentStartTime, '{h}:{i}:{s}') }}
            </template>
          </el-table-column>
          <el-table-column label="时间段结束" prop="segmentEndTime" width="160" align="center">
            <template slot-scope="scope">
              {{ parseTime(scope.row.segmentEndTime, '{h}:{i}:{s}') }}
            </template>
          </el-table-column>
          <el-table-column label="里程(km)" prop="segmentDistance" width="100" align="center">
            <template slot-scope="scope">
              <el-tag type="success" size="mini">{{ scope.row.segmentDistance }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="GPS点数" prop="gpsPointCount" width="90" align="center" />
          <el-table-column label="起点坐标" align="center" width="180">
            <template slot-scope="scope">
              <span class="coordinate">
                {{ scope.row.startLongitude }}, {{ scope.row.startLatitude }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="终点坐标" align="center" width="180">
            <template slot-scope="scope">
              <span class="coordinate">
                {{ scope.row.endLongitude }}, {{ scope.row.endLatitude }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="计算方式" prop="calculateMethod" width="100" align="center">
            <template slot-scope="scope">
              <el-tag :type="scope.row.calculateMethod === 'tianditu' ? 'warning' : 'info'" size="mini">
                {{ scope.row.calculateMethod === 'tianditu' ? '天地图' : 'Haversine' }}
              </el-tag>
            </template>
          </el-table-column>
        </el-table>
      </div>
 
      <!-- 无数据提示 -->
      <el-empty 
        v-else-if="!loading" 
        description="暂无GPS里程数据"
        :image-size="80"
      ></el-empty>
 
      <!-- 加载中 -->
      <div v-if="loading" class="loading-container">
        <el-skeleton :rows="5" animated />
      </div>
    </el-card>
  </div>
</template>
 
<script>
import { getSegmentsByTaskId, getTaskTotalMileage } from '@/api/system/gpsSegment'
 
export default {
  name: 'TaskMileageDetail',
  props: {
    taskId: {
      type: [Number, String],
      required: true
    }
  },
  data() {
    return {
      loading: false,
      totalMileage: '0.00',
      segmentList: [],
      segmentCount: 0,
      totalGpsPoints: 0
    }
  },
  watch: {
    taskId: {
      handler(newVal) {
        if (newVal) {
          this.loadData()
        }
      },
      immediate: true
    }
  },
  methods: {
    /** 加载数据 */
    loadData() {
      if (!this.taskId) {
        return
      }
      
      this.loading = true
      
      // 并行请求总里程和分段明细
      Promise.all([
        getTaskTotalMileage(this.taskId),
        getSegmentsByTaskId(this.taskId)
      ]).then(([totalRes, segmentRes]) => {
        // 处理总里程
        if (totalRes.code === 200) {
          this.totalMileage = (totalRes.data || 0).toFixed(2)
        }
        
        // 处理分段明细
        if (segmentRes.code === 200 && segmentRes.data) {
          this.segmentList = segmentRes.data
          this.segmentCount = this.segmentList.length
          
          // 计算总GPS点数
          this.totalGpsPoints = this.segmentList.reduce((sum, item) => {
            return sum + (item.gpsPointCount || 0)
          }, 0)
        }
      }).catch(error => {
        console.error('加载任务GPS里程数据失败', error)
        this.$message.error('加载GPS里程数据失败')
      }).finally(() => {
        this.loading = false
      })
    },
    
    /** 刷新数据 */
    refreshData() {
      this.loadData()
    }
  }
}
</script>
 
<style scoped lang="scss">
.task-mileage-detail {
  margin-top: 15px;
 
  .card-title {
    font-size: 16px;
    font-weight: 500;
    color: #303133;
    
    i {
      margin-right: 5px;
      color: #409EFF;
    }
  }
 
  .mileage-summary {
    margin-bottom: 20px;
    
    .stat-item {
      padding: 20px;
      text-align: center;
      border-radius: 4px;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: white;
      
      &.total-mileage {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      }
      
      &.segment-count {
        background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
      }
      
      &.gps-count {
        background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
      }
      
      .stat-label {
        font-size: 14px;
        opacity: 0.9;
        margin-bottom: 8px;
      }
      
      .stat-value {
        font-size: 28px;
        font-weight: bold;
        
        .unit {
          font-size: 14px;
          font-weight: normal;
          margin-left: 4px;
        }
      }
    }
  }
 
  .segment-detail {
    margin-top: 20px;
    
    .coordinate {
      font-family: 'Courier New', monospace;
      font-size: 12px;
      color: #606266;
    }
  }
 
  .loading-container {
    padding: 20px;
  }
}
</style>