Browse Source

修改卖家发货地址的验证逻辑

hulh 8 years ago
parent
commit
e2abd3efcb

+ 74 - 37
src/main/webapp/resources/js/vendor/controllers/forstore/vendor_delivery_ctrl.js

@@ -180,7 +180,7 @@ define(['app/app'], function(app) {
             $scope.isnotCheck = true;
             $modal.open({
                 templateUrl : 'static/view/common/modal/edit_address_modal.html',
-                controller : 'editAddrCtrl',
+                controller : 'editAddrDeCtrl',
                 size : 'lg',
                 resolve : {
                     addr : function(){
@@ -206,6 +206,7 @@ define(['app/app'], function(app) {
         var loadAddrs = function() {
             ShippingAddress.getListEnterprise({ship : false}, function(data) {
                 $scope.addresss = data;
+                $scope.total = $scope.addresss.length;
                 $scope.jsonSdAddress = {};
                 if($scope.addresss.length > 0) {
                     $scope.jsonSdAddress = $scope.addresss[0];
@@ -580,42 +581,19 @@ define(['app/app'], function(app) {
     }]);
 
     //地址编辑模态框
-    app.register.controller('editAddrCtrl', ['$scope', 'addr', '$modalInstance', 'toaster', '$http', 'ShippingAddress', function($scope, addr, $modalInstance, toaster, $http, ShippingAddress){
-        $scope.isSetTop = false;
+    app.register.controller('editAddrDeCtrl', ['$scope', 'addr', '$modalInstance', 'toaster', '$http', 'ShippingAddress', function($scope, addr, $modalInstance, toaster, $http, ShippingAddress){
+        if (addr){
+            $scope.isSetTop = addr.num == 1;
+            $scope.isModify = true;
+        }else {
+            $scope.isSetTop = false;
+            $scope.isModify = false;
+        }
 
         $scope.isSendType = true;
         //验证数据
         $scope.checkeds = {};
-        //验证数据
-        $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;
-                size = $scope.address.detailAddress.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) {
             $scope.division = data;
             if(addr){
@@ -628,16 +606,75 @@ define(['app/app'], function(app) {
                 $scope.address = addr;
                 $scope.addr = true;
             }
-        }).error(function(e) {
+        }).error(function() {
             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 () {
             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;
             address.area = strAres;
 

+ 0 - 1
src/main/webapp/resources/js/vendor/controllers/forstore/vendor_logistics_ctrl.js

@@ -364,7 +364,6 @@ define(['app/app', 'calendar'], function (app) {
 				if ($scope.address.name){
 					size = $scope.address.name.replace(/[^x00-xFF]/g,'**').length;
 					if (size > 20) {
-						console.log(size);
 						$scope.userError = true;
 						return;
 					}

+ 1 - 1
src/main/webapp/resources/view/vendor/forstore/vendor_delivery.html

@@ -144,7 +144,7 @@
                             <div>
                                 <a ng-if="checkinvoice.status!=404" class="taggle-address edit-address" ng-click="editAddr(jsonSdAddress)"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>&nbsp;编辑</a>
                                 <a ng-if="checkinvoice.status!=404" class="taggle-address" ng-click="taggleAddress(jsonSdAddress)"><i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;切换</a>
-                                <a ng-if="checkinvoice.status!=404" class="taggle-address" ng-click="editAddr()"><i class="fa fa-plus-square" aria-hidden="true"></i>&nbsp;新建</a>
+                                <a ng-if="checkinvoice.status!=404 && total < 20" class="taggle-address" ng-click="editAddr()"><i class="fa fa-plus-square" aria-hidden="true"></i>&nbsp;新建</a>
                             </div>
                         </span>
                     </li>