From 40ef38c045ac65c2e655e4bd5dce30f590017c7d Mon Sep 17 00:00:00 2001 From: Zhao Qiqi <1287235164@qq.com> Date: Wed, 6 Jul 2022 11:07:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yancheguanli/yancheguanliAdd.vue | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/anrui-scm/anrui-scm-ui/src/views/supplychain/yancheguanli/yancheguanliAdd.vue b/anrui-scm/anrui-scm-ui/src/views/supplychain/yancheguanli/yancheguanliAdd.vue index eacf3725e0..18f3d53c8b 100644 --- a/anrui-scm/anrui-scm-ui/src/views/supplychain/yancheguanli/yancheguanliAdd.vue +++ b/anrui-scm/anrui-scm-ui/src/views/supplychain/yancheguanli/yancheguanliAdd.vue @@ -55,6 +55,7 @@ placeholder="请输入洗车费" class="addinputw" clearable + @keyup.native="temp.price = oninput(temp.price,2)" /> @@ -135,6 +136,25 @@ export default { } }, methods: { + // 输入数字正则 + oninput(val, limit = 0) { + val = val.replace(/[^\d.]/g, '') //保留数字 + val = val.replace(/^00/, '0.') //开头不能有两个0 + val = val.replace(/^\./g, '0.') //开头为小数点转换为0. + val = val.replace(/\.{2,}/g, '.') //两个以上的小数点转换成一个 + val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.'); //只保留一个小数点 + /^0\d+/.test(val) ? val = val.slice(1) : '' //两位以上数字开头不能为0 + const str = '^(\\d+)\\.(\\d{' + limit + '}).*$' + const reg = new RegExp(str) + if (limit === 0) { + // 不需要小数点 + val = val.replace(reg, '$1') + } else { + // 通过正则保留小数点后指定的位数 + val = val.replace(reg, '$1.$2') + } + return val + }, showAdd(row) { this.$nextTick(() => { this.$refs['dataForm'].clearValidate()