Blame view

antis-ncc-admin/src/views/statisticsList/form7.vue 17.4 KB
9661fd47   李宇   ```
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
  <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-select v-model="query.storeId" placeholder="请选择门店" clearable filterable>
                  <el-option v-for="store in storeOptions" :key="store.id" :label="store.dm" :value="store.id" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="部门">
                <el-select v-model="query.departmentId" placeholder="请选择部门" clearable filterable>
                  <el-option v-for="dept in departmentOptions" :key="dept.id" :label="dept.fullName" :value="dept.id" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="开始时间">
                <el-date-picker 
                  v-model="query.startTime" 
                  type="datetime" 
                  value-format="yyyy-MM-dd HH:mm:ss" 
                  format="yyyy-MM-dd HH:mm:ss" 
                  placeholder="开始时间"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结束时间">
                <el-date-picker 
                  v-model="query.endTime" 
                  type="datetime" 
                  value-format="yyyy-MM-dd HH:mm:ss" 
                  format="yyyy-MM-dd HH:mm:ss" 
                  placeholder="结束时间"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
                <el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
  
        <!-- 数据表格 -->
        <div class="NCC-common-layout-main NCC-flex-main">
1b4e76c0   李宇   ```
54
55
56
57
58
59
60
          <NCC-table 
            v-loading="listLoading" 
            :data="list" 
            has-c
            show-summary
            :summary-method="getSummaries"
          >
9661fd47   李宇   ```
61
62
63
64
65
            <el-table-column prop="employeeName" label="员工姓名"  />
            <el-table-column prop="storeName" label="门店名称"  />
            <el-table-column prop="departmentName" label="部门名称"  />
            <el-table-column prop="inviteCount" label="邀请数"  >
              <template slot-scope="scope">
0d5e5446   李宇   ```
66
67
68
                <span class="clickable-cell" @click="handleInviteClick(scope.row)">
                  {{ scope.row.inviteCount || 0 }}
                </span>
9661fd47   李宇   ```
69
70
71
72
              </template>
            </el-table-column>
            <el-table-column prop="appointmentCount" label="预约数"  >
              <template slot-scope="scope">
0d5e5446   李宇   ```
73
74
75
                <span class="clickable-cell" @click="handleAppointmentClick(scope.row)">
                  {{ scope.row.appointmentCount || 0 }}
                </span>
9661fd47   李宇   ```
76
77
              </template>
            </el-table-column>
0d5e5446   李宇   ```
78
            <el-table-column prop="到店人数" label="到店人数"  >
9661fd47   李宇   ```
79
              <template slot-scope="scope">
0d5e5446   李宇   ```
80
81
82
                <span class="clickable-cell" @click="handleVisitClick(scope.row)">
                  {{ scope.row.visitCount || 0 }}
                </span>
9661fd47   李宇   ```
83
84
85
86
              </template>
            </el-table-column>
            <el-table-column prop="billingCount" label="开单数"  >
              <template slot-scope="scope">
0d5e5446   李宇   ```
87
88
89
                <span class="clickable-cell" @click="handleBillingClick(scope.row)">
                  {{ scope.row.billingCount || 0 }}
                </span>
9661fd47   李宇   ```
90
91
92
93
94
95
96
97
98
99
100
101
              </template>
            </el-table-column>
            <el-table-column prop="billingAmount" label="开单金额"  >
              <template slot-scope="scope">
                <span class="amount-value">¥{{ formatMoney(scope.row.billingAmount) }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="consumeAmount" label="消耗金额"  >
              <template slot-scope="scope">
                <span class="amount-paid">¥{{ formatMoney(scope.row.consumeAmount) }}</span>
              </template>
            </el-table-column>
86ade5ce   李宇   报表
102
103
104
105
106
107
108
109
110
111
            <el-table-column prop="refundAmount" label="退款金额"  >
              <template slot-scope="scope">
                <span class="amount-paid">¥{{ formatMoney(scope.row.refundAmount) }}</span>
              </template>
            </el-table-column>
            <el-table-column  label="个人业绩"  >
              <template slot-scope="scope">
                <span class="amount-paid">¥{{ formatMoney(scope.row.billingAmount - scope.row.refundAmount) }}</span>
              </template>
            </el-table-column>
9661fd47   李宇   ```
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
            <el-table-column prop="headCount" label="人头数"  >
              <template slot-scope="scope">
                {{ scope.row.headCount || 0 }}
              </template>
            </el-table-column>
            <el-table-column prop="personCount" label="人次"  >
              <template slot-scope="scope">
                {{ scope.row.personCount || 0 }}
              </template>
            </el-table-column>
            <el-table-column prop="projectCount" label="项目数"  >
              <template slot-scope="scope">
                {{ scope.row.projectCount || 0 }}
              </template>
            </el-table-column>
ad3658d9   李宇   ```
127
128
129
130
131
            <el-table-column prop="laborCost" label="手工费"  >
              <template slot-scope="scope">
                {{ scope.row.laborCost || 0 }}
              </template>
            </el-table-column>
9661fd47   李宇   ```
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
          </NCC-table>
  
          <!-- 分页组件 -->
          <pagination 
            v-show="total > 0" 
            :total="total" 
            :page.sync="query.currentPage"
            :limit.sync="query.pageSize" 
            @pagination="search" 
          />
        </div>
      </div>
    </div>
  </template>
  
  <script>
  import request from '@/utils/request'
  import Pagination from '@/components/Pagination'
  
  export default {
    name: 'StoreOverallStatistics',
    components: {
      Pagination
    },
    data() {
      return {
        query: {
          storeId: undefined,
          departmentId: undefined,
          startTime: undefined,
          endTime: undefined,
          currentPage: 1,
          pageSize: 20
        },
        storeOptions: [],
        departmentOptions: [],
        list: [],
        total: 0,
        listLoading: false
      }
    },
    created() {
86ade5ce   李宇   报表
174
175
176
177
178
179
  
      if (sessionStorage.getItem('isshaixuan') === 'false') {
        this.setDefaultTimeRange()
      } else{
        this.restoreQueryParams()
      }
9661fd47   李宇   ```
180
181
182
183
184
      this.initStoreOptions()
      this.initDepartmentOptions()
      this.search()
    },
    methods: {
86ade5ce   李宇   报表
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
      // 保存筛选条件到 sessionStorage
      saveQueryParams() {
        try {
          const paramsToSave = {
            storeId: this.query.storeId,
            departmentId: this.query.departmentId,
            startTime: this.query.startTime,
            endTime: this.query.endTime,
            currentPage: this.query.currentPage,
            pageSize: this.query.pageSize
          }
          sessionStorage.setItem('form7_query_params', JSON.stringify(paramsToSave))
          sessionStorage.setItem('isshaixuan', true)
        } catch (err) {
          console.error('保存筛选条件失败:', err)
        }
      },
  
      // 从 sessionStorage 恢复筛选条件
      restoreQueryParams() {
        try {
          const savedParams = sessionStorage.getItem('form7_query_params')
          if (savedParams) {
            const params = JSON.parse(savedParams)
            // 恢复筛选条件
            this.query.storeId = params.storeId || undefined
            this.query.departmentId = params.departmentId || undefined
            this.query.startTime = params.startTime || undefined
            this.query.endTime = params.endTime || undefined
            this.query.currentPage = params.currentPage || 1
            this.query.pageSize = params.pageSize || 20
            
            // 如果没有时间范围,设置默认值
            if (!this.query.startTime || !this.query.endTime) {
              this.setDefaultTimeRange()
            }
            sessionStorage.setItem('isshaixuan', false)
          } else {
            // 没有保存的条件,设置默认时间范围
            this.setDefaultTimeRange()
          }
        } catch (err) {
          console.error('恢复筛选条件失败:', err)
          // 出错时设置默认时间范围
          this.setDefaultTimeRange()
        }
      },
  
9661fd47   李宇   ```
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
      // 设置默认时间范围(本月1号到现在)
      setDefaultTimeRange() {
        const now = new Date()
        const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1)
        
        this.query.startTime = this.formatDateTime(firstDayOfMonth.getTime())
        this.query.endTime = this.formatDateTime(now.getTime())
      },
  
      // 初始化门店选项
      initStoreOptions() {
        request({
          url: '/api/Extend/LqMdxx',
          method: 'GET',
          data: {
            currentPage: 1,
            pageSize: 1000
          }
        }).then(res => {
          this.storeOptions = res.data.list || []
        }).catch(err => {
          console.error('获取门店列表失败:', err)
        })
      },
  
      // 初始化部门选项
      initDepartmentOptions() {
        request({
          url: '/api/permission/Organize/96240625-934F-490B-8AA6-0BC775B18468/Department',
          method: 'GET'
        }).then(res => {
          // 将树形结构扁平化
          this.departmentOptions = res.data.list.map(item => ({
            id: item.id,
            fullName: item.fullName
          }))
        }).catch(err => {
          console.error('获取部门列表失败:', err)
        })
      },
  
  
  
      // 查询数据
      search() {
        this.listLoading = true
86ade5ce   李宇   报表
279
280
        // 保存当前筛选条件
        // this.saveQueryParams()
9661fd47   李宇   ```
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
  
        const params = {
          currentPage: this.query.currentPage,
          pageSize: this.query.pageSize
        }
  
        if (this.query.storeId) {
          params.StoreId = this.query.storeId
        }
  
        if (this.query.departmentId) {
          params.DepartmentId = this.query.departmentId
        }
  
        if (this.query.startTime) {
          params.StartTime = this.query.startTime
        }
  
        if (this.query.endTime) {
          params.EndTime = this.query.endTime
        }
  
        request({
          url: '/api/Extend/lqkdkdjlb/get-health-coach-statistics',
          method: 'GET',
          data: params
        }).then(res => {
          if (res.data && res.data.list) {
            this.list = res.data.list
86ade5ce   李宇   报表
310
            this.total = (res.data.pagination && res.data.pagination.totalCount) || 0
9661fd47   李宇   ```
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
          } else {
            this.list = []
            this.total = 0
          }
          this.listLoading = false
        }).catch(err => {
          console.error('查询失败:', err)
          this.$message({
            type: 'error',
            message: '查询失败,请重试',
            duration: 1500
          })
          this.listLoading = false
        })
      },
  
      // 重置查询条件
      reset() {
        this.query = {
          storeId: undefined,
          departmentId: undefined,
          startTime: undefined,
          endTime: undefined,
          currentPage: 1,
          pageSize: 20
        }
        this.setDefaultTimeRange()
86ade5ce   李宇   报表
338
339
340
341
342
343
        // 清除保存的筛选条件
        try {
          sessionStorage.removeItem('form7_query_params')
        } catch (err) {
          console.error('清除保存的筛选条件失败:', err)
        }
9661fd47   李宇   ```
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
        this.list = []
        this.total = 0
        this.search()
      },
  
      // 格式化金额
      formatMoney(amount) {
        if (!amount && amount !== 0) return '0.00'
        return Number(amount).toFixed(2)
      },
  
      // 格式化日期时间(用于API传参)
      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}`
0d5e5446   李宇   ```
366
367
368
369
370
      },
  
      // 将时间字符串转换为时间戳(毫秒)
      getTimestamp(timeStr) {
        if (!timeStr) return ''
1b4e76c0   李宇   ```
371
372
373
374
375
376
377
378
379
380
381
382
383
384
        // 手动解析 yyyy-MM-dd HH:mm:ss 格式,避免时区问题
        const parts = timeStr.match(/(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})/)
        if (!parts) {
          // 如果格式不匹配,尝试使用 Date 解析
          return new Date(timeStr).getTime()
        }
        // 创建本地时间的 Date 对象
        const year = parseInt(parts[1], 10)
        const month = parseInt(parts[2], 10) - 1 // 月份从0开始
        const day = parseInt(parts[3], 10)
        const hours = parseInt(parts[4], 10)
        const minutes = parseInt(parts[5], 10)
        const seconds = parseInt(parts[6], 10)
        return new Date(year, month, day, hours, minutes, seconds).getTime()
0d5e5446   李宇   ```
385
386
387
388
389
      },
  
      // 处理邀请数点击事件
      handleInviteClick(row) {
        if (row && row.employeeId) {
86ade5ce   李宇   报表
390
          this.saveQueryParams()
0d5e5446   李宇   ```
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
          this.$router.push({
            path: '/lqYaoyjl',
            query: {
              employeeId: row.employeeId,
              storeId: row.storeId || '',
              startTime: this.getTimestamp(this.query.startTime),
              endTime: this.getTimestamp(this.query.endTime),
            }
          })
        } else {
          this.$message({
            type: 'warning',
            message: '无法获取健康师ID',
            duration: 1500
          })
        }
      },
  
      // 处理预约数点击事件
      handleAppointmentClick(row) {
        if (row && row.employeeId) {
86ade5ce   李宇   报表
412
          this.saveQueryParams()
0d5e5446   李宇   ```
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
          this.$router.push({
            path: '/lqYyjl',
            query: {
              employeeId: row.employeeId,
              storeId: row.storeId || '',
              startTime: this.getTimestamp(this.query.startTime),
              endTime: this.getTimestamp(this.query.endTime),
            }
          })
        } else {
          this.$message({
            type: 'warning',
            message: '无法获取健康师ID',
            duration: 1500
          })
        }
      },
  
      // 处理到店人数点击事件
      handleVisitClick(row) {
        if (row && row.employeeId) {
86ade5ce   李宇   报表
434
          this.saveQueryParams()
0d5e5446   李宇   ```
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
          this.$router.push({
            path: '/lqYyjl',
            query: {
              employeeId: row.employeeId,
              storeId: row.storeId || '',
              startTime: this.getTimestamp(this.query.startTime),
              endTime: this.getTimestamp(this.query.endTime),
              type:'已确认'
            }
          })
        } else {
          this.$message({
            type: 'warning',
            message: '无法获取健康师ID',
            duration: 1500
          })
        }
      },
  
      // 处理开单数点击事件
      handleBillingClick(row) {
        if (row && row.employeeId) {
86ade5ce   李宇   报表
457
          this.saveQueryParams()
0d5e5446   李宇   ```
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
          this.$router.push({
            path: '/lqKdKdjlb',
            query: {
              employeeId: row.employeeId,
              storeId: row.storeId || '',
              startTime: this.getTimestamp(this.query.startTime),
              endTime: this.getTimestamp(this.query.endTime),
            }
          })
        } else {
          this.$message({
            type: 'warning',
            message: '无法获取健康师ID',
            duration: 1500
          })
        }
1b4e76c0   李宇   ```
474
475
476
477
478
479
480
      },
  
      // 计算合计
      getSummaries(param) {
        const { columns, data } = param
        const sums = []
        
86ade5ce   李宇   报表
481
482
483
484
485
486
487
488
        // 预先计算总开单金额和总退款金额,用于计算个人业绩合计
        const totalBillingAmount = data.reduce((prev, curr) => {
          return prev + (Number(curr.billingAmount) || 0)
        }, 0)
        const totalRefundAmount = data.reduce((prev, curr) => {
          return prev + (Number(curr.refundAmount) || 0)
        }, 0)
        
1b4e76c0   李宇   ```
489
490
491
492
493
494
495
        columns.forEach((column, index) => {
          if (index === 2) {
            sums[index] = '合计'
            return
          }
          
          const prop = column.property
86ade5ce   李宇   报表
496
497
498
499
500
501
502
503
504
          const label = column.label
          
          // 处理个人业绩列(没有 prop,通过 label 判断)
          if (!prop && label === '个人业绩') {
            const totalPersonalPerformance = totalBillingAmount - totalRefundAmount
            sums[index] = `¥${this.formatMoney(totalPersonalPerformance)}`
            return
          }
          
1b4e76c0   李宇   ```
505
506
507
508
509
510
511
          if (!prop) {
            sums[index] = ''
            return
          }
          
          // 需要合计的数值字段
          if (['inviteCount', 'appointmentCount', 'visitCount', 'billingCount', 
ad3658d9   李宇   ```
512
               'headCount', 'personCount', 'projectCount', 'laborCost'].includes(prop)) {
1b4e76c0   李宇   ```
513
514
515
516
517
518
519
            const total = data.reduce((prev, curr) => {
              const value = Number(curr[prop]) || 0
              return prev + value
            }, 0)
            sums[index] = total
          } 
          // 金额字段需要格式化
86ade5ce   李宇   报表
520
          else if (['billingAmount', 'consumeAmount', 'refundAmount'].includes(prop)) {
1b4e76c0   李宇   ```
521
522
523
524
525
526
527
528
529
530
531
532
533
            const total = data.reduce((prev, curr) => {
              const value = Number(curr[prop]) || 0
              return prev + value
            }, 0)
            sums[index] = `¥${this.formatMoney(total)}`
          } 
          // 其他列(员工姓名、门店名称、部门名称)不显示合计
          else {
            sums[index] = ''
          }
        })
        
        return sums 
9661fd47   李宇   ```
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .amount-value {
    color: #409EFF;
    font-weight: 500;
  }
  
  .amount-paid {
    color: #67C23A;
    font-weight: 500;
  }
0d5e5446   李宇   ```
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
  
  .clickable-cell {
    color: #409EFF;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.3s;
  
    &:hover {
      color: #66b1ff;
      text-decoration: underline;
    }
  
    &:active {
      color: #3a8ee6;
    }
  }
9661fd47   李宇   ```
565
  </style>