AInicheOverview.js
18.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
;(function (angular) {
function AInicheOverview ($scope, aiNicheService,DTOptionsBuilder, DTColumnBuilder, $rootScope, toaster, Utils) {
$scope.tabActive = 1
// 跳转 活动列表 保养线索 流失线索 拦截
$scope.activityFlag = false
$scope.jumpLink = function(name, target) {
checkPermission(name, $scope.menuList, target)
if ($scope[target]) {
//跳往一件营销
$scope.jumpActivity()
} else {
toaster.pop({
type: 'error',
body: '您暂未开通该服务,请联系客服处理',
showCloseButton: true,
timeout: 3000
})
}
}
function checkPermission(pageTitle, data, name) {
angular.forEach(data, function(e) {
if (e.children) {
checkPermission(pageTitle, e.children, name)
} else {
if (e.pageTitle == pageTitle) {
$scope[name] = true
}
}
})
}
$scope.repairCount = {}
$scope.tabCbk = function (index) {
if (index == 1) {
if ($scope.chart4) destroyObj('chart4')
if ($scope.chart5) destroyObj('chart5')
if ($scope.chart6) destroyObj('chart6')
if ($scope.chart7) destroyObj('chart7')
if ($scope.chart8) destroyObj('chart8')
} else if (index == 2) {
if ($scope.chart1) destroyObj('chart1')
if ($scope.chart2) destroyObj('chart2')
if ($scope.chart3) destroyObj('chart3')
if ($scope.chart6) destroyObj('chart6')
if ($scope.chart7) destroyObj('chart7')
if ($scope.chart8) destroyObj('chart8')
} else if (index == 3) {
if ($scope.chart1) destroyObj('chart1')
if ($scope.chart2) destroyObj('chart2')
if ($scope.chart3) destroyObj('chart3')
if ($scope.chart4) destroyObj('chart4')
if ($scope.chart5) destroyObj('chart5')
if ($scope.chart8) destroyObj('chart8')
} else if (index == 4) {
if ($scope.chart1) destroyObj('chart1')
if ($scope.chart2) destroyObj('chart2')
if ($scope.chart3) destroyObj('chart3')
if ($scope.chart4) destroyObj('chart4')
if ($scope.chart5) destroyObj('chart5')
if ($scope.chart6) destroyObj('chart6')
if ($scope.chart7) destroyObj('chart7')
aiNicheService.getCollisionStatementFunnelCount(function (res) {
if (res.returnCode == '0') {
$scope.repairCount.totalCount = res.data.totalCount
$scope.repairCount.followedCount = res.data.followedCount
$scope.repairCount.shopCount = res.data.shopCount
}
})
}
$scope.tabActive = index
}
function destroyObj (chart) {
if ($scope[chart]) $scope[chart].destroy()
$scope[chart] = null
}
$scope.chart1 = null
$scope.chart2 = null
$scope.chart3 = null
$scope.chart4 = null
$scope.chart5 = null
$scope.chart6 = null
$scope.chart7 = null
$scope.chart8 = null
// 保养卡list数据
$scope.reverseData1 = []
$scope.data1 = []
$scope.data2 = []
$scope.data3 = []
$scope.data4 = []
$scope.data5 = []
$scope.data6 = []
$scope.data7 = []
$scope.data8 = []
$scope.cardList = [
{
name: '保养到期客户',
cardTpe: '推荐:常规保养卡服务',
content: '预计达成交易用户25%,平均客单价800元,带来经济收益10000元。'
}, {
name: '服务半径外客户',
cardTpe: '推荐:基础保养卡服务',
content: '预计达成交易用户20%,平均客单价600元,带来经济收益8000元。'
}, {
name: '流失客户',
cardTpe: '推荐:5折保养券',
content: '预计达成交易用户20%,平均客单价300元,带来经济收益6000元。'
}
]
$scope.bgColor = [{}, {}, {}, {}, {}, {}]
var rankColor = ['#01C292', '#3090FF', '#00B0FF', '#12DCAA', '#FFAB00', '#FFD600']
// 可以通过调整这个数值控制分割空白处的间距,0-1 之间的数值
var sliceNumber = 0.005
// 自定义 other 的图形,增加两条线
G2.Shape.registerShape('interval', 'sliceShape', {
draw: function draw (cfg, container) {
var points = cfg.points
var path = []
path.push(['M', points[0].x, points[0].y])
path.push(['L', points[1].x, points[1].y - sliceNumber])
path.push(['L', points[2].x, points[2].y - sliceNumber])
path.push(['L', points[3].x, points[3].y])
path.push('Z')
path = this.parsePath(path)
return container.addShape('path', {
attrs: {
fill: cfg.color,
path: path
}
})
}
})
$scope.noData1 = false
$scope.lossAuth = false
$scope.maintainAuth = false
$scope.shopAuth = false
$scope.repairAuth = true
$scope.$watch('tabActive', function () {
if ($scope.tabActive == 1) {
$scope.loss.lossSelect = ''
// 判断权限
checkPermission('流失线索', $scope.menuList, 'lossAuth')
if ($scope.lossAuth) {
// 线索,柱状图
aiNicheService.getCountLossCustomer(function (res) {
if (res.returnCode == '0') {
if (res.data[0].total == 0 || res.data[0].total == null) {
$scope.noData1 = true
} else {
$scope.reverseData1 = JSON.parse(JSON.stringify(res.data))
$scope.data1 = res.data.reverse()
// $scope.data1 = [{merchantName: '4545', number: 1}, {merchantName: 'ff', number: 0}]
}
} else {
$scope.noData1 = true
}
$scope.chart1 = new G2.Chart({
container: document.getElementById('columnarNode'),
forceFit: true,
padding: [30, 30, 40, 140],
height: 268
})
$scope.chart1.source($scope.data1)
$scope.chart1.axis('merchantName', {
line: {
storke: '#14BA8E'
},
label: {
textStyle: {
fontSize: '11',
fill: '#888888',
textAlign: 'right'
}
}
})
$scope.chart1.scale('number', {
alias: '次数',
nice: true,
minTickInterval: 2
})
$scope.chart1.coord().transpose()
$scope.chart1.interval().position('merchantName*number').size(10).color('number', ['#14BA8E'])
$scope.chart1.render()
})
} else {
$scope.noData1 = true
}
// 按时间(未返店)
aiNicheService.getMileageClassifyMonth(function (res) {
var total = '- -'
if ($scope.lossAuth && res.returnCode == '0') {
$scope.data2 = res.data
total = res.data[res.data.length - 1].total
}
$scope.chart2 = new G2.Chart({
container: document.getElementById('timeNode'),
forceFit: true,
height: 200,
padding: [30],
options: {
legends: false
}
})
// var total = res.data.length == 0 && res.data ? $scope.data2[0].total : res.data[0].total
drawChart($scope.data2, $scope.chart2, '总量', total)
})
// 按里程
aiNicheService.getMileageClassifyNoShop(function (res) {
var total = '- -'
if ($scope.lossAuth && res.returnCode == '0') {
$scope.data3 = res.data
total = res.data[0].total
}
$scope.chart3 = new G2.Chart({
container: document.getElementById('mileageNode'),
forceFit: true,
height: 200,
padding: [30],
options: {
legends: false
}
})
drawChart($scope.data3, $scope.chart3, '总量', total)
})
} else if ($scope.tabActive == 2) {
$scope.loss.lossSelect = ''
checkPermission('保养线索', $scope.menuList, 'maintainAuth')
// 保养线索,总里程
aiNicheService.getCountTotalClassify(function (res) {
var total = '- -'
if ($scope.maintainAuth && res.returnCode == '0') {
$scope.data4 = res.data
total = res.data[0].total
}
$scope.chart4 = new G2.Chart({
container: document.getElementById('mileageTotal'),
forceFit: true,
height: 200,
padding: [30],
options: {
legends: false
}
})
// var total = res.data.length == 0 ? $scope.data4[0].total : res.data[0].total
drawChart($scope.data4, $scope.chart4, '总人数', total)
})
// 保养线索,距离上次到店里程
aiNicheService.getMileageClassify(function (res) {
var total = '- -'
if ($scope.maintainAuth && res.returnCode == '0') {
$scope.data5 = res.data
total = res.data[0].total
}
$scope.chart5 = new G2.Chart({
container: document.getElementById('lastMileage'),
forceFit: true,
height: 200,
padding: [30],
options: {
legends: false
}
})
// var total = res.data.length != 0 ? $scope.data5[0].total : res.data[0].total
drawChart($scope.data5, $scope.chart5, '总人数', total)
})
} else if ($scope.tabActive == 3) {
checkPermission('到店线索', $scope.menuList, 'shopAuth')
// 到店线索,忠诚客户分析
aiNicheService.getClassifyYearBackCount(function (res) {
var total = '- -'
if ($scope.shopAuth && res.returnCode == '0') {
$scope.data6 = res.data
total = res.data[0].total
}
$scope.chart6 = new G2.Chart({
container: document.getElementById('loyalCustomer'),
forceFit: true,
height: 200,
padding: [30],
options: {
legends: false
}
})
// var total = res.data.length == 0 ? $scope.data6[0].total : res.data[0].total
drawChart($scope.data6, $scope.chart6, '总人数', total)
})
$scope.loss.lossSelect = '1'
} else if ($scope.tabActive == 4) {
$scope.loss.lossSelect = ''
// checkPermission('送修线索', $scope.menuList, 'repairAuth')
aiNicheService.getCollisionStatementDisposeTimeCount(function (res) {
var total = '- -'
if ($scope.repairAuth && res.returnCode == '0') {
$scope.data8 = res.data
var arr = ['1分钟内', '1~3分钟', '3~5分钟', '5~60分钟', '1~24小时', '24小时以上']
$scope.data8.forEach((item, index) => {
item.remark = arr[index]
})
$scope.data8.total = res.data.totalCount
total = res.data[0].totalCount
}
$scope.chart8 = new G2.Chart({
container: document.getElementById('repairNode'),
forceFit: true,
height: 200,
padding: [30],
options: {
legends: false
}
})
var bgColor = ['#01C292', '#3090FF', '#00B0FF', '#12DCAA', '#FFAB00', '#FFD600']
angular.forEach($scope.data8, function (item, index) {
$scope.bgColor[index]['background-color'] = rankColor[index]
})
if (total == 0 || total == '- -') {
var info = [{
count: 1,
remark: 1
}]
$scope.chart8.source(info)
bgColor = ['#CFD3D5']
$scope.chart8.tooltip(false)
} else {
$scope.chart8.source($scope.data8)
$scope.chart8.tooltip({
showTitle: false
})
}
$scope.chart8.coord('theta', {
innerRadius: 0.75
})
$scope.chart8.guide().html({
position: ['50%', '50%'],
html: `<div class="g2-guide-html"><div class="value">${total}</div><div class="title">总量</div></div>`
})
$scope.chart8.intervalStack().position('count').color('remark', bgColor).shape('sliceShape')
$scope.chart8.render()
// drawChart($scope.data8, $scope.chart8, '总量', total)
})
}
})
$scope.loss = {}
$scope.$watch('loss.lossSelect', function () {
if ($scope.chart7) $scope.chart7.destroy()
if ($scope.loss.lossSelect == '1') {
getCountClassifyDistance()
} else if ($scope.loss.lossSelect == '2') {
getNoCountTotalMileageClassify()
}
}, true)
function getCountClassifyDistance() {
checkPermission('到店线索', $scope.menuList, 'shopAuth')
// 未返厂客户分析
aiNicheService.getCountClassifyDistance(function (res) {
var total = '- -'
if ($scope.shopAuth && res.returnCode == '0') {
$scope.data7 = res.data
total = res.data[0].total
}
drawShop(res.data, total)
})
}
function getNoCountTotalMileageClassify () {
aiNicheService.getNoCountTotalMileageClassify(function (res) {
var total = '- -'
if (res.returnCode == '0') {
$scope.data7 = res.data
total = res.data[0].total
}
drawShop(res.data, total)
})
}
function drawShop (data, total) {
$scope.chart7 = new G2.Chart({
container: document.getElementById('notReturned'),
forceFit: true,
height: 200,
padding: [30],
options: {
legends: false
}
})
// var total = data.length == 0 ? $scope.data7[0].total : data[0].total
drawChart($scope.data7, $scope.chart7, '总人数', total)
}
$scope.changeDate = function(){
// $scope.dataType = 0;
$scope.sTime = ''
$scope.eTime = ''
$scope.searchForm.dateRange = {}
var params = getParams()
// if (params.sTime) delete params.sTime
// if (params.eTime) delete params.eTime
$scope.dtInstance.query(params)
}
// $scope.dateRange = {
// startDate: moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
// endDate: moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')
// }
$scope.searchForm = {}
$scope.drOptions = {
opens: 'right',
eventHandlers: {
'apply.daterangepicker':function(ev, picker){
$scope.sTime = picker.startDate.format('YYYY-MM-DD HH:mm:ss');
$scope.eTime = picker.endDate.format('YYYY-MM-DD HH:mm:ss');
$scope.searchForm.dateRange = {
startDate: picker.startDate,
endDate: picker.endDate
}
var params = getParams();
$scope.dtInstance.query(params)
$scope.$apply();
},
'cancel.daterangepicker': function (ev, picker) {
$scope.sTime = '';
$scope.eTime = '';
$scope.searchForm.dateRange = {}
var params = getParams();
$scope.dtInstance.query(params)
$scope.$apply()
}
}
};
$scope.dtColumns = [
DTColumnBuilder.newColumn('merchantName').withOption('width',160).withTitle('店面名称'),
DTColumnBuilder.newColumn('precentage').withOption('width', 120).withTitle('占比').renderWith(function (e, dt, rowData, config) {
return rowData.precentage + '%'
}),
DTColumnBuilder.newColumn('collisionCount').withOption('width',120).withTitle('线索总数'),
DTColumnBuilder.newColumn('followCount').withOption('width',120).withTitle('已跟进'),
DTColumnBuilder.newColumn('notFollowCount').withOption('width',120).withTitle('暂未跟进'),
];
$scope.dtOptions = DTOptionsBuilder.newOptions()
$scope.dtInstance = {
serverData : aiNicheService.countGroupByMerchant
};
function getParams(){
var obj = {};
if ($scope.factoryMerchantId) obj.factoryMerchantId = $scope.factoryMerchantId
if ($scope.provinceMerchantId) obj.provinceMerchantId = $scope.provinceMerchantId
if ($scope.cityMerchantId) obj.cityMerchantId = $scope.cityMerchantId
if ($scope.shopMerchantId) obj.merchantId = $scope.shopMerchantId
if ($scope.sTime) obj.sTime = $scope.sTime
if ($scope.eTime) obj.eTime = $scope.eTime
var options = {}
options.condition = obj
return options;
}
$scope.$watch('factoryMerchantId + provinceMerchantId + cityMerchantId + shopMerchantId', function(val) {
if (val || val == '') {
var params = getParams()
$scope.dtInstance.query(params)
}
})
// 导出
$scope.exportExcel = function () {
// if ($scope.isExporting) return;
var params = getParams().condition;
// $scope.isExporting = true;
var title = '送修线索';
Utils.exportExcel3("collision/exportCountGroupByMerchant", params, title, 'GET', function () {
// $scope.isExporting = false;
})
}
// 画圆环的公共方法
// data: 数据的数组
function drawChart(data, chart, totalName, total) {
var bgColor = ['#01C292', '#3090FF', '#00B0FF', '#12DCAA', '#FFAB00', '#FFD600']
angular.forEach(data, function (item, index) {
$scope.bgColor[index]['background-color'] = rankColor[index]
})
if (total == 0 || total == '- -') {
var info = [{
number: 1,
name: 1
}]
chart.source(info)
bgColor = ['#CFD3D5']
chart.tooltip(false)
} else {
chart.source(data)
chart.tooltip({
showTitle: false
})
}
chart.coord('theta', {
innerRadius: 0.75
})
chart.guide().html({
position: ['50%', '50%'],
html: `<div class="g2-guide-html"><div class="value">${total}</div><div class="title">${totalName}</div></div>`
})
chart.intervalStack().position('number').color('name', bgColor).shape('sliceShape')
chart.render()
}
function checkPermission (pageTitle, data, name) {
angular.forEach(data, function (e) {
if (e.children) {
checkPermission(pageTitle, e.children, name)
} else {
if (e.pageTitle == pageTitle) {
$scope[name] = true
}
}
})
}
}
angular.module('AIniche').controller('AInicheOverview', AInicheOverview)
})(angular)