batch-detail-dialog.vue
15.8 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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<template>
<el-dialog title="批次详情" :close-on-click-modal="false" :visible.sync="visible"
class="NCC-dialog NCC-dialog_center" lock-scroll width="1000px">
<div v-loading="loading">
<!-- 批次基本信息 -->
<el-card class="box-card" shadow="never">
<div slot="header" class="card-header">
<span>批次基本信息</span>
</div>
<el-row :gutter="20">
<el-col :span="8">
<div class="info-item">
<span class="label">批次ID:</span>
<span class="value">{{ batchInfo.BatchId || '无' }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">创建时间:</span>
<span class="value">{{ formatDateTime(batchInfo.CreateTime) }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">创建人:</span>
<span class="value">{{ batchInfo.CreateUserName || '无' }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">总记录数:</span>
<span class="value">{{ batchInfo.TotalCount || 0 }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">有效记录数:</span>
<span class="value">{{ batchInfo.EffectiveCount || 0 }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">无效记录数:</span>
<span class="value">{{ batchInfo.IneffectiveCount || 0 }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">总使用数量:</span>
<span class="value">{{ batchInfo.TotalUsageQuantity || 0 }}</span>
</div>
</el-col>
<!-- <el-col :span="8">
<div class="info-item">
<span class="label">总使用金额:</span>
<span class="value">¥{{ formatMoney(batchInfo.TotalUsageAmount) }}</span>
</div>
</el-col> -->
</el-row>
</el-card>
<!-- 申请记录信息 -->
<el-card v-if="batchInfo.ApplicationInfo" class="box-card" shadow="never" style="margin-top: 20px;">
<div slot="header" class="card-header">
<span>申请记录信息</span>
</div>
<el-row :gutter="20">
<el-col :span="8">
<div class="info-item">
<span class="label">申请编号:</span>
<span class="value">{{ batchInfo.ApplicationInfo.Id || '无' }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">申请人:</span>
<span class="value">{{ batchInfo.ApplicationInfo.ApplicationUserName || '无' }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">申请门店:</span>
<span class="value">{{ batchInfo.ApplicationInfo.ApplicationStoreName || '无' }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">申请时间:</span>
<span class="value">{{ formatDateTime(batchInfo.ApplicationInfo.ApplicationTime) }}</span>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">审批状态:</span>
<el-tag :type="getStatusType(batchInfo.ApplicationInfo.ApprovalStatus)" size="small">
{{ batchInfo.ApplicationInfo.ApprovalStatus || '无' }}
</el-tag>
</div>
</el-col>
<el-col :span="8">
<div class="info-item">
<span class="label">是否已领取:</span>
<el-tag :type="batchInfo.ApplicationInfo.IsReceived === 1 ? 'success' : 'info'" size="small">
{{ batchInfo.ApplicationInfo.IsReceived === 1 ? '已领取' : '未领取' }}
</el-tag>
</div>
</el-col>
<el-col :span="8" v-if="batchInfo.ApplicationInfo.ReceiveTime">
<div class="info-item">
<span class="label">领取时间:</span>
<span class="value">{{ formatDateTime(batchInfo.ApplicationInfo.ReceiveTime) }}</span>
</div>
</el-col>
<el-col :span="8" v-if="batchInfo.ApplicationInfo.ReceiveUser">
<div class="info-item">
<span class="label">领取人:</span>
<span class="value">{{ batchInfo.ApplicationInfo.ReceiveUserName || '无' }}</span>
</div>
</el-col>
<el-col :span="24" v-if="batchInfo.ApplicationInfo.Remarks">
<div class="info-item">
<span class="label">备注:</span>
<span class="value">{{ batchInfo.ApplicationInfo.Remarks || '无' }}</span>
</div>
</el-col>
</el-row>
</el-card>
<!-- 使用记录列表 -->
<el-card class="box-card" shadow="never" style="margin-top: 20px;">
<div slot="header" class="card-header">
<span>使用记录列表</span>
</div>
<!-- 添加仓库筛选 -->
<div class="filter-container" style="margin-bottom: 15px;">
<el-select v-model="filterStore" placeholder="请选择仓库" clearable style="width: 200px;" @change="handleFilterStoreChange">
<el-option
v-for="store in storeList"
:key="store"
:label="store"
:value="store">
</el-option>
</el-select>
<el-button type="text" icon="el-icon-printer" @click="handlePrint()" class="print-btn" style="margin-left: 10px;">
打印
</el-button>
</div>
<NCC-table :data="filteredUsageRecords"
:header-cell-style="{ background: '#f5f7fa', color: '#606266' }">
<el-table-column label="产品名称" align="center" prop="productName" />
<el-table-column label="单价" align="center" >
<template slot-scope="scope">
<span>¥{{ formatMoney(scope.row.unitPrice) }}</span>
</template>
</el-table-column>
<el-table-column label="门店" align="center" prop="storeName"/>
<el-table-column label="仓库" align="center" prop="productWarehouse"/>
<el-table-column label="使用时间" align="center" prop="usageTime" width="150">
<template slot-scope="scope">
<span>{{ formatDateTime(scope.row.usageTime) }}</span>
</template>
</el-table-column>
<el-table-column label="使用数量" align="center" prop="usageQuantity" />
<el-table-column label="合计金额" align="center" prop="totalAmount" >
<template slot-scope="scope">
<span class="amount-text">¥{{ formatMoney(scope.row.totalAmount) }}</span>
</template>
</el-table-column>
<el-table-column label="是否有效" align="center">
<template slot-scope="scope">
<el-tag :type="scope.row.isEffective === 1 ? 'success' : 'info'" size="small">
{{ scope.row.isEffective === 1 ? '有效' : '无效' }}
</el-tag>
</template>
</el-table-column>
</NCC-table>
</el-card>
</div>
</el-dialog>
</template>
<script>
import { getBatchInfo } from '@/api/extend/lqInventory'
export default {
data() {
return {
storeList:[],
filterStore:'',
visible: false,
loading: false,
batchInfo: {
BatchId: '',
CreateTime: null,
CreateUser: '',
CreateUserName: '',
TotalCount: 0,
EffectiveCount: 0,
IneffectiveCount: 0,
TotalUsageQuantity: 0,
TotalUsageAmount: 0,
UsageRecords: [],
ApplicationInfo: null
}
}
},
computed: {
// 筛选后的使用记录
filteredUsageRecords() {
if (!this.filterStore) {
return this.batchInfo.UsageRecords || []
}
return (this.batchInfo.UsageRecords || []).filter(record =>
record.productWarehouse === this.filterStore
)
}
},
methods: {
handleFilterStoreChange(e){
console.log(e)
// this.filterStore = e
},
init(batchId) {
this.visible = true
this.loading = true
this.filterStore = '' // 重置筛选
this.batchInfo = {
BatchId: '',
CreateTime: null,
CreateUser: '',
CreateUserName: '',
TotalCount: 0,
EffectiveCount: 0,
IneffectiveCount: 0,
TotalUsageQuantity: 0,
TotalUsageAmount: 0,
UsageRecords: [],
ApplicationInfo: null
}
getBatchInfo(batchId).then(res => {
this.loading = false
if (res.code == 200 && res.data) {
this.batchInfo = res.data
// 生成仓库列表
this.generateStoreList()
} else {
this.$message({
type: 'error',
message: res.msg || '查询失败'
})
}
}).catch(() => {
this.loading = false
})
},
// 生成仓库列表(去重)
generateStoreList() {
const records = this.batchInfo.UsageRecords || []
const storeSet = new Set()
records.forEach(record => {
if (record.productWarehouse) {
storeSet.add(record.productWarehouse)
}
})
this.storeList = Array.from(storeSet)
},
// 重置筛选
resetFilter() {
this.filterStore = ''
},
getStatusType(status) {
const statusMap = {
'待审批': 'info',
'审批中': 'warning',
'已通过': 'success',
'未通过': 'danger',
'已退回': 'info'
}
return statusMap[status] || 'info'
},
formatDateTime(timestamp) {
if (!timestamp) return '无'
const date = new Date(timestamp)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
const seconds = String(date.getSeconds()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
},
formatMoney(amount) {
if (!amount && amount !== 0) return '0.00'
return Number(amount).toFixed(2)
},
// 打印功能
handlePrint() {
let printContent = this.buildPrintContent()
// 打开新窗口并打印
let newWindow = window.open('_blank')
if (!newWindow) {
this.$message.error('无法打开打印窗口,请检查浏览器弹窗设置')
return
}
newWindow.document.write(printContent)
newWindow.document.close()
// 等待内容加载完成后打印
setTimeout(() => {
newWindow.print()
}, 300)
},
// 构建打印内容
buildPrintContent() {
let batchData = this.batchInfo
console.log(batchData)
// 格式化时间
const formatDateTime = (timestamp) => {
if (!timestamp) return '无'
try {
const date = new Date(timestamp)
if (isNaN(date.getTime())) return '无'
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
const seconds = String(date.getSeconds()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
} catch (e) {
return '无'
}
}
const formatDate = (timestamp) => {
if (!timestamp) return '无'
try {
const date = new Date(timestamp)
if (isNaN(date.getTime())) return '无'
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
} catch (e) {
return '无'
}
}
const formatMoney = (amount) => {
if (!amount && amount !== 0) return '0.00'
return Number(amount).toFixed(2)
}
// 过滤出有效记录(isEffective === 1)
let effectiveRecords = batchData.UsageRecords ? batchData.UsageRecords.filter(item => item.isEffective === 1) : []
// 过滤仓库
if(this.filterStore){
let oneeffectiveRecords = effectiveRecords
effectiveRecords = oneeffectiveRecords.filter(item => item.productWarehouse == this.filterStore)
}
console.log(effectiveRecords)
// 获取门店名称
console.log(batchData.ApplicationInfo.ApplicationStoreName)
const storeName = effectiveRecords.length > 0 ? (effectiveRecords[0].storeName || '无') : '无'
let usageTableRows = ''
if (effectiveRecords.length > 0) {
effectiveRecords.forEach((item, index) => {
usageTableRows += `
<tr>
<td style="text-align: center;">${index + 1}</td>
<td>${item.productName || '无'}</td>
<td style="text-align: center;">${item.usageQuantity || 0}</td>
</tr>
`
})
} else {
usageTableRows = '<tr><td colspan="3" style="text-align: center;">暂无有效使用记录</td></tr>'
}
return `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>产品使用批次详情</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Microsoft YaHei", Arial, sans-serif;
font-size: 13px;
padding: 15px;
color: #333;
}
.print-header {
text-align: center;
margin-bottom: 15px;
border-bottom: 2px solid #333;
padding-bottom: 10px;
}
.print-header h1 {
font-size: 22px;
font-weight: bold;
margin-bottom: 5px;
}
.print-info {
margin-bottom: 12px;
}
.print-info table {
width: 100%;
border-collapse: collapse;
margin-bottom: 12px;
}
.print-info table td {
padding: 6px 10px;
border: 1px solid #ddd;
}
.print-info table td:first-child {
background-color: #f5f5f5;
font-weight: bold;
width: 200px;
text-align: right;
}
.print-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 12px;
}
.print-table thead {
display: table-header-group;
}
.print-table tbody {
display: table-row-group;
}
.print-table th,
.print-table td {
border: 1px solid #ddd;
padding: 5px 6px;
text-align: left;
font-size: 12px;
}
.print-table th {
background-color: #f5f5f5;
font-weight: bold;
text-align: center;
}
.print-table tbody tr {
page-break-inside: avoid;
}
.print-footer {
margin-top: 15px;
padding-top: 10px;
border-top: 1px solid #ddd;
text-align: right;
font-size: 11px;
color: #666;
}
@media print {
body {
padding: 8px;
}
.print-header {
page-break-after: avoid;
margin-bottom: 12px;
padding-bottom: 8px;
}
.print-info {
page-break-after: avoid;
margin-bottom: 10px;
}
.print-table {
page-break-inside: auto;
}
.print-table thead {
display: table-header-group;
}
.print-table tbody tr {
page-break-inside: avoid;
}
}
</style>
</head>
<body>
<div class="print-header">
<h1>产品使用批次详情</h1>
</div>
<div class="print-info">
<table>
<tr>
<td>门店名称:</td>
<td>${storeName}</td>
</tr>
</table>
</div>
<div class="print-info">
<h3 style="margin-bottom: 8px; font-size: 14px;">使用记录明细</h3>
<table class="print-table">
<thead>
<tr>
<th style="width: 50px;">序号</th>
<th>产品名称</th>
<th style="width: 100px;">数量</th>
</tr>
</thead>
<tbody>
${usageTableRows}
</tbody>
</table>
</div>
<div class="print-footer">
<p>打印时间:${formatDateTime(new Date().getTime())}</p>
</div>
</body>
</html>
`
}
}
}
</script>
<style lang="scss" scoped>
.box-card {
margin-bottom: 0;
}
.card-header {
font-weight: 600;
font-size: 16px;
}
.info-item {
display: flex;
align-items: center;
margin-bottom: 12px;
.label {
color: #606266;
font-weight: 500;
min-width: 100px;
}
.value {
color: #303133;
}
}
.amount-text {
color: #67C23A;
font-weight: 600;
}
::v-deep .el-table__header-wrapper {
.el-table__header {
th {
background-color: #f5f7fa;
color: #606266;
font-weight: 600;
}
}
}
</style>