answerChooesCtrl.js 3.01 KB
(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);