|
@@ -15,10 +15,10 @@
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
<div class="line">
|
|
|
- <el-form-item label="市场价:" prop="normalPrice" :rules="{required:true, validator:checkPrice, type:'float', trigger:'blur'}">
|
|
|
+ <el-form-item label="市场价:" prop="normalPrice" :rules="{required:true, validator:checkMultiplePrice, type:'float', trigger:'blur'}">
|
|
|
<el-input v-model="formData.normalPrice" size="small" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="成本价:" prop="costPrice" :rules="{required:true, validator:checkPrice, type:'float', trigger:'blur'}">
|
|
|
+ <el-form-item label="成本价:" prop="costPrice" :rules="{required:true, validator:checkMultiplePrice, type:'float', trigger:'blur'}">
|
|
|
<el-input v-model="formData.costPrice" size="small" />
|
|
|
</el-form-item>
|
|
|
</div>
|
|
@@ -41,10 +41,10 @@
|
|
|
<div v-show="formData.ladderPriceFlag === 1" class="multiple">
|
|
|
<div class="group">
|
|
|
<div v-for="(item, index) in formData.ladderPriceList" :key="'ladderPrice'+index" class="line">
|
|
|
- <el-form-item label="起订量" label-width="60px" style="width:130px" :prop="'ladderPriceList.' + index + '.buyNum'" :rules="{validator:checkNumber, type:'number', trigger:'blur'}">
|
|
|
+ <el-form-item label="起订量" label-width="60px" style="width:130px" :prop="'ladderPriceList.' + index + '.buyNum'" :rules="{validator:checkMultipleNumber, type:'number', trigger:'blur'}">
|
|
|
<el-input v-model.number="item.buyNum" size="small" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="及以上,单价为" label-width="120px" style="width:210px" :prop="'ladderPriceList.' + index + '.buyPrice'" :rules="{validator:checkPrice, type:'float', trigger:'blur'}">
|
|
|
+ <el-form-item label="及以上,单价为" label-width="120px" style="width:210px" :prop="'ladderPriceList.' + index + '.buyPrice'" :rules="{validator:checkMultiplePrice, type:'float', trigger:'blur'}">
|
|
|
<el-input v-model="item.buyPrice" size="small" />
|
|
|
</el-form-item>
|
|
|
</div>
|
|
@@ -113,8 +113,8 @@ export default {
|
|
|
rules: {
|
|
|
classifyID: [{ required: true, message: '*必填', trigger: 'change' }],
|
|
|
ladderPriceFlag: [{ required: true, message: '*必填', trigger: 'change' }],
|
|
|
- retailPrice: [{ validator: this.checkPrice, type: 'float', trigger: 'blur' }],
|
|
|
- minBuyNumber: [{ validator: this.checkNumber, type: 'number', trigger: 'blur' }]
|
|
|
+ retailPrice: [{ validator: this.checkSinglePrice, type: 'float', trigger: 'blur' }],
|
|
|
+ minBuyNumber: [{ validator: this.checkSingleNumber, type: 'number', trigger: 'blur' }]
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -152,6 +152,9 @@ export default {
|
|
|
this.formData.ladderPriceList.push(JSON.parse(JSON.stringify(item)))
|
|
|
}
|
|
|
})
|
|
|
+ for (let i = 0; i < this.formData.ladderPriceList.length; i++) {
|
|
|
+ this.formData.ladderPriceList[i].buyPrice = this.toFloatFilter(this.formData.ladderPriceList[i].buyPrice)
|
|
|
+ }
|
|
|
}
|
|
|
this.ladderSize = this.formData.ladderPriceList.length
|
|
|
}
|
|
@@ -175,6 +178,11 @@ export default {
|
|
|
updateGoods() {
|
|
|
this.$refs['dataForm'].validate((valid) => {
|
|
|
if (valid) {
|
|
|
+ if (this.postData.ladderPriceList && this.postData.ladderPriceList.length > 0) {
|
|
|
+ for (let i = 0; i < this.postData.ladderPriceList.length; i++) {
|
|
|
+ this.postData.ladderPriceList[i].delFlag = 1
|
|
|
+ }
|
|
|
+ } else { this.postData.ladderPriceList = [] }
|
|
|
this.postData.classifyID = this.formData.classifyID
|
|
|
this.postData.normalPrice = this.formData.normalPrice
|
|
|
this.postData.costPrice = this.formData.costPrice
|
|
@@ -182,24 +190,15 @@ export default {
|
|
|
if (this.formData.ladderPriceFlag === 0) {
|
|
|
this.postData.retailPrice = this.formData.retailPrice
|
|
|
this.postData.minBuyNumber = this.formData.minBuyNumber
|
|
|
- for (let i = 0; i < this.postData.ladderPriceList.length; i++) {
|
|
|
- this.postData.ladderPriceList[i].delFlag = 1
|
|
|
- }
|
|
|
} else {
|
|
|
for (let i = 0; i < this.formData.ladderPriceList.length; i++) {
|
|
|
- this.formData.ladderPriceList[i].delFlag = 0
|
|
|
- }
|
|
|
- if (!this.postData.ladderPriceList || this.postData.ladderPriceList.length === 0) {
|
|
|
- this.postData.ladderPriceList = this.formData.ladderPriceList
|
|
|
- } else {
|
|
|
- for (let i = 0; i < this.postData.ladderPriceList.length; i++) {
|
|
|
- if (this.formData.ladderPriceList[i]) {
|
|
|
- this.postData.ladderPriceList[i].buyNum = this.formData.ladderPriceList[i].buyNum
|
|
|
- this.postData.ladderPriceList[i].buyPrice = this.formData.ladderPriceList[i].buyPrice
|
|
|
- this.postData.ladderPriceList[i].delFlag = 0
|
|
|
- } else {
|
|
|
- this.postData.ladderPriceList[i].delFlag = 1
|
|
|
- }
|
|
|
+ if (this.postData.ladderPriceList[i]) {
|
|
|
+ this.postData.ladderPriceList[i].delFlag = 0
|
|
|
+ this.postData.ladderPriceList[i].ladderNum = this.formData.ladderPriceList[i].ladderNum
|
|
|
+ this.postData.ladderPriceList[i].buyNum = this.formData.ladderPriceList[i].buyNum
|
|
|
+ this.postData.ladderPriceList[i].buyPrice = this.formData.ladderPriceList[i].buyPrice
|
|
|
+ } else {
|
|
|
+ this.postData.ladderPriceList.push(JSON.parse(JSON.stringify(this.formData.ladderPriceList[i])))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -212,38 +211,91 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
/** 自定义校验规则 */
|
|
|
- checkPrice(rule, value, callback) {
|
|
|
+ checkSinglePrice(rule, value, callback) {
|
|
|
+ if (this.formData.ladderPriceFlag === 1) {
|
|
|
+ return callback()
|
|
|
+ }
|
|
|
if (!value) {
|
|
|
return callback(new Error('*必填'))
|
|
|
}
|
|
|
this.$nextTick(() => {
|
|
|
if (!Number.parseFloat(value * 1)) {
|
|
|
- callback(new Error('*请输入正确的金额'))
|
|
|
+ return callback(new Error('*请输入正确的金额'))
|
|
|
} else {
|
|
|
if (('' + value).split('.').length > 1 && ('' + value).split('.')[1].length > 2) {
|
|
|
return callback(new Error('*最多保留两位小数'))
|
|
|
} else {
|
|
|
- callback()
|
|
|
+ return callback()
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- checkNumber(rule, value, callback) {
|
|
|
+ checkSingleNumber(rule, value, callback) {
|
|
|
+ if (this.formData.ladderPriceFlag === 1) {
|
|
|
+ return callback()
|
|
|
+ }
|
|
|
if (!value) {
|
|
|
return callback(new Error('*必填'))
|
|
|
}
|
|
|
this.$nextTick(() => {
|
|
|
if (!Number.isInteger(value)) {
|
|
|
- callback(new Error('*起订量数值填写错误'))
|
|
|
+ return callback(new Error('*起订量数值填写错误'))
|
|
|
+ } else {
|
|
|
+ return callback()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ checkMultiplePrice(rule, value, callback) {
|
|
|
+ if (this.formData.ladderPriceFlag === 0) {
|
|
|
+ return callback()
|
|
|
+ }
|
|
|
+ if (!value) {
|
|
|
+ return callback(new Error('*必填'))
|
|
|
+ }
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (!Number.parseFloat(value * 1)) {
|
|
|
+ return callback(new Error('*请输入正确的金额'))
|
|
|
+ } else {
|
|
|
+ if (('' + value).split('.').length > 1 && ('' + value).split('.')[1].length > 2) {
|
|
|
+ return callback(new Error('*最多保留两位小数'))
|
|
|
+ } else {
|
|
|
+ return callback()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ checkMultipleNumber(rule, value, callback) {
|
|
|
+ if (this.formData.ladderPriceFlag === 0) {
|
|
|
+ return callback()
|
|
|
+ }
|
|
|
+ if (!value) {
|
|
|
+ return callback(new Error('*必填'))
|
|
|
+ }
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (!Number.isInteger(value)) {
|
|
|
+ return callback(new Error('*起订量数值填写错误'))
|
|
|
} else {
|
|
|
if ((rule.fullField.indexOf('2') > 0 && this.formData.ladderPriceList[2].buyNum <= this.formData.ladderPriceList[1].buyNum) ||
|
|
|
(rule.fullField.indexOf('1') > 0 && this.formData.ladderPriceList[1].buyNum <= this.formData.ladderPriceList[0].buyNum)) {
|
|
|
return callback(new Error('*起订量必须大于上一个阶梯'))
|
|
|
} else {
|
|
|
- callback()
|
|
|
+ return callback()
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
+ },
|
|
|
+ /** 两位小数转换 */
|
|
|
+ toFloatFilter(num) {
|
|
|
+ let result = '' + num
|
|
|
+ const temp = result.split('.')
|
|
|
+ if (temp.length === 1) {
|
|
|
+ result += '.00'
|
|
|
+ } else if (temp.length > 1) {
|
|
|
+ if (temp[1].length < 2) {
|
|
|
+ result += '0'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
}
|
|
|
}
|
|
|
}
|