This commit is contained in:
2022-12-12 09:59:03 +08:00
parent 937a34f05e
commit f99c22984f
4 changed files with 130 additions and 146 deletions

View File

@@ -102,10 +102,32 @@ const _sfc_main = defineComponent({
});
const isPassword = computed(() => type.value == "password");
const composing = ref(false);
const formatMoney = function(s) {
var noNegative = true;
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")) + "";
if (parseFloat(s) < 0) {
s = Math.abs(s).toFixed(2) + "";
noNegative = false;
}
var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
var t = "";
for (let i = 0; i < l.length; i++) {
if (i % 3 == 2 && i != l.length - 1) {
t += l[i] + ",";
} else {
t += l[i] + "";
}
}
return (noNegative ? "" : "-") + t.split("").reverse().join("") + "." + r;
};
watch(() => props.type, () => {
type.value = props.type;
});
watch(() => props.modelValue, () => {
if (props.qfw) {
currentValue.value = formatMoney(props.modelValue.toString());
return;
}
currentValue.value = String(props.modelValue == null ? "" : props.modelValue);
});
const onInput = function(event) {
@@ -140,24 +162,6 @@ const _sfc_main = defineComponent({
onNumberBlur(event);
}
if (props.qfw) {
var formatMoney = function(s) {
var noNegative = true;
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")) + "";
if (parseFloat(s) < 0) {
s = Math.abs(s).toFixed(2) + "";
noNegative = false;
}
var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
var t = "";
for (let i = 0; i < l.length; i++) {
if (i % 3 == 2 && i != l.length - 1) {
t += l[i] + ",";
} else {
t += l[i] + "";
}
}
return (noNegative ? "" : "-") + t.split("").reverse().join("") + "." + r;
};
try {
let reg = /\d{1,3}(?=(\d{3})+$)/g;
console.log("\u6DFB\u52A0\uFF0C", formatMoney(props.modelValue.toString()));