Blame view

antis-ncc-admin/src/views/statisticsList/form20.vue 16.6 KB
0df75a77   李宇   最新
1
2
3
4
5
  <template>
    <div class="NCC-common-layout">
      <div class="NCC-common-layout-center">
        <!-- 筛选条件 -->
        <el-row class="NCC-common-search-box" :gutter="16">
ffd6aaca   李宇   最新
6
          <el-form @submit.native.prevent >
0df75a77   李宇   最新
7
8
9
10
11
12
13
14
15
16
17
18
19
            <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">
ffd6aaca   李宇   最新
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
              <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">
0df75a77   李宇   最新
37
38
39
40
41
42
43
44
45
46
              <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>
  
        <!-- 统计卡片 -->
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
47
48
49
50
        <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>
0df75a77   李宇   最新
51
            </div>
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
52
53
54
            <div class="stat-content">
              <div class="stat-label">开单业绩</div>
              <div class="stat-value">¥{{ formatMoney(summaryData.totalOrderAchievement) }}</div>
0df75a77   李宇   最新
55
            </div>
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
56
57
58
59
          </div>
          <div class="stat-card consume-card">
            <div class="stat-icon">
              <i class="el-icon-goods"></i>
0df75a77   李宇   最新
60
            </div>
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
61
62
63
            <div class="stat-content">
              <div class="stat-label">消耗业绩</div>
              <div class="stat-value">¥{{ formatMoney(summaryData.totalConsumeAchievement) }}</div>
0df75a77   李宇   最新
64
            </div>
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
65
66
67
68
          </div>
          <div class="stat-card refund-card">
            <div class="stat-icon">
              <i class="el-icon-refresh-left"></i>
0df75a77   李宇   最新
69
            </div>
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
            <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 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>
0df75a77   李宇   最新
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  
        <!-- 数据表格 -->
        <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>
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
114
115
116
117
118
            <el-table-column prop="DepartmentName" label="部门" min-width="120" sortable="custom">
              <template slot-scope="scope">
                <span>{{ scope.row.DepartmentName || '无' }}</span>
              </template>
            </el-table-column>
0df75a77   李宇   最新
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
            <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>
0df75a77   李宇   最新
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
            <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: {
ffd6aaca   李宇   最新
159
160
          month: '',
          departmentId: ''
0df75a77   李宇   最新
161
162
163
164
165
166
        },
        list: [],
        originalList: [], // 保存原始数据,用于取消排序时恢复
        listLoading: false,
        summaryData: null,
        sortProp: '',
ffd6aaca   李宇   最新
167
168
        sortOrder: '',
        departmentOptions: [] // 部门选项列表
0df75a77   李宇   最新
169
170
171
172
173
174
175
176
177
178
179
      }
    },
    computed: {
      // 计算表格高度
      tableHeight() {
        // 减去头部、筛选条件、统计卡片、分页等高度
        return window.innerHeight - 350
      }
    },
    created() {
      this.setDefaultMonth()
ffd6aaca   李宇   最新
180
      this.loadDepartmentOptions()
0df75a77   李宇   最新
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
      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)
        }
  
ffd6aaca   李宇   最新
213
214
215
216
217
        // 如果选择了部门,添加部门筛选参数
        if (this.query.departmentId) {
          params.DepartmentId = this.query.departmentId
        }
  
0df75a77   李宇   最新
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
        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,
            totalPersonTimes: 0,
            totalLaborCost: 0
          }
          return
        }
  
        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: data.reduce((sum, item) => sum + (parseInt(item.PersonCount) || 0), 0),
          totalPersonTimes: data.reduce((sum, item) => sum + (parseInt(item.PersonTimes) || 0), 0),
          totalLaborCost: data.reduce((sum, item) => sum + (parseFloat(item.LaborCost) || 0), 0)
        }
      },
  
      // 重置查询条件
      reset() {
        this.setDefaultMonth()
ffd6aaca   李宇   最新
334
        this.query.departmentId = ''
0df75a77   李宇   最新
335
336
337
338
339
340
341
342
        this.list = []
        this.originalList = []
        this.summaryData = null
        this.sortProp = ''
        this.sortOrder = ''
        this.search()
      },
  
ffd6aaca   李宇   最新
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
      // 加载部门选项(科技部)
      loadDepartmentOptions() {
        request({
          url: '/api/Extend/Organize/GetByName',
          method: 'GET',
          data: {
            organizeName: '科技部'
          }
        }).then(res => {
          this.departmentOptions = res.data || []
        }).catch(() => {
          this.departmentOptions = []
        })
      },
  
0df75a77   李宇   最新
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
      // 格式化金额
      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)
      },
  
      // 导出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',
            '员工姓名',
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
389
            '部门',
0df75a77   李宇   最新
390
391
392
393
            '开单业绩',
            '消耗业绩',
            '退卡业绩',
            '人头',
0df75a77   李宇   最新
394
395
396
397
398
399
400
            '手工费'
          ]
          
          // 构建数据行
          const dataRows = this.list.map(row => [
            row.EmployeeId || '无',
            row.EmployeeName || '无',
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
401
            row.DepartmentName || '无',
0df75a77   李宇   最新
402
403
404
405
            this.formatMoney(row.OrderAchievement),
            this.formatMoney(row.ConsumeAchievement),
            this.formatMoney(row.RefundAchievement),
            row.PersonCount !== null && row.PersonCount !== undefined ? row.PersonCount : 0,
0df75a77   李宇   最新
406
407
408
409
410
411
412
413
414
415
416
417
418
            this.formatMoney(row.LaborCost)
          ])
          
          // 合并表头和数据
          const excelData = [headers, ...dataRows]
          
          // 创建工作簿
          const ws = XLSX.utils.aoa_to_sheet(excelData)
          
          // 设置列宽
          ws['!cols'] = [
            { wch: 18 }, // 员工ID
            { wch: 12 }, // 员工姓名
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
419
            { wch: 12 }, // 部门
0df75a77   李宇   最新
420
421
422
423
            { wch: 15 }, // 订单业绩
            { wch: 15 }, // 耗卡业绩
            { wch: 15 }, // 退款业绩
            { wch: 10 }, // 人数
0df75a77   李宇   最新
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
            { 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 {
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
467
468
469
470
471
    margin-bottom: 20px;
    display: flex;
    gap: 20px;
    justify-content: space-between;
    width: 100%;
0df75a77   李宇   最新
472
473
    
    .stat-card {
0df75a77   李宇   最新
474
475
      background: #fff;
      border-radius: 12px;
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
476
477
478
479
480
481
482
483
      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;
      flex: 1;
      min-width: 0;
0df75a77   李宇   最新
484
      
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
485
486
487
488
489
490
491
492
493
      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
      }
      
      .stat-icon {
        width: 60px;
        height: 60px;
        border-radius: 50%;
0df75a77   李宇   最新
494
        display: flex;
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
495
        align-items: center;
0df75a77   李宇   最新
496
        justify-content: center;
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
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
        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%);
      }
      
      &.labor-card .stat-icon {
        background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
      }
      
      .stat-content {
        flex: 1;
        min-width: 0;
0df75a77   李宇   最新
526
527
        
        .stat-label {
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
528
529
          font-size: 14px;
          color: #7f8c8d;
0df75a77   李宇   最新
530
531
532
533
          margin-bottom: 8px;
        }
        
        .stat-value {
97c1bdaf   “wangming”   feat: 优化库存扣减逻辑和报销...
534
535
536
537
          font-size: 28px;
          font-weight: 700;
          color: #2c3e50;
          line-height: 1.2;
0df75a77   李宇   最新
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
        }
      }
    }
  }
  
  .table-wrapper {
    height: 100%;
    
    ::v-deep .el-table__body-wrapper {
      overflow-y: scroll !important;
    }
  }
  
  .amount-value {
    color: #409EFF;
    font-weight: 500;
  }
  </style>