Browse Source

求购频道校验

yangc 8 years ago
parent
commit
6e59aa2318
2 changed files with 55 additions and 14 deletions
  1. 10 1
      components/applyPurchase/ApplyInfo.vue
  2. 45 13
      components/applyPurchase/PublishApply.vue

+ 10 - 1
components/applyPurchase/ApplyInfo.vue

@@ -103,6 +103,15 @@
     }
     }
     return len
     return len
   }
   }
+  let cutOutString = function (str, length) {
+    for (let i = 1; i <= str.length; i++) {
+      if (getRealLen(str.substr(0, i)) > length) {
+        str = str.substr(0, i - 1)
+        break
+      }
+    }
+    return str
+  }
   import Page from '~components/common/page/pageComponent.vue'
   import Page from '~components/common/page/pageComponent.vue'
   import Loading from '~components/common/loading/PageLoading.vue'
   import Loading from '~components/common/loading/PageLoading.vue'
   export default {
   export default {
@@ -302,7 +311,7 @@
       },
       },
       onProduceDateChange: function () {
       onProduceDateChange: function () {
         if (this.sayPriceObj.produceDate && getRealLen(this.sayPriceObj.produceDate) > 12) {
         if (this.sayPriceObj.produceDate && getRealLen(this.sayPriceObj.produceDate) > 12) {
-          this.sayPriceObj.produceDate = this.sayPriceObj.produceDate.substring(0, this.sayPriceObj.produceDate.length - 1)
+          this.sayPriceObj.produceDate = cutOutString(this.sayPriceObj.produceDate, 12)
         }
         }
       },
       },
       checkAllSayPrice: function () {
       checkAllSayPrice: function () {

+ 45 - 13
components/applyPurchase/PublishApply.vue

@@ -150,6 +150,15 @@
     }
     }
     return len
     return len
   }
   }
+  let cutOutString = function (str, length) {
+    for (let i = 1; i <= str.length; i++) {
+      if (getRealLen(str.substr(0, i)) > length) {
+        str = str.substr(0, i - 1)
+        break
+      }
+    }
+    return str
+  }
   let isIncludeChinese = function (str) {
   let isIncludeChinese = function (str) {
     for (let i = 0; i < str.length; i++) {
     for (let i = 0; i < str.length; i++) {
       if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
       if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
@@ -267,18 +276,14 @@
         this.$http.get('/search/similarComponents', {params: {keyword: this.applyObj.code}})
         this.$http.get('/search/similarComponents', {params: {keyword: this.applyObj.code}})
           .then(response => {
           .then(response => {
             this.similarCode = response.data
             this.similarCode = response.data
-            if (response.data.length) {
-              this.showSimilarCodeList = true
-            }
+            this.showSimilarCodeList = response.data.length > 0
           })
           })
       },
       },
       getSimilarBrand: function () {
       getSimilarBrand: function () {
         this.$http.get('/search/similarBrands', {params: {keyword: this.applyObj.brand}})
         this.$http.get('/search/similarBrands', {params: {keyword: this.applyObj.brand}})
           .then(response => {
           .then(response => {
             this.similarBrand = response.data
             this.similarBrand = response.data
-            if (response.data.length) {
-              this.showSimilarBrandList = true
-            }
+            this.showSimilarBrandList = response.data.length > 0
           })
           })
       },
       },
       checkCode: function () {
       checkCode: function () {
@@ -340,7 +345,7 @@
       },
       },
       onProduceDateChange: function () {
       onProduceDateChange: function () {
         if (this.applyObj.produceDate && getRealLen(this.applyObj.produceDate) > 12) {
         if (this.applyObj.produceDate && getRealLen(this.applyObj.produceDate) > 12) {
-          this.applyObj.produceDate = this.applyObj.produceDate.substring(0, this.applyObj.produceDate.length - 1)
+          this.applyObj.produceDate = cutOutString(this.applyObj.produceDate, 12)
         }
         }
       },
       },
       onEncapsulationChange: function () {
       onEncapsulationChange: function () {
@@ -349,22 +354,49 @@
         }
         }
       },
       },
       onCodeChange: function () {
       onCodeChange: function () {
-        if (this.applyObj.code && getRealLen(this.applyObj.code) > 100) {
-          this.applyObj.code = this.applyObj.code.substring(0, this.applyObj.code.length - 1)
+        if ((/[^\x00-\xff]/g).test(this.applyObj.code)) {
+          let chineseIndex = -1
+          for (let i = 0; i < this.applyObj.code.length; i++) {
+            if ((/[^\x00-\xff]/g).test(this.applyObj.code.charAt(i))) {
+              chineseIndex = i
+              break
+            }
+          }
+          this.applyObj.code = cutOutString(this.applyObj.code, chineseIndex)
+        } else if (this.applyObj.code && getRealLen(this.applyObj.code) > 100) {
+          this.applyObj.code = cutOutString(this.applyObj.code, 100)
         } else {
         } else {
           this.getSimilarCode()
           this.getSimilarCode()
         }
         }
       },
       },
       onBrandChange: function () {
       onBrandChange: function () {
-        if (this.applyObj.brand && getRealLen(this.applyObj.brand) > 50) {
-          this.applyObj.brand = this.applyObj.brand.substring(0, this.applyObj.brand.length - 1)
+        if ((/[^\x00-\xff]/g).test(this.applyObj.brand)) {
+          let chineseIndex = -1
+          for (let i = 0; i < this.applyObj.brand.length; i++) {
+            if ((/[^\x00-\xff]/g).test(this.applyObj.brand.charAt(i))) {
+              chineseIndex = i
+              break
+            }
+          }
+          this.applyObj.brand = cutOutString(this.applyObj.brand, chineseIndex)
+        } else if (this.applyObj.brand && getRealLen(this.applyObj.brand) > 50) {
+          this.applyObj.brand = cutOutString(this.applyObj.brand, 50)
         } else {
         } else {
           this.getSimilarBrand()
           this.getSimilarBrand()
         }
         }
       },
       },
       onAmountInput: function () {
       onAmountInput: function () {
-        if (this.applyObj.amount.length > 8 || !(/^[0-9]*$/).test(this.applyObj.amount)) {
-          this.applyObj.amount = this.applyObj.amount.substring(0, this.applyObj.amount.length - 1)
+        if (!(/^[0-9]*$/).test(this.applyObj.amount)) {
+          let chineseIndex = -1
+          for (let i = 0; i < this.applyObj.amount.length; i++) {
+            if (!(/^[0-9]*$/).test(this.applyObj.amount.charAt(i))) {
+              chineseIndex = i
+              break
+            }
+          }
+          this.applyObj.amount = cutOutString(this.applyObj.amount, chineseIndex)
+        } else if (this.applyObj.amount.length > 8) {
+          this.applyObj.amount = cutOutString(this.applyObj.amount, 8)
         }
         }
       },
       },
       onSuccess: function (data) {
       onSuccess: function (data) {