diff --git a/pages-shop/shop/detail.vue b/pages-shop/shop/detail.vue index 067ae43..d137ac6 100644 --- a/pages-shop/shop/detail.vue +++ b/pages-shop/shop/detail.vue @@ -9,7 +9,7 @@ {{ detail.title || detail.name || '-' }} - {{ (detail.points_required ? (detail.points_required).toFixed(0) : '0') || (detail.price ? (detail.price / 100).toFixed(1) : '0.0') }} + {{ formatPoints( detail.price) }} 积分 @@ -51,6 +51,20 @@ function formatPrice(p) { return (Number(p) / 100).toFixed(2) } +// 格式化积分显示 - 不四舍五入,保留两位小数 +function formatPoints(value) { + if (value === undefined || value === null) return '0.00' + const num = Number(value) + if (isNaN(num)) return '0.00' + + // 价格字段单位是分,如 1250 = 12.50积分 + // 除以100得到显示值 + const finalValue = num / 100 + + // 使用 Math.floor 避免四舍五入,保留两位小数 + return String(Math.floor(finalValue * 100) / 100).replace(/(\.\d)$/, '$10') +} + async function fetchDetail(id) { loading.value = true isOutOfStock.value = false @@ -103,7 +117,7 @@ async function onRedeem() { }) return } - + const token = uni.getStorageSync('token') if (!token) { uni.showModal({ @@ -114,8 +128,8 @@ async function onRedeem() { }) return } - - const points = (detail.value.points_required ? (detail.value.points_required).toFixed(0) : '0') || (detail.value.price ? (detail.value.price / 100).toFixed(1) : '0.0') + + const points = formatPoints(p.price) uni.showModal({ title: '确认兑换', content: `是否消耗 ${points} 积分兑换 ${p.title || p.name}?`, @@ -125,7 +139,7 @@ async function onRedeem() { try { const userId = uni.getStorageSync('user_id') if (!userId) throw new Error('用户ID不存在') - + await redeemProductByPoints(userId, p.id, 1) uni.hideLoading() uni.showModal({ diff --git a/pages-user/settings/index.vue b/pages-user/settings/index.vue new file mode 100644 index 0000000..b5e0443 --- /dev/null +++ b/pages-user/settings/index.vue @@ -0,0 +1,183 @@ + + + + + diff --git a/pages.json b/pages.json index 11a0dba..15e70c5 100644 --- a/pages.json +++ b/pages.json @@ -154,6 +154,13 @@ "style": { "navigationBarTitleText": "购买协议" } + }, + { + "path": "settings/index", + "style": { + "navigationBarTitleText": "设置", + "navigationStyle": "custom" + } } ] }, diff --git a/pages/mine/index.vue b/pages/mine/index.vue index 8e8140c..c460433 100644 --- a/pages/mine/index.vue +++ b/pages/mine/index.vue @@ -204,6 +204,12 @@ 扫雷 + + + + + 设置 + @@ -1025,6 +1031,9 @@ export default { if (!this.checkPhoneBound()) return uni.navigateTo({ url: '/pages-game/game/minesweeper/index' }) }, + toSettings() { + uni.navigateTo({ url: '/pages-user/settings/index' }) + }, // 抖音IM客服回调 onImCallback(e) { console.log('[Douyin IM] 跳转IM客服成功', e.detail) diff --git a/pages/shop/index.vue b/pages/shop/index.vue index 84a0d9d..bd8ddb4 100644 --- a/pages/shop/index.vue +++ b/pages/shop/index.vue @@ -262,13 +262,28 @@ function cleanUrl(u) { function normalizeItems(list, kind) { if (!Array.isArray(list)) return [] + + // 格式化积分显示 - 不四舍五入,保留两位小数 + const formatPoints = (value) => { + if (value === undefined || value === null) return '0.00' + const num = Number(value) + if (isNaN(num)) return '0.00' + + // 价格字段单位是分,如 1250 = 12.50积分 + // 除以100得到显示值 + const finalValue = num / 100 + + // 使用 Math.floor 避免四舍五入,保留两位小数 + return String(Math.floor(finalValue * 100) / 100).replace(/(\.\d)$/, '$10') + } + return list.map((i, idx) => ({ id: i.id, kind: i.kind || kind, image: cleanUrl(i.main_image || i.image || ''), title: i.name || i.title || '', price: i.price || i.discount_value || 0, - points: i.points_required ? (i.points_required).toFixed(0) : (i.price ? (i.price / 100).toFixed(1) : (i.discount_value ? (i.discount_value / 100).toFixed(1) : '0')), + points: formatPoints(i.price || i.discount_value), stock: i.in_stock ? 99 : 0, // Simplified stock check if returned as bool discount_value: i.discount_value || 0, min_spend: i.min_spend || 0,