questionnaireManagerCtrl.js
13.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
(function (angular) {
function questionnaireManagerCtrl($scope,questionnaireService,SweetAlertX,DTColumnBuilder,DTOptionsBuilder,$uibModal) {
$scope.questionnaire = {};
$scope.statusList = [
{value : null, text : '全部'},
{value : 0, text : '待完善'},
{value : 1, text : '待发送'},
{value : 2, text : '已发送'},
{value : 3, text : '已撤回'}];
$scope.unanswerTypeList = [
{value : null, text : '全部'},
{value : 1, text : '大于0'},
{value : 2, text : '等于0'}];
$scope.typeList = [
{value : null, text : '全部'},
{value : 1, text : '打分型'},
{value : 2, text : '多选型'}];
$scope.operateList = [
[{name : '查看与编辑'},{name : '查看商户明细'},{name : '复制'}],//待完善
[{name : '发送'},{name : '查看与编辑'},{name : '查看商户明细'},{name : '复制'}],//待发送
[{name : '撤回'},{name : '查看问卷'},{name : '查看结果'},{name : '查看商户明细'},{name : '复制'}],//已发送
[{name : '发送'},{name : '查看问卷'},{name : '查看结果'},{name : '查看商户明细'},{name : '复制'}]//已撤回
];
$scope.dtColumns = [
DTColumnBuilder.newColumn('code').withOption('width',40).withTitle('问卷编号'),
DTColumnBuilder.newColumn('name').withOption('width',80).withTitle('问卷名称'),
DTColumnBuilder.newColumn('copyCode').withOption('width',40).withTitle('问卷来源'),
DTColumnBuilder.newColumn('type').withOption('width',30).withTitle('类型').renderWith(function(data, type, obj, oSettings) {
for(var i in $scope.typeList){
if($scope.typeList[i].value === data){
return $scope.typeList[i].text;
}
}
}),
DTColumnBuilder.newColumn('status').withOption('width',30).withTitle('状态').renderWith(function(data, type, obj, oSettings) {
for(var i in $scope.statusList){
if($scope.statusList[i].value === data){
return $scope.statusList[i].text;
}
}
}),
DTColumnBuilder.newColumn('respondentsCount').withOption('width',40).withTitle('调查商户数').renderWith(function(data, type, obj, oSettings) {
return data || '--';
}),
DTColumnBuilder.newColumn('unanswerCount').withOption('width',40).withTitle('待提交商户').renderWith(function(data, type, obj, oSettings) {
if(obj.status === 0 || obj.status === 1){
return '--';
}
return data;
}),
DTColumnBuilder.newColumn('createdDate').withOption('width',60).withTitle('创建时间'),
DTColumnBuilder.newColumn('updatedDate').withOption('width',60).withTitle('更新时间'),
DTColumnBuilder.newColumn(null).withTitle('操作').withOption('width', 180).withClass('text-center').renderWith(function(data, type, full, oSettings) {
var str = '<div class="form-inline">';
angular.forEach($scope.operateList[data.status],function (item) {
str += '<div class="form-group"><a class="btn btn-link" ng-click="operate(\''+ item.name +'\','+ data.id +',\''+ data.code+'\',' +'\''+ data.name+'\','+ data.type +')">'+ item.name +'</a></div>'
});
str += '</div>';
return str;
})
];
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('id','id')
.withFixedColumns({
leftColumns: 1,
rightColumns: 0
})
.withOption('lengthMenu', [20,40,60,100])
.withOption('select', {
type: 'checkbox'
})
.withOption('num', true)
.withButtons([{
text : '批量发送',
action : function(e, dt, node, config) {
$scope.changeStatusList(2,'发送');
}
},{
text : '批量撤回',
action : function(e, dt, node, config) {
$scope.changeStatusList(3,'撤回');
}
},{
text : '新建问卷',
action : function(e, dt, node, config) {
$scope.add();
}
}]);
$scope.dtInstance = {
serverData : questionnaireService.list
};
$scope.operate = function (name,id,code,qnName,type) {
switch (name){
case '查看与编辑':
$scope.view(id);
break;
case '查看问卷':
$scope.view(id);
break;
case '查看商户明细':
$scope.viewMerchant(id,code,qnName);
break;
case '查看结果':
$scope.answer(qnName,id, code, type);
break;
case '复制':
$scope.copy(id);
break;
case '发送':
$scope.changeStatus(id,2,'发送');
break;
case '撤回':
$scope.changeStatus(id,3,'撤回');
break;
default:
break;
}
};
$scope.answer = function (name, id, code, type) {
if (type == 2) {
$uibModal.open({
templateUrl : 'biz/questionnaire/view/answerExamineChooesView.html',
controller : 'answerExamineChooesCtrl',
size : 'lg',
scope:$scope,
resolve : {
pageParam : function() {
return {
qnId: id,
qnCode: code,
qnName: name,
qnType: type
};
} }
}).result.then(function(){
//关闭弹框后执行方法
},function () {
$scope.select();
});
} else if (type == 1) {
$uibModal.open({
templateUrl : 'biz/questionnaire/view/answerExamineGradeView.html',
controller : 'answerExamineGradeCtrl',
size : 'lg',
scope:$scope,
resolve : {
pageParam : function() {
return {
qnId: id,
qnCode: code,
qnName: name,
qnType: type
};
} }
}).result.then(function(){
//关闭弹框后执行方法
},function () {
$scope.select();
});
}
};
$scope.viewMerchant = function (id,code,qnName) {
$uibModal.open({
templateUrl : 'biz/questionnaire/view/viewMerchantDetail.html',
controller : 'viewMerchantDetailCtrl',
size : 'lg',
scope:$scope,
resolve : {
param: function () {
return {
id:id,
code:code,
qnName:qnName
};
}
}
}).result.then(function(){
//关闭弹框后执行方法
},function () {
$scope.select();
});
};
$scope.view = function (id) {
$uibModal.open({
templateUrl : 'biz/questionnaire/view/viewQuestionnaire.html',
controller : 'viewQuestionnaireCtrl',
size : 'lg',
scope:$scope,
resolve : {
param: function () {
return id;
}
}
}).result.then(function(){
//关闭弹框后执行方法
},function () {
$scope.select();
});
};
$scope.changeStatus = function (ids,status,name) {
SweetAlertX.confirm({
text: "是否确认"+ name +"问卷?",
confirmButtonText: "确认",
cancelButtonText: "取消"
}, function () {
questionnaireService.changeStatus({ids:ids,status:status},function (res) {
if(res && res.data){
$scope.select();
SweetAlertX.alert('',name + '问卷成功','success');
}else {
SweetAlertX.alert('',name + '问卷失败','error');
}
});
})
};
$scope.changeStatusList = function(status,name){
var _selectedItems = $scope.dtInstance.getSelectItems();
var ids = [];
if (_selectedItems.length > 0) {
for (var i = 0; i < _selectedItems.length; i++) {
var o = _selectedItems[i];
ids.push(o.id);
}
$scope.changeStatus(ids,status,name);
} else {
SweetAlertX.alert('','请选择需要'+ name +'的问卷','error');
}
};
$scope.getParam = function () {
var info = $scope.questionnaire;
var param = {};
var obj = {};
if($scope.selectCondition && $scope.conditionText){
param[$scope.selectCondition] = $scope.conditionText;
}
if(info.status != null){
param.status = info.status.value;
}
if(info.unanswerType != null){
param.unanswerType = info.unanswerType.value;
}
if(info.type != null){
param.type = info.type.value;
}
if (info.createTime && info.createTime.startDate && info.createTime.endDate) {
param.createdDateStart = info.createTime.startDate.format('YYYY-MM-DD HH:mm:ss');
param.createdDateEnd = info.createTime.endDate.format('YYYY-MM-DD HH:mm:ss');
}
if (info.updateTime && info.updateTime.startDate && info.updateTime.endDate) {
param.updatedDateStart = info.updateTime.startDate.format('YYYY-MM-DD HH:mm:ss');
param.updatedDateEnd = info.updateTime.endDate.format('YYYY-MM-DD HH:mm:ss');
}
if($scope.copyCode){
param.copyCode = $scope.copyCode;
}
obj.condition = param;
return obj;
};
$scope.select = function () {
var param = $scope.getParam();
$scope.dtInstance.query(param);
};
$scope.add = function () {
$uibModal.open({
templateUrl : 'biz/questionnaire/view/addQuestionnaire.html',
controller : 'addQuestionnaireCtrl',
size : 'lg',
scope:$scope,
resolve : {}
}).result.then(function(){
//关闭弹框后执行方法
},function () {
$scope.select();
});
};
$scope.copy = function (id) {
questionnaireService.getById({id:id},function (res) {
if(res && res.data){
$uibModal.open({
templateUrl : 'copy',
controller : 'copyCtrl',
size : 'md',
scope:$scope,
resolve : {
param: function () {
return res.data;
}
}
}).result.then(function(){
//关闭弹框后执行方法
},function () {
$scope.select();
});
}
});
}
}
function copyCtrl($scope,param,questionnaireService,$uibModalInstance,SweetAlertX) {
$scope.questionnaire = param;
$scope.copyTypes = [
{value:1,text:'仅复制问卷'},
{value:2,text:'复制问卷+所有调查商户'},
{value:3,text:'复制问卷+待提交商户'}
];
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
$scope.confirm = function () {
if ($scope.copyForm.$invalid) {
// 验证没通过
$scope.submitted = true;
return;
}
if(!$scope.questionnaire || !$scope.questionnaire.code || !$scope.copyType){
return;
}
var obj = {
qnCode:$scope.questionnaire.code,
type:$scope.copyType.value
};
questionnaireService.copy(obj,function (res) {
if(res && res.data){
$scope.close();
SweetAlertX.alert('','复制问卷成功','success');
}else{
SweetAlertX.alert('','复制问卷失败','error');
}
})
}
}
angular.module('questionnaire')
.controller('questionnaireManagerCtrl', questionnaireManagerCtrl)
.controller('copyCtrl', copyCtrl);
})(angular);