functionCtrl.js 4.69 KB
(function(angular) {
	function functionCtrl($scope, DTOptionsBuilder, DTColumnBuilder, systemService, $uibModal, $filter, $state) {
		
		var typeShow = (function () {
            return function (e, dt, node, config) {
                var results = null;
                if (node.functionAttrType == '1') {
                    results = "文本输入框"
                } else if (node.functionAttrType == '2') {
                    results = "单项旋转框"
                } else if (node.functionAttrType == '3') {
                    results = "按钮"
                } else if (node.functionAttrType == '4') {
                    results = "文本输入框(属性限制)"
                } else if (node.functionAttrType == '5') {
                    results = "后台业务开关"
                }
                return results;
            };
        })();
		
		$scope.dtColumns = [
            DTColumnBuilder.newColumn('menuCode').withOption('width',60).withTitle('菜单编号'),
            DTColumnBuilder.newColumn('menuName').withOption('width',120).withTitle('菜单名称'),
            DTColumnBuilder.newColumn('menuUrl').withOption('width',80).withTitle('菜单地址'),
            DTColumnBuilder.newColumn('functionName').withOption('width',100).withTitle('功能名称'),
            DTColumnBuilder.newColumn('functionAttrName').withOption('width',120).withTitle('功能属性名'),
            DTColumnBuilder.newColumn('functionAttrType').withOption('width',120).withTitle('功能属性类型').renderWith(typeShow),
            DTColumnBuilder.newColumn('functionRemark').withOption('width',180).withTitle('功能备注'),
            DTColumnBuilder.newColumn('userLimitType').withOption('width',100).withTitle('用户群体').renderWith(function(e, dt, node, config){
            	if(node.userLimitType == 0){
            		return "指定角色";
            	}else if(node.userLimitType == 1){
            		return "用户类型";
            	}else if(node.userLimitType == 2){
            		return "指定用户ID";
            	}else if(node.userLimitType == 3){
            		return "所属商户用户类型";
            	}
            	return "";
            }),
            DTColumnBuilder.newColumn('createdDate').withOption('width',140).withTitle('创建时间').renderWith(function(e, dt, node, config){
            	return $filter('date')(new Date(node.createdDate), 'yyyy-MM-dd HH:mm:ss');
            }),
            DTColumnBuilder.newColumn(null).withTitle(function(){
            	return '操作';
            }).withOption('width', 60).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="functionAddOrUpdate('+ data.id +')">编辑</a></div>'
	               // +'<div class="form-group"><a class="btn btn-link" ng-click="menuAddOrUpdate('+ data.id +')">删除</a></div>';
	            str += '</div>';
                return str;
            })
        ];
		$scope.dtOptions = DTOptionsBuilder.newOptions()
		.withOption('id','id')
		.withFixedColumns({
            leftColumns: 2,
            rightColumns: 0
        })
        
		$scope.dtInstance = {
			serverData : systemService.getFunctionList
		};
		
		$scope.changeMenu = function(type){
			if(type == 1){
				$scope.secondMenuCode = null;
				$scope.thirdMenuCode = null;
			}else if(type == 2){
				$scope.thirdMenuCode = null;
			}
		}

		function getParams(){
			var obj = {};
			if($scope.thirdMenuCode){
				obj.menuCode = $scope.thirdMenuCode.code;
    		}else if($scope.secondMenuCode){
    			obj.menuCode = $scope.secondMenuCode.code;
    		}else if($scope.firsrMenuCode){
    			obj.menuCode = $scope.firsrMenuCode.code;
    		}
			if($scope.functionName){// 功能名称
				obj.functionName = $scope.functionName;
			}
			if($scope.functionAttrType){// 功能类型
				obj.functionAttrType = $scope.functionAttrType;
			}
			if($scope.userLimitType){// 功能类型
				obj.userLimitType = $scope.userLimitType;
			}
			return obj;
		}

		//查询列表
		$scope.functionListForm = function(){
			$scope.dtInstance.query(getParams());
		}
		
	   	$scope.functionAddOrUpdate = function (id) {
	        $uibModal.open({
	            templateUrl: 'biz/system/view/functionAdd.html',
	            controller: 'functionAddCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'id':id}
	                }
	            }
	        }).result.then(function (data) {
	        	$scope.functionListForm();
	        },function(){
	        	$scope.functionListForm();
	        })
	    };
	}
	angular.module('system').controller('functionCtrl', functionCtrl)
})(angular);