Преглед на файлове

修复买家中心地址验证不统一和不可点击的问题

hulh преди 8 години
родител
ревизия
73de1ad77f
променени са 1 файла, в които са добавени 61 реда и са изтрити 33 реда
  1. 61 33
      src/main/webapp/resources/js/usercenter/controllers/forstore/buyer_home_ctrl.js

+ 61 - 33
src/main/webapp/resources/js/usercenter/controllers/forstore/buyer_home_ctrl.js

@@ -86,8 +86,8 @@ define(['app/app', 'calendar'], function(app) {
         $scope.editAddr = function(isSetTop, addr) {
             $scope.isnotCheck = true;
             $modal.open({
-                templateUrl : $rootScope.rootPath + '/static/view/prod/modal/editAddr_modal.html',
-                controller : 'editAddrCtrl',
+                templateUrl : $rootScope.rootPath + '/static/view/common/modal/edit_address_modal.html',
+                controller : 'editAddrHomeCtrl',
                 size : 'lg',
                 resolve : {
                     isSetTop : function(){
@@ -194,46 +194,61 @@ define(['app/app', 'calendar'], function(app) {
     }]);
 
     //地址编辑模态框
-    app.register.controller('editAddrCtrl', ['$scope', 'isSetTop', 'addr', '$modalInstance', 'toaster', '$http', 'ShippingAddress', function($scope, isSetTop, addr, $modalInstance, toaster, $http, ShippingAddress){
-        $scope.isSetTop = isSetTop;
+    app.register.controller('editAddrHomeCtrl', ['$scope', 'isSetTop', 'addr', '$modalInstance', 'toaster', '$http', 'ShippingAddress', function($scope, isSetTop, addr, $modalInstance, toaster, $http, ShippingAddress){
+        if (addr){
+            $scope.isSetTop = addr.num == 1;
+        }else {
+            $scope.isSetTop = isSetTop;
+        }
         //验证数据
         $scope.checkeds = {};
-        $scope.checkform = function(name,num) {
+
+        $scope.checkForm = function(num) {
             var size;
             if(num == 1) {
-                size = document.getElementById("muserName").value.length;
-                console.log(size);
-                if (size > 10) {
-                    $scope.userError = true;
-                    console.log($scope.linkError);
-                    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;
-                // console.log($scope.userError);
             } else if(num == 2) {
-                size = document.getElementById("maddr").value.length;
-                console.log(size);
-                if (size > 30) {
-                    $scope.addrError = true;
-                    console.log($scope.linkError);
-                    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.addrError = false;
-                console.log($scope.userError);
             } else if(num == 3) {
-                if(angular.isUndefined(name)) {
-                    $scope.checkeds.tel = false;
-                } else {
-                    $scope.checkeds.tel = true;
+                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) {
-                if(angular.isUndefined(name)) {
-                    $scope.checkeds.landlineNumber = false;
-                } else {
-                    $scope.checkeds.landlineNumber = true;
+                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;
                 }
             }
         };
+
         $http.get('static/js/prod/data/city.json').success(function(data) {
             $scope.division = data;
             if(addr){
@@ -246,16 +261,29 @@ define(['app/app', 'calendar'], function(app) {
                 $scope.address = addr;
                 $scope.addr = true;
             }
-        }).error(function(e) {
+        }).error(function() {
             toaster.pop('error', '系统错误 ' + '加载城市信息失败');
         });
 
         $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;