appServiceCtrl.js 4.28 KB
(function(angular) {
	function appServiceCtrl($scope, DTOptionsBuilder, DTColumnBuilder, dopService,$uibModal, $filter, $state, $rootScope,SweetAlertX) {		
		$scope.dtColumns = [
		    DTColumnBuilder.newColumn('serviceName').withOption('width',120).withTitle('服务名称'),
		    DTColumnBuilder.newColumn('serviceMethod').withOption('width',180).withTitle('服务方法'),
		    DTColumnBuilder.newColumn('serviceVersion').withOption('width',80).withTitle('服务版本号'),
		    DTColumnBuilder.newColumn('appId').withOption('width',120).withTitle('所属应用ID'),
		    DTColumnBuilder.newColumn('serviceStatus').withOption('width',60).withTitle('服务状态').renderWith(function(e, dt, node, config){
            	if(node.serviceStatus == 1){
            		return '启用';
            	}else if(node.serviceStatus == 2){
            		return '停用';
            	}else if(node.serviceStatus == 3){
            		return '异常';
            	}
            	return "";
            }),
            DTColumnBuilder.newColumn('updatedDate').withOption('width',120).withTitle('更新时间').renderWith(function(e, dt, node, config){
            	return $filter('date')(new Date(node.updatedDate), 'yyyy-MM-dd HH:mm:ss');
            })
        ];
		if($rootScope.loginUser.isSuper){
			$scope.dtColumns.push(DTColumnBuilder.newColumn(null).withTitle(function(){
            	return '操作';
            }).withOption('width', 120).withClass('text-center').renderWith(function(data, type, full, oSettings) {
            	var str = '<div class="form-inline">'
	                +'<div class="form-group"><a class="btn btn-link" ng-click="insertOrUpdate('+ data.id +')">修改</a></div>'
	                +'<div class="form-group"><a class="btn btn-link" ng-click="deleteAppService('+ data.id +')">删除</a></div>';
	            str += '</div>';
                return str;
            }))
		}
		$scope.dtOptions = DTOptionsBuilder.newOptions()
		.withOption('id','id')
		.withFixedColumns({
              rightColumns: 1
         });

		$scope.dtInstance = {
			serverData : dopService.searchAppService
		};

		$scope.getParams =function(){
			var condition = {};
			if($scope.serviceName){
				condition.serviceName = $scope.serviceName;
			}
			if($scope.serviceMethod){
				condition.serviceMethod = $scope.serviceMethod;
			}
			if($scope.appAccessId){
				condition.appAccessId = $scope.appAccessId;
			}
			return {'condition':condition};
		}


		//查询
		$scope.submitForm = function(){
			$scope.dtInstance.query($scope.getParams());
		}
		
		$scope.insertOrUpdate = function (id) {
	        $uibModal.open({
	            templateUrl: 'biz/dop/view/appServiceAccessDialog.html',
	            controller: 'appServiceAccessDialogCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'id':id}
	                }
	            }
	        }).result.then(function (data) {
	        	$scope.dtInstance.query($scope.getParams());
	        },function(){
	        	$scope.dtInstance.query($scope.getParams());
	        })
	    };
	    
	    $scope.deleteAppService = function(id){
	    	SweetAlertX.swal({
                title: "确定要删除吗?",
                text: "",
                type: "info",
                showCancelButton: true,
                closeOnConfirm: false,
                showLoaderOnConfirm: true,
                confirmButtonText: "确认",
                cancelButtonText: "取消",
            },function(b){
                if(b){
                	dopService.deleteAppService({'id':id},function(res){
        	    		swal({type: 'success',title: '',text: res.message||'操作成功',showConfirmButton:false,timer: 1500},function(){
        	    			 window.sweetAlert.close();
        	    			$scope.dtInstance.query($scope.getParams());
                        });
            		});
                }
            });
	    };
		
		$scope.init = function(){
        	dopService.getAllAppAccess(null,function(res){
    			if(res.returnCode == 0){
    				$scope.appAccessList = res.data;
    			}else{
    				swal({type: 'error',title: '',text: res.message||'查询失败',timer: 1500},function(){window.sweetAlert.close();});
    			}
    		})
        };
        $scope.init();
		
	}

	angular.module('dop').controller('appServiceCtrl', appServiceCtrl)
})(angular);