wechatMenuConfigCtrl.js 5.66 KB
(function(angular) {
	function wechatMenuConfigCtrl($scope, DTOptionsBuilder, DTColumnBuilder, systemService,$uibModal, $filter, $state,Utils,$rootScope,SweetAlertX) {		
		$scope.wechatConfigList = [];
		$scope.init = function(){
			systemService.listWechatConfig({appType:'BIZ'},function(res){
    			if(res.returnCode == 0){
    				$scope.wechatConfigList = res.data;
    				$scope.wechatConfigList.unshift({'wechatAppid':'','wechatName':'全部','id':'0'});
    			}
    		});
		};
		$scope.init();
		
		$scope.dtColumns = [
		    DTColumnBuilder.newColumn('id').withOption('width',40).withTitle('菜单ID'),
		    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('type').withOption('width',60).withTitle('菜单类型').renderWith(function(e, dt, node, config){
            	if(node.type == 'view'){
            		return '网页';
            	}else if(node.type == 'click'){
            		return '点击';
            	}else if(node.type == 'miniprogram'){
            		return '小程序';
            	}
            	return "";
            }),
		    DTColumnBuilder.newColumn('name').withOption('width',60).withTitle('菜单标题'),
		    DTColumnBuilder.newColumn('menuKey').withOption('width',60).withTitle('菜单KEY值'),
		    DTColumnBuilder.newColumn('url').withOption('width',180).withTitle('菜单网页链接'),
		    DTColumnBuilder.newColumn('appid').withOption('width',80).withTitle('小程序APPID'),
		    DTColumnBuilder.newColumn('pagepath').withOption('width',120).withTitle('小程序页面路径'),
		    DTColumnBuilder.newColumn('parentId').withOption('width',60).withTitle('父菜单ID'),
            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', 120).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="updateWechatMenu(\''+ data.wechatAppid +'\')">创建微信菜单</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({
			leftColumns: 0,
            rightColumns: 1,
            width: 300
         });

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

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


		//查询
		$scope.submitForm = function(){
			$scope.dtInstance.query($scope.getParams());
		}
		
		$scope.addOrUpdate = function (wechatMenuId) {
	        $uibModal.open({
	            templateUrl: 'biz/system/view/wechatManager/wechatMenuConfigAdd.html',
	            controller: 'wechatMenuConfigAddCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'wechatMenuId':wechatMenuId}
	                }
	            }
	        }).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.deleteWechatMenuConfigById({'id':wechatMenuId},function(res){
        	    		swal({type: 'success',title: '',text: res.message||'操作成功',showConfirmButton:false,timer: 1500},function(){
        	    			 window.sweetAlert.close();
        	    			$scope.dtInstance.query($scope.getParams());
                        });
            		});
                }
            });
	    };
	    $scope.updateWechatMenu=function(wechatAppid){
	    	console.log(wechatAppid)
	    	systemService.updateWechatMenu({'wechatAppid':wechatAppid},function(res){
	    		if(res.returnCode == 0){
    				swal({type: 'success',title: '',text: res.message||'操作成功',showConfirmButton:false,timer: 1500},function(){
                        window.sweetAlert.close();
                    });
    			}else{
    				swal({type: 'error',title: '',text: res.message||'操作失败',timer: 1500},function(){window.sweetAlert.close();});
    			}
    		});
	    };
	}

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