diff --git a/src/utils/format.js b/src/utils/format.js index 3a49b01..69788f0 100644 --- a/src/utils/format.js +++ b/src/utils/format.js @@ -4,9 +4,10 @@ * @param {number} price - 需要格式化的价格。 * @param {number} min - 价格的最小值。 * @param {number} max - 价格的最大值,默认为100000000。 + * @param {Boolean} returnIsArea - 是否返回值符合范围区间,默认为false。 * @returns {number} - 返回格式化后的价格,如果超出范围则返回最小值或最大值。 */ -export const formatPrice = (price,min=-Infinity, max = 100000000 ) => { +export const formatPrice = (price,min=-Infinity, max = 100000000,returnIsArea=false ) => { if(price === undefined || price === null||price===''){ return 0 } @@ -14,7 +15,11 @@ export const formatPrice = (price,min=-Infinity, max = 100000000 ) => { const newval = parseFloat(price.toFixed(2)) // 如果价格大于最大值,返回最大值 if (newval > max) { - return max + return returnIsArea?{value:max,error:true}:max + } + // 如果价格小于最小值,返回最小值 + if (newval < min) { + return returnIsArea?{value:min,error:true}:min } // 如果价格小于最小值,返回最小值 if (newval < min) { diff --git a/src/views/product/add_shop.vue b/src/views/product/add_shop.vue index 2e2306c..380fb50 100644 --- a/src/views/product/add_shop.vue +++ b/src/views/product/add_shop.vue @@ -88,7 +88,7 @@ @@ -519,8 +519,23 @@ export default { methods: { priceFormat(item,key){ + const messageheight=48; + const offset=window.innerHeight/2-(messageheight/2) -100 this.$nextTick(()=>{ - item[key]=formatPrice(item[key],0,100000000) + const min=0; + const max=100000000; + const newval=formatPrice(item[key],min,max,true) + console.log(newval) + if(typeof newval!=='number'){ + item[key]=newval.value + this.$message({ + offset, + message: `请输入${min}到${max}范围内的数字`, + type: "error" + }); + }else{ + item[key]=newval + } }) }, // 删除分组商品