From 016ebf7b62d0fad91da8508d1e2dec1601a41707 Mon Sep 17 00:00:00 2001 From: YeMingfei666 <1619116647@qq.com> Date: Thu, 25 Jul 2024 11:32:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E7=AE=A1=E7=90=86-=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=97=B6=E5=AF=B9=E4=BB=B7=E6=A0=BC=E9=87=91=E9=A2=9D=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E8=BF=9B=E8=A1=8C=E9=99=90=E5=88=B6=E5=92=8C=E6=95=B0?= =?UTF-8?q?=E5=AD=97=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/format.js | 25 ++++++++++++++++++++++ src/views/product/add_shop.vue | 39 ++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 src/utils/format.js diff --git a/src/utils/format.js b/src/utils/format.js new file mode 100644 index 0000000..3a49b01 --- /dev/null +++ b/src/utils/format.js @@ -0,0 +1,25 @@ +/** + * 格式化价格函数,将价格限定在指定的最小值和最大值范围内,并保留两位小数。 + * + * @param {number} price - 需要格式化的价格。 + * @param {number} min - 价格的最小值。 + * @param {number} max - 价格的最大值,默认为100000000。 + * @returns {number} - 返回格式化后的价格,如果超出范围则返回最小值或最大值。 + */ +export const formatPrice = (price,min=-Infinity, max = 100000000 ) => { + if(price === undefined || price === null||price===''){ + return 0 + } + // 将价格转换为浮点数并保留两位小数 + const newval = parseFloat(price.toFixed(2)) + // 如果价格大于最大值,返回最大值 + if (newval > max) { + return max + } + // 如果价格小于最小值,返回最小值 + if (newval < min) { + return min + } + // 返回格式化后的价格 + return newval +} \ No newline at end of file diff --git a/src/views/product/add_shop.vue b/src/views/product/add_shop.vue index 086484e..2e2306c 100644 --- a/src/views/product/add_shop.vue +++ b/src/views/product/add_shop.vue @@ -88,38 +88,38 @@ @@ -200,7 +200,7 @@ @@ -209,7 +209,7 @@ @@ -218,7 +218,7 @@ @@ -227,7 +227,7 @@ @@ -236,7 +236,7 @@ @@ -245,7 +245,7 @@ @@ -255,7 +255,7 @@ @@ -303,13 +303,13 @@
开启后: 收银完成后会自动打印对应数量的标签数
- +
单份商品打包费。注:店铺开启外卖模式下该数据才生效
- + @@ -355,6 +355,7 @@ import uploadImg from "@/components/uploadImg"; import settings from "@/settings"; import dayjs from "dayjs"; import { RandomNumBoth } from "@/utils"; +import { formatPrice } from "@/utils/format"; export default { components: { @@ -516,6 +517,12 @@ export default { } }, methods: { + + priceFormat(item,key){ + this.$nextTick(()=>{ + item[key]=formatPrice(item[key],0,100000000) + }) + }, // 删除分组商品 delGoods(goods, index, $index) { goods.splice(index, 1);