Browse Source

收票人及详细地址验证

yangc 8 years ago
parent
commit
f4d5d35d6b

+ 85 - 78
src/main/webapp/resources/js/usercenter/controllers/forstore/buyer_invoice_ctrl.js

@@ -48,93 +48,100 @@ define(['app/app'], function(app) {
         $scope.bill = {};
         $scope.bill.address = {};
 
-            //保存发票信息
-            $scope.saveBill = function(flag) {
-                var dataValidFlag = $scope.checkValidFrom();
-                if (!flag && dataValidFlag && $scope.bill.is_agree) {
-                    $scope.bill.kind = $scope.billType
-                    if (!$scope.isAdd) { //修改
-                        doSave('修改发票信息');
-                    } else { // 新增
-                        doSave('添加发票');
-                    }
-                } else if (flag || !dataValidFlag) {
-                    toaster.pop('error', '请填写正确的发票信息');
-                } else {
-                    toaster.pop('error', '请勾选并阅读《发票须知》');
-                }
-            };
-            var doSave = function (message) {
-                $scope.bill.area = $scope.bill.address.province + "," + $scope.bill.address.city + "," + $scope.bill.address.district;
-                var file = null;
-                if($scope.bill.billInfo&&$scope.bill.billInfo[0]) {
-                    file = $scope.bill.billInfo[0];
+        //保存发票信息
+        $scope.saveBill = function(flag) {
+            var dataValidFlag = $scope.checkValidFrom();
+            if (!flag && dataValidFlag && $scope.bill.is_agree) {
+                $scope.bill.kind = $scope.billType
+                if (!$scope.isAdd) { //修改
+                    doSave('修改发票信息');
+                } else { // 新增
+                    doSave('添加发票');
                 }
-                $upload.upload({
-                    url: 'trade/bill/save',
-                    file: file,
-                    method: 'POST',
-                    data: {
-                        bill: $scope.bill
-                    }
-                }).success(function(data){
-                    toaster.pop('success', message + '成功');
-                    $scope.changeBillStatusFlag = false
-                    $state.reload();
-                }).error(function(data){
-                    toaster.pop('error', message + '失败');
-                });
+            } else if (flag || !dataValidFlag) {
+                toaster.pop('error', '请填写正确的发票信息');
+            } else {
+                toaster.pop('error', '请勾选并阅读《发票须知》');
             }
-
-            $scope.isDoUpload = false;
-            //上传发票许可证
-            $scope.onUploadPermission = function () {
-                $scope.isDoUpload = true;
-                if (event.target.files[0].size < 3*1024*1024) {
-                    $scope.bill.attachUrl = event.target.files[0].name;
-                } else {
-                    $scope.bill.attachUrl = '';
-                }
+        };
+        var doSave = function (message) {
+            $scope.bill.area = $scope.bill.address.province + "," + $scope.bill.address.city + "," + $scope.bill.address.district;
+            var file = null;
+            if($scope.bill.billInfo&&$scope.bill.billInfo[0]) {
+                file = $scope.bill.billInfo[0];
             }
-
-            //判断中文字符串的长度
-            var getRealStringLen = function (str) {
-                var realLength = 0, len = str.length, charCode = -1;
-                for (var i = 0; i < len; i++) {
-                    charCode = str.charCodeAt(i);
-                    if (charCode >= 0 && charCode <= 128) realLength += 1;
-                    else realLength += 2;
+            $upload.upload({
+                url: 'trade/bill/save',
+                file: file,
+                method: 'POST',
+                data: {
+                    bill: $scope.bill
                 }
-                return realLength;
-            }
+            }).success(function(data){
+                toaster.pop('success', message + '成功');
+                $scope.changeBillStatusFlag = false
+                $state.reload();
+            }).error(function(data){
+                toaster.pop('error', message + '失败');
+            });
+        }
 
-            $scope.validForm = {
-                validBillHead: true,
-                validBillName: true,
-                validBankName: true,
-                validDetailAddress: true,
-                validCompanyAddress: true
+        $scope.isDoUpload = false;
+        //上传发票许可证
+        $scope.onUploadPermission = function () {
+            $scope.isDoUpload = true;
+            if (event.target.files[0].size < 3*1024*1024) {
+                $scope.bill.attachUrl = event.target.files[0].name;
+            } else {
+                $scope.bill.attachUrl = '';
             }
+        }
 
-            $scope.checkValidFrom = function () {
-                var flag = true
-                angular.forEach($scope.validForm, function (item) {
-                    if (!item) {
-                        flag = false;
-                    }
-                })
-                return flag;
+        //判断中文字符串的长度
+        var getRealStringLen = function (str) {
+            var realLength = 0, len = str.length, charCode = -1;
+            for (var i = 0; i < len; i++) {
+                charCode = str.charCodeAt(i);
+                if (charCode >= 0 && charCode <= 128) realLength += 1;
+                else realLength += 2;
             }
-        $scope.checkValidFrom();
-            //发票抬头check
-            $scope.checkBillHead = function () {
-                var len = getRealStringLen($scope.bill.head);
-                if (len > 100) {
-                    $scope.validForm.validBillHead = false;
-                } else {
-                    $scope.validForm.validBillHead = true;
+            return realLength;
+        }
+
+        $scope.validForm = {
+            validBillHead: true,
+            validBillName: true,
+            validBankName: true,
+            validDetailAddress: true,
+            validCompanyAddress: true
+        }
+        $scope.initFlag = {
+            initBillHead: true,
+            initBillName: true,
+            initBankName: true,
+            initDetailAddress: true,
+            initCompanyAddress: true
+        }
+
+        $scope.checkValidFrom = function () {
+            var flag = true
+            angular.forEach($scope.validForm, function (item) {
+                if (!item) {
+                    flag = false;
                 }
+            })
+            return flag;
+        }
+        $scope.checkValidFrom();
+        //发票抬头check
+        $scope.checkBillHead = function () {
+            var len = getRealStringLen($scope.bill.head);
+            if (len > 100) {
+                $scope.validForm.validBillHead = false;
+            } else {
+                $scope.validForm.validBillHead = true;
             }
+        }
 
         //收票人check
         $scope.checkBillName = function () {
@@ -238,7 +245,7 @@ define(['app/app'], function(app) {
                     case 2:
                         $scope.bill.address.district = item;
                         break;
-            }
+                }
             });
         };
         //删除按钮点击

+ 9 - 6
src/main/webapp/resources/view/usercenter/forstore/buyer_invoice.html

@@ -432,6 +432,9 @@
         position: relative;
         top: 5px;
     }
+    .bg-fff8ee {
+        background: #fff8ee;
+    }
 </style>
 <!--右侧主体部分-->
 <div class="user_right fr u_c_invoice">
@@ -525,14 +528,14 @@
                     <div class="form-group">
                         <label class="col-md-2 control-label"><b class="text-inverse">*</b>发票抬头:</label>
                         <div class="form-input-line">
-                            <input type="text" class="form-control" ng-model="bill.head" ng-focus="form.billHead.$touched = false" ng-blur="form.billHead.$touched = true; checkBillHead()" name="billHead" required="required" placeholder="请输入发票抬头">
+                            <input type="text" class="form-control" ng-class="{'bg-fff8ee': !initFlag.initBillHead&&(form.billHead.$invalid || !validForm.validBillHead)}" ng-model="bill.head" ng-focus="form.billHead.$touched = false; initFlag.initBillHead = false;" ng-blur="form.billHead.$touched = true; checkBillHead()" name="billHead" required="required" placeholder="请输入发票抬头">
                         </div>
                         <div class="text-inverse error col-md-3" ng-show="form.billHead.$touched&&(form.billHead.$invalid || !validForm.validBillHead)" ng-bind="form.billHead.$error.required?'请填写发票抬头':'请勿超过50个字'"></div>
                     </div>
                     <div class="form-group" ng-if="billType == 1205">
                         <label class="col-md-2 control-label"><b class="text-inverse">*</b>单位地址:</label>
                         <div class="form-input-line">
-                            <input type="text" class="form-control" ng-model="bill.companyAddress" ng-focus="form.companyAddr.$touched = false" ng-blur="form.companyAddr.$touched = true; checkCompanyAddress()" name="companyAddr" required="required" placeholder="请输入单位地址">
+                            <input type="text" class="form-control" ng-class="{'bg-fff8ee': !initFlag.initCompanyAddress&&(form.companyAddr.$invalid || !validForm.validCompanyAddress)}" ng-model="bill.companyAddress" ng-focus="form.companyAddr.$touched = false; initFlag.initCompanyAddress = false;" ng-blur="form.companyAddr.$touched = true; checkCompanyAddress()" name="companyAddr" required="required" placeholder="请输入单位地址">
                         </div>
                         <div class="text-inverse error col-md-3" ng-show="form.companyAddr.$touched&&(form.companyAddr.$invalid || !validForm.validCompanyAddress)" ng-bind="form.companyAddr.$error.required?'请填写单位地址':'请勿超过50个字'"></div>
                     </div>
@@ -553,7 +556,7 @@
                     <div class="form-group"  ng-if="billType == 1205">
                         <label class="col-md-2 control-label"><b class="text-inverse">*</b>开户银行:</label>
                         <div class="form-input-line">
-                            <input type="text" class="form-control" ng-model="bill.bankName" ng-focus="form.bankName.$touched = false" ng-blur="form.bankName.$touched = true; checkBankName()" name="bankName" required="required" placeholder="请输入开户银行">
+                            <input type="text" class="form-control" ng-class="{'bg-fff8ee': !initFlag.initBankName&&(form.bankName.$invalid || !validForm.validBankName)}" ng-model="bill.bankName" ng-focus="form.bankName.$touched = false;initFlag.initBankName = false;" ng-blur="form.bankName.$touched = true; checkBankName()" name="bankName" required="required" placeholder="请输入开户银行">
                         </div>
                         <div class="text-inverse error col-md-3" ng-show="form.bankName.$touched&&(form.bankName.$invalid || !validForm.validBankName)" ng-bind="form.bankName.$error.required?'请填写开户银行':'请勿超过30个字'"></div>
                     </div>
@@ -579,7 +582,7 @@
                     <div class="form-group">
                         <label class="col-md-2 control-label"><b class="text-inverse">*</b>收票人:</label>
                         <div class="form-input-line">
-                            <input id="mzbillname" type="text" class="form-control" ng-focus="form.billName.$touched = false" ng-blur="form.billName.$touched = true; checkBillName()" ng-model="bill.name" name="billName" required="required" placeholder="请输入收票人">
+                            <input id="mzbillname" ng-class="{'bg-fff8ee': !initFlag.initBillName&&(form.billName.$invalid || !validForm.validBillName)}" type="text" class="form-control" ng-focus="form.billName.$touched = false; initFlag.initBillName = false;" ng-blur="form.billName.$touched = true; checkBillName()" ng-model="bill.name" name="billName" required="required" placeholder="请输入收票人">
                         </div>
                         <div class="text-inverse error col-md-3" ng-show="form.billName.$touched&&(form.billName.$invalid || !validForm.validBillName)" ng-bind="form.billName.$error.required?'请填写收票人姓名':'请勿超过10个字'"></div>
                     </div>
@@ -620,8 +623,8 @@
                     <div class="form-group">
                         <label class="col-md-2 control-label"><b class="text-inverse">*</b>详细地址:</label>
                         <div class="form-input-line" style="width: 502px">
-                            <input id="mzaddress" type="text" class="form-control" required="required" name="billDetail" ng-model="bill.detailAddress" title="建议您填写详细发件地址,如街道名,门牌号,楼层和房间号等信息"
-                            placeholder="建议您填写详细发件地址,如街道名,门牌号,楼层和房间号等信息" ng-focus="form.billDetail.$touched = false" ng-blur="form.billDetail.$touched = true; checkDetailAddress()" >
+                            <input id="mzaddress" type="text" class="form-control" ng-class="{'bg-fff8ee': !initFlag.initDetailAddress&&(form.billDetail.$invalid|| !validForm.validDetailAddress)}" required="required" name="billDetail" ng-model="bill.detailAddress" title="建议您填写详细发件地址,如街道名,门牌号,楼层和房间号等信息"
+                            placeholder="建议您填写详细发件地址,如街道名,门牌号,楼层和房间号等信息" ng-focus="form.billDetail.$touched = false; initFlag.initDetailAddress = false;" ng-blur="form.billDetail.$touched = true; checkDetailAddress()" >
                         </div>
                         <div class="text-inverse error col-md-3" ng-show="form.billDetail.$touched&&(form.billDetail.$invalid|| !validForm.validDetailAddress)" ng-bind="form.billDetail.$error.required?'请填写详细地址':'请勿超过30个字'"></div>
                     </div>