personalPerformance.js
16.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
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/supervisor-miniprogram/'
import api from '~/api/crew/index'
const MERCHANT_DATA_LIST = [{
text: '总产值',
width: 240,
key: 'totalValue'
}, {
text: '客单价',
key: 'averagePrice',
width: 140
}, {
text: '总触客数',
key: 'totalCustomers',
width: 140
}, {
text: '总成交数',
key: 'totalDeals',
width: 140
}]
const INDEX_DATA_LIST = [
{
text: '总产值',
key: 'totalValue',
ratioKey: 'totalValueRate',
background: 'linear-gradient(90deg, #3d76fc 0%, #4da6ff 100%)',
width: 288,
tip: '当前员工+门店+业务+统计周期下,全部订单金额总和',
},
{
text: '客单价',
key: 'averagePrice',
ratioKey: 'averagePriceRate',
background: 'linear-gradient(90deg, #42cccf 0%, #36d9a5 100%)',
width: 208,
tip: '当前员工+门店+业务+统计周期下,产值/升级订单数',
},
{
text: '日报完成率',
key: 'dailyPerformanceRate',
background: 'linear-gradient(90deg, #5e69fff0 0%, #4079ffa6 100%)',
width: 192,
tip: '当前员工+门店+业务+统计周期下,完成日报天数/总天数',
},
]
const ANALYSE_ITEMS = [
{ id: 'preSalesContactCount', posClass: 'arrival', name: '触客数(售前)', key: 'preSaleCustomerCount', momKey: 'preSaleCustomerCountRate' },
{ id: 'afterSalesContactCount', posClass: 'after', name: '触客数(售后)', key: 'postSaleCustomerCount', momKey: 'postSaleCustomerCountRate' },
{ id: 'totalContactCount', posClass: 'total_to_store', name: '总触客数', key: 'customerCount', momKey: 'customerCountRate' },
{ id: 'preSalesConversionRate', posClass: 'sqzhuanhualv', name: '售前转化率', key: 'preSaleConversionRate', momKey: 'preSaleConversionRateRate', valueType: 'rate' },
{ id: 'afterSalesConversionRate', posClass: 'shzhuanhualv', name: '售后转化率', key: 'postSaleConversionRate', momKey: 'postSaleConversionRateRate', valueType: 'rate' },
{ id: 'conversionRate', posClass: 'percent', name: '转化率', key: 'conversionRate', momKey: 'conversionRateRate', valueType: 'rate' },
{ id: 'preSalesDealCount', posClass: 'sqordernum', name: '成交数(售前)', key: 'preSaleDealCount', momKey: 'preSaleDealCountRate' },
{ id: 'afterSalesDealCount', posClass: 'shordernum', name: '成交数(售后)', key: 'postSaleDealCount', momKey: 'postSaleDealCountRate' },
{ id: 'totalDealCount', posClass: 'make', name: '总成交数', key: 'dealCount', momKey: 'dealCountRate' },
]
const STATS_ITEMS = [
{
label: '整车延保',
key: 'yanbao',
dealCountKey: 'vehicleWarrantyDealCount',
penetrationRateKey: 'vehicleWarrantyPenetrationEmployee',
penetrationTargetKey: 'vehicleWarrantyPenetrationEmployeeDD',
conversionRateKey: 'vehicleWarrantyConversionRate',
conversionTargetKey: 'vehicleWarrantyConversionRateDD',
},
{
label: '安心包',
key: 'anxinbao',
dealCountKey: 'safetyPackDealCount',
penetrationRateKey: 'safetyPackPenetrationEmployee',
penetrationTargetKey: 'safetyPackPenetrationEmployeeDD',
conversionRateKey: 'safetyPackConversionRate',
conversionTargetKey: 'safetyPackConversionRateDD',
},
{
label: '轮胎',
key: 'luntai',
dealCountKey: 'tireDealCount',
penetrationRateKey: 'tirePenetrationEmployee',
penetrationTargetKey: 'tirePenetrationEmployeeDD',
conversionRateKey: 'tireConversionRate',
conversionTargetKey: 'tireConversionRateDD',
},
{
label: '电池',
key: 'dianchi',
dealCountKey: 'batteryDealCount',
penetrationRateKey: 'batteryPenetrationEmployee',
penetrationTargetKey: 'batteryPenetrationEmployeeDD',
conversionRateKey: 'batteryConversionRate',
conversionTargetKey: 'batteryConversionRateDD',
},
]
const QINGGAI_STATS_ITEMS = [
{
label: '原厂车窗膜',
key: 'chechuangmo',
dealCountKey: 'windowFilmCount',
avgOutputKey: 'windowFilmValue',
penetrationRateKey: 'windowFilmPenetrationEmployee',
penetrationTargetKey: '',
conversionRateKey: 'windowFilmConversion',
conversionTargetKey: '',
},
{
label: '原厂车身膜',
key: 'cheshenmo',
dealCountKey: 'bodyFilmDealCount',
avgOutputKey: 'bodyFilmValue',
penetrationRateKey: 'bodyFilmPenetrationEmployee',
penetrationTargetKey: '',
conversionRateKey: 'bodyFilmConversion',
conversionTargetKey: '',
},
{
label: '原厂精品附件',
key: 'jingpin',
dealCountKey: 'accessoriesDealCount',
avgOutputKey: 'accessoriesValue',
penetrationRateKey: 'accessoriesPenetrationEmployee',
penetrationTargetKey: '',
conversionRateKey: 'accessoriesConversion',
conversionTargetKey: '',
},
]
const HELP_TEXT_DEFAULT = [
{ title: '触客数(售前)', content: '当前员工+门店+业务+统计周期下,全部触客数(售前)之和。' },
{ title: '触客数(售后)', content: '当前员工+门店+业务+统计周期下,全部触客数(售后)之和。' },
{ title: '总触客数', content: '当前员工+门店+业务+统计周期下,全部触客数之和。' },
{ title: '成交数(售前)', content: '当前员工+门店+业务+统计周期下,售前流量成交的订单数。' },
{ title: '成交数(售后)', content: '当前员工+门店+业务+统计周期下,售后流量成交的订单数。' },
{ title: '总成交数', content: '当前员工+门店+业务+统计周期下,成交的总订单数。' },
{ title: '售前转化率', content: '当前员工+门店+业务+统计周期下,成交数(售前)/触客数(售前)。' },
{ title: '售后转化率', content: '当前员工+门店+业务+统计周期下,成交数(售后)/触客数(售后)。' },
{ title: '转化率', content: '当前员工+门店+业务+统计周期下,总成交数/总触客数。' },
]
const HELP_TEXT_QINGGAI = [
{ title: '触客台次', content: '当前员工+门店+业务+统计周期下,全部触客台次之和。' },
{ title: '转化率', content: '当前员工+门店+业务+统计周期下,总成交数/触客台次。' },
{ title: '总成交量', content: '当前员工+门店+业务+统计周期下,成交的总订单数。' },
]
const formatDash = (val) => {
if (val === null || val === undefined) return '-'
if (typeof val === 'string' && val.trim() === '') return '-'
return String(val)
}
const toNumber = (v) => {
if (v === null || v === undefined) return null
if (typeof v === 'number') return isNaN(v) ? null : v
const s = String(v).trim()
if (!s) return null
const n = Number(s.replace(/[,%\s]/g, ''))
return isNaN(n) ? null : n
}
const formatNumber = (v) => {
const n = toNumber(v)
if (n === null) return '-'
const str = String(n).includes('.') ? n.toFixed(2).replace(/\.?0+$/, '') : String(n)
return formatThousands(str)
}
const formatThousands = (v) => {
const s = String(v)
if (!s) return s
const isNeg = s[0] === '-'
const raw = isNeg ? s.slice(1) : s
const [intPart, decPart] = raw.split('.')
const intFmt = String(intPart || '0').replace(/\B(?=(\d{3})+(?!\d))/g, ',')
const res = decPart ? `${intFmt}.${decPart}` : intFmt
return isNeg ? `-${res}` : res
}
const parseNumeric = (val) => {
const s = typeof val === 'string' ? val.trim() : val
if (s === null || s === undefined || (typeof s === 'string' && s === '')) return null
const n = typeof s === 'number' ? s : parseFloat(String(s).replace(/[^\d.\-]/g, ''))
if (Number.isNaN(n)) return null
return n
}
const getValueColor = (val) => {
let n = null
if (typeof val === 'string') {
const cleaned = val.replace(/%/g, '').replace(/,/g, '')
n = parseFloat(cleaned)
if (isNaN(n)) n = null
} else if (typeof val === 'number') {
n = val
} else {
n = null
}
if (n === null) return '#999ea8'
if (n > 0) return '#FF0000'
if (n < 0) return '#35C376'
return '#FF9D0A'
}
const getMomArrow = (val) => {
const parsePercentage = (value) => {
if (typeof value !== 'string') return parseNumeric?.(value) ?? null
const cleaned = value.replace(/%/g, '').replace(/,/g, '')
const num = parseFloat(cleaned)
return isNaN(num) ? null : num
}
const n = parsePercentage(val)
if (n === null) return ''
if (n > 0) return `${IMG_URL}icon-red-rise.png`
if (n < 0) return `${IMG_URL}icon-green-decline.png`
return `${IMG_URL}just01.png`
}
const getIndexMomArrow = (val) => {
const parsePercentage = (value) => {
if (typeof value !== 'string') return parseNumeric?.(value) ?? null
const cleaned = value.replace(/%/g, '').replace(/,/g, '')
const num = parseFloat(cleaned)
return isNaN(num) ? null : num
}
const n = parsePercentage(val)
if (n === null) return ''
if (n > 0) return `${IMG_URL}rise.png`
if (n < 0) return `${IMG_URL}decline.png`
return `${IMG_URL}icon-white-just01.png`
}
const getQueryTypeFromDateScreen = (ctx) => {
const comp = ctx.selectComponent('#dateScreen')
const dateCurrent = comp?.data?.dateCurrent
if (dateCurrent === 1) return 'week'
if (dateCurrent === 2) return 'month'
return 'day'
}
Component({
properties: {
detailInfo: {
type: Object,
value: {},
observer: function () {
},
},
selectedMerchantObj: {
type: Object
},
merchantList: {
type: Array
},
initTimeDimension: {
type: Number,
value: -1
},
initStartDate: {
type: String,
value: ''
},
initEndDate: {
type: String,
value: ''
}
},
data: {
IMG_URL,
dateRange: { startDay: '', endDay: '' },
statCards: [],
analyseChunks: [],
businessStatsRows: [],
showSummaryAnalysis: true,
helpVisible: false,
helpTextArr: [],
tipsText: '',
tipsTitle: '',
trendList: [],
IMG_URL,
opts: {
keys: ['time', 'output', 'predictOutput'],
color: '#D1D7F5',
lineColr: '#2C66F7',
tickCount: 10
},
lineData: []
},
methods: {
_beginRequest() {
this._reqSeq = (this._reqSeq || 0) + 1
return this._reqSeq
},
_isLatestRequest(seq) {
return seq === this._reqSeq
},
onDateSearch(e) {
this.setData({
startStr: e.detail.startDay?.replace(/\//g, '-'),
endStr: e.detail.endDay?.replace(/\//g, '-'),
dateType: e.detail.timeDimension
}, () => {
this.refreshViewModel()
})
this.triggerEvent('datesave', {
scope: 'personalPerformance',
timeDimension: e.detail.timeDimension,
startDate: e.detail.startDay,
endDate: e.detail.endDay
}, { bubbles: true, composed: true })
},
openHelp(e) {
this._helpDialogSeq = (this._helpDialogSeq || 0) + 1
const { target } = e?.currentTarget?.dataset || {}
this.setData({
tipsTitle: target?.text || '',
tipsText: target?.tip || '',
helpVisible: true
})
},
closeHelp() {
const seq = (this._helpDialogSeq = (this._helpDialogSeq || 0) + 1)
this.setData({
helpVisible: false,
})
setTimeout(() => {
if (this._helpDialogSeq !== seq) return
if (this.data.helpVisible) return
this.setData({
tipsTitle: '',
tipsText: ''
})
}, 350)
},
async refreshViewModel() {
const seq = this._beginRequest()
let { detailInfo, startStr, endStr, dateType, selectedMerchantObj } = this.data
let params = {
employeePhone: detailInfo.employeePhone,
employeeId: selectedMerchantObj?.employeeId,
dateType,
bizs: detailInfo.scene,
startDate: startStr,
endDate: endStr,
merchantId: selectedMerchantObj?.merchantId
}
wx.$util.showLoading()
api.getEmployeePerformanceData(params).then(res => {
if (!this._isLatestRequest(seq)) return
wx.$util.hideLoading()
let { code, data, message } = res
if (code == 0) {
const staffData = data?.employeeData || {}
const merchantData = data?.storeData || {}
const showSummaryAnalysis = detailInfo?.scene == 1 || detailInfo?.scene == 2
const statMerchants = MERCHANT_DATA_LIST.map((item) => {
const value = formatNumber(merchantData[item.key])
return {...item, value}
})
const statCards = INDEX_DATA_LIST.map((item) => {
const value = item.key === 'dailyPerformanceRate' ? staffData[item.key] : formatNumber(staffData[item.key])
const momRaw = item.ratioKey ? staffData[item.ratioKey] : '-'
const momValue = item.ratioKey ? momRaw || '-' : '-'
const momColor = item.ratioKey ? getValueColor(momRaw) : '#999EA8'
const momArrow = item.ratioKey ? getIndexMomArrow(momRaw) : ''
return {
...item,
value,
momValue,
momColor,
momArrow,
showMom: !!item.ratioKey,
}
})
const analyseChunks = ANALYSE_ITEMS.map((item) => {
const raw = (staffData[item.key] ?? '') === '' ? '-' : staffData[item.key]
const momRaw = (staffData[item.momKey] ?? '') === '' ? '-' : staffData[item.momKey]
const value = item.valueType === 'rate' ? raw : formatDash(raw)
const momValue = momRaw
return {
id: item.id,
posClass: item.posClass,
name: item.name,
valueType: item.valueType || 'count',
value: item.valueType === 'rate' ? '' : value,
rateValue: item.valueType === 'rate' ? value : '',
momValue,
momColor: getValueColor(momRaw),
momArrow: getMomArrow(momRaw),
showMom: true,
}
})
const sourceItems = detailInfo?.scene == 2 ? QINGGAI_STATS_ITEMS : STATS_ITEMS
const businessStatsRows = sourceItems.map((item) => {
if (detailInfo?.scene == 2) {
return {
key: item.key,
label: item.label,
cols: [
{ label: '成交数', value: (staffData?.[item.dealCountKey] ?? '') === '' ? '-' : staffData?.[item.dealCountKey] },
{ label: '单车采购产值', value: (staffData?.[item.avgOutputKey] ?? '') === '' ? '-' : staffData?.[item.avgOutputKey], colClass: 'width-col' },
{ label: '渗透率', value: (staffData?.[item.penetrationRateKey] ?? '') === '' ? '-' : staffData?.[item.penetrationRateKey], colorClass: 'blue' },
{ label: '转化率', value: (staffData?.[item.conversionRateKey] ?? '') === '' ? '-' : staffData?.[item.conversionRateKey], colorClass: 'blue' },
],
}
}
const penetrationTarget = item.penetrationTargetKey ? staffData?.[item.penetrationTargetKey] : '-'
const conversionTarget = item.conversionTargetKey ? staffData?.[item.conversionTargetKey] : '-'
return {
key: item.key,
label: item.label,
cols: [
{ label: '成交数', value: (staffData?.[item.dealCountKey] ?? '') === '' ? '-' : staffData?.[item.dealCountKey] },
{ label: '渗透率', value: item.penetrationRateKey && (staffData?.[item.penetrationRateKey] ?? '') !== '' ? staffData?.[item.penetrationRateKey] : '-', subLabel: penetrationTarget === '-' ? '' : `兜底目标${(penetrationTarget ?? '') === '' ? '-' : penetrationTarget}`, colorClass: 'blue' },
{ label: '转化率', value: item.conversionRateKey && (staffData?.[item.conversionRateKey] ?? '') !== '' ? staffData?.[item.conversionRateKey] : '-', subLabel: conversionTarget === '-' ? '' : `兜底目标${(conversionTarget ?? '') === '' ? '-' : conversionTarget}`, colorClass: 'blue' },
],
}
})
const helpTextArr = HELP_TEXT_DEFAULT
this.getTrendList()
this.setData({
statMerchants,
statCards,
analyseChunks,
businessStatsRows,
showSummaryAnalysis,
helpTextArr
})
} else {
wx.$util.showToast(message)
}
}).catch(() => {
if (!this._isLatestRequest(seq)) return
wx.$util.hideLoading()
})
},
// 获取个人产值趋势及达成率
getTrendList() {
const seq = this._beginRequest()
let { detailInfo, startStr, endStr, dateType, selectedMerchantObj } = this.data
let params = {
staffUuids: [selectedMerchantObj?.employeeId],
cycleType: dateType,
bizs: detailInfo.scene,
startTime: startStr,
endTime: endStr,
merchantIds: [selectedMerchantObj?.merchantId]
}
api.getEmployeeOutPutTrendApi(params).then(res => {
if (!this._isLatestRequest(seq)) return
let { code, data, message } = res
if (code == 0) {
data?.list?.forEach((val, index) => {
val.predictOutput = data?.listpredict?.[index] ? data?.listpredict?.[index].output: ''
})
this.setData({trendList: data?.list || []})
} else {
wx.$util.showToast(message)
}
})
},
handleChangeMerchant(e) {
let { merchantList, selectedMerchantObj } = this.data
this.setData({
showSelectPopup: true,
selectOptions: merchantList,
selectValue: selectedMerchantObj.merchantId ? [selectedMerchantObj.merchantId] : []
})
this.triggerEvent('changeMerchant', true)
},
handlePopupConfirm(e) {
let { items } = e.detail
let thisPage = wx.$router.getPageInstance()
thisPage.setData({
selectedMerchantObj: {
merchantId: items[0].merchantId,
merchantName: items[0]?.merchantName,
employeeId: items[0].employeeId
}
}, () => {
this.refreshViewModel()
})
this.hideSelectPopup()
},
hideSelectPopup() {
this.setData({
showSelectPopup: false
})
this.triggerEvent('changeMerchant', false)
},
},
})