OrderDetail.vue
14.7 KB
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ArrowLeft, VideoPlay, Download, Picture } from '@element-plus/icons-vue'
import type { OrderDetail, ApiResponse } from '../types/order'
import { qualityApi } from '../api'
import { ElMessage } from 'element-plus'
const route = useRoute()
const router = useRouter()
const loading = ref(false)
const orderDetail = ref<OrderDetail | null>(null)
// Image Preview State
const previewImageList = ref<string[]>([])
const currentVideoUrl = ref('')
const videoDialogVisible = ref(false)
const envImagesVisible = ref(false)
const envImageList = ref<string[]>([])
// Fetch Data
const fetchDetail = async () => {
loading.value = true
try {
// 从路由参数获取 applyId
const applyId = route.params.id as string
// 调用接口获取详情
const response = await qualityApi.getProcessByApplyId({
applyId
}) as ApiResponse<any>
if (response.code === 200 || response.code === 0) {
const data = response.data || {}
const processList = data.processList || []
const videoList = data.videoList || []
// 格式化时间戳
const formatTimestamp = (timestamp: number | null) => {
if (!timestamp) return ''
const date = new Date(timestamp)
return date.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
}).replace(/\//g, '-')
}
// 获取质检状态描述
const getStatusDesc = (checkStatus: string) => {
const statusMap: any = {
'1': '未开始',
'2': '进行中',
'3': '已完成',
'4': '无法质检'
}
return statusMap[checkStatus] || '未知'
}
// 合并基础信息和详情数据
orderDetail.value = {
// 基础信息(从接口 data 获取)
id: data.applyId || applyId,
applyId: data.applyId || applyId,
workerId: data.campaignId || '',
businessAccount: data.accNbr || '',
orderIds: data.orderCode || '', // 直接使用 orderCode 字符串
city: data.areaName || '',
status: getStatusDesc(data.checkStatus),
cannotQcReason: data.failReason || '',
startTime: formatTimestamp(data.startTime),
endTime: formatTimestamp(data.endTime),
completeTime: formatTimestamp(data.endTime),
noPhotoCount: data.noShowNum || 0,
manualInputCount: data.manualInputNum || 0,
envAbnormalCount: data.cheatNum || 0,
isCheating: data.isCheat === 1 || false,
// 新增字段(从接口 data 获取)
installAddress: data.addressName || '',
orderType: data.serviceNames ? data.serviceNames.join(', ') : '',
deviceType: data.terminalClassList ? data.terminalClassList.join(', ') : '',
totalDuration: data.videoDuration ? formatDuration(data.videoDuration) : '',
// 质检步骤(从 processList 获取)
steps: processList.map((item: any, index: number) => ({
id: item.id || index,
name: item.process || `步骤${index + 1}`,
duration: formatDuration(item.useTime),
result: item.result || '通过',
imageUrl: item.pubPicUrl || item.picUrl || '',
isAbnormal: item.findCheat || 0,
recognizeType: item.recognizeType || 0
})),
// 视频列表(从 videoList 获取)
videos: videoList.map((item: any, index: number) => ({
id: item.id || index,
name: `视频${index + 1} - ${item.callId || ''}`,
videoUrl: item.recordFile || '',
thumbnailUrl: '', // 如果有缩略图字段可以映射
duration: formatDuration(item.videoDuration || 0)
}))
}
// 准备图片预览列表
previewImageList.value = orderDetail.value.steps
.map(s => s.imageUrl)
.filter(url => url)
}
} catch (error) {
console.error('获取工单详情失败:', error)
// 错误提示已在 request.ts 中统一处理
} finally {
loading.value = false
}
}
// 辅助函数:格式化时长
const formatDuration = (seconds: number): string => {
if (!seconds) return '0秒'
const hours = Math.floor(seconds / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
const secs = seconds % 60
const parts = []
if (hours > 0) parts.push(`${hours}小时`)
if (minutes > 0) parts.push(`${minutes}分`)
if (secs > 0 || parts.length === 0) parts.push(`${secs}秒`)
return parts.join('')
}
// Handlers
const handleBack = () => {
router.back()
}
const showEnvImages = () => {
// Show abnormal images
if (orderDetail.value?.steps) {
const abnormalSteps = orderDetail.value.steps.filter(s => s.isAbnormal > 0)
const sources = abnormalSteps.length > 0 ? abnormalSteps : orderDetail.value.steps.slice(0, 3)
envImageList.value = sources.map(s => s.imageUrl).filter(url => url)
if (envImageList.value.length > 0) {
envImagesVisible.value = true
} else {
ElMessage.warning('暂无异常图片')
}
}
}
const playVideo = async (recordFile: string) => {
// 检查 recordFile 是否存在
if (!recordFile) {
ElMessage.warning('暂不支持播放')
return
}
try {
// 调用接口获取视频播放地址
const response = await qualityApi.getVideoUrl({
url: recordFile
}) as ApiResponse<any>
if (response.code === 200 || response.code === 0) {
// 假设接口返回的视频地址在 data 字段中
const videoUrl = response.data || recordFile
currentVideoUrl.value = videoUrl
videoDialogVisible.value = true
}
} catch (error) {
console.error('获取视频地址失败:', error)
// 错误提示已在 request.ts 中统一处理
}
}
const downloadVideo = (url: string) => {
const link = document.createElement('a')
link.href = url
link.target = '_blank'
link.download = 'video.mp4'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
const downloadAllVideos = async () => {
try {
const applyId = route.params.id as string
const blob = await qualityApi.downloadAllVideos({ applyId })
// 创建下载链接
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `视频_${applyId}.zip`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
ElMessage.success('下载成功')
} catch (error) {
console.error('下载视频失败:', error)
// 错误提示已在 request.ts 中统一处理
}
}
const downloadScreenshots = async () => {
try {
const applyId = route.params.id as string
const blob = await qualityApi.downloadScreenshots({ applyId })
// 创建下载链接
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `截图_${applyId}.zip`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
ElMessage.success('下载成功')
} catch (error) {
console.error('下载截图失败:', error)
// 错误提示已在 request.ts 中统一处理
}
}
onMounted(() => {
fetchDetail()
})
</script>
<template>
<div v-loading="loading" class="order-detail">
<!-- Header -->
<div class="flex items-center gap-4 mb-6">
<el-button :icon="ArrowLeft" circle @click="handleBack" />
<h2 class="text-xl font-bold">质检工单详情</h2>
</div>
<div v-if="orderDetail">
<!-- 1. Basic Info -->
<el-card shadow="never" class="mb-4">
<template #header>
<div class="font-bold">基础信息</div>
</template>
<el-descriptions :column="3" border>
<el-descriptions-item label="Apply_id">{{ orderDetail.applyId }}</el-descriptions-item>
<el-descriptions-item label="业务账号">{{ orderDetail.businessAccount }}</el-descriptions-item>
<el-descriptions-item label="所属地市">{{ orderDetail.city }}</el-descriptions-item>
<el-descriptions-item label="装机地址">{{ orderDetail.installAddress || '-' }}</el-descriptions-item>
<el-descriptions-item label="师傅工号">{{ orderDetail.workerId }}</el-descriptions-item>
<el-descriptions-item label="工单类型">{{ orderDetail.orderType || '-' }}</el-descriptions-item>
<el-descriptions-item label="设备类型">{{ orderDetail.deviceType || '-' }}</el-descriptions-item>
<el-descriptions-item label="工单ID">
{{ orderDetail.orderIds || '-' }}
</el-descriptions-item>
<el-descriptions-item label="质检状态">
<el-tag :type="orderDetail.status === '已完成' ? 'success' : ''">{{ orderDetail.status }}</el-tag>
</el-descriptions-item>
<el-descriptions-item label="无法质检原因">{{ orderDetail.cannotQcReason || '-' }}</el-descriptions-item>
<el-descriptions-item label="开始时间">{{ orderDetail.startTime }}</el-descriptions-item>
<el-descriptions-item label="完成时间">{{ orderDetail.completeTime || '-' }}</el-descriptions-item>
<el-descriptions-item label="不能拍/手动">
<div class="flex gap-4">
<span>不能拍: <span class="font-bold text-red-500">{{ orderDetail.noPhotoCount }}</span></span>
<span>手动: <span class="font-bold text-orange-500">{{ orderDetail.manualInputCount }}</span></span>
</div>
</el-descriptions-item>
<el-descriptions-item label="环境异常">
<span class="font-bold text-red-500 mr-2">{{ orderDetail.envAbnormalCount }}</span>
<el-button v-if="orderDetail.envAbnormalCount > 0" size="small" :icon="Picture" @click="showEnvImages">查看图片</el-button>
</el-descriptions-item>
<el-descriptions-item label="总耗时">{{ orderDetail.totalDuration }}</el-descriptions-item>
</el-descriptions>
</el-card>
<!-- 2. QC Details -->
<el-card shadow="never" class="mb-4">
<template #header>
<div class="font-bold">质检详情</div>
</template>
<el-table :data="orderDetail.steps" border style="width: 100%">
<el-table-column type="index" label="序号" width="60" align="center" />
<el-table-column prop="name" label="检测环节" />
<el-table-column prop="duration" label="环节耗时" />
<el-table-column prop="result" label="通过类型">
<template #default="{ row }">
<el-tag type="success" v-if="row.result === '通过'">{{ row.result }}</el-tag>
<el-tag type="danger" v-else>{{ row.result }}</el-tag>
</template>
</el-table-column>
<el-table-column label="查看图片">
<template #default="{ row, $index }">
<el-image
v-if="row.imageUrl"
style="width: 50px; height: 50px"
:src="row.imageUrl"
:zoom-rate="1.2"
:max-scale="7"
:min-scale="0.2"
:preview-src-list="previewImageList"
:initial-index="$index"
fit="cover"
preview-teleported
hide-on-click-modal
/>
<span v-else class="text-gray-400">无图片</span>
</template>
</el-table-column>
<el-table-column prop="recognizeType" label="识别方式">
<template #default="{ row }">
<span>{{ row.recognizeType === 1 ? '自动识别' : row.recognizeType === 2 ? '手输' : '-' }}</span>
</template>
</el-table-column>
<el-table-column prop="isAbnormal" label="是否异常">
<template #default="{ row }">
<span :class="{'text-red-500 font-bold': row.isAbnormal === 1}">{{ row.isAbnormal === 1 ? '是' : '否' }}</span>
</template>
</el-table-column>
</el-table>
</el-card>
<!-- 3. Videos -->
<el-card shadow="never" class="mb-4">
<template #header>
<div class="flex justify-between items-center">
<span class="font-bold">质检视频</span>
<div class="gap-2 flex">
<el-button type="primary" :icon="Download" @click="downloadAllVideos">下载全部视频</el-button>
<el-button type="success" :icon="Download" @click="downloadScreenshots">下载质检截图</el-button>
</div>
</div>
</template>
<div v-if="orderDetail.videos.length > 0" class="space-y-2">
<div
v-for="(video, index) in orderDetail.videos"
:key="video.id"
class="flex items-center justify-between p-3 border rounded hover:bg-gray-50 transition"
>
<div class="flex items-center gap-3 flex-1">
<el-icon class="text-blue-500"><VideoPlay /></el-icon>
<span
class="text-blue-600 hover:text-blue-800 cursor-pointer hover:underline"
@click="playVideo(video.videoUrl)"
>
视频{{ index + 1 }}{{ video.name ? ' - ' + video.name : '' }}
</span>
</div>
<el-button
v-if="video.videoUrl"
link
type="primary"
:icon="Download"
@click="downloadVideo(video.videoUrl)"
>
下载
</el-button>
</div>
</div>
<div v-else class="text-center text-gray-400 py-8">
暂无视频
</div>
</el-card>
</div>
<!-- Video Player Dialog -->
<el-dialog v-model="videoDialogVisible" title="视频播放" width="800px" destroy-on-close align-center>
<video controls autoplay class="w-full max-h-[60vh] bg-black">
<source :src="currentVideoUrl" type="video/mp4">
您的浏览器不支持 Video 标签。
</video>
</el-dialog>
<!-- Environment Images Dialog (Using Image Viewer) -->
<el-image-viewer
v-if="envImagesVisible"
:url-list="envImageList"
@close="envImagesVisible = false"
/>
</div>
</template>
<style scoped>
:deep(.el-descriptions__label) {
font-weight: bold;
background-color: #fafafa;
}
</style>