This commit is contained in:
YeMingfei666 2024-07-25 11:33:38 +08:00
commit 0122589289
2 changed files with 48 additions and 16 deletions

25
src/utils/format.js Normal file
View File

@ -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
}

View File

@ -88,38 +88,38 @@
<el-table :data="form.skuList" border>
<el-table-column label="售价" prop="salePrice">
<template v-slot="scope">
<el-input-number v-model="scope.row.salePrice" controls-position="right"></el-input-number>
<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>
</template>
</el-table-column>
<el-table-column label="会员价" prop="memberPrice">
<template v-slot="scope">
<el-input-number v-model="scope.row.memberPrice" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'memberPrice')" @blur="priceFormat(scope.row,'memberPrice')" v-model="scope.row.memberPrice" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="成本价" prop="costPrice">
<template v-slot="scope">
<el-input-number v-model="scope.row.costPrice" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'costPrice')" @blur="priceFormat(scope.row,'costPrice')" v-model="scope.row.costPrice" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="原价" prop="originPrice">
<template v-slot="scope">
<el-input-number v-model="scope.row.originPrice" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'originPrice')" @blur="priceFormat(scope.row,'originPrice')" v-model="scope.row.originPrice" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="起售数量" prop="suit">
<template slot-scope="scope">
<el-input-number v-model="scope.row.suit" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'suit')" @blur="priceFormat(scope.row,'suit')" v-model="scope.row.suit" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="库存数量" prop="stockNumber">
<template v-slot="scope">
<el-input-number v-model="scope.row.stockNumber" :disabled="!!form.id"
<el-input-number @change="priceFormat(scope.row,'stockNumber')" @blur="priceFormat(scope.row,'stockNumber')" v-model="scope.row.stockNumber" :disabled="!!form.id"
controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="分销金额" prop="firstShared">
<template v-slot="scope">
<el-input-number v-model="scope.row.firstShared" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'firstShared')" @blur="priceFormat(scope.row,'firstShared')" v-model="scope.row.firstShared" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="商品条码">
@ -200,7 +200,7 @@
<i class="icon el-icon-edit" @click="batchNumber('salePrice')"></i>
</template>
<template slot-scope="scope">
<el-input-number 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">
@ -209,7 +209,7 @@
<i class="icon el-icon-edit" @click="batchNumber('memberPrice')"></i>
</template>
<template slot-scope="scope">
<el-input-number v-model="scope.row.memberPrice" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'memberPrice')" @blur="priceFormat(scope.row,'memberPrice')" v-model="scope.row.memberPrice" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="成本价" prop="costPrice">
@ -218,7 +218,7 @@
<i class="icon el-icon-edit" @click="batchNumber('costPrice')"></i>
</template>
<template slot-scope="scope">
<el-input-number v-model="scope.row.costPrice" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'costPrice')" @blur="priceFormat(scope.row,'costPrice')" v-model="scope.row.costPrice" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="原价" prop="originPrice">
@ -227,7 +227,7 @@
<i class="icon el-icon-edit" @click="batchNumber('originPrice')"></i>
</template>
<template slot-scope="scope">
<el-input-number v-model="scope.row.originPrice" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'originPrice')" @blur="priceFormat(scope.row,'originPrice')" v-model="scope.row.originPrice" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="起售数量" prop="suit">
@ -236,7 +236,7 @@
<i class="icon el-icon-edit" @click="batchNumber('suit')"></i>
</template>
<template slot-scope="scope">
<el-input-number v-model="scope.row.suit" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'originsuitrice')" @blur="priceFormat(scope.row,'suit')" v-model="scope.row.suit" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="库存数量" prop="stockNumber">
@ -245,7 +245,7 @@
<i class="icon el-icon-edit" @click="batchNumber('stockNumber')" v-if="!form.id"></i>
</template>
<template slot-scope="scope">
<el-input-number v-model="scope.row.stockNumber" :disabled="!!scope.row.id"
<el-input-number @change="priceFormat(scope.row,'stockNumber')" @blur="priceFormat(scope.row,'stockNumber')" v-model="scope.row.stockNumber" :disabled="!!scope.row.id"
controls-position="right"></el-input-number>
</template>
</el-table-column>
@ -255,7 +255,7 @@
<i class="icon el-icon-edit" @click="batchNumber('firstShared')"></i>
</template>
<template slot-scope="scope">
<el-input-number v-model="scope.row.firstShared" controls-position="right"></el-input-number>
<el-input-number @change="priceFormat(scope.row,'firstShared')" @blur="priceFormat(scope.row,'firstShared')" v-model="scope.row.firstShared" controls-position="right"></el-input-number>
</template>
</el-table-column>
<el-table-column label="商品条码">
@ -303,13 +303,13 @@
<div class="tips">开启后: 收银完成后会自动打印对应数量的标签数</div>
</el-form-item>
<el-form-item label="打包费">
<el-input-number 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" :min="0"></el-input-number>
<div class="tips">
单份商品打包费店铺开启外卖模式下该数据才生效
</div>
</el-form-item>
<el-form-item label="虚拟销量">
<el-input-number 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" :min="0"></el-input-number>
</el-form-item>
</template>
<el-form-item label="排序" v-if="form.id">
@ -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);