This commit is contained in:
YeMingfei666 2024-07-25 13:59:57 +08:00
commit 3ea8aeab34
2 changed files with 26 additions and 6 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) {

View File

@ -88,7 +88,7 @@
<el-table :data="form.skuList" border>
<el-table-column label="售价" prop="salePrice">
<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>
</el-table-column>
<el-table-column label="会员价" prop="memberPrice">
@ -303,13 +303,13 @@
<div class="tips">开启后: 收银完成后会自动打印对应数量的标签数</div>
</el-form-item>
<el-form-item label="打包费">
<el-input-number @change="priceFormat(form,'packFee')" @blur="priceFormat(form,'packFee')" v-model="form.packFee" controls-position="right" :min="0"></el-input-number>
<el-input-number @change="priceFormat(form,'packFee')" @blur="priceFormat(form,'packFee')" v-model="form.packFee" controls-position="right" ></el-input-number>
<div class="tips">
单份商品打包费店铺开启外卖模式下该数据才生效
</div>
</el-form-item>
<el-form-item label="虚拟销量">
<el-input-number @change="priceFormat(form,'baseSalesNumber')" @blur="priceFormat(form,'baseSalesNumber')" v-model="form.baseSalesNumber" controls-position="right" :min="0"></el-input-number>
<el-input-number @change="priceFormat(form,'baseSalesNumber')" @blur="priceFormat(form,'baseSalesNumber')" v-model="form.baseSalesNumber" controls-position="right" ></el-input-number>
</el-form-item>
</template>
<el-form-item label="排序" v-if="form.id">
@ -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
}
})
},
//