functionAddCtrl.js 5.25 KB
(function (angular) {
    function functionAddCtrl($scope, params, $http, $uibModalInstance, $uibModal, DTColumnBuilder, DTOptionsBuilder,systemService,$rootScope) {
    	$scope.functionId = params.id;
    	$scope.menuCode = params.menuCode;
    	$scope.menuName = params.menuName;
    	
    	$scope.formData = {
    		functionAttrType:''
    	}
    	
    	$scope.functionAttrTypes=[
             {id:1,name:'文本输入框'},
             {id:2,name:'单项选择框'},
             {id:3,name:'按钮'},
             {id:4,name:'文本输入框(属性限制)'},
             {id:5,name:'后台业务开关'}
         ];
    	$scope.changeMenu = function(type){
			if(type == 1){
				$scope.formData.secondMenuCode = null;
				$scope.formData.thirdMenuCode = null;
			}else if(type == 2){
				$scope.formData.thirdMenuCode = null;
			}
		}
        $scope.addFunction = function (userType) {
    		if($scope.creatForm.$invalid || $scope.formData.functionAttrType == undefined){
                $scope.isInValidate = true;
                return false;
            }
    		var params = {};
    		if($scope.functionId){
    			params.id = $scope.functionId;
    		}
    		if($scope.menuCode){
    			params.menuCode = $scope.menuCode;
    		}else if($scope.formData.thirdMenuCode){
    			params.menuCode = $scope.formData.thirdMenuCode.code;
    		}else if($scope.formData.secondMenuCode){
    			params.menuCode = $scope.formData.secondMenuCode.code;
    		}else{
    			params.menuCode = $scope.formData.firsrMenuCode.code;
    		}
    		params.functionName = $scope.formData.functionName;
    		params.functionAttrName = $scope.formData.functionAttrName;
    		params.functionAttrType = $scope.formData.functionAttrType.id;
    		params.userLimitType = $scope.formData.userLimitType;
    		if(params.userLimitType != 0 && $scope.formData.userLimitDataIdStrs){
    			params.userLimitDataIdStrs = $scope.formData.userLimitDataIdStrs;
    		}
    		if ($scope.formData.functionRemark) {
    			params.functionRemark = $scope.formData.functionRemark;
    		}
    		if ((params.functionAttrType == 2 || params.functionAttrType == 4 ) && $scope.formData.addFunctionValueStrs) {
    			params.functionValueStrs = $scope.formData.addFunctionValueStrs;
    		}
    		params.orderNo = $scope.formData.orderNo;
    		console.log(params)
    		systemService.addOrUpdateFunction($.param(params),function(res){
    			if(res.returnCode == 0){
    				swal({type: 'success',title: '',text: res.message||'操作成功',showConfirmButton:false,timer: 1500},function(){
                        window.sweetAlert.close();
                        $uibModalInstance.close();
                    });
    			}else{
    				swal({type: 'error',title: '',text: res.message||'操作失败',timer: 1500},function(){window.sweetAlert.close();});
    			}
    		});
        };
        
        $scope.init = function(){
        	if($scope.functionId){
        		systemService.getFunctionById({'id':$scope.functionId},function(res){// 通过id获取到功能内容 a按钮,1,1;b按钮,2,2;
        			if(res.returnCode == 0){
        				$scope.formData = res.data;
        				$scope.formData.userLimitType = res.data.userLimitType + '';
        				if(res.data.dataIds && res.data.dataIds.length > 0){
        					$scope.formData.userLimitDataIdStrs = res.data.dataIds.join(",");
        				}
        				$scope.formData.functionAttrType = $scope.functionAttrTypes[res.data.functionAttrType-1];
        				for(var i = 0;i< $rootScope.curUserMenuClassList.length;i++){
        					var firsrMenuCode = $rootScope.curUserMenuClassList[i];
        					if(firsrMenuCode.code == res.data.menuCode){
        						$scope.formData.firsrMenuCode = firsrMenuCode;
        						break;
        					}
        					var isBreak = false;
        					for(var j = 0;j< firsrMenuCode.sublist.length;j++){
            					var secondMenuCode = firsrMenuCode.sublist[j];
            					if(secondMenuCode.code == res.data.menuCode){
            						$scope.formData.firsrMenuCode = firsrMenuCode;
            						$scope.formData.secondMenuCode = secondMenuCode;
            						isBreak = true;
            						break;
            					}
            					for(var k = 0;k< secondMenuCode.sublist.length;k++){
                					var thirdMenuCode = secondMenuCode.sublist[k];
                					if(thirdMenuCode.code == res.data.menuCode){
                						$scope.formData.firsrMenuCode = firsrMenuCode;
                						$scope.formData.secondMenuCode = secondMenuCode;
                						$scope.formData.thirdMenuCode = thirdMenuCode;
                						isBreak = true;
                						break;
                					}
                				}
            					if(isBreak){
            						break;
            					}
            				}
        					if(isBreak){
        						break;
        					}
        				}
        				
        				
        			}else{
        				swal({type: 'error',title: '',text: res.message||'查询失败',timer: 1500},function(){window.sweetAlert.close();});
        			}
        		})
        	} else {
        		$scope.formData.functionAttrType = $scope.functionAttrTypes[1];
        		$scope.formData.userLimitType = '0';
        	}
        };
        $scope.init();
    }
    angular.module('system').controller('functionAddCtrl', functionAddCtrl);

})(angular);