This commit is contained in:
闫晓茹 2023-03-01 17:47:29 +08:00
parent 622a50df62
commit 8d67cac8d6

View File

@ -281,9 +281,9 @@
</el-form-item>
<el-form-item label="优惠券适用门槛" prop="couponConsumePrice">
<el-input
@keyup.native="form.couponConsumePrice =oninput(form.couponConsumePrice) "
:change="checkPrice()"
maxlength="8"
v-model="form.couponConsumePrice"
placeholder="请输入优惠券适用门槛"
style="width: 220px"
@ -536,6 +536,28 @@ export default {
this.getList();
},
methods: {
/**只能输入数字且有小数点最多保留两位*/
checkPrice(){
let checkPlan = '' + this.form.couponConsumePrice
checkPlan = checkPlan
.replace(/[^\d.]/g, '') // .
.replace(/\.{2,}/g, '.') // .
.replace(/^\./g, '') // .
.replace('.', '$#$')
.replace(/\./g, '')
.replace('$#$', '.')
if (checkPlan.indexOf('.') < 0 && checkPlan !== '') {
// 0102
checkPlan = parseFloat(checkPlan) + ''
} else if (checkPlan.indexOf('.') >= 0) {
checkPlan = checkPlan
.replace(/^()*(\d+)\.(\d\d).*$/, '$1$2.$3') //
}
this.form.couponConsumePrice = checkPlan
},
oninput(num) {
let str = num;
const len1 = str.substr(0, 1);