configureAddCtrl.js 3.16 KB
(function (angular) {
    function configureAddCtrl($scope, params, $http, $uibModalInstance, $uibModal, DTColumnBuilder, DTOptionsBuilder,globalFunctionService,systemService,$rootScope,$filter) {
    	var confGroup = params.confGroup;
    	
    	$scope.getConfigure = function(confGroup){
			systemService.getConfigureByConfGroup({'confGroup':confGroup},function(res){
				if(res.returnCode == 0){
					$scope.confDescription = res.data.confDescription;
					if(res.data.confKeyList){
						var isAppendValue = false;
						var keys = res.data.confKeyList.join(",");
						if(res.data.confValueList){
							var values = res.data.confValueList.join(",");
							if(values != keys){
								isAppendValue = true;
							}
						}
						var confStr = "";
						for(var i = 0;i<res.data.confKeyList.length;i++){
							if(confStr != ""){
								confStr += "&";
							}
							confStr += res.data.confKeyList[i];
							if(isAppendValue && res.data.confValueList && res.data.confValueList[i]){
								confStr+= "|" + res.data.confValueList[i];
								if(res.data.confNameList && res.data.confNameList[i]){
									confStr+= "|" + res.data.confNameList[i];
								}
							}
						}
						$scope.confKeys = confStr;
					}
				}
			})
		}
    	
    	$scope.confGroupSelectArr = globalFunctionService.getFunctionVal('configureList', 'confGroup') || [];//配置分组
		if($scope.confGroupSelectArr.length > 0){
			if(confGroup){
				var cg = $filter('filter')($scope.confGroupSelectArr, {code: confGroup}, true);
				$scope.confGroup=cg[0] || $scope.confGroupSelectArr[0];
			}else{
				$scope.confGroup=$scope.confGroupSelectArr[0];
			}
			$scope.getConfigure($scope.confGroup.code);
		}
		
		
        $scope.addOrUpdate = function (userType) {
    		if($scope.creatForm.$invalid){
                $scope.isInValidate = true;
                return false;
            }
    		var params = {};
    		if($scope.confGroup){
    			params.confGroup = $scope.confGroup.code;
    		}
    		if($scope.confKeys){
    			params.confKeyList = new Array();
    			params.confValueList = new Array();
    			params.confNameList = new Array();
    			var c = $scope.confKeys.split("&");
    			for(var index = 0;index<c.length;index++){
    				var confArr = c[index].split("|");
    				params.confKeyList.push(confArr[0].trim());
    				if(confArr[1]){
    					params.confValueList.push(confArr[1].trim());
    					if(confArr[2]){
        					params.confNameList.push(confArr[2].trim());
        				}
    				}
    			}
    		}
    		if($scope.confDescription){
    			params.confDescription = $scope.confDescription;
    		}
    		systemService.insertOrUpdateConfigure(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();});
    			}
    		});
        };
    }
    angular.module('system').controller('configureAddCtrl', configureAddCtrl);

})(angular);