This commit is contained in:
Viet An
2026-06-18 09:10:36 +07:00
parent b7c82e944d
commit 87397be8bf
18 changed files with 78 additions and 90 deletions

View File

@@ -1,10 +0,0 @@
<script setup>
const { $empty, $numtoString } = useNuxtApp();
const props = defineProps({
value: Number,
});
</script>
<template>
<span>{{ $empty(value) ? "-" : $numtoString(value) }}</span>
</template>

View File

@@ -37,10 +37,10 @@ export default {
},
created() {
if (this.defaultValue) {
this.value = this.value !== undefined ? this.$numtoString(this.value) : this.$numtoString(0);
this.value = this.value !== undefined ? this.$formatNum(this.value) : this.$formatNum(0);
} else {
if (this.value !== undefined && this.value !== null) {
this.value = this.$numtoString(this.value);
this.value = this.$formatNum(this.value);
} else {
this.value = "";
}
@@ -48,7 +48,7 @@ export default {
},
watch: {
record() {
this.value = this.$numtoString(this.record[this.attr]);
this.value = this.$formatNum(this.record[this.attr]);
},
},
methods: {
@@ -71,14 +71,14 @@ export default {
getDisplayValue(recordValue) {
if (this.defaultValue) {
if (recordValue === null || recordValue === undefined || recordValue === "") {
return this.$numtoString(0);
return this.$formatNum(0);
}
return this.$numtoString(recordValue);
return this.$formatNum(recordValue);
} else {
if (recordValue === null || recordValue === undefined || recordValue === "") {
return "";
}
return this.$numtoString(recordValue);
return this.$formatNum(recordValue);
}
},
doCheck() {
@@ -90,11 +90,11 @@ export default {
},
checkChange() {
if (!this.$empty(this.value)) {
this.value = this.$numtoString(this.$formatNumber(this.value));
this.$emit("number", this.$formatNumber(this.value));
this.value = this.$formatNum(this.$parseNum(this.value));
this.$emit("number", this.$parseNum(this.value));
} else {
if (this.defaultValue) {
this.value = this.$numtoString(0);
this.value = this.$formatNum(0);
this.$emit("number", 0);
} else {
this.value = "";

View File

@@ -462,31 +462,31 @@ const getMenu = function () {
};
var selectTab = getMenu()[0];
var datatype = store.datatype;
var current = 1;
var value1 = undefined;
var value2 = undefined;
// var current = 1;
// var value1 = undefined;
// var value2 = undefined;
const moneyunit = store.moneyunit;
const radioType = store.datatype.find((v) => v.code === currentField.format);
var selectUnit = currentField.format === "number" ? moneyunit.find((v) => v.detail === currentField.unit) : undefined;
var bgcolor = undefined;
var radioBGcolor = colorchoice.find((v) => v.code === "none");
var color = undefined;
var radioColor = colorchoice.find((v) => v.code === "none");
var textsize = undefined;
var radioSize = colorchoice.find((v) => v.code === "none");
// var selectUnit = currentField.format === "number" ? moneyunit.find((v) => v.detail === currentField.unit) : undefined;
// var bgcolor = undefined;
// var radioBGcolor = colorchoice.find((v) => v.code === "none");
// var color = undefined;
// var radioColor = colorchoice.find((v) => v.code === "none");
// var textsize = undefined;
// var radioSize = colorchoice.find((v) => v.code === "none");
var minwidth = undefined;
var radioWidth = colorchoice.find((v) => v.code === "none");
var radioMaxWidth = colorchoice.find((v) => v.code === "none");
// var radioWidth = colorchoice.find((v) => v.code === "none");
// var radioMaxWidth = colorchoice.find((v) => v.code === "none");
var maxwidth = undefined;
var selectAlign = undefined;
var radioAlign = colorchoice.find((v) => v.code === "none");
// var selectAlign = undefined;
// var radioAlign = colorchoice.find((v) => v.code === "none");
var radioTemplate = ref(colorchoice.find((v) => v.code === (currentField.template ? "option" : "none"))["code"]);
var selectPlacement = store.placement.find((v) => v.code === "is-right");
var selectScheme = store.colorscheme.find((v) => v.code === "is-primary");
var radioTooltip = store.colorchoice.find((v) => v.code === "none");
var selectField = undefined;
var tags = currentField.tags ? currentField.tags.map((v) => fields.find((x) => x.name === v)) : [];
var formula = currentField.formula ? currentField.formula : undefined;
// var selectPlacement = store.placement.find((v) => v.code === "is-right");
// var selectScheme = store.colorscheme.find((v) => v.code === "is-primary");
// var radioTooltip = store.colorchoice.find((v) => v.code === "none");
// var selectField = undefined;
// var tags = currentField.tags ? currentField.tags.map((v) => fields.find((x) => x.name === v)) : [];
// var formula = currentField.formula ? currentField.formula : undefined;
var decimal = currentField.decimal;
let shortmenu = store.menuchoice.filter((x) =>
currentField.format === "number"

View File

@@ -615,7 +615,7 @@ const checkExpression = function () {
tagsField.forEach((v) => {
let myRegExp = new RegExp(v.name, "g");
val = val.replace(myRegExp, Math.random());
exp = exp.replace(myRegExp, "formatNumber(row['" + v.name + "'])");
exp = exp.replace(myRegExp, "parseNum(row['" + v.name + "'])");
});
try {
let value = $calc(val);

View File

@@ -147,7 +147,7 @@ const {
$empty,
$find,
$getEditRights,
$formatNumber,
$parseNum,
$multiSort,
$remove,
$stripHtml,
@@ -420,8 +420,8 @@ const frontendFilter = function (newVal) {
else {
let text = "";
filter.map((y, k) => {
text += `${k > 0 ? (filter[k - 1].operator === "and" ? " &&" : " ||") : ""} ${$formatNumber(x[name])}
${y.condition === "=" ? "==" : y.condition === "<>" ? "!==" : y.condition} ${$formatNumber(y.value)}`;
text += `${k > 0 ? (filter[k - 1].operator === "and" ? " &&" : " ||") : ""} ${$parseNum(x[name])}
${y.condition === "=" ? "==" : y.condition === "<>" ? "!==" : y.condition} ${$parseNum(y.value)}`;
});
return $calc(text);
}
@@ -541,7 +541,7 @@ const updateData = async function (newVal) {
}
if (newVal.tablesetting) {
tablesetting = newVal.tablesetting;
perPage = $formatNumber(tablesetting.find((v) => v.code == "per-page").detail);
perPage = $parseNum(tablesetting.find((v) => v.code == "per-page").detail);
currentPage = 1;
}
tablesetting = $copy(pagedata.tablesetting || gridsetting);

View File

@@ -238,7 +238,7 @@ export default {
this.tagsField.forEach((v) => {
let myRegExp = new RegExp(v.name, "g");
val = val.replace(myRegExp, Math.random());
exp = exp.replace(myRegExp, "field.formatNumber(row['" + v.name + "'])");
exp = exp.replace(myRegExp, "field.parseNum(row['" + v.name + "'])");
});
try {
let value = this.$calc(val);

View File

@@ -221,8 +221,8 @@ const {
$stripHtml,
$snackbar,
$dayjs,
$formatNumber,
$numtoString,
$parseNum,
$formatNum,
$empty,
$unique,
$multiSort,
@@ -523,9 +523,9 @@ const formatCellValue = (value, field) => {
if (value === undefined || value === null || value === "") return "-";
if (field.format === "number") {
const num = $formatNumber(value);
const num = $parseNum(value);
if (num === undefined) return "-";
return $numtoString(num, "vi-VN", field.decimal || 0, field.decimal || 0);
return $formatNum(num, "vi-VN", field.decimal || 0, field.decimal || 0);
}
if (field.format === "date") {
@@ -596,8 +596,8 @@ const getDataCellStyle = (row, leaf) => {
if (cell && leaf.field) {
if (leaf.field === "paid_amount") {
const amount = $formatNumber(cell.amount) || 0;
const paid = $formatNumber(cell.paid_amount) || 0;
const amount = $parseNum(cell.amount) || 0;
const paid = $parseNum(cell.paid_amount) || 0;
if (paid >= amount) {
style += " background-color: #d4edda;";
} else if (paid > 0) {
@@ -608,8 +608,8 @@ const getDataCellStyle = (row, leaf) => {
}
if (leaf.field === "to_date") {
const dueDate = cell.to_date;
const paid = $formatNumber(cell.paid_amount) || 0;
const amount = $formatNumber(cell.amount) || 0;
const paid = $parseNum(cell.paid_amount) || 0;
const amount = $parseNum(cell.amount) || 0;
if (dueDate && paid < amount) {
const today = new Date();
const due = new Date(dueDate);

View File

@@ -433,7 +433,7 @@ export default {
checkTimeopt() {
if (this.timeopt > 0) {
let obj = this.$find(this.options, {
code: this.$formatNumber(this.timeopt),
code: this.$parseNum(this.timeopt),
});
if (obj) this.current = obj.code;
}
@@ -442,7 +442,7 @@ export default {
if (this.timeopt.disable.indexOf("time") >= 0) this.enableTime = false;
if (this.timeopt.time) {
let obj = this.$find(this.options, {
code: this.$formatNumber(this.timeopt.time),
code: this.$parseNum(this.timeopt.time),
});
if (obj) this.current = obj.code;
}

View File

@@ -3,7 +3,7 @@ const props = defineProps({
invItem: Object,
});
const { $dayjs, $numtoString } = useNuxtApp();
const { $dayjs, $formatNum } = useNuxtApp();
const emit = defineEmits("unselect");
</script>
@@ -54,13 +54,13 @@ const emit = defineEmits("unselect");
<div class="px-4 py-3 is-flex-grow-1 rounded-md has-background-blue-95 has-text-blue-40">
<p class="fs-13">Giá đơn vị</p>
<p class="fs-16 font-semibold">
{{ $numtoString(invItem.unit_price, { hasUnit: true }) }}
{{ $formatNum(invItem.unit_price, { hasUnit: true }) }}
</p>
</div>
<div class="px-4 py-3 is-flex-grow-1 rounded-md has-background-purple-90 has-text-purple-40">
<p class="fs-13">Tổng giá trị</p>
<p class="fs-16 font-semibold">
{{ $numtoString(invItem.total, { hasUnit: true }) }}
{{ $formatNum(invItem.total, { hasUnit: true }) }}
</p>
</div>
</div>

View File

@@ -2,7 +2,7 @@
const props = defineProps({
invoice: Object,
});
const { $numtoString } = useNuxtApp();
const { $formatNum } = useNuxtApp();
</script>
<template>
@@ -11,7 +11,7 @@ const { $numtoString } = useNuxtApp();
<div class="is-flex-grow-1 p-3 rounded-md has-background-white-bis">
<p class="fs-13 has-text-grey">Tổng tiền</p>
<p class="font-bold">
{{ $numtoString(invoice.total, { hasUnit: true }) }}
{{ $formatNum(invoice.total, { hasUnit: true }) }}
</p>
</div>
<div class="is-flex-grow-1 p-3 rounded-md has-background-success-95">
@@ -22,7 +22,7 @@ const { $numtoString } = useNuxtApp();
<div class="p-4 mt-4 rounded-md has-background-danger-95">
<p class="fs-13 has-text-danger-50">Còn lại</p>
<p class="fs-20 font-bold has-text-danger-40">
{{ $numtoString(invoice.total, { hasUnit: true }) }}
{{ $formatNum(invoice.total, { hasUnit: true }) }}
</p>
</div>
</div>

View File

@@ -3,7 +3,7 @@ const props = defineProps({
invoice: Object,
});
const { $getdata, $numtoString } = useNuxtApp();
const { $getdata, $formatNum } = useNuxtApp();
const invoiceDetails = ref([]);
onMounted(async () => {
invoiceDetails.value = await $getdata("Invoice_Detail", { filter: { invoice: props.invoice.id } });
@@ -22,12 +22,12 @@ onMounted(async () => {
<div class="fs-15 is-flex is-justify-content-space-between">
<p>{{ invoiceDetail.variant__product__name }}</p>
<p class="font-semibold">
{{ $numtoString(invoiceDetail.price, { hasUnit: true }) }}
{{ $formatNum(invoiceDetail.price, { hasUnit: true }) }}
</p>
</div>
<div class="is-flex is-gap-8 fs-13 has-text-grey-dark mt-1">
<p>SL: {{ invoiceDetail.quantity }}</p>
<p>Đơn giá: {{ $numtoString(invoiceDetail.price, { hasUnit: true }) }}</p>
<p>Đơn giá: {{ $formatNum(invoiceDetail.price, { hasUnit: true }) }}</p>
<p>
Giảm:
{{ new Intl.NumberFormat("vi-VN", { style: "percent" }).format(invoiceDetail.discount) }}
@@ -40,19 +40,19 @@ onMounted(async () => {
<tbody class="has-text-right">
<tr>
<td class="has-text-grey-dark">Tổng tiền hàng</td>
<td>{{ $numtoString(invoice.total_amount, { hasUnit: true }) }}</td>
<td>{{ $formatNum(invoice.total_amount, { hasUnit: true }) }}</td>
</tr>
<tr>
<td class="has-text-grey-dark">Phí vận chuyển</td>
<td>{{ $numtoString(invoice.shipping_fee, { hasUnit: true }) }}</td>
<td>{{ $formatNum(invoice.shipping_fee, { hasUnit: true }) }}</td>
</tr>
<tr>
<td class="has-text-grey-dark">Giảm giá</td>
<td>{{ $numtoString(invoice.discount_amount, { hasUnit: true }) }}</td>
<td>{{ $formatNum(invoice.discount_amount, { hasUnit: true }) }}</td>
</tr>
<tr class="font-bold">
<td>Tổng cộng</td>
<td class="fs-17">{{ $numtoString(invoice.final_amount, { hasUnit: true }) }}</td>
<td class="fs-17">{{ $formatNum(invoice.final_amount, { hasUnit: true }) }}</td>
</tr>
</tbody>
</table>

View File

@@ -9,7 +9,7 @@ const props = defineProps({
invoice: Object,
});
const { $dayjs, $numtoString } = useNuxtApp();
const { $dayjs, $formatNum } = useNuxtApp();
const emit = defineEmits(["unselect"]);
const tabs = [
@@ -89,7 +89,7 @@ const activeTab = ref(tabs[0]);
<div class="px-6 py-4 has-background-primary-95 rounded-lg mt-6">
<p>Tổng giá trị đơn hàng</p>
<p class="font-bold fs-25">
{{ $numtoString(invoice.total_amount, { hasUnit: true }) }}
{{ $formatNum(invoice.total_amount, { hasUnit: true }) }}
</p>
</div>
</div>

View File

@@ -286,7 +286,7 @@ export default {
data.map((x) => {
if (self.$empty(x[name])) x[name] = null;
else {
if (self.$isNumber(x[name])) x[name] = self.$formatNumber(x[name]);
if (self.$isNumber(x[name])) x[name] = self.$parseNum(x[name]);
else {
x["error"] = `${name} không phải là số`;
error = true;

View File

@@ -3,7 +3,7 @@ const props = defineProps({
cartItem: Object,
deleteable: Boolean,
});
const { $deleteapi, $numtoString, $snackbar } = useNuxtApp();
const { $deleteapi, $formatNum, $snackbar } = useNuxtApp();
const { getCarts } = inject("pos");
const showConfirmModal = ref();
const isDeleting = ref(false);
@@ -51,7 +51,7 @@ async function removeFromCart() {
</div>
</div>
<p class="has-text-primary-50 font-medium">
{{ $numtoString(cartItem.imei__variant__price, { hasUnit: true }) }}
{{ $formatNum(cartItem.imei__variant__price, { hasUnit: true }) }}
</p>
</div>
<button

View File

@@ -200,12 +200,12 @@ async function createOrder() {
<span>Tạm tính</span>
<span> ({{ activeCartItems.length }} sản phẩm)</span>
</td>
<td class="has-text-right">{{ $numtoString(subtotal, { hasUnit: true }) }}</td>
<td class="has-text-right">{{ $formatNum(subtotal, { hasUnit: true }) }}</td>
</tr>
<tr>
<td class="font-bold fs-14">Tổng cộng</td>
<td class="has-text-right has-text-success-35 font-bold fs-17">
{{ $numtoString(subtotal, { hasUnit: true }) }}
{{ $formatNum(subtotal, { hasUnit: true }) }}
</td>
</tr>
</tbody>

View File

@@ -9,7 +9,7 @@ import useOrderInfo from "~/components/pos/composables/useOrderInfo";
import SearchBox from "~/components/SearchBox.vue";
const store = useStore();
const { $numtoString } = useNuxtApp();
const { $formatNum } = useNuxtApp();
const { carts, cartItems, customers, getCarts, isPending } = useCartData();
@@ -313,12 +313,12 @@ provide("pos", {
<span>Tạm tính</span>
<span> ({{ activeCartItems?.length || 0 }} sản phẩm)</span>
</td>
<td class="has-text-right">{{ $numtoString(subtotal, { hasUnit: true }) }}</td>
<td class="has-text-right">{{ $formatNum(subtotal, { hasUnit: true }) }}</td>
</tr>
<tr>
<td class="font-bold fs-14">Tổng cộng</td>
<td class="has-text-right has-text-success-35 font-bold fs-17">
{{ $numtoString(subtotal, { hasUnit: true }) }}
{{ $formatNum(subtotal, { hasUnit: true }) }}
</td>
</tr>
</tbody>

View File

@@ -115,8 +115,8 @@ export default defineNuxtPlugin(() => {
return !isNaN(val);
};
const numtoString = function (val, config = undefined) {
if (empty(val)) return "0";
const formatNum = function (val, config = undefined) {
if (empty(val)) return "-";
val = val.toString().replace(/,/g, "");
if (isNaN(val)) return;
@@ -137,7 +137,7 @@ export default defineNuxtPlugin(() => {
return Number(val).toLocaleString(type, typeof decimal === "number" ? options : undefined) + unit;
};
const formatNumber = function (val) {
const parseNum = function (val) {
if (empty(val)) return;
val = val.toString().replace(/[,\.]/g, "");
if (val.indexOf("%") > 0) {
@@ -148,7 +148,7 @@ export default defineNuxtPlugin(() => {
};
const formatUnit = function (val, unit, decimal, string, mindecimal) {
val = formatNumber(val);
val = parseNum(val);
if (val === undefined) return;
let percentage = unit === 0.01 || unit === "0.01" ? "%" : "";
val = unit ? val / Number(unit) : val;
@@ -167,7 +167,7 @@ export default defineNuxtPlugin(() => {
let valid = 0;
tags.forEach((v) => {
let myRegExp = new RegExp(v, "g");
let res = this.$formatNumber(row[v]);
let res = this.$parseNum(row[v]);
if (res) valid = 1;
val = val.replace(myRegExp, `(${res || 0})`);
});
@@ -190,7 +190,7 @@ export default defineNuxtPlugin(() => {
const calculateFunc = function (row, cols, func, decimal, unit) {
let value;
let arr1 = cols.map((v) => this.$formatNumber(row[v]));
let arr1 = cols.map((v) => this.$parseNum(row[v]));
let arr = arr1.filter((v) => v);
if (arr.length === 0) return { success: false, value: undefined };
if (func === "max") value = Math.max(...arr);
@@ -322,8 +322,8 @@ export default defineNuxtPlugin(() => {
const key = sortKeys[index];
if (key) {
const direction = sortObject[key];
let val1 = format[key] === "number" ? (empty(a[key]) ? 0 : this.$formatNumber(a[key])) : a[key];
let val2 = format[key] === "number" ? (empty(b[key]) ? 0 : this.$formatNumber(b[key])) : b[key];
let val1 = format[key] === "number" ? (empty(a[key]) ? 0 : this.$parseNum(a[key])) : a[key];
let val2 = format[key] === "number" ? (empty(b[key]) ? 0 : this.$parseNum(b[key])) : b[key];
sorted = keySort(val1, val2, direction);
index++;
}
@@ -447,8 +447,8 @@ export default defineNuxtPlugin(() => {
remove,
stripHtml,
isNumber,
numtoString,
formatNumber,
formatNum,
parseNum,
formatUnit,
calc,
calculate,

View File

@@ -15,7 +15,6 @@ import Email from "~/components/marketing/email/Email.vue";
import Avatarbox from "~/components/common/Avatarbox.vue";
import CountdownTimer from "~/components/common/CountdownTimer.vue";
import FormatNumber from "~/components/common/FormatNumber.vue";
import FormatDate from "~/components/common/FormatDate.vue";
import InputNumber from "~/components/common/InputNumber.vue";
import CountWithAdd from "~/components/common/CountWithAdd.vue";
@@ -101,7 +100,6 @@ const components = {
InputNumber,
MenuPhone,
MenuParam,
FormatNumber,
FormatDate,
MenuAdd,
MenuNote,