Upload.vue
10 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
<template>
<div class="upload-container">
<el-card>
<template #header>
<div class="card-header">
<span>上传工单</span>
</div>
</template>
<div class="upload-section">
<el-upload
class="upload-demo"
drag
:auto-upload="false"
:on-change="handleFileChange"
:before-upload="beforeUpload"
accept=".csv,.xlsx,.xls"
:show-file-list="false"
:disabled="uploading"
>
<div v-if="uploading" class="uploading-overlay">
<el-icon class="is-loading"><loading /></el-icon>
<div class="uploading-text">上传中...</div>
</div>
<template v-else>
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
<div class="el-upload__text">
将文件拖到此处,或<em>点击上传</em>
</div>
</template>
<template #tip>
<div class="el-upload__tip">
请上传CSV或Excel文件,且不超过10MB
</div>
</template>
</el-upload>
<div style="margin-top: 20px; text-align: center;">
<el-button type="primary" @click="handleDownloadTemplate">
下载模板
</el-button>
</div>
</div>
<div class="filter-section" v-if="originalTableData.length > 0">
<el-row :gutter="20" style="margin-bottom: 20px;">
<el-col :span="6">
<el-input
v-model="filterForm.accNbr"
placeholder="业务账号"
></el-input>
</el-col>
<el-col :span="6">
<el-input
v-model="filterForm.campaignIdStr"
placeholder="工维人员工号"
></el-input>
</el-col>
<el-col :span="6">
<el-button type="primary" @click="handleFilter">查询</el-button>
<el-button @click="resetFilter">重置</el-button>
</el-col>
<el-col :span="6" style="text-align: right;">
<el-button type="success" @click="submitData">确定提交</el-button>
</el-col>
</el-row>
<el-table :data="tableData" border style="width: 100%" :row-class-name="tableRowClassName">
<!-- <el-table-column label="状态" width="80" align="center">
<template #default="scope">
<el-icon v-if="scope.row.reason && scope.row.reason.trim() !== ''" color="#f56c6c" size="20">
<Warning />
</el-icon>
<el-icon v-else color="#67c23a" size="20">
<SuccessFilled />
</el-icon>
</template>
</el-table-column> -->
<el-table-column prop="reason" label="错误信息">
<template #default="scope">
<span v-if="scope.row.reason && scope.row.reason.trim() !== ''">
<el-icon color="#f56c6c" style="margin-right: 5px;"><Warning /></el-icon>
{{ scope.row.reason }}
</span>
<span v-else>{{ scope.row.reason }}</span>
</template>
</el-table-column>
<el-table-column prop="campaignId" label="工维人员工号"></el-table-column>
<el-table-column prop="accNbr" label="业务账号"></el-table-column>
<el-table-column prop="orderCode" label="工单号"></el-table-column>
<el-table-column prop="addressName" label="装机地址"></el-table-column>
<el-table-column prop="serviceName" label="工单类型"></el-table-column>
<el-table-column prop="isFttrUser" :formatter="formatFttrUser" label="是否FTTR用户"></el-table-column>
<el-table-column prop="terminalClass" label="设备类型"></el-table-column>
<el-table-column prop="deviceNumber" label="设备串号"></el-table-column>
</el-table>
</div>
</el-card>
</div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Warning, SuccessFilled, Loading, UploadFilled } from '@element-plus/icons-vue'
import { submitWorkOrders, uploadOrderFile } from '../utils/api'
const router = useRouter()
const tableData = ref([])
const originalTableData = ref([]) // 保存原始数据的副本
const uploading = ref(false) // 上传状态
const filterForm = reactive({
accNbr: '',
campaignIdStr: ''
})
const formatFttrUser = (row, column, cellValue) => {
if(cellValue === -1){
return ''
}
return cellValue === '1' ? '是' : '否'
}
const beforeUpload = (file) => {
const isLt10M = file.size / 1024 / 1024 < 10
if (!isLt10M) {
ElMessage.error('上传文件大小不能超过 10MB!')
}
return isLt10M
}
const handleFileChange = async (file) => {
const isLt10M = file.size / 1024 / 1024 < 10
if (!isLt10M) {
ElMessage.error('上传文件大小不能超过 10MB!')
return
}
uploading.value = true // 开始上传
try {
// 使用自定义的uploadOrderFile接口上传文件
const response = await uploadOrderFile(file.raw)
if (response.code === 200) {
ElMessage.success('文件上传成功')
// 使用后端返回的真实数据
const data = response.data.data || []
tableData.value = data
originalTableData.value = [...data] // 保存原始数据副本
} else {
ElMessage.error(response.msg || '文件上传失败')
}
} catch (error) {
ElMessage.error('文件上传失败: ' + error.message)
console.error('Upload error:', error)
} finally {
uploading.value = false // 上传结束
}
}
const handleFilter = () => {
// 在前端进行筛选(基于已上传的数据)
if (!filterForm.accNbr && !filterForm.campaignIdStr) {
ElMessage.warning('请输入至少一个筛选条件')
return
}
// 根据筛选条件过滤数据
const filteredData = originalTableData.value.filter(item => {
// 确保字段是字符串类型后再进行匹配
const accNbrStr = item.accNbr != null ? String(item.accNbr) : ''
const campaignIdStr = item.campaignId != null ? String(item.campaignId) : ''
const matchAccNbr = !filterForm.accNbr ||
(accNbrStr && accNbrStr.includes(filterForm.accNbr))
const matchCampaignId = !filterForm.campaignIdStr ||
(campaignIdStr && campaignIdStr.includes(filterForm.campaignIdStr))
return matchAccNbr && matchCampaignId
})
// 更新表格数据
tableData.value = filteredData
ElMessage.success(`筛选完成,共找到 ${filteredData.length} 条记录`)
}
const resetFilter = () => {
// 重置筛选表单
filterForm.accNbr = ''
filterForm.campaignIdStr = ''
// 恢复原始数据
tableData.value = [...originalTableData.value]
ElMessage.info('筛选条件已重置')
}
// 表格行样式类名
const tableRowClassName = ({ row, rowIndex }) => {
// 如果reason有值,则添加错误行样式
if (row.reason && row.reason.trim() !== '') {
return 'error-row'
}
return ''
}
const submitData = async () => {
if (!originalTableData.value || originalTableData.value.length === 0) {
ElMessage.warning('没有数据可提交')
return
}
// 检查是否有错误信息的记录
const hasErrorRecords = originalTableData.value.some(item => item.reason && item.reason.trim() !== '')
if (hasErrorRecords) {
ElMessage.error('信息有误,请修改表格内容后再提交')
return
}
try {
// 调用后端API提交数据
const response = await submitWorkOrders({
orderList: originalTableData.value
})
if (response.code === 200) {
ElMessage.success('数据提交成功')
// 清空表格数据
tableData.value = []
originalTableData.value = []
// 延迟跳转到质检信息列表页面
setTimeout(() => {
router.push('/quality-list')
}, 1500)
} else {
ElMessage.error(response.msg || '数据提交失败')
}
} catch (error) {
ElMessage.error('数据提交失败: ' + error.message)
console.error('Submit error:', error)
}
}
const handleDownloadTemplate = async () => {
try {
// 动态导入Excel文件
const module = await import('/src/assets/order_tem.xlsx')
const response = await fetch(module.default)
const blob = await response.blob()
// 创建下载链接
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = '视频质检工单数据模板.xlsx'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
ElMessage.success('模板下载成功')
} catch (error) {
ElMessage.error('模板下载失败: ' + error.message)
}
}
</script>
<style scoped>
.upload-container {
padding: 20px;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.upload-section {
margin-bottom: 30px;
}
/* 错误行样式 */
.error-row {
background-color: #fef0f0 !important;
border-left: 3px solid #f56c6c !important;
animation: shake 0.5s ease-in-out;
}
.error-row:hover {
background-color: #fde2e2 !important;
}
/* 错误行中的所有单元格样式 */
.error-row td {
color: #f56c6c !important;
font-weight: 500;
border-color: #f56c6c !important;
}
/* 错误信息列样式 */
.error-row .cell {
font-weight: bold;
color: #f56c6c !important;
}
/* 特别强调错误信息单元格 */
.error-row .el-table_1_column_10 .cell {
font-weight: bold;
text-decoration: underline;
}
/* 上传中的遮罩层样式 */
.uploading-overlay {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px;
background-color: rgba(255, 255, 255, 0.9);
border-radius: 6px;
}
.uploading-overlay .el-icon {
font-size: 32px;
color: #409eff;
margin-bottom: 16px;
}
.uploading-text {
font-size: 16px;
color: #409eff;
font-weight: 500;
}
/* 抖动动画效果 */
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-2px); }
75% { transform: translateX(2px); }
}
</style>