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);