answerChooesCtrl.js
3.01 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
(function (angular) {
function answerChooesCtrl($scope,pagetType,questionnaireExamineService,SweetAlertX,$uibModalInstance,DTColumnBuilder,DTOptionsBuilder,$http,$state,$uibModal,Utils) {
$scope.questions = [{}];
$scope.selectAllinfoforQuestionnaire = function(){
questionnaireExamineService.selectAllinfoforQuestionnaire({'qnId':pagetType.qnId,'qnType':pagetType.qnType}, function (result) {
if (result.returnCode == 0) {
$scope.questions=result.data;
}
});
}
$scope.IsSuccess = function() {
console.log($scope.questions);
var success = true;
if ($scope.questions) {
$scope.questions.forEach(function (item) {
var notOk = true;
item.answerList.forEach(function (tem) {
if (tem.check == true) {
notOk = false;
}
});
console.log(notOk);
if (notOk) {
success = false;
item.message = "请至少选择一项";
} else {
item.message = "";
}
});
}
return success;
}
$scope.init = function(){
$scope.qnName = pagetType.qnName;
$scope.selectAllinfoforQuestionnaire();
}
$scope.getParam = function () {
var params = {};
params.code = pagetType.qnCode;
params.id = pagetType.qnId;
params.name = pagetType.qnName;
params.questionDtoList = $scope.questions;
return params;
}
$scope.init();
$scope.checkAll = function(them) {
console.log(them)
if (them.item.checkItem) {
them.item.answerList.forEach(function (item) {
item.check =true;
});
} else {
them.item.answerList.forEach(function (item) {
item.check =false;
});
}
}
$scope.sa = function() {
var params = $scope.getParam();
questionnaireExamineService.saveDraftChooesAnswer(params, function (result) {
questionnaireExamineService.saveDraftChooesAnswer(params, function (result) {
if(result.returnCode == 0) {
$uibModalInstance.dismiss(0);
SweetAlertX.alert('','保存草稿成功','success');
} else {
$uibModalInstance.dismiss(0);
SweetAlertX.alert('','保存草稿失败','success');
}
});
});
}
$scope.save = function () {
var params = $scope.getParam();
if ($scope.IsSuccess()) {
questionnaireExamineService.saveChooesAnswer(params, function (result) {
if(result.returnCode == 0) {
$uibModalInstance.dismiss(0);
SweetAlertX.alert('','保存提交成功','success');
} else {
$uibModalInstance.dismiss(0);
SweetAlertX.alert('','保存提交失败','success');
}
});
}
}
}
angular.module('questionnaire')
.controller('answerChooesCtrl', answerChooesCtrl);
})(angular);