serviceManagerDialogCtrl.js 2.52 KB
(function (angular) {
    function serviceManagerDialogCtrl($scope, params, $http, $uibModalInstance, $uibModal, dopService,$filter,$rootScope) {
    	$scope.serviceStatusList = [{id:1,name:'启用'},{id:2,name:'停用'},{id:3,name:'异常'}];
    	$scope.id = params.id;
    	
        $scope.ok = function () {
    		if($scope.creatForm.$invalid){
                $scope.isInValidate = true;
                return false;
            }
    		var params = {};
    		if($scope.id){
    			params.id = $scope.id;
    		}
    		params.serviceName = $scope.info.serviceName;
    		params.serviceMethod = $scope.info.serviceMethod;
    		params.serviceModule = $scope.info.serviceModule;
    		if($scope.info.serviceStatus){
    			params.serviceStatus = $scope.info.serviceStatus.id;
    		}
    		if($scope.id){
    			dopService.updateService(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();});
	    			}
	    		});
    		}else{
    			dopService.insertService(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(){
        	$scope.info={};
        	if($scope.id){
        		dopService.getService({'id':$scope.id},function(res){
        			if(res.returnCode == 0){
        				$scope.info = res.data;
        				angular.forEach($scope.serviceStatusList, function(r){
    						if(r.id == $scope.info.serviceStatus){
    							$scope.info.serviceStatus = r;
    						}
    					});
        			}else{
        				swal({type: 'error',title: '',text: res.message||'查询失败',timer: 1500},function(){window.sweetAlert.close();});
        			}
        		})
        	}
        };
        $scope.init();
    }
    angular.module('dop').controller('serviceManagerDialogCtrl', serviceManagerDialogCtrl);

})(angular);