优化-增加商品添加时数字输入框如果输入值超范围时重置数据的弹窗提醒

This commit is contained in:
2024-07-25 13:52:30 +08:00
parent 51c9c9e15c
commit 6aea8a9c8e
2 changed files with 24 additions and 4 deletions

View File

@@ -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) {