wechatReplyConfigCtrl.js 5.57 KB
(function(angular) {
	function wechatReplyConfigCtrl($scope, DTOptionsBuilder, DTColumnBuilder, systemService,$uibModal, $filter, $state,Utils,$rootScope,SweetAlertX) {		
		$scope.wechatConfigList = [];
		systemService.listWechatConfig({appType:'BIZ'},function(res){
			if(res.returnCode == 0){
				$scope.wechatConfigList = res.data;
				$scope.wechatConfigList.unshift({'wechatAppid':'','wechatName':'全部','id':'0'});
			}
		});
		
		
		$scope.dtColumns = [
		    DTColumnBuilder.newColumn('wechatAppid').withOption('width',120).withTitle('公众号').renderWith(function(e, dt, node, config){
		    	var wechatConfig = $filter('filter')($scope.wechatConfigList, { wechatAppid: node.wechatAppid }, true);
		    	console.log(wechatConfig)
		    	if(wechatConfig && wechatConfig.length > 0){
		    		return wechatConfig[0].wechatName;
		    	}
            	return "";
            }),
		    DTColumnBuilder.newColumn('msgType').withOption('width',80).withTitle('接收消息类型').renderWith(function(e, dt, node, config){
            	if(node.msgType == 'text'){
            		return '文本消息';
            	}else if(node.msgType == 'event'){
            		if(node.event == "subscribe"){
            			return '关注事件' + (node.eventKey ? '(扫码)':'');
            		}else if(node.event == "SCAN"){
            			return '扫码';
            		}else if(node.event == "LOCATION"){
            			return '上报地理位置';
            		}else if(node.event == "CLICK"){
            			return '点击菜单';
            		}else if(node.event == "VIEW"){
            			return '点击菜单链接';
            		}
            	}
            	return "";
            }),
		    DTColumnBuilder.newColumn('content').withOption('width',100).withTitle('接收消息内容'),
		    DTColumnBuilder.newColumn('replyMsgType').withOption('width',80).withTitle('回复消息类型').renderWith(function(e, dt, node, config){
            	if(node.replyMsgType == 'text'){
            		return '文本消息';
            	}else if(node.replyMsgType == 'image'){
            		return '图片消息';
            	}else if(node.replyMsgType == 'news'){
            		return '图文消息';
            	}else if(node.replyMsgType == 'video'){
            		return '视频消息';
            	}else if(node.replyMsgType == 'voice'){
            		return '语音消息';
            	}
            	return "";
            }),
            DTColumnBuilder.newColumn('remark').withOption('width',150).withTitle('备注'),
            DTColumnBuilder.newColumn('orderNo').withOption('width',60).withTitle('排序值'),
            DTColumnBuilder.newColumn('updatedBy').withOption('width',100).withTitle('最后操作人'),
            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', 100).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="addOrUpdate('+ data.id +')">修改</a></div>'
	                +'<div class="form-group"><a class="btn btn-link" ng-click="deleteMenu('+ data.id +')">删除</a></div>';
	            str += '</div>';
                return str;
            }))
		}
		$scope.dtOptions = DTOptionsBuilder.newOptions()
		.withOption('id','id')
//		.withFixedColumns({
//              rightColumns: 1
//         });

		$scope.dtInstance = {
			serverData : systemService.getWechatReplyConfigPageList
		};

		$scope.getParams =function(){
			var condition = {};
			if($scope.wechatConfig){
				condition.wechatAppid = $scope.wechatConfig.wechatAppid;
			}
			return {'condition':condition};
		}


		//查询
		$scope.submitForm = function(){
			$scope.dtInstance.query($scope.getParams());
		}
		
		$scope.addOrUpdate = function (wechatReplyId) {
	        $uibModal.open({
	            templateUrl: 'biz/system/view/wechatManager/wechatReplyConfigAdd.html',
	            controller: 'wechatReplyConfigAddCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'wechatReplyId':wechatReplyId}
	                }
	            }
	        }).result.then(function (data) {
	        	$scope.dtInstance.query($scope.getParams());
	        },function(){
	        	$scope.dtInstance.query($scope.getParams());
	        })
	    };
	    $scope.deleteMenu = function(wechatMenuId){
	    	SweetAlertX.swal({
                title: "确定要删除吗?",
                text: "",
                type: "info",
                showCancelButton: true,
                closeOnConfirm: false,
                showLoaderOnConfirm: true,
                confirmButtonText: "确认",
                cancelButtonText: "取消",
            },function(b){
                if(b){
                	systemService.deleteWechatReplyConfigById({'id':wechatMenuId},function(res){
        	    		swal({type: 'success',title: '',text: res.message||'操作成功',showConfirmButton:false,timer: 1500},function(){
        	    			 window.sweetAlert.close();
        	    			$scope.dtInstance.query($scope.getParams());
                        });
            		});
                }
            });
	    	
	    };
	}

	angular.module('system').controller('wechatReplyConfigCtrl', wechatReplyConfigCtrl)
})(angular);