初版:教务抢课系统 jwxt(从线上实例导出)
This commit is contained in:
@@ -0,0 +1,606 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN" class="scroll-smooth">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
||||
<title>订单状态 - {{ brand_name }}</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<script>
|
||||
tailwind.config = {
|
||||
darkMode: 'class',
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
dark: {
|
||||
bg: '#0a0a0a',
|
||||
card: '#171717',
|
||||
border: '#262626'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;800;900&family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap"
|
||||
rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Inter', 'Noto Sans SC', sans-serif;
|
||||
transition: background-color 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
.glass {
|
||||
background: rgba(255, 255, 255, 0.85);
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.dark .glass {
|
||||
background: rgba(23, 23, 23, 0.85);
|
||||
border: 1px solid rgba(38, 38, 38, 0.9);
|
||||
}
|
||||
|
||||
.layer-4 {
|
||||
box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.dark .layer-4 {
|
||||
box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
.bg-grid {
|
||||
background-size: 40px 40px;
|
||||
background-image: linear-gradient(to right, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
|
||||
linear-gradient(to bottom, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
|
||||
}
|
||||
|
||||
.dark .bg-grid {
|
||||
background-image: linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
|
||||
linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
|
||||
}
|
||||
|
||||
@keyframes shake {
|
||||
0%, 100% { transform: translateX(0); }
|
||||
10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
|
||||
20%, 40%, 60%, 80% { transform: translateX(5px); }
|
||||
}
|
||||
|
||||
.shake {
|
||||
animation: shake 0.5s ease-in-out;
|
||||
}
|
||||
|
||||
@keyframes pulse-warning {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.6; }
|
||||
}
|
||||
|
||||
.pulse-warning {
|
||||
animation: pulse-warning 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
/* Toast 通知 */
|
||||
@media (min-width: 769px) {
|
||||
.toast-container {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
z-index: 9999;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.toast {
|
||||
background: #2c3e50;
|
||||
color: white;
|
||||
padding: 14px 22px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 10px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
transform: translateX(100%);
|
||||
opacity: 0;
|
||||
transition: all 0.3s ease;
|
||||
pointer-events: all;
|
||||
min-width: 250px;
|
||||
max-width: 350px;
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
transform: translateX(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.toast-container {
|
||||
position: fixed;
|
||||
bottom: max(20px, env(safe-area-inset-bottom));
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
z-index: 9999;
|
||||
pointer-events: none;
|
||||
width: 90%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.toast {
|
||||
background: #2c3e50;
|
||||
color: white;
|
||||
padding: 12px 20px;
|
||||
border-radius: 24px;
|
||||
margin-bottom: 8px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
|
||||
transform: translateY(100px);
|
||||
opacity: 0;
|
||||
transition: all 0.3s ease;
|
||||
pointer-events: all;
|
||||
width: 100%;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.toast.error {
|
||||
background: #e74c3c;
|
||||
}
|
||||
|
||||
.toast.success {
|
||||
background: #27ae60;
|
||||
}
|
||||
|
||||
.dark .toast.error {
|
||||
background: #ff6b6b;
|
||||
}
|
||||
|
||||
.dark .toast.success {
|
||||
background: #4caf50;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="bg-neutral-50 text-neutral-900 dark:bg-dark-bg dark:text-neutral-100 min-h-screen">
|
||||
<!-- Toast 通知容器 -->
|
||||
<div class="toast-container" id="toastContainer"></div>
|
||||
|
||||
<!-- 导航 -->
|
||||
<nav class="fixed w-full z-50 glass border-b border-black/5 dark:border-white/10 transition-colors duration-300">
|
||||
<div class="max-w-6xl mx-auto px-4 md:px-6 h-16 flex justify-between items-center">
|
||||
<a href="/buy" class="flex items-center gap-2 md:gap-3 group cursor-pointer">
|
||||
<div class="w-8 h-8 bg-black dark:bg-white rounded-lg flex items-center justify-center text-white dark:text-black font-bold text-sm group-hover:rotate-12 transition-transform shrink-0">
|
||||
S</div>
|
||||
<span class="font-bold tracking-tight text-sm md:text-base truncate">{{ brand_name }}</span>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<main class="pt-24 md:pt-32 pb-16 md:pb-24 px-4 md:px-6 bg-grid min-h-screen flex items-center justify-center">
|
||||
<div class="max-w-md w-full">
|
||||
<div class="glass rounded-2xl md:rounded-3xl p-8 md:p-12 layer-4 text-center" id="mainCard">
|
||||
<!-- 加载状态 -->
|
||||
<div id="loadingState">
|
||||
<div class="w-20 h-20 md:w-24 md:h-24 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center mx-auto mb-6">
|
||||
<svg class="w-10 h-10 md:w-12 md:h-12 text-blue-500 animate-spin" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">正在查询订单...</h1>
|
||||
<p class="text-neutral-500 dark:text-neutral-400">请稍候</p>
|
||||
</div>
|
||||
|
||||
<!-- 订单过期状态 -->
|
||||
<div id="expiredState" class="hidden">
|
||||
<div class="w-20 h-20 md:w-24 md:h-24 bg-orange-100 dark:bg-orange-900/30 rounded-full flex items-center justify-center mx-auto mb-6">
|
||||
<svg class="w-10 h-10 md:w-12 md:h-12 text-orange-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">订单已过期</h1>
|
||||
<p class="text-neutral-500 dark:text-neutral-400 mb-6">
|
||||
该订单已超过5分钟有效期,请重新下单
|
||||
</p>
|
||||
<div class="bg-neutral-100 dark:bg-neutral-800 rounded-xl p-4 mb-6">
|
||||
<div class="text-xs text-neutral-500 dark:text-neutral-400 mb-1">原订单号</div>
|
||||
<div class="text-sm font-mono text-neutral-700 dark:text-neutral-300" id="expiredOrderId">-</div>
|
||||
</div>
|
||||
<a href="/buy" class="block w-full py-3 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-xl hover:shadow-lg transition-all">
|
||||
重新购买
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- 订单取消状态 -->
|
||||
<div id="cancelledState" class="hidden">
|
||||
<div class="w-20 h-20 md:w-24 md:h-24 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center mx-auto mb-6">
|
||||
<svg class="w-10 h-10 md:w-12 md:h-12 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">订单已取消</h1>
|
||||
<p class="text-neutral-500 dark:text-neutral-400 mb-2" id="cancelReason">您已取消该订单</p>
|
||||
<p class="text-neutral-500 dark:text-neutral-400 mb-6">
|
||||
如需继续购买,请重新下单
|
||||
</p>
|
||||
<a href="/buy" class="block w-full py-3 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-xl hover:shadow-lg transition-all">
|
||||
重新购买
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- 支付失败状态 -->
|
||||
<div id="failedState" class="hidden">
|
||||
<div class="w-20 h-20 md:w-24 md:h-24 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-6 shake">
|
||||
<svg class="w-10 h-10 md:w-12 md:h-12 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">支付失败</h1>
|
||||
<p class="text-neutral-500 dark:text-neutral-400 mb-6" id="errorMsg">
|
||||
支付过程中出现问题,请重新尝试
|
||||
</p>
|
||||
<div class="bg-neutral-100 dark:bg-neutral-800 rounded-xl p-4 mb-6">
|
||||
<div class="text-xs text-neutral-500 dark:text-neutral-400 mb-1">订单号</div>
|
||||
<div class="text-sm font-mono text-neutral-700 dark:text-neutral-300" id="failedOrderId">-</div>
|
||||
</div>
|
||||
<div class="space-y-3">
|
||||
<a href="/buy" class="block w-full py-3 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-xl hover:shadow-lg transition-all">
|
||||
重新购买
|
||||
</a>
|
||||
<a href="/" class="block w-full py-3 bg-neutral-200 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-semibold rounded-xl hover:bg-neutral-300 dark:hover:bg-neutral-700 transition-colors">
|
||||
返回首页
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 订单待支付状态(5分钟内) -->
|
||||
<div id="pendingState" class="hidden">
|
||||
<!-- 倒计时警告 -->
|
||||
<div class="bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-xl p-4 mb-6 pulse-warning">
|
||||
<div class="flex items-center gap-3">
|
||||
<svg class="w-6 h-6 text-orange-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
<div class="text-left">
|
||||
<div class="text-sm font-semibold text-orange-800 dark:text-orange-200">订单即将过期</div>
|
||||
<div class="text-xs text-orange-600 dark:text-orange-400 mt-0.5">
|
||||
剩余 <span id="countdown" class="font-bold">--:--</span> 自动失效
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-20 h-20 md:w-24 md:h-24 bg-yellow-100 dark:bg-yellow-900/30 rounded-full flex items-center justify-center mx-auto mb-6">
|
||||
<svg class="w-10 h-10 md:w-12 md:h-12 text-yellow-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">等待支付</h1>
|
||||
<p class="text-neutral-500 dark:text-neutral-400 mb-6">
|
||||
订单尚未支付,如需取消请点击下方按钮
|
||||
</p>
|
||||
|
||||
<div class="bg-neutral-100 dark:bg-neutral-800 rounded-xl p-4 mb-6">
|
||||
<div class="text-xs text-neutral-500 dark:text-neutral-400 mb-1">订单号</div>
|
||||
<div class="text-sm font-mono text-neutral-700 dark:text-neutral-300" id="pendingOrderId">-</div>
|
||||
<div class="text-xs text-neutral-500 dark:text-neutral-400 mt-2 mb-1">应付金额</div>
|
||||
<div class="text-lg font-bold text-neutral-900 dark:text-white">¥<span id="pendingAmount">-</span></div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3">
|
||||
<button id="retryPayBtn" onclick="retryPay()" class="w-full py-3 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-xl hover:shadow-lg transition-all">
|
||||
继续支付
|
||||
</button>
|
||||
<button id="cancelOrderBtn" onclick="cancelOrder()" class="w-full py-3 bg-neutral-200 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-semibold rounded-xl hover:bg-neutral-300 dark:hover:bg-neutral-700 transition-colors">
|
||||
取消订单
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
// 全局变量
|
||||
let orderId = null;
|
||||
let countdownTimer = null;
|
||||
let currentOrderStatus = null;
|
||||
|
||||
// Toast 通知
|
||||
function showToast(message, type = 'info', duration = 3000) {
|
||||
const container = document.getElementById('toastContainer');
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast ${type}`;
|
||||
toast.innerHTML = `<span>${message}</span>`;
|
||||
container.appendChild(toast);
|
||||
setTimeout(() => toast.classList.add('show'), 10);
|
||||
setTimeout(() => {
|
||||
toast.classList.remove('show');
|
||||
setTimeout(() => toast.remove(), 400);
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// 主题初始化
|
||||
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
||||
document.documentElement.classList.add('dark');
|
||||
}
|
||||
|
||||
// 从URL获取订单号
|
||||
function getOrderIdFromUrl() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
return urlParams.get('orderNo') || urlParams.get('order_id') || '{{ order_id }}';
|
||||
}
|
||||
|
||||
// 查询订单状态
|
||||
async function fetchOrderStatus(orderId) {
|
||||
try {
|
||||
const response = await fetch(`/api/orders/${orderId}/status`);
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('查询订单状态失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单详情
|
||||
async function fetchOrder(orderId) {
|
||||
try {
|
||||
const response = await fetch(`/api/orders/${orderId}`);
|
||||
const data = await response.json();
|
||||
return data.order;
|
||||
} catch (error) {
|
||||
console.error('获取订单详情失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取支付参数并跳转
|
||||
async function retryPay() {
|
||||
if (!orderId) return;
|
||||
|
||||
const btn = document.getElementById('retryPayBtn');
|
||||
btn.disabled = true;
|
||||
btn.textContent = '正在获取支付信息...';
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/api/orders/${orderId}/payment_params`);
|
||||
const data = await response.json();
|
||||
|
||||
if (!data.success) {
|
||||
showToast(data.message || '获取支付信息失败', 'error');
|
||||
btn.disabled = false;
|
||||
btn.textContent = '继续支付';
|
||||
return;
|
||||
}
|
||||
|
||||
// 构建支付表单
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = 'https://api-4ndv48ogy5fk.zhifu.fm.it88168.com/api/startOrder';
|
||||
form.target = '_self';
|
||||
form.style.display = 'none';
|
||||
|
||||
const fields = ['merchantNum', 'orderNo', 'amount', 'notifyUrl', 'returnUrl', 'payType', 'sign', 'returnType', 'subject'];
|
||||
fields.forEach(field => {
|
||||
if (data.params && data.params[field]) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = field;
|
||||
input.value = data.params[field];
|
||||
form.appendChild(input);
|
||||
}
|
||||
});
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
|
||||
} catch (error) {
|
||||
console.error('支付跳转失败:', error);
|
||||
showToast('支付跳转失败,请重试', 'error');
|
||||
btn.disabled = false;
|
||||
btn.textContent = '继续支付';
|
||||
}
|
||||
}
|
||||
|
||||
// 取消订单
|
||||
async function cancelOrder() {
|
||||
if (!orderId) return;
|
||||
|
||||
if (!confirm('确定要取消这个订单吗?取消后无法恢复。')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const btn = document.getElementById('cancelOrderBtn');
|
||||
btn.disabled = true;
|
||||
btn.textContent = '正在取消...';
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/orders/${orderId}/cancel`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ reason: '用户主动取消' })
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
showToast('订单已取消', 'success');
|
||||
// 停止倒计时
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer);
|
||||
}
|
||||
// 更新UI
|
||||
document.getElementById('pendingState').classList.add('hidden');
|
||||
document.getElementById('cancelledState').classList.remove('hidden');
|
||||
} else {
|
||||
showToast(data.message || '取消订单失败', 'error');
|
||||
btn.disabled = false;
|
||||
btn.textContent = '取消订单';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('取消订单失败:', error);
|
||||
showToast('取消订单失败,请重试', 'error');
|
||||
btn.disabled = false;
|
||||
btn.textContent = '取消订单';
|
||||
}
|
||||
}
|
||||
|
||||
// 更新倒计时显示
|
||||
function updateCountdown(remainingSeconds) {
|
||||
const countdownEl = document.getElementById('countdown');
|
||||
if (remainingSeconds <= 0) {
|
||||
countdownEl.textContent = '00:00';
|
||||
// 停止倒计时
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer);
|
||||
}
|
||||
// 刷新状态
|
||||
checkOrderStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
const minutes = Math.floor(remainingSeconds / 60);
|
||||
const seconds = remainingSeconds % 60;
|
||||
countdownEl.textContent = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
// 检查订单状态
|
||||
async function checkOrderStatus() {
|
||||
if (!orderId) return;
|
||||
|
||||
const data = await fetchOrderStatus(orderId);
|
||||
if (!data) {
|
||||
showFailedState('无法获取订单状态');
|
||||
return;
|
||||
}
|
||||
|
||||
currentOrderStatus = data;
|
||||
|
||||
// 根据状态显示不同UI
|
||||
if (data.status === 'pending') {
|
||||
if (data.is_expired || data.remaining_seconds <= 0) {
|
||||
showExpiredState();
|
||||
} else {
|
||||
showPendingState(data, await fetchOrder(orderId));
|
||||
}
|
||||
} else if (data.status === 'cancelled' || data.status === 'expired') {
|
||||
if (data.status === 'cancelled') {
|
||||
showCancelledState(data.cancel_reason);
|
||||
} else {
|
||||
showExpiredState();
|
||||
}
|
||||
} else if (data.status === 'paid' || data.status === 'processed') {
|
||||
// 订单已支付,跳转到成功页面
|
||||
window.location.href = `/success/${orderId}`;
|
||||
} else {
|
||||
// 其他状态(如 failed)
|
||||
showFailedState();
|
||||
}
|
||||
}
|
||||
|
||||
// 显示加载状态
|
||||
function showLoadingState() {
|
||||
document.getElementById('loadingState').classList.remove('hidden');
|
||||
document.getElementById('expiredState').classList.add('hidden');
|
||||
document.getElementById('cancelledState').classList.add('hidden');
|
||||
document.getElementById('failedState').classList.add('hidden');
|
||||
document.getElementById('pendingState').classList.add('hidden');
|
||||
}
|
||||
|
||||
// 显示订单过期状态
|
||||
function showExpiredState() {
|
||||
document.getElementById('loadingState').classList.add('hidden');
|
||||
document.getElementById('expiredState').classList.remove('hidden');
|
||||
document.getElementById('cancelledState').classList.add('hidden');
|
||||
document.getElementById('failedState').classList.add('hidden');
|
||||
document.getElementById('pendingState').classList.add('hidden');
|
||||
document.getElementById('expiredOrderId').textContent = orderId;
|
||||
}
|
||||
|
||||
// 显示订单取消状态
|
||||
function showCancelledState(reason) {
|
||||
document.getElementById('loadingState').classList.add('hidden');
|
||||
document.getElementById('expiredState').classList.add('hidden');
|
||||
document.getElementById('cancelledState').classList.remove('hidden');
|
||||
document.getElementById('failedState').classList.add('hidden');
|
||||
document.getElementById('pendingState').classList.add('hidden');
|
||||
document.getElementById('cancelReason').textContent = reason || '您已取消该订单';
|
||||
}
|
||||
|
||||
// 显示支付失败状态
|
||||
function showFailedState(errorMsg) {
|
||||
document.getElementById('loadingState').classList.add('hidden');
|
||||
document.getElementById('expiredState').classList.add('hidden');
|
||||
document.getElementById('cancelledState').classList.add('hidden');
|
||||
document.getElementById('failedState').classList.remove('hidden');
|
||||
document.getElementById('pendingState').classList.add('hidden');
|
||||
if (errorMsg) {
|
||||
document.getElementById('errorMsg').textContent = errorMsg;
|
||||
}
|
||||
document.getElementById('failedOrderId').textContent = orderId;
|
||||
}
|
||||
|
||||
// 显示待支付状态
|
||||
async function showPendingState(statusData, orderData) {
|
||||
document.getElementById('loadingState').classList.add('hidden');
|
||||
document.getElementById('expiredState').classList.add('hidden');
|
||||
document.getElementById('cancelledState').classList.add('hidden');
|
||||
document.getElementById('failedState').classList.add('hidden');
|
||||
document.getElementById('pendingState').classList.remove('hidden');
|
||||
|
||||
document.getElementById('pendingOrderId').textContent = orderId;
|
||||
if (orderData) {
|
||||
document.getElementById('pendingAmount').textContent = orderData.final_amount || orderData.amount || '-';
|
||||
}
|
||||
|
||||
// 启动倒计时
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer);
|
||||
}
|
||||
|
||||
let remaining = statusData.remaining_seconds || 0;
|
||||
updateCountdown(remaining);
|
||||
|
||||
countdownTimer = setInterval(() => {
|
||||
remaining--;
|
||||
updateCountdown(remaining);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// 页面加载时查询订单状态
|
||||
window.addEventListener('load', async () => {
|
||||
orderId = getOrderIdFromUrl();
|
||||
|
||||
if (!orderId || orderId === '{{ order_id }}') {
|
||||
// 没有订单号,跳转到购买页面
|
||||
window.location.href = '/buy';
|
||||
return;
|
||||
}
|
||||
|
||||
showLoadingState();
|
||||
|
||||
// 延迟一点再查询,让用户看到加载状态
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
checkOrderStatus();
|
||||
});
|
||||
|
||||
// 页面离开时清理定时器
|
||||
window.addEventListener('beforeunload', () => {
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user