Browse Source

添加用户,删除用户

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@764 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
suntg 11 years ago
parent
commit
327d328a3e

+ 101 - 2
src/main/webapp/resources/js/index/app.js

@@ -1878,7 +1878,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 		});
 	});
 	
-	app.controller('UserCtrl', function($scope, $rootScope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal){
+	app.controller('UserCtrl', function($scope, $rootScope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http){
 		$scope.editing = false;
 		$scope.loading = true;
 		AuthenticationService.getAuthentication().success(function(data) {
@@ -1942,8 +1942,107 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 			});
 		};
 		
-		$scope.addUser = function(newUser) {
+		$scope.newUser = {};
+		
+		/**
+		 * 添加用户
+		 */
+		$scope.addUser = function() {
 			$scope.adding = true;
+			console.log($scope.newUser);
+			AccountUser.add({}, $scope.newUser, function(){
+				toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
+				$scope.newUser = {userSex: 'M'};
+				AccountUser.getAll({}, function(data){
+					users = data;
+					$scope.tableParams.reload();
+				});
+				$scope.adding = false;
+				$scope.newUserForm.newUserTel.$setValidity('available', false);
+				$scope.newUserForm.newUserEmail.$setValidity('available', false);
+				$scope.userTelSuccess = false;
+				$scope.userTelError = false;
+				$scope.userEmailSuccess = false;
+				$scope.userEmailError = false;
+			}, function(response){
+				toaster.pop('error', '错误', response.data);
+			});
+		};
+		
+		/**
+		 * 验证手机号是否可用
+		 */
+		$scope.telValid = function(tel) {
+			console.log($scope.newUser);
+			if(tel) {
+				$http.get('account/user/telEnable', {
+					params: {
+						tel: tel
+					}
+				}).success(function(data){
+					data = eval(data);
+					if(data == true) {
+						$scope.newUserForm.newUserTel.$setValidity('available', true);
+						$scope.userTelSuccess = true;
+						$scope.userTelError = false;
+					} else {
+						$scope.newUserForm.newUserTel.$setValidity('available', false);
+						$scope.userTelError = true;
+						$scope.userTelSuccess = false;
+					}
+				}).error(function(){
+					$scope.userTelSuccess = false;
+					$scope.userTelError = true;
+				});
+			} else {
+				$scope.userTelSuccess = false;
+				$scope.userTelError = false;
+			}
+		};
+		
+		/**
+		 * 验证邮箱是否可用
+		 */
+		$scope.emailValid = function(email) {
+			if(email) {
+				$http.get('account/user/emailEnable', {
+					params: {
+						email: email
+					}
+				}).success(function(data){
+					data = eval(data);
+					if(data == true) {
+						$scope.newUserForm.newUserEmail.$setValidity('available', true);
+						$scope.userEmailSuccess = true;
+						$scope.userEmailError = false;
+					} else {
+						$scope.newUserForm.newUserEmail.$setValidity('available', false);
+						$scope.userEmailError = true;
+						$scope.userEmailSuccess = false;
+					}
+				}).error(function(){
+					$scope.userEmailError = true;
+					$scope.userEmailSuccess = false;
+				});
+			} else {
+				$scope.userEmailError = false;
+				$scope.userEmailSuccess = false;
+			}
+		};
+		
+		/**
+		 * 删除用户
+		 */
+		$scope.removeUser = function(uu) {
+			AccountUser.remove({uu: uu}, function(){
+				toaster.pop('success', '提示', '删除用户成功。');
+				AccountUser.getAll({}, function(data){
+					users = data;
+					$scope.tableParams.reload();
+				});
+			}, function(){
+				toaster.pop('error', '提示', '删除用户失败。');
+			});
 		};
 	});
 	

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

@@ -17,6 +17,22 @@ define([ 'ngResource' ], function() {
 			updatePassword: {
 				url: 'account/user/updatePassword',
 				method: 'POST'
+			},
+			telEnable: {
+				url: 'account/user/telEnable',
+				method: 'GET'
+			},
+			emailEnable: {
+				url: 'account/user/emailEnable',
+				method: 'GET'
+			},
+			add: {
+				url: 'account/user/addUser',
+				method: 'POST'
+			},
+			remove: {
+				url: 'account/user/removeUser',
+				method: 'GET'
 			}
 		});
 	}).factory('ErpLog', function($resource) {