This commit is contained in:
weiwei committed 2025-09-08 18:02:09 +08:00
commit b35b718fa2
2 files changed
+47 -9

No files matched your search

+42 -4
View File
@@ -67,12 +67,14 @@
<el-col :span="12" class="mb20">
<el-form-item label="SPU售价" prop="spuPrice">
<el-input-number v-model="form.spuPrice" :precision="2" :min="0" placeholder="请输入SPU售价" style="width: 100%"/>
<span class="price-tip">单位:元</span>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="划线价" prop="originalPrice">
<el-input-number v-model="form.originalPrice" :precision="2" :min="0" placeholder="请输入划线价" style="width: 100%"/>
<span class="price-tip">单位:元</span>
</el-form-item>
</el-col>
</template>
@@ -159,7 +161,7 @@
<el-table-column label="售价" width="140" align="center">
<template #header>
<span class="required">*</span> 售价
<span class="required">*</span> 售价(元)
</template>
<template #default="scope">
<div class="sku-cell">
@@ -184,9 +186,10 @@
<div class="sku-cell">
<el-input-number
v-model="scope.row.stock"
:precision="2"
:min="0"
size="small"
placeholder="0"
placeholder="0.00"
:class="{ 'is-error': (scope.row.stock === undefined || scope.row.stock < 0) && form.skuList.length > 0 }"
@blur="validateSkuField(scope.$index, 'stock')"
/>
@@ -360,7 +363,7 @@ const addSku = () => {
skuCode: '',
skuName: '',
price: 0,
stock: 0,
stock: 0.0,
barcode: '',
weightG: 0,
status: '0'
@@ -492,6 +495,20 @@ const onSubmit = async () => {
submitData.skuList = [];
}
// 价格转换:元转分
if (submitData.spuPrice) {
submitData.spuPrice = Math.round(submitData.spuPrice * 100);
}
if (submitData.originalPrice) {
submitData.originalPrice = Math.round(submitData.originalPrice * 100);
}
if (submitData.skuList && submitData.skuList.length > 0) {
submitData.skuList = submitData.skuList.map((sku: any) => ({
...sku,
price: sku.price ? Math.round(sku.price * 100) : 0
}));
}
form.id ? await putObj(submitData) : await addObj(submitData);
useMessage().success(form.id ? '修改成功' : '添加成功');
visible.value = false;
@@ -516,9 +533,23 @@ const getmallProductData = async (id: string) => {
await loadCategoryTree(form.merchantId);
}
// 价格转换:分转元
if (form.spuPrice) {
form.spuPrice = form.spuPrice / 100;
}
if (form.originalPrice) {
form.originalPrice = form.originalPrice / 100;
}
if (form.skuList && form.skuList.length > 0) {
form.skuList = form.skuList.map((sku: any) => ({
...sku,
price: sku.price ? sku.price / 100 : 0
}));
}
// 处理分类ID回显为数组
if (res.data.categoryId && categoryOptions.value.length) {
form.categoryId = findCategoryPath(categoryOptions.value, res.data.categoryId);
form.categoryId = findCategoryPath(categoryOptions.value, res.data.categoryId) as any;
}
// 如果没有SKU数据,根据定价方式初始化
@@ -749,6 +780,13 @@ defineExpose({
z-index: 2000;
}
// 价格提示样式
.price-tip {
font-size: 12px;
color: #909399;
margin-left: 8px;
}
:deep(.el-dialog__body) {
background: #fff;
position: relative;
+5 -5
View File
@@ -74,8 +74,8 @@
<div v-else class="no-sku">暂无SKU</div>
</div>
<div v-else>
<div class="spu-price">¥{{ scope.row.spuPrice || 0 }}</div>
<div v-if="scope.row.originalPrice" class="original-price">¥{{ scope.row.originalPrice }}</div>
<div class="spu-price">¥{{ ((scope.row.spuPrice || 0) / 100).toFixed(2) }}</div>
<div v-if="scope.row.originalPrice" class="original-price">¥{{ ((scope.row.originalPrice || 0) / 100).toFixed(2) }}</div>
</div>
</template>
</el-table-column>
@@ -150,7 +150,7 @@
<el-table-column prop="skuName" label="SKU名称" width="200"/>
<el-table-column prop="price" label="售价" width="120" align="right">
<template #default="scope">
<span class="price">¥{{ scope.row.price }}</span>
<span class="price">¥{{ ((scope.row.price || 0) / 100).toFixed(2) }}</span>
</template>
</el-table-column>
<el-table-column prop="stock" label="库存" width="100" align="center"/>
@@ -238,13 +238,13 @@ const {
// 获取SKU最低价格
const getMinPrice = (skuList: any[]) => {
if (!skuList || skuList.length === 0) return 0;
return Math.min(...skuList.map(sku => sku.price || 0));
return (Math.min(...skuList.map(sku => (sku.price || 0) / 100))).toFixed(2);
};
// 获取SKU最高价格
const getMaxPrice = (skuList: any[]) => {
if (!skuList || skuList.length === 0) return 0;
return Math.max(...skuList.map(sku => sku.price || 0));
return (Math.max(...skuList.map(sku => (sku.price || 0) / 100))).toFixed(2);
};
// 获取SKU总库存