Blame view

antis-ncc-admin/src/views/statisticsList/form16.vue 15.6 KB
86ade5ce   李宇   报表
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
  <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.startTime" 
                  type="datetime" 
                  value-format="timestamp" 
                  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="timestamp" 
                  format="yyyy-MM-dd HH:mm:ss" 
                  placeholder="结束时间"
                />
              </el-form-item>
            </el-col>
b1146e00   李宇   最新
29
            <!-- <el-col :span="6">
86ade5ce   李宇   报表
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
              <el-form-item label="门店">
                <el-select
                  v-model="query.storeIds"
                  placeholder="请选择门店"
                  multiple
                  filterable
                  clearable
                  :style='{"width":"100%"}'>
                  <el-option
                    v-for="store in storeOptions"
                    :key="store.id"
                    :label="store.dm"
                    :value="store.id">
                  </el-option>
                </el-select>
              </el-form-item>
b1146e00   李宇   最新
46
            </el-col> -->
86ade5ce   李宇   报表
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
            <el-col :span="6">
              <el-form-item label="拓客活动">
                <el-select
                  v-model="query.eventId"
                  placeholder="请选择拓客活动"
                  filterable
                  clearable
                  :style='{"width":"100%"}'>
                  <el-option
                    v-for="event in eventOptions"
                    :key="event.id"
                    :label="event.eventName"
                    :value="event.id">
                  </el-option>
                </el-select>
              </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">
8eb72f90   李宇   最新
75
76
77
78
79
80
81
          <el-table 
            v-loading="listLoading" 
            :data="list" 
            border 
            stripe 
            :height="tableHeight"
            @sort-change="handleSortChange">
86ade5ce   李宇   报表
82
83
84
            <el-table-column prop="StoreName" label="门店名称" min-width="150">
              <template slot-scope="scope">
                <i class="el-icon-shop" style="margin-right: 4px; color: #409EFF;"></i>
b1146e00   李宇   最新
85
86
87
88
89
90
                <span 
                  class="store-name-link" 
                  @click="handleStoreNameClick(scope.row)"
                  style="cursor: pointer; color: #409EFF; text-decoration: underline;">
                  {{ scope.row.StoreName || '无' }}
                </span>
86ade5ce   李宇   报表
91
92
              </template>
            </el-table-column>
36493279   李宇   最新
93
            <el-table-column prop="TotalCount" label="总人数" min-width="120" sortable="custom" >
86ade5ce   李宇   报表
94
95
96
97
98
99
100
101
102
103
104
              <template slot-scope="scope">
                <i class="el-icon-s-data" style="margin-right: 4px; color: #67C23A;"></i>
                <span>{{ scope.row.TotalCount !== null && scope.row.TotalCount !== undefined ? scope.row.TotalCount : 0 }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="TkMemberCount" label="拓客会员数" min-width="130" sortable="custom" >
              <template slot-scope="scope">
                <i class="el-icon-user-solid" style="margin-right: 4px; color: #409EFF;"></i>
                <span>{{ scope.row.TkMemberCount !== null && scope.row.TkMemberCount !== undefined ? scope.row.TkMemberCount : 0 }}</span>
              </template>
            </el-table-column>
7606a6ad   “wangming”   fix: update produ...
105
            <el-table-column prop="InviteCount" label="沟通数" min-width="120" sortable="custom" >
86ade5ce   李宇   报表
106
107
108
109
110
111
112
113
114
115
116
              <template slot-scope="scope">
                <i class="el-icon-phone-outline" style="margin-right: 4px; color: #67C23A;"></i>
                <span>{{ scope.row.InviteCount !== null && scope.row.InviteCount !== undefined ? scope.row.InviteCount : 0 }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="AppointmentCount" label="预约数" min-width="120" sortable="custom" >
              <template slot-scope="scope">
                <i class="el-icon-date" style="margin-right: 4px; color: #67C23A;"></i>
                <span>{{ scope.row.AppointmentCount !== null && scope.row.AppointmentCount !== undefined ? scope.row.AppointmentCount : 0 }}</span>
              </template>
            </el-table-column>
36493279   李宇   最新
117
            <el-table-column prop="ConsumeCount" label="耗卡数" min-width="120" sortable="custom" >
86ade5ce   李宇   报表
118
119
120
121
122
              <template slot-scope="scope">
                <i class="el-icon-shopping-cart-2" style="margin-right: 4px; color: #67C23A;"></i>
                <span>{{ scope.row.ConsumeCount !== null && scope.row.ConsumeCount !== undefined ? scope.row.ConsumeCount : 0 }}</span>
              </template>
            </el-table-column>
36493279   李宇   最新
123
            <el-table-column prop="BillingCount" label="开单数(链路)" min-width="130" sortable="custom" >
86ade5ce   李宇   报表
124
125
126
127
128
              <template slot-scope="scope">
                <i class="el-icon-document" style="margin-right: 4px; color: #67C23A;"></i>
                <span>{{ scope.row.BillingCount !== null && scope.row.BillingCount !== undefined ? scope.row.BillingCount : 0 }}</span>
              </template>
            </el-table-column>
36493279   李宇   最新
129
            <el-table-column prop="BillingAmount" label="开单金额(链路)" min-width="140" sortable="custom" >
86ade5ce   李宇   报表
130
131
132
133
134
              <template slot-scope="scope">
                <i class="el-icon-money" style="margin-right: 4px; color: #67C23A;"></i>
                <span class="amount-paid">¥{{ formatMoney(scope.row.BillingAmount) }}</span>
              </template>
            </el-table-column>
36493279   李宇   最新
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
            <el-table-column prop="VisitCount" label="到店人数" min-width="120" sortable="custom" >
              <template slot-scope="scope">
                <i class="el-icon-location" style="margin-right: 4px; color: #409EFF;"></i>
                <span>{{ scope.row.VisitCount !== null && scope.row.VisitCount !== undefined ? scope.row.VisitCount : 0 }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="VisitRate" label="到店率" min-width="100" sortable="custom" >
              <template slot-scope="scope">
                <i class="el-icon-data-line" style="margin-right: 4px; color: #67C23A;"></i>
                <span>{{ formatPercentage(scope.row.VisitRate) }}%</span>
              </template>
            </el-table-column>
            <el-table-column prop="TotalBillingCount" label="开单数(全部)" min-width="130" sortable="custom" >
              <template slot-scope="scope">
                <i class="el-icon-document-copy" style="margin-right: 4px; color: #67C23A;"></i>
                <span>{{ scope.row.TotalBillingCount !== null && scope.row.TotalBillingCount !== undefined ? scope.row.TotalBillingCount : 0 }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="TotalBillingAmount" label="开单金额(全部)" min-width="140" sortable="custom" >
              <template slot-scope="scope">
                <i class="el-icon-coin" style="margin-right: 4px; color: #67C23A;"></i>
                <span class="amount-paid">¥{{ formatMoney(scope.row.TotalBillingAmount) }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="ConversionRate" label="成交率" min-width="100" sortable="custom" >
              <template slot-scope="scope">
                <i class="el-icon-data-analysis" style="margin-right: 4px; color: #67C23A;"></i>
                <span>{{ formatPercentage(scope.row.ConversionRate) }}%</span>
              </template>
            </el-table-column>
86ade5ce   李宇   报表
165
166
167
          </el-table>
        </div>
      </div>
b1146e00   李宇   最新
168
169
170
171
172
173
174
  
      <!-- 线索池客户统计弹窗 -->
      <lead-customer-statistics-dialog
        :visible="dialogVisible"
        :initial-query="dialogQuery"
        @close="handleDialogClose"
      />
86ade5ce   李宇   报表
175
176
177
178
179
180
    </div>
  </template>
  
  <script>
  import request from '@/utils/request'
  import { getLqEventList } from '@/api/extend/lqevent'
b1146e00   李宇   最新
181
  import LeadCustomerStatisticsDialog from './components/lead-customer-statistics-dialog.vue'
86ade5ce   李宇   报表
182
183
184
  
  export default {
    name: 'StoreStatistics',
b1146e00   李宇   最新
185
186
187
    components: {
      LeadCustomerStatisticsDialog
    },
86ade5ce   李宇   报表
188
189
190
191
192
193
194
195
196
197
198
199
200
201
    data() {
      return {
        query: {
          startTime: undefined,
          endTime: undefined,
          storeIds: [],
          eventId: undefined
        },
        storeOptions: [],
        eventOptions: [],
        list: [],
        originalList: [], // 保存原始数据,用于取消排序时恢复
        listLoading: false,
        sortProp: '',
b1146e00   李宇   最新
202
203
204
205
206
207
208
209
        sortOrder: '',
        dialogVisible: false,
        dialogQuery: {
          startTime: undefined,
          endTime: undefined,
          eventId: undefined,
          storeIds: []
        }
86ade5ce   李宇   报表
210
211
      }
    },
8eb72f90   李宇   最新
212
213
214
215
216
217
218
    computed: {
      // 计算表格高度
      tableHeight() {
        // 根据视口高度动态计算,减去筛选条件等的高度
        return 'calc(100vh - 280px)'
      }
    },
86ade5ce   李宇   报表
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
    created() {
      this.setDefaultTimeRange()
      this.initStoreOptions()
      this.initEventOptions()
      this.search()
    },
    methods: {
      // 设置默认时间范围(本月1号到现在)
      setDefaultTimeRange() {
        const now = new Date()
        const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1)
        
        this.query.startTime = firstDayOfMonth.getTime()
        this.query.endTime = now.getTime()
      },
  
      // 初始化门店选项
      initStoreOptions() {
        request({
          url: '/api/Extend/LqMdxx',
          method: 'GET',
          data: {
            currentPage: 1,
            pageSize: 1000
          }
        }).then(res => {
          if (res.data && res.data.list) {
            this.storeOptions = res.data.list
          }
        }).catch(() => {
          this.storeOptions = []
        })
      },
  
      // 初始化拓客活动选项
      initEventOptions() {
        getLqEventList({
          page: 1,
          rows: 1000
        }).then(res => {
          if (res.code == 200 && res.data && res.data.list) {
            this.eventOptions = res.data.list
          } else {
            this.eventOptions = []
          }
        }).catch(() => {
          this.eventOptions = []
        })
      },
  
      // 处理排序变化
      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()
        })
      },
  
      // 查询数据
      search() {
        this.listLoading = true
  
        const params = {}
  
        if (this.query.startTime) {
          params.startTime = this.formatDateTimeISO(this.query.startTime)
        }
  
        if (this.query.endTime) {
          params.endTime = this.formatDateTimeISO(this.query.endTime)
        }
  
        if (this.query.storeIds && this.query.storeIds.length > 0) {
          params.storeIds = this.query.storeIds
        }
  
        if (this.query.eventId) {
          params.eventId = this.query.eventId
        }
  
        request({
          url: '/api/Extend/lqstatistics/get-store-statistics-list',
          method: 'POST',
          data: params
        }).then(res => {
          if (res.data && res.data.list) {
            this.list = res.data.list
            this.originalList = [...res.data.list] // 保存原始数据
          } else {
            this.list = []
            this.originalList = []
          }
          this.listLoading = false
        }).catch(err => {
          console.error('查询失败:', err)
          this.$message({
            type: 'error',
            message: '查询失败,请重试',
            duration: 1500
          })
          this.listLoading = false
          this.list = []
          this.originalList = []
        })
      },
  
      // 重置查询条件
      reset() {
        this.query = {
          startTime: undefined,
          endTime: undefined,
          storeIds: [],
          eventId: undefined
        }
        this.setDefaultTimeRange()
        this.sortProp = ''
        this.sortOrder = ''
        this.list = []
        this.originalList = []
        this.search()
      },
  
      // 格式化金额
      formatMoney(amount) {
        if (!amount && amount !== 0) return '0.00'
        return Number(amount).toFixed(2)
      },
  
36493279   李宇   最新
398
399
400
401
402
403
      // 格式化百分比
      formatPercentage(rate) {
        if (rate === null || rate === undefined) return '0.00'
        return Number(rate).toFixed(2)
      },
  
86ade5ce   李宇   报表
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
      // 格式化日期时间(用于API传参,ISO格式,保持本地时间不转换时区)
      formatDateTimeISO(timestamp) {
        if (!timestamp) return ''
        const date = new Date(timestamp)
        // 生成本地时间的 ISO 格式字符串,不进行时区转换
        // 使用本地时间的各个部分,格式化为 ISO 格式,末尾加 Z 以符合接口要求
        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')
        const milliseconds = String(date.getMilliseconds()).padStart(3, '0')
        // 使用本地时间的值,格式化为 ISO 格式(末尾加 Z 以符合接口格式要求)
        return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`
b1146e00   李宇   最新
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
      },
  
      // 处理门店名称点击事件
      handleStoreNameClick(row) {
        // 设置弹窗的查询条件:当前时间、活动、门店
        this.dialogQuery = {
          startTime: this.query.startTime,
          endTime: this.query.endTime,
          eventId: this.query.eventId,
          storeIds: row.StoreId ? [row.StoreId] : []
        }
        // 打开弹窗
        this.dialogVisible = true
      },
  
      // 处理弹窗关闭
      handleDialogClose() {
        this.dialogVisible = false
86ade5ce   李宇   报表
437
438
439
440
441
442
443
444
445
446
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .amount-paid {
    color: #67C23A;
    font-weight: 500;
  }
b1146e00   李宇   最新
447
448
449
450
451
452
  
  .store-name-link {
    &:hover {
      color: #66b1ff !important;
    }
  }
86ade5ce   李宇   报表
453
  </style>