form20.vue
19.4 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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
<template>
<div class="NCC-common-layout">
<div class="NCC-common-layout-center">
<!-- 筛选条件 -->
<el-row class="NCC-common-search-box" :gutter="16">
<el-form @submit.native.prevent >
<el-col :span="6">
<el-form-item label="选择月份">
<el-date-picker
v-model="query.month"
type="month"
value-format="yyyy-MM"
format="yyyy-MM"
placeholder="选择月份"
style="width: 100%;"
/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="部门">
<el-select
v-model="query.departmentId"
placeholder="请选择部门"
filterable
clearable
style="width: 100%;">
<el-option
v-for="dept in departmentOptions"
:key="dept.Id || dept.id"
:label="dept.FullName || dept.fullName"
:value="dept.Id || dept.id">
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label-width="0">
<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
<el-button icon="el-icon-download" @click="exportExcel()">导出Excel</el-button>
</el-form-item>
</el-col>
</el-form>
</el-row>
<!-- 统计卡片 -->
<div class="statistics-cards" v-if="summaryData">
<div class="stat-card order-card">
<div class="stat-icon">
<i class="el-icon-shopping-cart-full"></i>
</div>
<div class="stat-content">
<div class="stat-label">开单业绩</div>
<div class="stat-value">¥{{ formatMoney(summaryData.totalOrderAchievement) }}</div>
</div>
</div>
<div class="stat-card consume-card">
<div class="stat-icon">
<i class="el-icon-goods"></i>
</div>
<div class="stat-content">
<div class="stat-label">消耗业绩</div>
<div class="stat-value">¥{{ formatMoney(summaryData.totalConsumeAchievement) }}</div>
</div>
</div>
<div class="stat-card refund-card">
<div class="stat-icon">
<i class="el-icon-refresh-left"></i>
</div>
<div class="stat-content">
<div class="stat-label">退卡业绩</div>
<div class="stat-value">¥{{ formatMoney(summaryData.totalRefundAchievement) }}</div>
</div>
</div>
<div class="stat-card person-card">
<div class="stat-icon">
<i class="el-icon-user-solid"></i>
</div>
<div class="stat-content">
<div class="stat-label">消耗人头</div>
<div class="stat-value">{{ summaryData.totalPersonCount || 0 }}</div>
</div>
</div>
<div class="stat-card order-person-card">
<div class="stat-icon">
<i class="el-icon-user"></i>
</div>
<div class="stat-content">
<div class="stat-label">开单人头</div>
<div class="stat-value">{{ summaryData.totalOrderPersonCount || 0 }}</div>
</div>
</div>
<div class="stat-card conversion-card">
<div class="stat-icon">
<i class="el-icon-data-line"></i>
</div>
<div class="stat-content">
<div class="stat-label">消耗开单转化率</div>
<div class="stat-value">{{ formatPercent(summaryData.totalConsumeOrderConversionRate) }}%</div>
</div>
</div>
<div class="stat-card labor-card">
<div class="stat-icon">
<i class="el-icon-coin"></i>
</div>
<div class="stat-content">
<div class="stat-label">手工费</div>
<div class="stat-value">¥{{ formatMoney(summaryData.totalLaborCost) }}</div>
</div>
</div>
</div>
<!-- 数据表格 -->
<div class="NCC-common-layout-main NCC-flex-main table-wrapper">
<el-table
v-loading="listLoading"
:data="list"
border
stripe
:max-height="tableHeight"
@sort-change="handleSortChange">
<el-table-column prop="EmployeeId" label="员工ID" width="180" sortable="custom">
<template slot-scope="scope">
<span>{{ scope.row.EmployeeId || '无' }}</span>
</template>
</el-table-column>
<el-table-column prop="EmployeeName" label="员工姓名" min-width="120" sortable="custom">
<template slot-scope="scope">
<span>{{ scope.row.EmployeeName || '无' }}</span>
</template>
</el-table-column>
<el-table-column prop="DepartmentName" label="部门" min-width="120" sortable="custom">
<template slot-scope="scope">
<span>{{ scope.row.DepartmentName || '无' }}</span>
</template>
</el-table-column>
<el-table-column prop="OrderAchievement" label="开单业绩" min-width="130" sortable="custom">
<template slot-scope="scope">
<span class="amount-value">¥{{ formatMoney(scope.row.OrderAchievement) }}</span>
</template>
</el-table-column>
<el-table-column prop="ConsumeAchievement" label="消耗业绩" min-width="130" sortable="custom">
<template slot-scope="scope">
<span class="amount-value">¥{{ formatMoney(scope.row.ConsumeAchievement) }}</span>
</template>
</el-table-column>
<el-table-column prop="RefundAchievement" label="退卡业绩" min-width="130" sortable="custom">
<template slot-scope="scope">
<span class="amount-value">¥{{ formatMoney(scope.row.RefundAchievement) }}</span>
</template>
</el-table-column>
<el-table-column prop="PersonCount" label="消耗人头" width="100" sortable="custom">
<template slot-scope="scope">
<span>{{ scope.row.PersonCount !== null && scope.row.PersonCount !== undefined ? scope.row.PersonCount : 0 }}</span>
</template>
</el-table-column>
<el-table-column prop="OrderPersonCount" label="开单人头" width="100" sortable="custom">
<template slot-scope="scope">
<span>{{ scope.row.OrderPersonCount !== null && scope.row.OrderPersonCount !== undefined ? scope.row.OrderPersonCount : 0 }}</span>
</template>
</el-table-column>
<el-table-column prop="ConsumeOrderConversionRate" label="消耗开单转化率" min-width="140" sortable="custom">
<template slot-scope="scope">
<span class="rate-value">{{ formatPercent(scope.row.ConsumeOrderConversionRate) }}%</span>
</template>
</el-table-column>
<el-table-column prop="LaborCost" label="手工费" min-width="130" sortable="custom">
<template slot-scope="scope">
<span class="amount-value">¥{{ formatMoney(scope.row.LaborCost) }}</span>
</template>
</el-table-column>
</el-table>
</div>
</div>
</div>
</template>
<script>
import request from '@/utils/request'
import { saveAs } from 'file-saver'
export default {
name: 'TechTeacherConsumeStatistics',
data() {
return {
query: {
month: '',
departmentId: ''
},
list: [],
originalList: [], // 保存原始数据,用于取消排序时恢复
listLoading: false,
summaryData: null,
sortProp: '',
sortOrder: '',
departmentOptions: [] // 部门选项列表
}
},
computed: {
// 计算表格高度
tableHeight() {
// 减去头部、筛选条件、统计卡片、分页等高度
return window.innerHeight - 350
}
},
created() {
this.setDefaultMonth()
this.loadDepartmentOptions()
this.search()
},
methods: {
// 设置默认月份(当前月份)
setDefaultMonth() {
const now = new Date()
const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0')
this.query.month = `${year}-${month}`
},
// 查询数据
search() {
if (!this.query.month) {
this.$message({
type: 'warning',
message: '请选择月份',
duration: 1500
})
return
}
this.listLoading = true
// 解析年月
const [year, month] = this.query.month.split('-')
const params = {
Year: parseInt(year),
Month: parseInt(month)
}
// 如果选择了部门,添加部门筛选参数
if (this.query.departmentId) {
params.DepartmentId = this.query.departmentId
}
request({
url: '/api/Extend/lqtechteachersalary/statistics',
method: 'GET',
data: params
}).then(res => {
if (res.data && Array.isArray(res.data)) {
this.list = res.data
this.originalList = JSON.parse(JSON.stringify(res.data)) // 保存原始数据
// 计算汇总数据
this.calculateSummary(res.data)
} else {
this.list = []
this.originalList = []
this.summaryData = null
}
this.listLoading = false
}).catch(err => {
console.error('查询失败:', err)
this.$message({
type: 'error',
message: '查询失败,请重试',
duration: 1500
})
this.listLoading = false
this.list = []
this.originalList = []
this.summaryData = null
})
},
// 处理排序变化
handleSortChange({ column, prop, order }) {
if (!order) {
// 取消排序,恢复原始顺序
this.sortProp = ''
this.sortOrder = ''
if (this.originalList.length > 0) {
this.list = JSON.parse(JSON.stringify(this.originalList))
}
return
}
this.sortProp = prop
this.sortOrder = order === 'ascending' ? 'asc' : 'desc'
this.sortList()
},
// 对列表进行排序
sortList() {
if (!this.sortProp || !this.sortOrder) {
return
}
// 从原始数据开始排序,确保每次排序都是基于原始数据
const sourceList = this.originalList.length > 0 ? JSON.parse(JSON.stringify(this.originalList)) : JSON.parse(JSON.stringify(this.list))
// 创建新数组并排序
const sortedList = sourceList.sort((a, b) => {
let aVal = a[this.sortProp]
let bVal = b[this.sortProp]
// 处理空值
if (aVal === null || aVal === undefined) aVal = 0
if (bVal === null || bVal === undefined) bVal = 0
// 数值类型直接比较
if (typeof aVal === 'number' && typeof bVal === 'number') {
return this.sortOrder === 'asc' ? aVal - bVal : bVal - aVal
}
// 字符串类型
aVal = String(aVal || '')
bVal = String(bVal || '')
if (this.sortOrder === 'asc') {
return aVal.localeCompare(bVal)
} else {
return bVal.localeCompare(aVal)
}
})
// 重新赋值整个数组以触发响应式更新
this.list = sortedList
this.$nextTick(() => {
this.$forceUpdate()
})
},
// 计算汇总数据
calculateSummary(data) {
if (!data || data.length === 0) {
this.summaryData = {
totalOrderAchievement: 0,
totalConsumeAchievement: 0,
totalRefundAchievement: 0,
totalPersonCount: 0,
totalOrderPersonCount: 0,
totalPersonTimes: 0,
totalLaborCost: 0,
totalConsumeOrderConversionRate: 0
}
return
}
const totalPersonCount = data.reduce((sum, item) => sum + (parseInt(item.PersonCount) || 0), 0)
const totalOrderPersonCount = data.reduce((sum, item) => sum + (parseInt(item.OrderPersonCount) || 0), 0)
// 计算总转化率:总开单人头 / 总消耗人头
const totalConsumeOrderConversionRate = totalPersonCount > 0
? (totalOrderPersonCount / totalPersonCount) * 100
: 0
this.summaryData = {
totalOrderAchievement: data.reduce((sum, item) => sum + (parseFloat(item.OrderAchievement) || 0), 0),
totalConsumeAchievement: data.reduce((sum, item) => sum + (parseFloat(item.ConsumeAchievement) || 0), 0),
totalRefundAchievement: data.reduce((sum, item) => sum + (parseFloat(item.RefundAchievement) || 0), 0),
totalPersonCount: totalPersonCount,
totalOrderPersonCount: totalOrderPersonCount,
totalPersonTimes: data.reduce((sum, item) => sum + (parseInt(item.PersonTimes) || 0), 0),
totalLaborCost: data.reduce((sum, item) => sum + (parseFloat(item.LaborCost) || 0), 0),
totalConsumeOrderConversionRate: totalConsumeOrderConversionRate
}
},
// 重置查询条件
reset() {
this.setDefaultMonth()
this.query.departmentId = ''
this.list = []
this.originalList = []
this.summaryData = null
this.sortProp = ''
this.sortOrder = ''
this.search()
},
// 加载部门选项(科技部)
loadDepartmentOptions() {
request({
url: '/api/Extend/Organize/GetByName',
method: 'GET',
data: {
organizeName: '科技部'
}
}).then(res => {
this.departmentOptions = res.data || []
}).catch(() => {
this.departmentOptions = []
})
},
// 格式化金额
formatMoney(amount) {
if (amount === null || amount === undefined || amount === '') {
return '0.00'
}
const num = parseFloat(amount)
if (isNaN(num)) {
return '0.00'
}
return num.toFixed(2)
},
// 格式化百分比
formatPercent(rate) {
if (rate === null || rate === undefined || rate === '') {
return '0.00'
}
const num = parseFloat(rate)
if (isNaN(num)) {
return '0.00'
}
return num.toFixed(2)
},
// 导出Excel
async exportExcel() {
if (!this.list || this.list.length === 0) {
this.$message({
type: 'warning',
message: '暂无数据可导出',
duration: 1500
})
return
}
try {
// 动态导入 xlsx 库
const XLSX = await import('xlsx')
// 构建表头
const headers = [
'员工ID',
'员工姓名',
'部门',
'开单业绩',
'消耗业绩',
'退卡业绩',
'消耗人头',
'开单人头',
'消耗开单转化率(%)',
'手工费'
]
// 构建数据行
const dataRows = this.list.map(row => [
row.EmployeeId || '无',
row.EmployeeName || '无',
row.DepartmentName || '无',
this.formatMoney(row.OrderAchievement),
this.formatMoney(row.ConsumeAchievement),
this.formatMoney(row.RefundAchievement),
row.PersonCount !== null && row.PersonCount !== undefined ? row.PersonCount : 0,
row.OrderPersonCount !== null && row.OrderPersonCount !== undefined ? row.OrderPersonCount : 0,
this.formatPercent(row.ConsumeOrderConversionRate),
this.formatMoney(row.LaborCost)
])
// 合并表头和数据
const excelData = [headers, ...dataRows]
// 创建工作簿
const ws = XLSX.utils.aoa_to_sheet(excelData)
// 设置列宽
ws['!cols'] = [
{ wch: 18 }, // 员工ID
{ wch: 12 }, // 员工姓名
{ wch: 12 }, // 部门
{ wch: 15 }, // 开单业绩
{ wch: 15 }, // 消耗业绩
{ wch: 15 }, // 退卡业绩
{ wch: 12 }, // 消耗人头
{ wch: 12 }, // 开单人头
{ wch: 18 }, // 消耗开单转化率
{ wch: 15 } // 手工费
]
// 创建工作簿
const wb = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(wb, ws, '科技部老师耗卡业绩')
// 生成文件名
const [year, month] = this.query.month.split('-')
const fileName = `科技部老师耗卡业绩_${year}年${month}月_${new Date().getTime()}.xlsx`
// 导出文件
const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'array' })
saveAs(new Blob([wbout], { type: 'application/octet-stream' }), fileName)
this.$message({
type: 'success',
message: '导出成功',
duration: 1500
})
} catch (error) {
console.error('导出失败:', error)
if (error.message && error.message.includes('xlsx')) {
this.$message({
type: 'error',
message: '导出失败:请先安装 xlsx 库,运行命令: npm install xlsx --save',
duration: 3000
})
} else {
this.$message({
type: 'error',
message: '导出失败:' + (error.message || '未知错误'),
duration: 2000
})
}
}
}
}
}
</script>
<style lang="scss" scoped>
.statistics-cards {
margin-bottom: 20px;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
width: 100%;
.stat-card {
background: #fff;
border-radius: 12px;
padding: 24px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
transition: all 0.3s ease;
height: 120px;
min-width: 0;
&:hover {
transform: translateY(-2px);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.stat-icon {
width: 60px;
height: 60px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16px;
font-size: 24px;
color: #fff;
flex-shrink: 0;
}
&.order-card .stat-icon {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
&.consume-card .stat-icon {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}
&.refund-card .stat-icon {
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}
&.person-card .stat-icon {
background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}
&.order-person-card .stat-icon {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
&.conversion-card .stat-icon {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}
&.labor-card .stat-icon {
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}
.stat-content {
flex: 1;
min-width: 0;
.stat-label {
font-size: 14px;
color: #7f8c8d;
margin-bottom: 8px;
}
.stat-value {
font-size: 28px;
font-weight: 700;
color: #2c3e50;
line-height: 1.2;
}
}
}
}
.table-wrapper {
height: 100%;
::v-deep .el-table__body-wrapper {
overflow-y: scroll !important;
}
}
.amount-value {
color: #409EFF;
font-weight: 500;
}
.rate-value {
color: #67C23A;
font-weight: 500;
}
</style>