Browse Source

批量发布校验

yangc 8 years ago
parent
commit
480a4feee2
2 changed files with 50 additions and 50 deletions
  1. 46 10
      components/applyPurchase/BatchPublish.vue
  2. 4 40
      components/applyPurchase/PublishApply.vue

+ 46 - 10
components/applyPurchase/BatchPublish.vue

@@ -153,6 +153,15 @@
     }
     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'
   export default {
     data () {
@@ -467,34 +476,61 @@
         }
       },
       onProduceDateChange: function () {
-//        console.log(getRealLen(this.modifyObj.produceDate))
         if (this.modifyObj.produceDate && getRealLen(this.modifyObj.produceDate) > 12) {
-          console.log(this.modifyObj.produceDate.substring(0, this.modifyObj.produceDate.length - 1))
-          this.modifyObj.produceDate = this.modifyObj.produceDate.substring(0, this.modifyObj.produceDate.length - 1)
+          this.modifyObj.produceDate = cutOutString(this.modifyObj.produceDate, 12)
         }
       },
       onEncapsulationChange: function () {
         if (this.modifyObj.encapsulation && getRealLen(this.modifyObj.encapsulation) > 20) {
-          this.modifyObj.encapsulation = this.modifyObj.encapsulation.substring(0, this.modifyObj.encapsulation.length - 1)
+          this.modifyObj.encapsulation = cutOutString(this.modifyObj.encapsulation, 20)
         }
       },
       onCodeChange: function () {
-        if (this.modifyObj.code && getRealLen(this.modifyObj.code) > 30) {
-          this.modifyObj.code = this.modifyObj.code.substring(0, this.modifyObj.code.length - 1)
+        this.modifyObj.code = this.modifyObj.code.trim()
+        if ((/[^\x00-\xff]/g).test(this.modifyObj.code)) {
+          let chineseIndex = -1
+          for (let i = 0; i < this.modifyObj.code.length; i++) {
+            if ((/[^\x00-\xff]/g).test(this.modifyObj.code.charAt(i))) {
+              chineseIndex = i
+              break
+            }
+          }
+          this.modifyObj.code = cutOutString(this.modifyObj.code, chineseIndex)
+        } else if (this.modifyObj.code && getRealLen(this.modifyObj.code) > 100) {
+          this.modifyObj.code = cutOutString(this.modifyObj.code, 100)
         } else {
           this.getSimilarCode()
         }
       },
       onBrandChange: function () {
-        if (this.modifyObj.brand && getRealLen(this.modifyObj.brand) > 20) {
-          this.modifyObj.brand = this.modifyObj.brand.substring(0, this.modifyObj.brand.length - 1)
+        this.modifyObj.brand = this.modifyObj.brand.trim()
+        if ((/[^\x00-\xff]/g).test(this.modifyObj.brand)) {
+          let chineseIndex = -1
+          for (let i = 0; i < this.modifyObj.brand.length; i++) {
+            if ((/[^\x00-\xff]/g).test(this.modifyObj.brand.charAt(i))) {
+              chineseIndex = i
+              break
+            }
+          }
+          this.modifyObj.brand = cutOutString(this.modifyObj.brand, chineseIndex)
+        } else if (this.modifyObj.brand && getRealLen(this.modifyObj.brand) > 50) {
+          this.modifyObj.brand = cutOutString(this.modifyObj.brand, 50)
         } else {
           this.getSimilarBrand()
         }
       },
       onAmountInput: function () {
-        if (this.modifyObj.amount.length > 8 || !(/^[0-9]*$/).test(this.modifyObj.amount)) {
-          this.modifyObj.amount = this.modifyObj.amount.substring(0, this.modifyObj.amount.length - 1)
+        if (!(/^[0-9]*$/).test(this.modifyObj.amount)) {
+          let chineseIndex = -1
+          for (let i = 0; i < this.modifyObj.amount.length; i++) {
+            if (!(/^[0-9]*$/).test(this.modifyObj.amount.charAt(i))) {
+              chineseIndex = i
+              break
+            }
+          }
+          this.modifyObj.amount = cutOutString(this.modifyObj.amount, chineseIndex)
+        } else if (this.modifyObj.amount.length > 8) {
+          this.modifyObj.amount = cutOutString(this.modifyObj.amount, 8)
         }
       },
       setCode: function (code) {

+ 4 - 40
components/applyPurchase/PublishApply.vue

@@ -159,14 +159,6 @@
     }
     return str
   }
-  let isIncludeChinese = function (str) {
-    for (let i = 0; i < str.length; i++) {
-      if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
-        return true
-      }
-    }
-    return false
-  }
   export default {
     data () {
       return {
@@ -187,9 +179,7 @@
 //          encapsulation: true,
 //          produceDate: true,
           amount: true,
-          deadline: true,
-          brandChinese: true,
-          codeChinese: true
+          deadline: true
         },
         pickerOptions: {
           disabledDate (time) {
@@ -250,17 +240,9 @@
               })
           } else {
             if (!this.validObj.code) {
-              if (!this.validObj.codeChinese) {
-                this.$message.error('请勿填中文符号')
-              } else {
-                this.$message.error('型号不能为空')
-              }
+              this.$message.error('型号不能为空')
             } else if (!this.validObj.brand) {
-              if (!this.validObj.brandChinese) {
-                this.$message.error('请勿填中文符号')
-              } else {
-                this.$message.error('品牌不能为空')
-              }
+              this.$message.error('品牌不能为空')
             } else if (!this.validObj.deadline) {
               this.$message.error('截止日期不能为空')
             } else if (!this.validObj.amount || !this.validObj.unitPrice) {
@@ -288,34 +270,16 @@
       },
       checkCode: function () {
         this.validObj.code = this.applyObj.code && this.applyObj.code !== ''
-        if (isIncludeChinese(this.applyObj.code)) {
-          this.validObj.code = false
-          this.validObj.codeChinese = false
-        } else {
-          this.validObj.codeChinese = true
-        }
         return this.validObj.code
       },
       checkBrand: function () {
         this.validObj.brand = this.applyObj.brand && this.applyObj.brand !== ''
-        if (isIncludeChinese(this.applyObj.brand)) {
-          this.validObj.brand = false
-          this.validObj.brandChinese = false
-        } else {
-          this.validObj.brandChinese = true
-        }
         return this.validObj.brand
       },
       checkUnitPrice: function () {
         this.validObj.unitPrice = this.applyObj.unitPrice === '' ? true : this.applyObj.unitPrice > 0 && this.applyObj.unitPrice < 100000000
         return this.validObj.unitPrice
       },
-//      checkEncapsulation: function () {
-//        this.validObj.encapsulation = this.applyObj.encapsulation && this.applyObj.encapsulation !== ''
-//      },
-//      checkProduceDate: function () {
-//        this.validObj.produceDate = this.applyObj.produceDate && this.applyObj.produceDate !== ''
-//      },
       checkAmount: function () {
         this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 100000000
         return this.validObj.amount
@@ -350,7 +314,7 @@
       },
       onEncapsulationChange: function () {
         if (this.applyObj.encapsulation && getRealLen(this.applyObj.encapsulation) > 20) {
-          this.applyObj.encapsulation = this.applyObj.encapsulation.substring(0, this.applyObj.encapsulation.length - 1)
+          this.applyObj.encapsulation = cutOutString(this.applyObj.encapsulation, 20)
         }
       },
       onCodeChange: function () {