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

1

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