fix: 修复 MALL 商品保存时 SKU 价格被反复 *100 的漂移

pull/341/head
YunaiV 2026-05-02 20:23:43 +08:00
parent 627e31f1b0
commit b293e112c6
2 changed files with 50 additions and 54 deletions

View File

@ -181,13 +181,11 @@ async function handleSubmit() {
.merge(descriptionFormApi) .merge(descriptionFormApi)
.merge(otherFormApi) .merge(otherFormApi)
.submitAllForm(true); .submitAllForm(true);
values.skus = formData.value.skus;
// SKU name // SKU name
if (!values.name || values.name.trim() === '') { if (!values.name || values.name.trim() === '') {
message.error('商品名称不能为空'); message.error('商品名称不能为空');
return; return;
} }
if (values.skus) {
try { try {
// sku // sku
skuListRef.value.validateSku(); skuListRef.value.validateSku();
@ -195,17 +193,16 @@ async function handleSubmit() {
message.error('【库存价格】不完善,请填写相关信息'); message.error('【库存价格】不完善,请填写相关信息');
return; return;
} }
values.skus.forEach((item) => {
// sku name 使 SKU
item.name = values.name;
// //
item.price = convertToInteger(item.price); values.skus = formData.value.skus!.map((item) => ({
item.marketPrice = convertToInteger(item.marketPrice); ...item,
item.costPrice = convertToInteger(item.costPrice); name: values.name,
item.firstBrokeragePrice = convertToInteger(item.firstBrokeragePrice); price: convertToInteger(item.price),
item.secondBrokeragePrice = convertToInteger(item.secondBrokeragePrice); marketPrice: convertToInteger(item.marketPrice),
}); costPrice: convertToInteger(item.costPrice),
} firstBrokeragePrice: convertToInteger(item.firstBrokeragePrice),
secondBrokeragePrice: convertToInteger(item.secondBrokeragePrice),
}));
// //
const newSliderPicUrls: any[] = []; const newSliderPicUrls: any[] = [];
values.sliderPicUrls!.forEach((item: any) => { values.sliderPicUrls!.forEach((item: any) => {
@ -235,14 +232,15 @@ async function getDetail() {
formLoading.value = true; formLoading.value = true;
try { try {
const res = await getSpu(spuId.value!); const res = await getSpu(spuId.value!);
// //
res.skus?.forEach((item) => { res.skus = res.skus?.map((item) => ({
item.price = formatToFraction(item.price); ...item,
item.marketPrice = formatToFraction(item.marketPrice); price: formatToFraction(item.price),
item.costPrice = formatToFraction(item.costPrice); marketPrice: formatToFraction(item.marketPrice),
item.firstBrokeragePrice = formatToFraction(item.firstBrokeragePrice); costPrice: formatToFraction(item.costPrice),
item.secondBrokeragePrice = formatToFraction(item.secondBrokeragePrice); firstBrokeragePrice: formatToFraction(item.firstBrokeragePrice),
}); secondBrokeragePrice: formatToFraction(item.secondBrokeragePrice),
}));
formData.value = res; formData.value = res;
// //
infoFormApi.setValues(res).then(); infoFormApi.setValues(res).then();

View File

@ -181,13 +181,11 @@ async function handleSubmit() {
.merge(descriptionFormApi) .merge(descriptionFormApi)
.merge(otherFormApi) .merge(otherFormApi)
.submitAllForm(true); .submitAllForm(true);
values.skus = formData.value.skus;
// SKU name // SKU name
if (!values.name || values.name.trim() === '') { if (!values.name || values.name.trim() === '') {
ElMessage.error('商品名称不能为空'); ElMessage.error('商品名称不能为空');
return; return;
} }
if (values.skus) {
try { try {
// sku // sku
skuListRef.value.validateSku(); skuListRef.value.validateSku();
@ -195,17 +193,16 @@ async function handleSubmit() {
ElMessage.error('【库存价格】不完善,请填写相关信息'); ElMessage.error('【库存价格】不完善,请填写相关信息');
return; return;
} }
values.skus.forEach((item) => {
// sku name 使 SKU
item.name = values.name;
// //
item.price = convertToInteger(item.price); values.skus = formData.value.skus!.map((item) => ({
item.marketPrice = convertToInteger(item.marketPrice); ...item,
item.costPrice = convertToInteger(item.costPrice); name: values.name,
item.firstBrokeragePrice = convertToInteger(item.firstBrokeragePrice); price: convertToInteger(item.price),
item.secondBrokeragePrice = convertToInteger(item.secondBrokeragePrice); marketPrice: convertToInteger(item.marketPrice),
}); costPrice: convertToInteger(item.costPrice),
} firstBrokeragePrice: convertToInteger(item.firstBrokeragePrice),
secondBrokeragePrice: convertToInteger(item.secondBrokeragePrice),
}));
// //
const newSliderPicUrls: any[] = []; const newSliderPicUrls: any[] = [];
values.sliderPicUrls!.forEach((item: any) => { values.sliderPicUrls!.forEach((item: any) => {
@ -235,14 +232,15 @@ async function getDetail() {
formLoading.value = true; formLoading.value = true;
try { try {
const res = await getSpu(spuId.value!); const res = await getSpu(spuId.value!);
// //
res.skus?.forEach((item) => { res.skus = res.skus?.map((item) => ({
item.price = formatToFraction(item.price); ...item,
item.marketPrice = formatToFraction(item.marketPrice); price: formatToFraction(item.price),
item.costPrice = formatToFraction(item.costPrice); marketPrice: formatToFraction(item.marketPrice),
item.firstBrokeragePrice = formatToFraction(item.firstBrokeragePrice); costPrice: formatToFraction(item.costPrice),
item.secondBrokeragePrice = formatToFraction(item.secondBrokeragePrice); firstBrokeragePrice: formatToFraction(item.firstBrokeragePrice),
}); secondBrokeragePrice: formatToFraction(item.secondBrokeragePrice),
}));
formData.value = res; formData.value = res;
// //
infoFormApi.setValues(res).then(); infoFormApi.setValues(res).then();