channelConfigAddCtrl.js 4.92 KB
(function (angular) {
    function channelConfigAddCtrl($scope, params, $http, $uibModalInstance, $uibModal,systemService,$filter,$rootScope) {
    	$scope.channelTypeList = [];
		systemService.getChannelTypeList(function(res){
			$scope.channelTypeList = res.data;
		});
    	$scope.id = params.channelId;
    	
        $scope.ok = function () {
    		if($scope.creatForm.$invalid){
                $scope.isInValidate = true;
                return false;
            }
    		var params = {};
    		if($scope.id){
    			params.id = $scope.id;
    		}
    		params.channelName = $scope.info.channelName;
    		params.channelType = $scope.info.channelType.confValue;
    		params.channelWebUrl = $scope.info.channelWebUrl;
    		params.channelWebName = $scope.info.channelWebName;
    		params.platformGroup = $scope.info.platformGroup;
    		params.channelLogo = $scope.info.channelLogo;
    		params.loginLogo = $scope.info.loginLogo;
    		params.wechatLoginLogo = $scope.info.wechatLoginLogo;
    		params.siteLogo = $scope.info.siteLogo;
    		params.platformChannelName = $scope.info.platformChannel.confKey;
    		params.platformChannelCode = $scope.info.platformChannel.confId;
    		params.wechatAppid = $scope.info.wechatAppid;
    		params.wechatPublicUrl = $scope.info.wechatPublicUrl;
    		systemService.addOrUpdateChannelConfig(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.choseUploadFile=function(file,type){
			if($(file).val()){
				switch(type){
				case 1:
					$scope.uploadChannelLogo = $(file).val();
					break;
				case 2:
					$scope.uploadLoginLogo = $(file).val();
					break;
				case 3:
					$scope.uploadSiteLogo = $(file).val();
					break;
				case 4:
					$scope.uploadWechatLoginLogo = $(file).val();
					break;
				}
                $scope.$apply();
                $scope.sendUploadFile($(file).val(),type);
			};
		};
		
		$scope.sendUploadFile=function(fileName,type){
            var b = '';
			if(fileName){
				var a = fileName.split('.');
                b = a[a.length-1];
			}
			$scope.showLoadingImg = true;
            $http({
                url: 'common/uploadImage',
                method: 'POST',
                headers: {
                    'Content-Type': undefined
                },
                transformRequest: function() {
                    var formData = new FormData();
                    formData.append('file', $('#upfile_' + type)[0].files[0]);
                    return formData;
                }
            }).success(function (res) {
                $scope.showValidate = false;
                $scope.showLoadingImg = false;
                if(res.returnCode == 0){
                	switch(type){
    				case 1:
    					$scope.info.channelLogo = res.data;
    					break;
    				case 2:
    					$scope.info.loginLogo = res.data;
    					break;
    				case 3:
    					$scope.info.siteLogo = res.data;
    					break;
    				case 4:
    					$scope.info.wechatLoginLogo = res.data;
    					break;
    				}
                }else{
                    swal({
                        type: 'error',
                        title: '',
                        text: res.message||'操作失败',
                        showConfirmButton:false,
                        timer: 1500
                    },function(){
                        swal.close();
                    });
                };
            });

		};

        $scope.init = function(){
        	$scope.info={};
        	//平台商户渠道类型
        	systemService.getChannelDictList(function(res){
        		$scope.channelDictList = res.data;
        		if($scope.id){
            		systemService.getChannelConfigById({'id':$scope.id},function(res){
            			if(res.returnCode == 0){
            				$scope.info = res.data;
            				angular.forEach($scope.channelDictList, function(r){
        						if(r.confId == $scope.info.platformChannelCode){
        							$scope.info.platformChannel = r;
        						}
        					});
            				angular.forEach($scope.channelTypeList, function(r){
        						if(r.confValue == $scope.info.channelType){
        							$scope.info.channelType = r;
        						}
        					});
            			}else{
            				swal({type: 'error',title: '',text: res.message||'查询失败',timer: 1500},function(){window.sweetAlert.close();});
            			}
            		})
            	}
        	});
        };
        $scope.init();
    }
    angular.module('system').controller('channelConfigAddCtrl', channelConfigAddCtrl);

})(angular);