diff --git a/pages/book/detail.vue b/pages/book/detail.vue index af1b647..01b5002 100644 --- a/pages/book/detail.vue +++ b/pages/book/detail.vue @@ -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) diff --git a/utils/index.ts b/utils/index.ts index 7490f19..8d31e23 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -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 }; } \ No newline at end of file