Merge branch 'dev' of e.coding.net:g-cphe0354/yinshoukeguanliduan/management into gyq

This commit is contained in:
gyq 2024-07-26 09:46:33 +08:00
commit b88ae01878
3 changed files with 69 additions and 17 deletions

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

@ -0,0 +1,30 @@
/**
* 格式化价格函数将价格限定在指定的最小值和最大值范围内并保留两位小数
*
* @param {number} price - 需要格式化的价格
* @param {number} min - 价格的最小值
* @param {number} max - 价格的最大值默认为100000000
* @param {Boolean} returnIsArea - 是否返回值符合范围区间默认为false
* @returns {number} - 返回格式化后的价格如果超出范围则返回最小值或最大值
*/
export const formatPrice = (price,min=-Infinity, max = 100000000,returnIsArea=false ) => {
if(price === undefined || price === null||price===''){
return 0
}
// 将价格转换为浮点数并保留两位小数
const newval = parseFloat((Math.floor(price * 100) / 100).toFixed(2))
// 如果价格大于最大值,返回最大值
if (newval > max) {
return returnIsArea?{value:max,error:true}:max
}
// 如果价格小于最小值,返回最小值
if (newval < min) {
return returnIsArea?{value:min,error:true}:min
}
// 如果价格小于最小值,返回最小值
if (newval < min) {
return min
}
// 返回格式化后的价格
return newval
}

View File

@ -92,7 +92,7 @@
<el-table-column label="上架">
<template v-slot="scope">
<el-switch v-model="scope.row.isGrounding" :active-value="true" :inactive-value="false"
v-if="scope.row.hasChildren || scope.row.hasChildren == false" @change="showChangesss($event, scope.row)"></el-switch>
v-if="!scope.row.hasChildren" @change="showChangesss($event, scope.row)"></el-switch>
</template>
</el-table-column>
<el-table-column label="操作" width="240px">

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 @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" ></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" ></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,27 @@ export default {
}
},
methods: {
priceFormat(item,key){
const messageheight=48;
const offset=window.innerHeight/2-(messageheight/2) -100
this.$nextTick(()=>{
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
}
})
},
//
delGoods(goods, index, $index) {
goods.splice(index, 1);