|
|
@@ -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) {
|