Files
GameParlor/target/classes/static/player/points.html
T
2026-09-11 07:15:51 +08:00

64 lines
3.0 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>积分兑换 · GameParlor</title>
<link rel="stylesheet" href="/app.css">
<script src="/js/vendor/tailwind.min.js"></script>
<script defer src="/js/vendor/alpine.min.js"></script>
</head>
<body x-data="pointsApp()" x-init="init()">
<div class="flex items-center justify-between mb-6">
<h2 class="text-xl font-bold">积分兑换</h2>
<div class="text-sm">我的积分:<span class="text-[#fbbf24] font-bold" x-text="me.points || 0"></span></div>
</div>
<p class="text-sm text-[#9a9aa5] mb-4">兑换比例:<span x-text="rate"></span> 积分 = 1 元(按商品原价换算)</p>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<template x-for="it in items" :key="it.type+it.id">
<div class="card card-hover p-4">
<div class="font-bold" x-text="it.name"></div>
<div class="text-xs text-[#9a9aa5] mt-1" x-text="it.type"></div>
<div class="text-[#00d4ff] font-bold mt-2" x-text="it.points + ' 积分'"></div>
<button class="btn btn-primary w-full mt-3 !py-1 text-xs" @click="exchange(it)" :disabled="(me.points||0) < it.points">兑换</button>
</div>
</template>
</div>
<script src="/app.js"></script>
<script>
function pointsApp() {
return {
me: {}, rate: 100, items: [],
async init() {
await initLayout('points');
this.me = await api('/api/user/me').catch(() => ({}));
const cfg = await api('/api/config').catch(() => ({}));
this.rate = Number(cfg.points_exchange_rate) || 100;
const slots = await api('/api/timeslots').catch(() => []);
const snacks = await api('/api/snacks').catch(() => []);
const combos = await api('/api/combos').catch(() => []);
slots.forEach(s => this.items.push({ type: 'TIMESLOT', id: s.id, name: s.durationMinutes + ' 分钟时长', price: s.basePrice, points: Math.ceil(s.basePrice * this.rate) }));
snacks.forEach(s => this.items.push({ type: 'SNACK', id: s.id, name: s.name, price: s.price, points: Math.ceil(s.price * this.rate) }));
combos.forEach(c => this.items.push({ type: 'COMBO', id: c.id, name: c.name, price: 0, points: 0 }));
// 套餐价格需单独取
for (const c of combos) {
const d = await api('/api/combos/' + c.id).catch(() => null);
if (d) {
const it = this.items.find(i => i.type === 'COMBO' && i.id === c.id);
if (it) { it.price = d.price; it.points = Math.ceil(d.price * this.rate); }
}
}
},
async exchange(it) {
await api('/api/member/points/exchange', { method: 'POST', body: JSON.stringify({ itemType: it.type, itemId: it.id }) });
toast('兑换成功', 'success');
this.me = await api('/api/user/me').catch(() => ({}));
}
};
}
</script>
</body>
</html>