From 449a91e582e9f95c1e49f957f7e2c6e1064bf4c1 Mon Sep 17 00:00:00 2001 From: tsui110 Date: Wed, 24 Dec 2025 14:08:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=BA=86=E5=85=91=E6=8D=A2?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E7=9A=84=E6=98=BE=E7=A4=BAUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/cabinet/index.vue | 63 +++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/pages/cabinet/index.vue b/pages/cabinet/index.vue index cca4c4e..0c051f7 100644 --- a/pages/cabinet/index.vue +++ b/pages/cabinet/index.vue @@ -52,7 +52,6 @@ 已选 {{ totalSelectedCount }} 件 - 预计兑换 {{ totalRedeemPoints }} 积分 @@ -144,6 +143,7 @@ const loading = ref(false) const page = ref(1) const pageSize = ref(100) const hasMore = ref(true) +const productMetaCache = new Map() const totalCount = computed(() => { return aggregatedList.value.reduce((sum, item) => sum + (item.count || 1), 0) @@ -157,14 +157,28 @@ const totalSelectedCount = computed(() => { return aggregatedList.value.reduce((sum, item) => sum + (item.selected ? item.selectedCount : 0), 0) }) -const totalRedeemPoints = computed(() => { - return aggregatedList.value.reduce((sum, item) => sum + (item.selected ? (Number(item.points) || 0) * (item.selectedCount || 0) : 0), 0) -}) - const isAllSelected = computed(() => { return aggregatedList.value.length > 0 && aggregatedList.value.every(item => item.selected) }) +async function fetchProductMeta(productId) { + const key = String(productId || '').trim() + if (!key) return null + if (productMetaCache.has(key)) return productMetaCache.get(key) + const res = await getProductDetail(productId) + const p = res && (res.data ?? res.result ?? res) + const meta = { + price: null + } + const rawPrice = (p && (p.price_sale ?? p.price)) ?? (res && res.price) + if (rawPrice !== undefined && rawPrice !== null) { + const n = Number(rawPrice) + if (!Number.isNaN(n)) meta.price = n / 100 + } + productMetaCache.set(key, meta) + return meta +} + onShow(() => { // Check for external tab switch request try { @@ -559,23 +573,11 @@ async function fetchProductPrices() { const list = currentList.value for (let i = 0; i < list.length; i++) { const item = list[i] - if (item.id && (!item.price || item.points === undefined || item.points === null)) { + if (item.id && !item.price) { try { - const res = await getProductDetail(item.id) - const p = res && (res.data ?? res.result ?? res) - if (res && (res.price !== undefined || res.data?.price !== undefined)) { - // 优先取 res.price,其次 res.data.price (兼容不同返回结构) - const raw = res.price !== undefined ? res.price : res.data?.price - const num = Number(raw) - item.price = isNaN(num) ? null : (num / 100) - } - if (p) { - const cands = [ - p.redeem_points, p.recycle_points, p.exchange_points, - p.points_redeem, p.points_value, p.points, p.points_required - ] - const val = cands.find(v => Number.isFinite(Number(v)) && Number(v) >= 0) - item.points = val !== undefined ? Number(val) : (item.points ?? 0) + const meta = await fetchProductMeta(item.id) + if (meta) { + if (!item.price && meta.price !== null) item.price = meta.price } } catch (e) { console.error('Fetch price failed for:', item.id, e) @@ -589,6 +591,12 @@ function toggleSelect(item) { if (item.selected) { // 选中时默认数量为最大值 item.selectedCount = item.count + if (!item.price && item.id) { + fetchProductMeta(item.id).then(meta => { + if (!meta) return + if (!item.price && meta.price !== null) item.price = meta.price + }).catch(() => {}) + } } } @@ -598,6 +606,12 @@ function toggleSelectAll() { item.selected = newState if (newState) { item.selectedCount = item.count + if (!item.price && item.id) { + fetchProductMeta(item.id).then(meta => { + if (!meta) return + if (!item.price && meta.price !== null) item.price = meta.price + }).catch(() => {}) + } } }) } @@ -635,7 +649,7 @@ async function onRedeem() { uni.showModal({ title: '确认兑换', - content: `确定要兑换选中的 ${allIds.length} 件物品,预计获得 ${totalRedeemPoints.value} 积分吗?此操作不可撤销。`, + content: `确定要兑换选中的 ${allIds.length} 件物品吗?此操作不可撤销。`, success: async (res) => { if (res.confirm) { uni.showLoading({ title: '处理中...' }) @@ -977,11 +991,6 @@ async function onShip() { flex-direction: column; gap: 6rpx; } -.selected-points { - font-size: 22rpx; - color: $brand-primary; - font-weight: 700; -} .btn-group { display: flex; gap: 20rpx;