Просмотр исходного кода

修复买家确认页和账户中心收货地址的验证逻辑

hulh 8 лет назад
Родитель
Сommit
c7ea825e46

+ 63 - 101
src/main/webapp/resources/js/usercenter/controllers/forstore/account_manager_ctrl.js

@@ -278,7 +278,11 @@ define(['app/app'], function(app) {
 						return false;
 						return false;
 					},
 					},
 					isModify : function () {
 					isModify : function () {
-						return true;
+						if (address){
+							return true;
+						}else {
+							return false;
+						}
 					}
 					}
 				}
 				}
 			}).result.then(function(address){
 			}).result.then(function(address){
@@ -286,133 +290,76 @@ define(['app/app'], function(app) {
 					$scope.loadAddresses();
 					$scope.loadAddresses();
 				}
 				}
 			}, function(){
 			}, function(){
-				toaster.pop('info', '提示 ' + '您已取消发货地址的编辑');
+				// toaster.pop('info', '提示 ' + '您已取消发货地址的编辑');
 			});
 			});
 		};
 		};
 
 
-		$scope.addAddress = function () {
-			$modal.open({
-				templateUrl : $rootScope.rootPath + '/static/view/common/modal/edit_address_modal.html',
-				controller : 'addAddrCtrl',
-				size : 'lg',
-				resolve : {
-					isSendType : function () {
-						return false;
-					},
-					isModify : function () {
-						return false;
-					}
-				}
-			}).result.then(function(address){
-				if (address) {
-					$scope.loadAddresses();
-				}
-			}, function(){
-				toaster.pop('info', '提示 ' + '您已取消发货地址的编辑');
-			});
-		};
-
-		//地址新增模态框
-		app.register.controller('addAddrCtrl', ['$scope', '$modalInstance', 'toaster', '$http', 'ShippingAddress', 'isSendType', 'isModify', function($scope, $modalInstance, toaster, $http, ShippingAddress, isSendType, isModify){
-			$scope.isSendType = isSendType;
-			$scope.isSetTop = false;
-			$scope.isModify = isModify;
-			$http.get('static/js/prod/data/city.json').success(function(data) {
-				$scope.division = data;
-			}).error(function() {
-				toaster.pop('error', '系统错误 ' + '加载城市信息失败');
-			});
-
-			$scope.checkForm = function(name, num) {
-				var size;
-				if(num == 1) {
-					size = document.getElementById("userName").value.length;
-					if (size > 10) {
-						$scope.userError = true;
-						return;
-					}
-					$scope.userError = false;
-				} else if(num == 2) {
-					size = document.getElementById("tel").value.length;
-					if (size > 11) {
-						$scope.telError = true;
-						return;
-					}
-					$scope.telError = false;
-				} else if(num == 3) {
-					size = document.getElementById("addr").value.length;
-					if (size > 30) {
-						$scope.addrError = true;
-						return;
-					}
-					$scope.addrError = false;
-				}
-			};
-
-			$scope.save = function () {
-				var address = $scope.address;
-
-				//拼装地区
-				address.area = address.province + ',' + address.city + ',' + address.district;
-
-
-				// send属性 控制本地址是否是发货地址
-				ShippingAddress.save({isSetTop: $scope.isSetTop, send: $scope.isSendType, isPersonal: !$scope.isSendType}, address, function(data){
-					toaster.pop('success', '成功 ', '保存收货地址成功');
-					$modalInstance.close(data);
-				}, function(){
-					toaster.pop('error', '系统错误 ', '保存收货地址失败');
-				});
-			};
-
-			$scope.cancel = function() {
-				$modalInstance.dismiss();
-			};
-		}]);
-
 		//地址编辑模态框
 		//地址编辑模态框
 		app.register.controller('editAddrCtrl', ['$scope', 'addr', '$modalInstance', 'toaster', '$http', 'ShippingAddress', 'isSendType', 'isModify', function($scope, addr, $modalInstance, toaster, $http, ShippingAddress, isSendType, isModify){
 		app.register.controller('editAddrCtrl', ['$scope', 'addr', '$modalInstance', 'toaster', '$http', 'ShippingAddress', 'isSendType', 'isModify', function($scope, addr, $modalInstance, toaster, $http, ShippingAddress, isSendType, isModify){
-			$scope.isSetTop = addr.num == 1;
+			if (addr){
+				$scope.isSetTop = addr.num == 1;
+			}else {
+				$scope.isSetTop = false;
+			}
 			$scope.isSendType = isSendType;
 			$scope.isSendType = isSendType;
 			$scope.isModify = isModify;
 			$scope.isModify = isModify;
 
 
-			$scope.checkForm = function(name, num) {
+			$scope.checkForm = function(num) {
 				var size;
 				var size;
 				if(num == 1) {
 				if(num == 1) {
-					size = document.getElementById("userName").value.length;
-					if (size > 10) {
-						$scope.userError = true;
-						return;
+					if ($scope.address.name){
+						size = $scope.address.name.replace(/[^x00-xFF]/g,'**').length;
+						if (size > 20) {
+							console.log(size);
+							$scope.userError = true;
+							return;
+						}
+						$scope.userError = false;
 					}
 					}
-					$scope.userError = false;
 				} else if(num == 2) {
 				} else if(num == 2) {
-					size = document.getElementById("tel").value.length;
-					if (size > 11) {
-						$scope.telError = true;
-						return;
+					if ($scope.address.tel){
+						size = $scope.address.tel.replace(/[^x00-xFF]/g,'**').length;
+						if (size < 8 || size > 11) {
+							$scope.telError = true;
+							return;
+						}
+						$scope.telError = false;
+						var telPatt = new RegExp("^[0-9]+$");
+						if (telPatt.test($scope.address.tel)){
+							$scope.telPatternError = false;
+						}else {
+							$scope.telPatternError = true;
+						}
 					}
 					}
-					$scope.telError = false;
 				} else if(num == 3) {
 				} else if(num == 3) {
-					size = document.getElementById("addr").value.length;
-					if (size > 30) {
-						$scope.addrError = true;
-						return;
+					if ($scope.address.detailAddress){
+						size = $scope.address.detailAddress.replace(/[^x00-xFF]/g,'**').length;
+						if (size > 60) {
+							$scope.addrError = true;
+							return;
+						}
+						$scope.addrError = false;
+					}
+				} else if(num == 4) {
+					var emailPatt = new RegExp("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$");
+					if ($scope.address.email.length > 0 && !emailPatt.test($scope.address.email)){
+						$scope.emailPatternError = true;
+					}else {
+						$scope.emailPatternError = false;
 					}
 					}
-					$scope.addrError = false;
 				}
 				}
 			};
 			};
 
 
 			$http.get('static/js/prod/data/city.json').success(function(data) {
 			$http.get('static/js/prod/data/city.json').success(function(data) {
 				$scope.division = data;
 				$scope.division = data;
 				if(addr && addr.area){
 				if(addr && addr.area){
-					$scope.address = addr;
+					// $scope.address = addr;
 					//拼装下拉选择框
 					//拼装下拉选择框
 					var arr = addr.area.split(',');
 					var arr = addr.area.split(',');
 					addr.province = arr[0];
 					addr.province = arr[0];
 					addr.city = arr[1];
 					addr.city = arr[1];
 					addr.district = arr[2];
 					addr.district = arr[2];
 					$scope.address = addr;
 					$scope.address = addr;
-					$scope.addr = true;
 				}
 				}
 			}).error(function() {
 			}).error(function() {
 				toaster.pop('error', '系统错误 ' + '加载城市信息失败');
 				toaster.pop('error', '系统错误 ' + '加载城市信息失败');
@@ -421,6 +368,21 @@ define(['app/app'], function(app) {
 			$scope.save = function () {
 			$scope.save = function () {
 				var address = $scope.address;
 				var address = $scope.address;
 
 
+				if (!address){
+					toaster.pop('error', '请补充未填写的信息');
+					return ;
+				}
+				if (!address.name || !address.province || !address.city || !address.district ||
+					!address.detailAddress || !address.tel){
+					toaster.pop('error', '请补充未填写的信息');
+					return ;
+				}
+				if ($scope.userError || $scope.telError || $scope.addrError || $scope.telPatternError ||
+					$scope.emailPatternError){
+					toaster.pop('error', '请修改红色框内的信息');
+					return ;
+				}
+
 				//拼装地区
 				//拼装地区
 				address.area = address.province + ',' + address.city + ',' + address.district;
 				address.area = address.province + ',' + address.city + ',' + address.district;
 
 

+ 77 - 36
src/main/webapp/resources/js/usercenter/controllers/forstore/order_pay_ctrl.js

@@ -450,6 +450,13 @@ define(['app/app'], function(app) {
 				resolve : {
 				resolve : {
 					addr : function(){
 					addr : function(){
 						return angular.copy(addr);
 						return angular.copy(addr);
+					},
+					isModify : function () {
+						if (addr){
+							return true;
+						}else {
+							return false;
+						}
 					}
 					}
 				}
 				}
 			}).result.then(function(address){
 			}).result.then(function(address){
@@ -563,66 +570,100 @@ define(['app/app'], function(app) {
 	}]);
 	}]);
 
 
 	//地址编辑模态框
 	//地址编辑模态框
-	app.register.controller('editAddrCtrl', ['$scope', 'addr', '$modalInstance', 'toaster', '$http', 'ShippingAddress', function($scope, addr, $modalInstance, toaster, $http, ShippingAddress){
+	app.register.controller('editAddrCtrl', ['$scope', 'addr', '$modalInstance', 'toaster', '$http', 'ShippingAddress', 'isModify', function($scope, addr, $modalInstance, toaster, $http, ShippingAddress, isModify){
 		if (addr){
 		if (addr){
 			$scope.isSetTop = addr.num == 1;
 			$scope.isSetTop = addr.num == 1;
 		}else {
 		}else {
 			$scope.isSetTop = false;
 			$scope.isSetTop = false;
 		}
 		}
+		$scope.isModify = isModify;
 		$scope.validEmail = function (email) {
 		$scope.validEmail = function (email) {
 			return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email)
 			return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email)
         };
         };
-        //验证数据
-        $scope.checkForm = function(name, num) {
-            var size;
-            if(num == 1) {
-                size = document.getElementById("userName").value.length;
-                console.log(size);
-                if (size > 10) {
-                    $scope.userError = true;
-                    return;
-                }
-                $scope.userError = false;
-            } else if(num == 2) {
-                size = document.getElementById("tel").value.length;
-                console.log(size);
-                if (size > 11) {
-                    $scope.telError = true;
-                    return;
-                }
-                $scope.telError = false;
-            } else if(num == 3) {
-                size = document.getElementById("addr").value.length;
-                console.log(size);
-                if (size > 30) {
-                    $scope.addrError = true;
-                    return;
-                }
-                $scope.addrError = false;
-            }
-        };
+
 		$http.get('static/js/prod/data/city.json').success(function(data) {
 		$http.get('static/js/prod/data/city.json').success(function(data) {
 			$scope.division = data;
 			$scope.division = data;
 			if(addr && addr.area){
 			if(addr && addr.area){
-				$scope.address = addr;
+				// $scope.address = addr;
 				//拼装下拉选择框
 				//拼装下拉选择框
 				var arr = addr.area.split(',');
 				var arr = addr.area.split(',');
 				addr.province = arr[0];
 				addr.province = arr[0];
 				addr.city = arr[1];
 				addr.city = arr[1];
 				addr.district = arr[2];
 				addr.district = arr[2];
 				$scope.address = addr;
 				$scope.address = addr;
-				$scope.addr = true;
+				// $scope.addr = true;
 			}
 			}
-		}).error(function(e) {
+		}).error(function() {
 			toaster.pop('error', '系统错误 ' + '加载城市信息失败');
 			toaster.pop('error', '系统错误 ' + '加载城市信息失败');
 		});
 		});
 
 
+        //验证数据
+		$scope.checkForm = function(num) {
+			var size;
+			if(num == 1) {
+				if ($scope.address.name){
+					size = $scope.address.name.replace(/[^x00-xFF]/g,'**').length;
+					if (size > 20) {
+						$scope.userError = true;
+						return;
+					}
+					$scope.userError = false;
+				}
+			} else if(num == 2) {
+				if ($scope.address.tel){
+					size = $scope.address.tel.replace(/[^x00-xFF]/g,'**').length;
+					if (size < 8 || size > 11) {
+						$scope.telError = true;
+						return;
+					}
+					$scope.telError = false;
+					var telPatt = new RegExp("^[0-9]+$");
+					if (telPatt.test($scope.address.tel)){
+						$scope.telPatternError = false;
+					}else {
+						$scope.telPatternError = true;
+					}
+				}
+			} else if(num == 3) {
+				if ($scope.address.detailAddress){
+					size = $scope.address.detailAddress.replace(/[^x00-xFF]/g,'**').length;
+					if (size > 60) {
+						$scope.addrError = true;
+						return;
+					}
+					$scope.addrError = false;
+				}
+			} else if(num == 4) {
+				var emailPatt = new RegExp("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$");
+				if ($scope.address.email.length > 0 && !emailPatt.test($scope.address.email)){
+					$scope.emailPatternError = true;
+				}else {
+					$scope.emailPatternError = false;
+				}
+			}
+		};
+
+
+
 		$scope.save = function () {
 		$scope.save = function () {
 			var address = $scope.address;
 			var address = $scope.address;
+
+			if (!address){
+				toaster.pop('error', '请补充未填写的信息');
+				return ;
+			}
+			if (!address.name || !address.province || !address.city || !address.district ||
+				!address.detailAddress || !address.tel){
+				toaster.pop('error', '请补充未填写的信息');
+				return ;
+			}
+			if ($scope.userError || $scope.telError || $scope.addrError || $scope.telPatternError ||
+				$scope.emailPatternError){
+				toaster.pop('error', '请修改红色框内的信息');
+				return ;
+			}
+
 			//拼装地区
 			//拼装地区
-			/**
-			 * TODO 这里没做校验
-			 */
 			var strAres = address.province + ',' + address.city + ',' + address.district;
 			var strAres = address.province + ',' + address.city + ',' + address.district;
 			address.area = strAres;
 			address.area = strAres;
 
 

+ 1 - 1
src/main/webapp/resources/view/usercenter/forstore/account_manager.html

@@ -161,7 +161,7 @@
 	<!--收货地址-->
 	<!--收货地址-->
 	<div class="logistic-content" ng-if="tab=='logistics'">
 	<div class="logistic-content" ng-if="tab=='logistics'">
 		<div class="menu-title row">现有收货地址<span>&nbsp;已保存<em>{{total}}</em>条,还能新增<em>{{canAddTotal-total}}</em>条地址</span></div>
 		<div class="menu-title row">现有收货地址<span>&nbsp;已保存<em>{{total}}</em>条,还能新增<em>{{canAddTotal-total}}</em>条地址</span></div>
-		<div class="add-log row" ng-if="total < canAddTotal"><button ng-click="addAddress()"><i class="fa fa-plus-square"></i>新增收货地址</button></div>
+		<div class="add-log row" ng-if="total < canAddTotal"><button ng-click="modifyAddress()"><i class="fa fa-plus-square"></i>新增收货地址</button></div>
 		<div class="log-tab">
 		<div class="log-tab">
 			<table class="table">
 			<table class="table">
 				<thead>
 				<thead>

+ 1 - 1
src/main/webapp/resources/view/usercenter/forstore/order_pay.html

@@ -387,7 +387,7 @@
 			</ul>
 			</ul>
 			<div class="f14 notice margin-top-20 margin-bottom-10 text-center" ng-if="sendAddress.length == 0">您还没有添加收货地址信息,请先新增收货地址信息</div>
 			<div class="f14 notice margin-top-20 margin-bottom-10 text-center" ng-if="sendAddress.length == 0">您还没有添加收货地址信息,请先新增收货地址信息</div>
 			<div class="pay_add">
 			<div class="pay_add">
-				<a class="add_adr fl" ng-click="addShippingAddress()" ng-if="order.status == 501"><i class="fa fa-plus-square" aria-hidden="true"></i>&nbsp;新增地址</a>
+				<a class="add_adr fl" ng-click="addShippingAddress()" ng-if="order.status == 501 && sendAddress.length < 20"><i class="fa fa-plus-square" aria-hidden="true"></i>&nbsp;新增地址</a>
 				<a class="add_adr fr" ng-click="toggleAddress()" ng-if="sendAddress.length/3 > 1"><b ng-if="expand">隐藏地址</b><b ng-if="!expand">显示地址</b></a>
 				<a class="add_adr fr" ng-click="toggleAddress()" ng-if="sendAddress.length/3 > 1"><b ng-if="expand">隐藏地址</b><b ng-if="!expand">显示地址</b></a>
 			</div>
 			</div>
 		</div>
 		</div>