修复:补充提交课程与图书选择商品公共组件价格处理

This commit is contained in:
2025-11-26 09:25:05 +08:00
parent bf3aa6a484
commit 110050ca58
2 changed files with 18 additions and 10 deletions

View File

@@ -235,16 +235,6 @@ async function loadBookInfo() {
if (res.bookInfo) {
bookInfo.value = res.bookInfo
goodsList.value = [{
productId: bookId.value,
productName: bookInfo.value.name,
productImages: bookInfo.value.images,
price: bookInfo.value.abroadPrice || 0,
vipPrice: null,
activityPrice: null,
isVipPrice: 0,
productAmount: 1,
}]
}
} catch (error) {
console.error('Failed to load book info:', error)

View File

@@ -56,4 +56,22 @@ export const copyToClipboard = (content: string, title: string = '') => {
console.error('复制失败:', error)
}
})
}
/**
* 计算最低价格
*/
export const calculateLowestPrice = (priceData: object): { key: string, value: number } => {
const validEntries = Object.entries(priceData)
.filter(([, value]) => typeof value === 'number' && value !== 0);
if (validEntries.length === 0) {
throw new Error('No valid non-zero price found in the data');
}
const [minKey, minValue] = validEntries.reduce((min, curr) =>
curr[1] < min[1] ? curr : min
);
return { key: minKey, value: minValue };
}