controllers.js
21.3 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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/* global angular */
(function (angular) {
/**
* MainCtrl - controller
*/
function MainCtrl($scope, routeConfig, $stateParams, commonResource,webSocketService, $location, $window, $state, $timeout, $uibModal, $rootScope, $http, $interval, localStorageService) {
// $scope.modalShow = false
// $scope.topShow = false
// $interval(function(){
// announce()
// }, 10000);
$scope.routeParams = $stateParams;
// this.helloText = '欢迎访问广联运营平台';
// this.descriptionText = '系统功能描述';
$scope.personalInfo = false
routeConfig.initedPromise.then(function (data) {
$scope.menuList = data.menuList;
checkPermission('个人信息', $scope.menuList, 'personalInfo')
});
$scope.safeApply = function (fn) {
var phase = this.$root.$$phase;
if (phase == '$apply' || phase == '$digest') {
if (fn && (typeof (fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
$scope.userInfo = {
islogin: false,
name: ''
};
$rootScope.loginUser = {};
$scope.checkMessageTask = null;
$scope.logout = function () {
if ($scope.checkMessageTask != null) {
window.clearInterval($scope.checkMessageTask);
}
$window.location.href = 'logout';
localStorageService.set('isLogout', true);
};
$scope.connectSocket = function(){
commonResource.getWsConfig(function(result){
if(result && result.sessionId){
webSocketService.connect(result.url,result.sessionId,result.unionId);
// webSocketService.addEventListner('test',function(message){
// console.log("1111",message,this);
// })
}else{
console.warn("get ws sessionId fail");
}
});
}
commonResource.getLoginUser(function (result) {
if (result) {
var data = result;
if (data) {
// console.log(data)
commonResource.getAllUserTypeList(function (res) {
$rootScope.allUserTypeList = res.data;
});
$rootScope.loginUser = data;
$scope.userInfo.islogin = true;
$scope.userInfo.name = data.userType == 1 ? data.employeeName : data.merchantName;
$rootScope.queryNotReadMessageCount();
$scope.lastestMsgList();
$rootScope.showNavBar = true
if ($rootScope.loginUser.channelConfig.channelType != 2) {
$rootScope.operationIssue = 'https://www.kancloud.cn/glsx/d1_1/1334599'
$rootScope.operationGuide = 'https://www.kancloud.cn/glsx/d1_1/1347364'
$rootScope.operationFunction = 'https://www.kancloud.cn/glsx/d1_1/1347371'
} else {
$rootScope.operationIssue = 'https://www.kancloud.cn/lianghh/bb_01/1348275' //运营栏常见问题 默认爱车保镖平台
$rootScope.operationGuide = 'https://www.kancloud.cn/lianghh/bb_01/1348283' //运营栏新手指引 默认爱车保镖平台
$rootScope.operationFunction = 'https://www.kancloud.cn/lianghh/bb_01/1348289' //运营栏功能亮点 默认爱车保镖平台
}
if ($scope.checkMessageTask != null) {
window.clearInterval($scope.checkMessageTask);
}
$rootScope.openPrivacyPolicy()
$scope.checkMessageTask = window.setInterval(function () {
$rootScope.queryNotReadMessageCount();
$scope.lastestMsgList();
}, 1000 * 60 * 5);
// }, 5000)
$scope.connectSocket();
} else {
$location.path('login')
}
if (data.needChangePassword) {
checkSwalInit()
}
}
});
// 公共方法
$rootScope.PressKey = function (k, el) {
var oEvent = document.createEvent('KeyboardEvent');
// Chromium Hack
Object.defineProperty(oEvent, 'keyCode', {
get: function () {
return this.keyCodeVal;
}
});
Object.defineProperty(oEvent, 'which', {
get: function () {
return this.keyCodeVal;
}
});
if (oEvent.initKeyboardEvent) {
oEvent.initKeyboardEvent("keyup", true, true, document.defaultView, false, false, false, false, k, k);
} else {
oEvent.initKeyEvent("keyup", true, true, document.defaultView, false, false, false, false, k, 0);
}
oEvent.keyCodeVal = k;
if (oEvent.keyCode !== k) {
console.log("keyCode mismatch " + oEvent.keyCode + "(" + oEvent.which + ")");
}
el.dispatchEvent(oEvent);
}
/**一键营销 --跳转活动列表 */
$rootScope.jumpActivity = function () {
localStorage.setItem('activitySatus', 'marketing.shopactivity.shoplist')
localStorage.setItem('isNewWindow', 0)
window.open('#/home/index', '_blank')
}
// 公告中心-页面跳转
$scope.jumpCenter = function () {
$state.go('home.announceCenter')
$rootScope.breadcrumb = ['公告管理', '公告中心']
}
//顶部菜单页面跳转
$scope.menuJump = function (url, click) {
if (click) {
if ($state.current.name == url) {
$uibModal.open({
animation: true,
templateUrl: 'editModal.html',
controller: 'editModalCtrl',
size: 'md',
resolve: {
detail: function () {
return $scope.detail
}
}
})
} else {
sessionStorage.setItem('isChangePwd', true)
}
}
$state.go(url)
}
// 未读消息数
$rootScope.notReadMessageCout = 0;
$rootScope.queryNotReadMessageCount = function () {
var params = {};
params.method = 'glsx.accounts.bulletin.message.unread.count';
commonResource.gopRouter(params, function (res) {
if (res.code == "0") {
$rootScope.notReadMessageCout = res.data.unreadCount;
$rootScope.noticeUnreadCount = res.data.noticeUnreadCount;
$rootScope.activityUnreadCount = res.data.activityUnreadCount;
$rootScope.advertisingUnreadCount = res.data.advertisingUnreadCount;
} else {
$rootScope.notReadMessageCout = 0;
$rootScope.noticeUnreadCount = 0;
$rootScope.activityUnreadCount = 0;
$rootScope.advertisingUnreadCount = 0;
}
});
}
function lastest(obj) {
console.log(obj)
obj.activityTime = obj.activityTime ? obj.activityTime.replace('00:00:00', '').replace('23:59:59', '') : null
switch (obj.bulletinType) {
case 1:
obj.bulletinName = "通知"
break
case 2:
obj.bulletinName = "活动"
break
case 3:
obj.bulletinName = "广告"
break
}
if (obj.showType == 1) {
setTimeout(function () {
obj.showType = null
$scope.$apply()
// setTimeout(function () {
// obj = {}
// }, 4000)
}, 9000) // 动画时间4s
} else {
$rootScope.titile = obj.titile
$rootScope.showGG = true
}
if (obj.messageId) {
var params = {};
params.messageId = obj.messageId
params.modifyType = 1
params.method = 'glsx.accounts.bulletin.message.modify.status';
commonResource.gopRouter(params, function (res) {});
}
}
// 获取最新消息
$scope.lastestMsg = {}
$scope.lastestMsgList = function () {
var params = {};
params.method = 'glsx.accounts.bulletin.message.latest';
commonResource.gopRouter(params, function (res) {
if (res.code == "0" && res.data.bulletinId != '') {
// res.data.publishStatus == 3 ?
// $rootScope.showGG = false: res.data.showType == 1 ?
// $scope.popLasetMsg = res.data && lastest($scope.popLasetMsg) : $scope.lastestMsg = res.data && lastest($scope.lastestMsg)
if (res.data.publishStatus == 3) {
$rootScope.showGG = false
var params = {};
params.messageId = res.data.messageId
params.modifyType = 1
params.method = 'glsx.accounts.bulletin.message.modify.status';
commonResource.gopRouter(params, function (res) {})
} else {
// res.data.showType == 1 ? $scope.popLasetMsg = res.data && lastest($scope.popLasetMsg) : $scope.lastestMsg = res.data && lastest($scope.lastestMsg)
if (res.data.showType == 1) {
$scope.popLasetMsg = res.data
lastest($scope.popLasetMsg)
} else {
$scope.lastestMsg = res.data
lastest($scope.lastestMsg)
}
}
// if (res.data.showType == 1) {
// $scope.popLasetMsg = res.data
// lastest($scope.popLasetMsg)
// } else {
// $scope.lastestMsg = res.data
// lastest($scope.lastestMsg)
// }
// $scope.lastestMsg.activityTime = $scope.lastestMsg.activityTime.replace('00:00:00', '').replace('23:59:59', '')
// $rootScope.titile = res.data.titile
// // $rootScope.titile = 'ceshi'
// console.log($scope.lastestMsg)
// switch ($scope.lastestMsg.bulletinType) {
// case 1:
// $scope.lastestMsg.bulletinName = "通知"
// break
// case 2:
// $scope.lastestMsg.bulletinName = "活动"
// break
// case 3:
// $scope.lastestMsg.bulletinName = "广告"
// break
// }
// if ($scope.popLasetMsg.showType == 1) {
// console.log($scope.popLasetMsg)
// setTimeout(function () {
// $scope.popLasetMsg.showType = null
// $scope.$apply()
// setTimeout(function () {
// $scope.popLasetMsg = {}
// }, 4000)
// }, 9000) // 动画时间4s
// }
// 修改状态-展示状态
// if ($scope.lastestMsg.messageId) {
// console.log('展示状态')
// $rootScope.showGG = true
// var params = {};
// params.messageId = $scope.lastestMsg.messageId
// params.modifyType = 1
// params.method = 'glsx.accounts.bulletin.message.modify.status';
// commonResource.gopRouter(params,function(res){
// });
// }
} else {
$scope.lastestMsg = {}
}
})
}
/**
*
* 通知弹窗提醒
*/
function notice() {
var count = 0;
commonResource.getNoticeList(function (result) {
count = result.recordsTotal;
if (count > 0 && $state.is('AIniche.collisionRemind') != undefined) {
swal({
type: 'info',
title: '',
text: '您好,您有' + count + '条碰撞提醒消息<br/>是否前往查看?',
html: true,
closeOnConfirm: false,
confirmButtonText: "是",
cancelButtonText: "否",
showCancelButton: true
}, function (result) {
//修改为已读取
commonResource.updateIsReadByType(function (result) {});
if (result) {
window.sweetAlert.close();
$scope.$apply(function () {
$state.go('AIniche.collisionRemind', {
status: 1
});
})
}
});
}
});
}
// 置顶或弹窗关闭
$scope.close = function (type) {
$scope.lastestMsg.showType = null
setTimeout(function () {
$scope.lastestMsg = {}
}, 4000)
}
// 置顶或弹窗-查看详情
$rootScope.viewDetail = function (showType) {
console.log(showType, $scope.popLasetMsg)
var params = {};
// if (showType == '2') {
// params.messageId = $scope.lastestMsg.messageId
// } else {
// params.messageId = $scope.popLasetMsg.messageId
// }
params.messageId = showType == 2 ? $scope.lastestMsg.messageId : $scope.popLasetMsg.messageId
params.method = 'glsx.accounts.bulletin.message.detail';
console.log(params);
commonResource.gopRouter(params, function (res) {
if (res.code == "0") {
console.log(res.data)
if (res.data.publishStatus == 3) {
swal({
type: 'warning',
title: '',
html: true,
text: '该公告已取消发布',
showConfirmButton: false,
timer: 2000
});
$rootScope.showGG = false
} else {
// res.data.bulletinType = showType == 2 ? $scope.lastestMsg.bulletinType : $scope.popLasetMsg.bulletinType
// res.data.bulletinType = $scope.lastestMsg.bulletinType
$uibModal.open({
templateUrl: 'biz/announcement/view/centerDetails.html',
controller: 'centerDetails',
size: 'lg',
resolve: {
parentData: function () {
return {
data: res.data,
viewStatus: res.data.viewStatus,
bulletinType: showType == 2 ? $scope.lastestMsg.bulletinType : $scope.popLasetMsg.bulletinType,
activityType: res.data.activityType
}
}
}
}).result
.then(function (data) {
$rootScope.showGG = false
})
}
$scope.lastestMsg = {}
} else {}
})
}
function checkSwalInit() {
return $timeout(function () {
if (typeof swal === 'function') {
if (!$state.is('system.personalInfo')) {
swal({
type: 'info',
title: '',
text: '系统检测您的密码安全等级低,请尽快修改!',
html: true,
closeOnConfirm: false,
confirmButtonText: "确认",
cancelButtonText: "取消",
showCancelButton: true
}, function (data) {
window.sweetAlert.close();
var params = {
switchGroup: 3,
switchType: 3,
status: 'N'
}
commonResource.updateUserSwitchInfo(params, function (res) {})
if (data) {
$scope.$apply(function () {
localStorageService.set('needChangePassword', true);
$state.go('system.personalInfo');
});
}
});
}
} else {
checkSwalInit()
}
}, 500)
}
$scope.guideFrom = [{
// 提单管理-首次
name: 'business',
src: 'images/guide/business.png',
color: '#3CD5BC'
}, {
// 售后商机-流失线索-首次
name: 'AIniche.lossWarn',
src: 'images/guide/lossWarn.png',
color: '#AA65FF'
}, {
// 售后商机-保养线索-首次
name: 'AIniche.maintainRemind',
src: 'images/guide/maintainRemind.png',
color: '#3C7DD5'
}, {
// 营销管理-活动管理-活动列表-是否配置活动
name: 'marketing.shopactivity.shoplist',
src: 'images/guide/shoplist.png',
color: '#FF9035'
// api: 'getTableData'
}, {
// 营销管理-优惠券管理-优惠券列表-是否配置优惠券
name: 'marketing.coupon.list',
src: 'images/guide/list.png',
color: '#2978FC'
// api: 'getCouponListInfo'
}, {
// 小程序-小程序授权-是否完成授权第一步
name: 'wechatauth.scan-auth',
src: 'images/guide/scan-auth.png',
color: '#26AFFF'
// api: 'loadTask'
}, {
// 客户管理-客户热力图-首次
name: 'customer.residenceAnalysis',
src: 'images/guide/residenceAnalysis.png',
color: '#00B787'
}, {
// 客户管理-客户画像-首次
name: 'customer.customerPortrait',
src: 'images/guide/customerPortrait.png',
color: '#F1BF00'
}]
function openTips(url) {
$uibModal.open({
templateUrl: 'biz/common/tips.html',
controller: 'tipsCtrl',
size: 'sm',
resolve: {
parentData: {
url: url
}
}
}).result.then(function () {
//关闭弹框后执行方法
}, function () {});
}
function openGuide(index) {
$uibModal.open({
title: '温馨提示',
templateUrl: 'biz/common/guide.html',
controller: 'guideCtrl',
size: 'lg',
resolve: {
item: $scope.guideFrom[index]
}
}).result.then(function () {
//关闭弹框后执行方法
}, function () {});
}
var guideStorage = localStorage.getItem('guide') ? localStorage.getItem('guide') : '';
$rootScope.$on('$stateChangeStart', function (evt, toState, toParams, fromState, fromParams) {
$scope.fullFromStateName = fromState.name;
$scope.fromStateName = fromState.name.split('.')[1];
// 新手引导
var reg = /^business/;
var index = -1;
var guideTemp = '';
$rootScope.tipsTemp = ''
guideStorage = localStorage.getItem('guide') ? localStorage.getItem('guide') : '';
if (reg.test(toState.name)) {
index = 0
// 提单管理
// var reg1 = /^business.[add|addQuRong|ysAdd]/
// if (reg1.test(toState.name)) {
// $rootScope.openTipsPop(toState.name)
// }
} else {
for (var i in $scope.guideFrom) {
if ($scope.guideFrom[i].name == toState.name) {
index = i
}
}
}
if (guideStorage && guideStorage.split(',').length == $scope.guideFrom.length) {
return 1;
}
if (index != -1) {
if (guideStorage) {
var arrGuide = guideStorage.split(',');
for (var i in arrGuide) {
if (arrGuide[i] == $scope.guideFrom[index].name)
return 1;
}
guideStorage.split(',').find(function (item) {
if (item == $scope.guideFrom[index].name)
return 1
})
}
guideTemp = guideStorage ? guideStorage + ',' : '';
localStorage.setItem('guide', guideTemp + $scope.guideFrom[index].name);
openGuide(index);
}
});
// 温馨提示
$rootScope.openTipsPop = function (url) {
if (localStorage.getItem('tips')) {
$rootScope.tipStorage = localStorage.getItem('tips')
$rootScope.tipsTemp = $rootScope.tipStorage ? $rootScope.tipStorage + ',' : ''
var tipsArr = $rootScope.tipStorage ? $rootScope.tipStorage.split(',').includes(url) : false
console.log(tipsArr)
if (!tipsArr) openTips(url)
} else {
var params = {
switchGroup: 2
}
commonResource.getUserSwitchInfo(params, function (res) {
if (res.returnCode == '0' && res.data.length != 0) {
for (var i = 0; i < res.data.length; i++) {
if (res.data[i].switchType == 1) {
$rootScope.tipsTemp = $rootScope.tipsTemp + 'business.add' + ','
} else if (res.data[i].switchType == 2) {
$rootScope.tipsTemp = $rootScope.tipsTemp + 'business.addQuRong' + ','
} else if (res.data[i].switchType == 3) {
$rootScope.tipsTemp = $rootScope.tipsTemp + 'business.ysAdd' + ','
}
}
localStorage.setItem('tips', $rootScope.tipsTemp)
$rootScope.tipStorage = localStorage.getItem('tips')
var tipsArr = $rootScope.tipStorage ? $rootScope.tipStorage.split(',').includes(url) : false
if (!tipsArr) openTips(url)
} else if (res.returnCode == '0' && res.data.length == 0) {
openTips(url)
if ($rootScope.tipsTemp) $rootScope.tipsTemp + ','
} else {
openTips(url)
}
})
}
}
// 跳转 活动列表 保养线索 流失线索 拦截
$rootScope.activityFlag = false
$rootScope.jumpLink = function (name, target) {
checkPermission(name, $scope.menuList, target)
if ($scope[target]) {
//跳往一件营销
$rootScope.jumpActivity()
} else {
toaster.pop({
type: 'error',
body: '您暂未开通该服务,请联系客服处理',
showCloseButton: true,
timeout: 3000
})
}
}
// 隐私政策
$rootScope.openPrivacyPolicy = function () {
commonResource.getConfigByGroupAndKey({
'confGroup': 'USER_AGREE_PRIVACY_POLICY_RECORD',
'confKey': $rootScope.loginUser.userId
}, function (res) {
if (!res.data) {
$uibModal.open({
title: '温馨提示',
templateUrl: 'biz/common/priPolicy.html',
controller: 'priPolicyCtrl',
size: 'md',
resolve: {}
}).result.then(function () {
//关闭弹框后执行方法
}, function () {});
}
})
}
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('inspinia')
.controller('MainCtrl', MainCtrl)
})(angular);