优化-增加商品添加时数字输入框如果输入值超范围时重置数据的弹窗提醒
This commit is contained in:
parent
51c9c9e15c
commit
6aea8a9c8e
|
|
@ -4,9 +4,10 @@
|
||||||
* @param {number} price - 需要格式化的价格。
|
* @param {number} price - 需要格式化的价格。
|
||||||
* @param {number} min - 价格的最小值。
|
* @param {number} min - 价格的最小值。
|
||||||
* @param {number} max - 价格的最大值,默认为100000000。
|
* @param {number} max - 价格的最大值,默认为100000000。
|
||||||
|
* @param {Boolean} returnIsArea - 是否返回值符合范围区间,默认为false。
|
||||||
* @returns {number} - 返回格式化后的价格,如果超出范围则返回最小值或最大值。
|
* @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===''){
|
if(price === undefined || price === null||price===''){
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +15,11 @@ export const formatPrice = (price,min=-Infinity, max = 100000000 ) => {
|
||||||
const newval = parseFloat(price.toFixed(2))
|
const newval = parseFloat(price.toFixed(2))
|
||||||
// 如果价格大于最大值,返回最大值
|
// 如果价格大于最大值,返回最大值
|
||||||
if (newval > max) {
|
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) {
|
if (newval < min) {
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@
|
||||||
<el-table :data="form.skuList" border>
|
<el-table :data="form.skuList" border>
|
||||||
<el-table-column label="售价" prop="salePrice">
|
<el-table-column label="售价" prop="salePrice">
|
||||||
<template v-slot="scope">
|
<template v-slot="scope">
|
||||||
<el-input-number :min="0" @change="priceFormat(scope.row,'salePrice')" @blur="priceFormat(scope.row,'salePrice')" v-model="scope.row.salePrice" controls-position="right"></el-input-number>
|
<el-input-number @change="priceFormat(scope.row,'salePrice')" @blur="priceFormat(scope.row,'salePrice')" v-model="scope.row.salePrice" controls-position="right"></el-input-number>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="会员价" prop="memberPrice">
|
<el-table-column label="会员价" prop="memberPrice">
|
||||||
|
|
@ -519,8 +519,23 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
priceFormat(item,key){
|
priceFormat(item,key){
|
||||||
|
const messageheight=48;
|
||||||
|
const offset=window.innerHeight/2-(messageheight/2) -100
|
||||||
this.$nextTick(()=>{
|
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
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 删除分组商品
|
// 删除分组商品
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue