wechatReplyConfigAddCtrl.js 4.37 KB
(function (angular) {
    function wechatReplyConfigAddCtrl($scope, params, $http, $uibModalInstance, $uibModal,systemService,$filter,$rootScope) {
    	$scope.receiveMsgTypeList = [{id:'text',name:'文本消息'},{id:'event',name:'事件'}];
    	$scope.replyMsgTypeList = [{id:'text',name:'文本消息'},{id:'image',name:'图片消息'},{id:'news',name:'图文消息'},{id:'video',name:'视频消息'},{id:'voice',name:'语音消息'}];
    	$scope.receiveEventList=[{id:'subscribe',name:'关注'},{id:'SCAN',name:'扫码'},{id:'LOCATION',name:'上报地理位置'},{id:'CLICK',name:'点击菜单'},{id:'VIEW',name:'点击菜单链接'}];
    	$scope.id = params.wechatReplyId;
    	$scope.wechatConfigList = [];
    	
        $scope.ok = function () {
    		if($scope.creatForm.$invalid){
                $scope.isInValidate = true;
                return false;
            }
    		var params = {};
    		if($scope.id){
    			params.id = $scope.id;
    		}
    		params.wechatAppid = $scope.info.wechatConfig.wechatAppid;
    		params.msgType = $scope.info.msgType.id;
    		if(params.msgType == 'text'){
    			params.content = $scope.info.content;
    		}else if(params.msgType == 'event'){
    			params.event = $scope.info.event.id;
    			if($scope.info.eventKey){
    				params.eventKey = $scope.info.eventKey;
    			}
    		}
    		params.replyMsgType = $scope.info.replyMsgType.id;
    		if(params.replyMsgType == 'text'){
    			params.replyContent = $scope.info.replyContent;
    		}else if(params.replyMsgType == 'image' || params.replyMsgType == 'voice' || params.replyMsgType == 'video'){
    			params.replyMediaId = $scope.info.replyMediaId;
    			if(params.replyMsgType == 'video'){
    				if($scope.info.replyTitle){
    					params.replyTitle = $scope.info.replyTitle;
    				}
    				if($scope.info.replyDescription){
    					params.replyDescription = $scope.info.replyDescription;
    				}
    			}
    		}else if(params.replyMsgType == 'news'){
    			params.replyTitle = $scope.info.replyTitle;
    			params.replyDescription = $scope.info.replyDescription;
    			params.replyPicUrl = $scope.info.replyPicUrl;
    			params.replyUrl = $scope.info.replyUrl;
    		}
    		params.orderNo = $scope.info.orderNo;
    		params.remark = $scope.info.remark;
    		systemService.addOrUpdateWechatReplyConfig(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={};
        	systemService.listWechatConfig({appType:'BIZ'},function(res){
    			if(res.returnCode == 0){
    				$scope.wechatConfigList = res.data;
    				if($scope.id){
    	        		systemService.getWechatReplyConfigById({'id':$scope.id},function(res){
    	        			if(res.returnCode == 0){
    	        				$scope.info = res.data;
    	        				angular.forEach($scope.receiveMsgTypeList, function(r){
    	    						if(r.id == $scope.info.msgType){
    	    							$scope.info.msgType = r;
    	    						}
    	    						if(r.id == 'event'){
    	    							angular.forEach($scope.receiveEventList, function(r){
    	    	    						if(r.id == $scope.info.event){
    	    	    							$scope.info.event = r;
    	    	    						}
    	    	    					});
    	    						}
    	    					});
    	        				angular.forEach($scope.replyMsgTypeList, function(r){
    	    						if(r.id == $scope.info.replyMsgType){
    	    							$scope.info.replyMsgType = r;
    	    						}
    	    					});
    	        				angular.forEach($scope.wechatConfigList, function(r){
    	    						if(r.wechatAppid == $scope.info.wechatAppid){
    	    							$scope.info.wechatConfig = r;
    	    						}
    	    					});
    	        			}else{
    	        				swal({type: 'error',title: '',text: res.message||'查询失败',timer: 1500},function(){window.sweetAlert.close();});
    	        			}
    	        		})
    	        	}
    			}
        	});
        	
        };
        $scope.init();
    }
    angular.module('system').controller('wechatReplyConfigAddCtrl', wechatReplyConfigAddCtrl);

})(angular);