questionnaireExamineCtrl.js 8.92 KB
(function (angular) {
    function questionnaireExamineCtrl($scope,questionnaireExamineService,DTColumnBuilder,DTOptionsBuilder,$http,$state,$uibModal,Utils) {

        $scope.questionnaire = {};

        $scope.answerStatusList = [{
            value : null,
            text : '全部'
        },{
            value : 1,
            text : '待提交'
        },{
            value : 2,
            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.dtColumns = [
            DTColumnBuilder.newColumn('code').withOption('width',60).withTitle('问卷编号'),
            DTColumnBuilder.newColumn('name').withOption('width',60).withTitle('问卷名称'),
            DTColumnBuilder.newColumn('type').withOption('width',30).withTitle('类型').renderWith(function(data, type, full, oSettings) {
                for(var i in $scope.typeList){
                    if($scope.typeList[i].value == data){
                        return $scope.typeList[i].text;
                    }
                }
            }),
            DTColumnBuilder.newColumn('answerStatus').withOption('width',30).withTitle('状态').renderWith(function(data, type, full, oSettings) {
                for(var i in $scope.answerStatusList){
                    if($scope.answerStatusList[i].value == data){
                        return $scope.answerStatusList[i].text;
                    }
                }
            }),
            DTColumnBuilder.newColumn('reUpdateDate').withOption('width',60).withTitle('更新时间'),
            DTColumnBuilder.newColumn(null).withTitle('操作').withOption('width', 90).withClass('text-center').renderWith(function(data, type, full, oSettings) {
                var str = '';
                if(data.answerStatus == 2) {
                	str +='<div class="form-group"><a class="btn btn-link" ng-click="examine(\''+ data.id +'\')">查看</a></div>';
                } else {
                	str +='<div class="form-inline">'
                    +'<div class="form-group"><a class="btn btn-link" ng-click="answer(\''+ data.id +'\')">答题</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('num', true);
        /*.withOption('select', {
        type: 'checkbox'
    	})*/
            

        $scope.dtInstance = {
    		serverData :  function(param){
    			var params =  $scope.getParam();
	        	angular.extend(param, params);
                return questionnaireExamineService.listExamine(param);
            } 
        		
        };

        $scope.getParam = function () {
            var info = $scope.questionnaire;
            var param = {};
            var obj = {};
            if($scope.selectCondition && $scope.conditionText){
                param[$scope.selectCondition] = $scope.conditionText;
            }
            if(info.answerStatus != null){
                param.answerStatus = info.answerStatus.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.startDate = info.createTime.startDate.format('YYYY-MM-DD HH:mm:ss');
                param.endDate = info.createTime.endDate.format('YYYY-MM-DD HH:mm:ss');
            }
            obj.condition = param;
            return obj;
        };

        $scope.select = function(){
            $scope.dtInstance.query();
        }
        
        
        // 跳转答题界面
        $scope.answer = function(id) {
        	questionnaireExamineService.findQuestionnaire({'id':id}, function (result) {
        		// 多选型
        		if (result.returnCode == 0) {
        			if (result.data.type == 2) {
            			$uibModal.open({
                            templateUrl : 'biz/questionnaire/view/answerChooes.html',
                            controller : 'answerChooesCtrl',
                            size : 'lg',
                            scope:$scope,
                            resolve : {
                            	pagetType : function() {
        	                        return {
        	                        	 qnId: result.data.id,
        	                        	 qnCode: result.data.code,
        	                        	 qnName: result.data.name,
        	                        	 qnType: result.data.type
        	                        };
        	                    }
        	                }
                        }).result.then(function(){
                            //关闭弹框后执行方法
                        },function () {
                            $scope.dtInstance.query();
                        });
            		} else if ((result.data.type == 1)){
            			$uibModal.open({
                            templateUrl : 'biz/questionnaire/view/answerGrade.html',
                            controller : 'answerGradeCtrl',
                            size : 'lg',
                            scope:$scope,
                            resolve : {
        	                	pagetType : function() {
        	                        return {
        	                        	 qnId: result.data.id,
        	                        	 qnCode: result.data.code,
        	                        	 qnName: result.data.name,
        	                        	 qnType: result.data.type
        	                        };
        	                        
        	                    }
        	                }
                        }).result.then(function(){
                            //关闭弹框后执行方法
                        },function () {
                        	
                            $scope.dtInstance.query();
                        });
            		} 
        		}
        	});
        }
        
        // 跳转答题界面
        $scope.examine = function(id) {
        	questionnaireExamineService.findQuestionnaire({'id':id}, function (result) {
        		// 多选型
        		if (result.returnCode == 0) {
        			if (result.data.type == 2) {
            			$uibModal.open({
                            templateUrl : 'biz/questionnaire/view/answerChooesView.html',
                            controller : 'answerChooesViewCtrl',
                            size : 'lg',
                            scope:$scope,
                            resolve : {
        	                	pagetType : function() {
        	                        return {
        	                        	 qnId: result.data.id,
        	                        	 qnCode: result.data.code,
        	                        	 qnName: result.data.name,
        	                        	 qnType: result.data.type
        	                        };
        	                    }
        	                }
                        }).result.then(function(){
                            //关闭弹框后执行方法
                        },function () {
                            $scope.dtInstance.query();
                        });
            		} else if ((result.data.type == 1)){
            			$uibModal.open({
                            templateUrl : 'biz/questionnaire/view/answerGradeView.html',
                            controller : 'answerGradeViewCtrl',
                            size : 'lg',
                            scope:$scope,
                            resolve : {
        	                	pagetType : function() {
        	                        return {
        	                        	 qnId: result.data.id,
        	                        	 qnCode: result.data.code,
        	                        	 qnName: result.data.name,
        	                        	 qnType: result.data.type
        	                        };
        	                    }
        	                }
                        }).result.then(function(){
                            //关闭弹框后执行方法
                        },function () {
                            $scope.dtInstance.query();
                        });
            		} 
        		}
        	});
        }
        
    }

    angular.module('questionnaire')
        .controller('questionnaireExamineCtrl', questionnaireExamineCtrl);
})(angular);