Browse Source

绑定用户到企业

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@1301 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
luoq 10 years ago
parent
commit
b1d845b1fb

+ 169 - 8
src/main/webapp/resources/js/index/app.js

@@ -10,20 +10,24 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 			url : "/index",
 			views : {
 				"left-view" : {
-					templateUrl : "static/tpl/index/home/left.html"
+					templateUrl : "static/tpl/index/home/left.html",
+					controller: 'LeftCtrl'
 				},
 				"right-view" : {
-					templateUrl : "static/tpl/index/home/right.html"
+					templateUrl : "static/tpl/index/home/right.html",
+					controller: 'RightCtrl'
 				}
 			}
 		}).state('home', {
 			url : "/",
 			views : {
 				"left-view" : {
-					templateUrl : "static/tpl/index/home/left.html"
+					templateUrl : "static/tpl/index/home/left.html",
+					controller: 'LeftCtrl'
 				},
 				"right-view" : {
-					templateUrl : "static/tpl/index/home/right.html"
+					templateUrl : "static/tpl/index/home/right.html",
+					controller: 'RightCtrl'
 				}
 			}
 		}).state('sale', {
@@ -250,7 +254,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 				else if(cur == 'USD') return '$';
 				else if(cur == 'EUR') return '€';
 				else if(cur == null || cur == '') return '¥';
-				else return cur;
+				else return cur; 
 			}
 		};
 	});
@@ -266,7 +270,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 		});
 	}]);
 	app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', function($scope, $window, AuthenticationService, toaster) {
-		$scope.isAuthed = AuthenticationService.isAuthed();
+		$scope.isAuthed = AuthenticationService.isAuthed();		//AuthenticationService模块在common/下
 		$scope.userInfo = {};
 		AuthenticationService.getAuthentication().success(function(data) {
 			if(data.enterprises) {
@@ -608,7 +612,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 		});
 	}]);
 	app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
-		SnapshotService.getNotice(5, function(data){
+		SnapshotService.getNotice(5, function(data){	//5表示首页显示的公告条数
 			$scope.notices = data;
 		});
 		
@@ -2820,6 +2824,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 	}]);
 	
 	app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert){
+		
 		$scope.editing = false;
 		$scope.loading = true;
 		AuthenticationService.getAuthentication().success(function(data) {
@@ -2885,8 +2890,25 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 		
 		$scope.newUser = {};
 		
+		//弹出添加用户模态框
+		$scope.addExistUser = function(){
+			var modalInstance = $modal.open({
+				animation :true,
+				templateUrl : 'static/tpl/index/account/addExistUser.html',
+				controller : 'AddExistUserCtrl',
+			});
+			
+			modalInstance.result.then(function(){
+				
+			}, function(){
+				
+			});
+		};
+		
+		
+		
 		/**
-		 * 添加用户
+		 * 添加未注册用户
 		 */
 		$scope.addUser = function() {
 			$scope.adding = true;
@@ -3102,6 +3124,81 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
   		};
 	}]);
 	
+	/*
+	 * 绑定用户到企业
+	 */
+	app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', function($scope, $modalInstance,  FuzzySearch,AuthenticationService){
+		$scope.searching = false;
+		//根据输入的内容查找用户
+		$scope.searchUser = function(keyWord) {
+			$scope.searching = true;
+			$scope.searchSuccess = false;
+			$scope.searchFailed = false;
+			$scope.illegalError = false;
+			$scope.reBindError = false;
+			$scope.bindSuccess = false;
+			$scope.okDisabled = false;
+			FuzzySearch.searchUser({keyWord : keyWord}, function(data){
+				$scope.searchSuccess = true;
+				$scope.searchFailed = false;
+				$scope.user = data;		//查询到的用户
+			}, function(response){
+				$scope.searchSuccess = false;
+				$scope.searchFailed = true;
+			});
+		};
+		
+		//确认绑定
+		$scope.ok = function (keyWord) {
+			AuthenticationService.getAuthentication().success(function(data) {
+				$scope.currentUser = data;	//当前登录的用户(管理员)
+				//不可自己绑定自己
+				if($scope.currentUser.userUU == $scope.user.userUU){
+						$scope.illegalError = true;
+						$scope.okDisabled = true;
+						return false;
+				}
+				
+				//用户未绑定到任何企业时
+				if(!$scope.user.enterprises){
+					//正常绑定
+					FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
+						$scope.bindSuccess = true;	//绑定成功
+						$scope.okDisabled = true;
+					}, function(response){
+					});
+					return true;
+				}
+				
+				//用户已绑定到某些企业时
+				for(var i = 0; i < $scope.currentUser.enterprises.length; i++){
+					if($scope.currentUser.enterprises[i].current){
+						for(var j  = 0; j < $scope.user.enterprises.length; j++){
+							//该用户已绑定到当前企业,不可重复绑定
+							if($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu){
+								$scope.reBindError = true;
+								$scope.okDisabled = true;
+								return false;	
+							}
+						}
+						//该用户未绑定到当前企业,可以进行绑定
+						FuzzySearch.bindUserToMyEnterprise({userUU : $scope.user.userUU}, function(data){
+							$scope.bindSuccess = true;	//绑定成功
+							$scope.okDisabled = true;
+						}, function(response){
+							console.log("绑定失败!");
+						});
+						
+					}
+				}
+			});	
+  		};
+  		
+  		$scope.cancel = function () {
+    		$modalInstance.dismiss();
+  		};
+	}]);
+	
 	app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
 		$scope.erpParams = new ngTableParams({
 			page : 1, 
@@ -3592,6 +3689,70 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 		}
 	});
 	
+	//弹出问题反馈模态框
+	app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function($scope, $modal, AuthenticationService){
+		//获取当前用户
+		AuthenticationService.getAuthentication().success(function(data) {
+			$scope.user = data;
+		});
+		$scope.showModal = function(){
+			var modalInstance = $modal.open({
+				animation: true,
+				templateUrl: 'static/tpl/serve/feedback.html',
+				controller: 'FeedbackCtrl',
+				resolve: {
+					user: function(){return $scope.user;}	//传递当前用户到模态框Controller
+				}
+			});
+			modalInstance.result.then(function(){
+				
+			}, function(){
+				
+			})
+		}
+	}]);
+	
+	/*
+	 * 提交我的反馈
+	 */
+	app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user){
+		$scope.isPublic = 1;	//默认公开
+		$scope.classId = 1;		//默认类别
+		$scope.user = user;		
+		$scope.ok = function(){
+			if(!$scope.user){	//用户未登录
+				$scope.uu = null;
+			}else{				//用户已登录
+				$scope.uu = $scope.user.userUU;
+			}
+			//FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
+			FeedBackService.feedBackQuestion({classId: $scope.classId, isPublic: $scope.isPublic, title: $scope.title, userUU: $scope.uu}, {}, 
+			   function(data){
+					toaster.pop('success', '成功', '您的问题反馈成功!');
+					$scope.cancel();
+			}, function(response){
+					toaster.pop('error', '错误', response.data);
+			});
+		}
+		$scope.cancel = function () {
+    		$modalInstance.dismiss();
+  		};
+	}]);
+	
+	//“我的问题反馈”跳转控制
+	app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', function($scope, AuthenticationService, toaster){
+		$scope.myFeedback = function(){
+			AuthenticationService.getAuthentication().success(function(data){
+				$scope.user = data;
+				if(!$scope.user){
+					toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
+					return false;
+				}else{
+					window.location.href = "./serve#/question/myFeedback";
+				}
+			});
+		}
+	}]);
 	
 	return app;
 });

+ 12 - 0
src/main/webapp/resources/js/index/services/Account.js

@@ -40,5 +40,17 @@ define([ 'ngResource' ], function() {
 		return $resource('account/resource', {});
 	}]).factory('AccountRole', ['$resource', function($resource) {
 		return $resource('account/role/:id');
+	}]).factory('FuzzySearch', ['$resource', function($resource){			//------------LQ---------
+		return $resource('account/user', {}, {
+			searchUser: {
+				url: 'account/user/searchUser',
+				method: 'GET'
+			},
+			//绑定用户到企业
+			bindUserToMyEnterprise: {
+				url: 'account/user/bindUser',
+				method: 'GET'
+			}
+		})
 	}]);
 });