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
(function(){
angular.module("app.manage")
.controller("activityeventCtrl",["$rootScope","$scope","HttpService","ToolService","UtilService","$state","$timeout","$stateParams",activityeventCtrl])
.controller("activityeventDetailCtrl",["$scope","$rootScope","HttpService","ToolService","UtilService","$q","$state","$stateParams","$timeout",activityeventDetailCtrl]);
function activityeventCtrl($rootScope,$scope,HttpService,ToolService,UtilService,$state,$timeout,$stateParams){
$scope.query = function(){
var eventPM = HttpService.getInfo("mng/virtual/find/"+$scope.appid);
ToolService.showLoading();
eventPM.then(function(data){
ToolService.hideLoading();
$scope.eventList = data;
});
}
$scope.$watch("appid",function(n){
if(angular.isDefined(n)){
$scope.query();
}
});
$scope.$on('flipinfo',function(e,msg){
$scope.flipPage = msg;
});
$scope.onUser = function(id){
ToolService.showLoading();
var userPM = HttpService.putInfo("mng/virtual/find/"+id+"/enable");
userPM.then(function(data){
ToolService.hideLoading();
ToolService.showTips("启用成功")
$scope.query();
});
}
$scope.offUser = function(id){
var userPM = HttpService.putInfo("mng/virtual/find/"+id+"/disable");
ToolService.showLoading();
userPM.then(function(data){
ToolService.hideLoading();
ToolService.showTips("停用成功")
$scope.query();
});
}
$scope.gopage = function(info){
if(angular.isDefined(info)){
$state.go("collect.activityeventDetail",{aid:info});
}else{
$state.go("collect.activityeventDetail");
}
}
}
function activityeventDetailCtrl($scope,$rootScope,HttpService,ToolService,UtilService,$q,$state,$stateParams,$timeout){
var editInfo = $stateParams.aid;
$scope.title = editInfo?"编辑虚拟事件":"新建虚拟事件";
$scope.inputdis = false;
if(editInfo == null){ //新建虚拟事件
editInfo = {eventList:[],type:'userdefine'};
$scope.specialEvents = [];
$scope.name = "";
}
else{
$scope.name = editInfo.ch_name;
if(editInfo.type == 'userdefine'){ //虚拟事件
$scope.specialEvents = [];
}
else{//活跃事件
$scope.inputdis = true;
if($scope.isweb){
$scope.specialEvents = ["pageview"];
}
else{
$scope.specialEvents = ["loggedin","reged","payment"];
}
}
}
var listId = editInfo.id;
var chooseStr = editInfo.eventList;
$scope.$watch("appid",function(n){
if(angular.isDefined(n)){
$scope.query();
}
});
/*var noFalse = [];
$scope.eventList.filter(function(item){
if(item.status == true){
noFalse.push(item);
}
});*/
$scope.query = function(){
var url = "";
if(editInfo!=null && editInfo.type != 'userdefine'){
url = "mng/virtual/unselect/"+$scope.appid;
}
else{
url = "mng/event/find/"+$scope.appid;
}
var eventPM = HttpService.getInfo(url);
ToolService.showLoading();
eventPM.then(function(data){
ToolService.hideLoading();
$scope.eventList = data.filter(function(item){
if(item.status == true){
if(chooseStr.indexOf(item.eventName) > -1 || $scope.specialEvents.indexOf(item.eventName)>-1){
item.ischeck = true;
}
else{
item.ischeck = false;
}
}
return item.status == true;
});
});
}
var chooseNum = 0,max = 5;
$scope.chooseItem = function(info){
chooseNum = 0;
for(var i = 0; i < $scope.eventList.length; i++){
if($scope.eventList[i].ischeck == true){
chooseNum = chooseNum + 1;
}
}
if(chooseNum < max){
info.ischeck = true;
}
else{
ToolService.showTips("最多可以选择"+max+"个");
}
}
$scope.cancelItem = function(info){
if($scope.specialEvents.indexOf(info.eventName)>-1){
info.ischeck = true;
}else{
info.ischeck = false;
}
}
$scope.selectAllEvent = function(){
if($scope.eventList.length > max){
ToolService.showTips("最多可以选择"+max+"个");
}
else{
$scope.selAll = !$scope.selAll;
$scope.eventList.filter(function(item){
if($scope.specialEvents.indexOf(item.eventName)>-1){
item.ischeck = true;
}else{
item.ischeck = $scope.selAll;
}
});
}
}
$scope.save = function(){
var chooseList = [];
for(var i = 0; i < $scope.eventList.length; i++){
if($scope.eventList[i].ischeck == true){
chooseList.push($scope.eventList[i].eventName);
}
}
var params = {
ch_name : $scope.name,
eventList : chooseList.join(",")
};
$scope.tip = {},error = false;
var verPar = {
name: {
key: 'spcname2',
val: params.ch_name,
txt: "含非法字符或过长(支持输入汉字、大小写字母、数字、下划线,长度限制40字符以内)"
}
};
$scope.tip = formJudge(verPar);
if($scope.tip.succ != true) {
error = true;
}
if(chooseList.length<2){
$scope.tip.moreparams = {
status:true,
txt:'请至少选择2个事件'
}
return false;
}
if(error){return false;}
var savePM = null,txt = "保存成功";
if(listId){
params.id = listId;
params.type = editInfo.type;
savePM = HttpService.putInfo("mng/virtual/update/"+$scope.appid,params);
}
else{
txt = "新建成功";
savePM = HttpService.postInfo("mng/virtual/userdefined/"+$scope.appid,params);
}
ToolService.showLoading();
savePM.then(function(data){
ToolService.hideLoading();
if(data.code == -6001){
$scope.tip.name = {
status:true,
txt:'名称重复'
}
ToolService.showTips("名称重复");
}
else{
$scope.cancel();
ToolService.showTips(txt);
}
},function(data){
ToolService.hideLoading();
if(data.code == -6001){
$scope.tip.name = {
status:true,
txt:'名称重复'
}
ToolService.showTips("名称重复");
}
});
}
$scope.cancel = function(){
$state.go("collect.activityevent");
}
}
})();