Commit 30a86de8 authored by 黄奎's avatar 黄奎

1

parent fd5aa2e3
...@@ -283,8 +283,10 @@ ...@@ -283,8 +283,10 @@
} else { } else {
validValue = this.$utils.checkPrice(value, true); validValue = this.$utils.checkPrice(value, true);
} }
// 更新数据 // 更新数据
item[field] = validValue; item[field] = validValue;
console.log("handleInput", item[field]);
// 触发其他逻辑(如计算) // 触发其他逻辑(如计算)
this.getTotal(); this.getTotal();
}, },
...@@ -297,7 +299,7 @@ ...@@ -297,7 +299,7 @@
} }
// 更新数据 // 更新数据
item[field] = formattedValue; item[field] = formattedValue;
this.$set(item, field, formattedValue); console.log("handleBlur", item[field]);
// 触发其他逻辑 // 触发其他逻辑
this.getTotal(); this.getTotal();
}, },
......
...@@ -237,43 +237,38 @@ function goZanYangUrl() { ...@@ -237,43 +237,38 @@ function goZanYangUrl() {
}); });
} }
//验证只能输入2位小数【负数:isMinus传true】 // utils.js
function checkPrice(value, isMinus) { function checkPrice(value, isMinus) {
var newValue = ''; // 确保 value 总是字符串
if (value) { let newValue = value === null || value === undefined ? '' : String(value);
newValue = value + '';
} const t = newValue[0] || '';
var t = newValue.length > 0 ? newValue[0] : ''; newValue = newValue.replace(/[^\d.]/g, ''); // 清除非法字符
newValue = newValue.replace(/[^\d.]/g, ''); //清除“数字”和“.”以外的字符 newValue = newValue.replace(/\.{2,}/g, '.'); // 保留第一个小数点
newValue = newValue.replace(/\.{2,}/g, '.'); //只保留第一个. 清除多余的 newValue = newValue
newValue = newValue .replace('.', "$#$")
.replace('.', "$#$") .replace(/\./g, '')
.replace(/\./g, '') .replace('$#$', '.');
.replace('$#$', '.'); newValue = newValue.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); // 限制两位小数
newValue = newValue.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
//如果第一位是负号,则允许添加 如果不允许添加负号 可以把这块注释掉 if (isMinus && t === '-') {
//是否允许负数 newValue = '-' + newValue;
if (isMinus && t == '-') { }
newValue = '-' + newValue; return newValue;
} }
return newValue;
} function checkInteger(value, isMinus) {
// 确保 value 总是字符串
//验证只能输入整数【负数:isMinus传true】 let newValue = value === null || value === undefined ? '' : String(value);
function checkInteger(value, isMinus) {
var newValue = ''; const t = newValue[0] || '';
if (value) { newValue = newValue.replace(/[^\d]/g, '');
newValue = value + ''; if (isMinus && t === '-') {
} newValue = '-' + newValue;
var t = newValue.length > 0 ? newValue[0] : ''; }
newValue = newValue.replace(/[^\d]/g, ''); return newValue;
//是否允许负数 }
if (isMinus && t == '-') {
newValue = '-' + newValue;
}
return newValue;
}
//判断是否为整数,小数,支持负数 //判断是否为整数,小数,支持负数
function checkIsNum(str) { function checkIsNum(str) {
var flag = false; var flag = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment