移除了兑换积分的显示UI
This commit is contained in:
parent
bfb7d7630f
commit
449a91e582
@ -52,7 +52,6 @@
|
||||
<view class="bottom-bar" v-if="hasSelected">
|
||||
<view class="selected-info">
|
||||
<text>已选 {{ totalSelectedCount }} 件</text>
|
||||
<text class="selected-points">预计兑换 {{ totalRedeemPoints }} 积分</text>
|
||||
</view>
|
||||
<view class="btn-group">
|
||||
<button class="action-btn btn-ship" @tap="onShip">发货</button>
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user