|
|
@@ -150,6 +150,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
|
|
|
+ }
|
|
|
let isIncludeChinese = function (str) {
|
|
|
for (let i = 0; i < str.length; i++) {
|
|
|
if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
|
@@ -267,18 +276,14 @@
|
|
|
this.$http.get('/search/similarComponents', {params: {keyword: this.applyObj.code}})
|
|
|
.then(response => {
|
|
|
this.similarCode = response.data
|
|
|
- if (response.data.length) {
|
|
|
- this.showSimilarCodeList = true
|
|
|
- }
|
|
|
+ this.showSimilarCodeList = response.data.length > 0
|
|
|
})
|
|
|
},
|
|
|
getSimilarBrand: function () {
|
|
|
this.$http.get('/search/similarBrands', {params: {keyword: this.applyObj.brand}})
|
|
|
.then(response => {
|
|
|
this.similarBrand = response.data
|
|
|
- if (response.data.length) {
|
|
|
- this.showSimilarBrandList = true
|
|
|
- }
|
|
|
+ this.showSimilarBrandList = response.data.length > 0
|
|
|
})
|
|
|
},
|
|
|
checkCode: function () {
|
|
|
@@ -340,7 +345,7 @@
|
|
|
},
|
|
|
onProduceDateChange: function () {
|
|
|
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 () {
|
|
|
@@ -349,22 +354,49 @@
|
|
|
}
|
|
|
},
|
|
|
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 {
|
|
|
this.getSimilarCode()
|
|
|
}
|
|
|
},
|
|
|
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 {
|
|
|
this.getSimilarBrand()
|
|
|
}
|
|
|
},
|
|
|
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) {
|