Files
check_in/templates/ticket.html
2026-01-28 23:43:12 +08:00

573 lines
20 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>购票报名 - {{ config.event_title }}</title>
<script src="/static/js/qrcode.min.js"></script>
<style>
:root {
--primary-color: {{ config.primary_color }};
--secondary-color: {{ config.secondary_color }};
--bg-color: {{ config.bg_color }};
--card-bg: rgba(12, 24, 50, 0.7);
--text-color: #ffffff;
--input-bg: rgba(0, 0, 0, 0.4);
--border-color: rgba(0, 242, 255, 0.3);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
background-image:
radial-gradient(circle at 50% 0%, #1a3a75 0%, #050814 60%),
radial-gradient(circle at 85% 30%, rgba(0, 242, 255, 0.1) 0%, transparent 40%),
radial-gradient(circle at 15% 70%, rgba(0, 102, 255, 0.15) 0%, transparent 40%);
background-attachment: fixed;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
.container {
width: 100%;
max-width: 600px;
margin-top: 40px;
margin-bottom: 60px;
animation: fadeIn 0.8s ease-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
header {
text-align: center;
margin-bottom: 40px;
}
h1 {
font-size: 2rem;
margin-bottom: 10px;
background: linear-gradient(180deg, #ffffff 0%, #d0eaff 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-weight: 900;
text-shadow: 0 0 20px rgba(0, 242, 255, 0.4);
}
.subtitle {
font-size: 1rem;
color: var(--primary-color);
letter-spacing: 2px;
opacity: 0.9;
}
.card {
background: var(--card-bg);
border-radius: 20px;
padding: 30px;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid var(--border-color);
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.form-group {
margin-bottom: 25px;
}
label {
display: block;
margin-bottom: 10px;
color: var(--primary-color);
font-size: 0.95rem;
font-weight: bold;
}
input[type="text"], input[type="tel"] {
width: 100%;
padding: 15px;
background: var(--input-bg);
border: 1px solid var(--border-color);
border-radius: 12px;
color: white;
font-size: 1.1rem;
outline: none;
transition: all 0.3s;
}
input:focus {
border-color: var(--primary-color);
box-shadow: 0 0 15px rgba(0, 242, 255, 0.2);
background: rgba(0, 0, 0, 0.6);
}
.submit-btn {
width: 100%;
padding: 18px;
background: linear-gradient(90deg, #0051ff 0%, #00f2ff 100%);
color: white;
border: none;
border-radius: 12px;
font-size: 1.2rem;
font-weight: bold;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 4px 15px rgba(0, 242, 255, 0.3);
margin-top: 20px;
position: relative;
overflow: hidden;
}
.submit-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 25px rgba(0, 242, 255, 0.5);
}
.submit-btn:disabled {
background: #444;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.price-tag {
text-align: center;
margin-bottom: 20px;
font-size: 1.2rem;
color: #fff;
}
.price-amount {
font-size: 2rem;
color: #ffaa00;
font-weight: bold;
margin: 0 5px;
}
#message {
margin-top: 20px;
padding: 15px;
border-radius: 12px;
text-align: center;
display: none;
font-weight: bold;
}
.success {
background: rgba(40, 167, 69, 0.2);
border: 1px solid #28a745;
color: #28a745;
}
.error {
background: rgba(220, 53, 69, 0.2);
border: 1px solid #dc3545;
color: #ff6b6b;
}
.loading {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid rgba(255,255,255,.3);
border-radius: 50%;
border-top-color: #fff;
animation: spin 1s ease-in-out infinite;
margin-right: 10px;
vertical-align: middle;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* Modal Styles */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
display: none;
justify-content: center;
align-items: center;
z-index: 1000;
backdrop-filter: blur(5px);
}
.modal-content {
background: #fff;
padding: 30px;
border-radius: 15px;
text-align: center;
max-width: 90%;
width: 400px;
position: relative;
box-shadow: 0 0 30px rgba(0, 242, 255, 0.2);
}
.modal-close {
position: absolute;
top: 10px;
right: 15px;
font-size: 24px;
cursor: pointer;
color: #333;
}
#qrcode {
margin: 20px auto;
display: flex;
justify-content: center;
}
.modal-title {
color: #333;
margin-bottom: 10px;
font-size: 1.2rem;
font-weight: bold;
}
.modal-tip {
color: #666;
font-size: 0.9rem;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>{{ config.event_title }}</h1>
<div class="subtitle">在线报名通道</div>
</header>
<div class="card">
<div class="price-tag">
报名费用 <span class="price-amount">¥{{ config.payment_amount }}</span>
</div>
<form id="paymentForm" onsubmit="handlePayment(event)">
{% set ordered_keys = ['name', 'phone', 'industry_company'] %}
{% for key in ordered_keys %}
{% set field = config.ticket_field_config.get(key) %}
{% if field and field.show %}
<div class="form-group">
<label>{{ field.label }}{% if field.required %} *{% endif %}</label>
{% if key == 'phone' %}
<input type="tel" id="{{ key }}" {% if field.required %}required{% endif %} placeholder="请输入{{ field.label }}" pattern="[0-9]{11}">
{% if config.enable_sms_verification %}
<div style="display: flex; gap: 10px; margin-top: 10px;">
<input type="text" id="verification_code" placeholder="请先发送验证码" style="flex: 1;" disabled>
<button type="button" id="send-code-btn" onclick="sendSmsCode()" style="width: auto; padding: 10px; font-size: 0.9rem; background: var(--secondary-color); margin-top: 0; border: none; border-radius: 8px; color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; min-width: 100px;">发送验证码</button>
</div>
{% endif %}
{% else %}
<input type="text" id="{{ key }}" {% if field.required %}required{% endif %} placeholder="请输入{{ field.label }}">
{% endif %}
</div>
{% endif %}
{% endfor %}
<button type="submit" class="submit-btn" id="submitBtn">
立即支付报名
</button>
</form>
<div id="message"></div>
</div>
</div>
<!-- QR Code Modal -->
<div id="qrModal" class="modal-overlay">
<div class="modal-content">
<span class="modal-close" onclick="closeModal()">&times;</span>
<div class="modal-title">微信扫码支付</div>
<div style="margin: 15px 0; color: #28a745; font-weight: bold; font-size: 1.1rem;">
<span style="display:inline-block; margin-right:5px; vertical-align:middle;">📱</span>
请使用微信“扫一扫”
</div>
<div id="qrcode"></div>
<div id="payment-status" style="color: #666; font-size: 14px; margin-top: 15px;">等待支付...</div>
</div>
</div>
<script>
let pollTimer = null;
let isCodeVerified = false;
function updateSubmitButtonState() {
const btn = document.getElementById('submitBtn');
const codeInput = document.getElementById('verification_code');
// Only update if not in loading state (checking innerHTML for loading spinner)
if (btn.innerHTML.includes('loading')) return;
if (codeInput) {
if (isCodeVerified && codeInput.value.trim().length === 4) {
btn.disabled = false;
} else {
btn.disabled = true;
}
} else {
btn.disabled = false;
}
}
async function verifyCode() {
const codeInput = document.getElementById('verification_code');
const phoneInput = document.getElementById('phone');
if (!codeInput) return;
const code = codeInput.value.trim();
const phone = phoneInput ? phoneInput.value.trim() : '';
if (code.length === 4 && phone) {
try {
const res = await fetch('/api/verify-sms-code', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({phone: phone, code: code})
});
const data = await res.json();
if (data.success) {
isCodeVerified = true;
showMessage('验证码正确', 'success');
} else {
isCodeVerified = false;
showMessage('验证码错误', 'error');
}
} catch(e) {
isCodeVerified = false;
}
} else {
isCodeVerified = false;
}
updateSubmitButtonState();
}
function closeModal() {
document.getElementById('qrModal').style.display = 'none';
if (pollTimer) clearInterval(pollTimer);
document.getElementById('qrcode').innerHTML = '';
// Reset button state
const btn = document.getElementById('submitBtn');
btn.innerHTML = '立即支付报名';
updateSubmitButtonState();
}
// Initialize button state on load
window.addEventListener('DOMContentLoaded', () => {
const codeInput = document.getElementById('verification_code');
const phoneInput = document.getElementById('phone');
if (codeInput) {
updateSubmitButtonState();
codeInput.addEventListener('input', verifyCode);
}
if (phoneInput) {
phoneInput.addEventListener('input', () => {
isCodeVerified = false;
updateSubmitButtonState();
});
}
});
async function handlePayment(e) {
e.preventDefault();
const btn = document.getElementById('submitBtn');
const msg = document.getElementById('message');
const originalText = "立即支付报名"; // Hardcoded or get from element
// Validate
const getVal = (id) => {
const el = document.getElementById(id);
return el ? el.value.trim() : '';
};
const name = getVal('name');
const phone = getVal('phone');
if (!name || !phone) {
showMessage('请填写必填项', 'error');
return;
}
// Loading State
btn.disabled = true;
btn.innerHTML = '<span class="loading"></span> 处理中...';
msg.style.display = 'none';
const data = {
name: name,
phone: phone,
verification_code: getVal('verification_code'),
company_name: getVal('industry_company')
};
// Check Screen Width
const isWideScreen = window.innerWidth > 768;
const apiEndpoint = isWideScreen ? '/api/payment/native' : '/api/payment/h5';
try {
const res = await fetch(apiEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
const result = await res.json();
if (result.success) {
if (isWideScreen && result.code_url) {
// Show Native Pay QR Code
document.getElementById('qrModal').style.display = 'flex';
document.getElementById('qrcode').innerHTML = ''; // Clear previous
new QRCode(document.getElementById("qrcode"), {
text: result.code_url,
width: 200,
height: 200
});
// Start Polling
startPolling(result.out_trade_no);
} else if (result.h5_url) {
// H5 Redirect
showMessage('正在跳转支付...', 'success');
window.location.href = result.h5_url;
} else {
throw new Error('未获取到支付链接');
}
} else {
showMessage(result.message || '支付请求失败', 'error');
btn.innerHTML = originalText;
updateSubmitButtonState();
}
} catch (err) {
console.error(err);
showMessage(err.message || '网络请求错误,请重试', 'error');
btn.innerHTML = originalText;
updateSubmitButtonState();
}
}
function startPolling(out_trade_no) {
const statusDiv = document.getElementById('payment-status');
let attempts = 0;
const maxAttempts = 600; // 30 mins max
if (pollTimer) clearInterval(pollTimer);
pollTimer = setInterval(async () => {
attempts++;
if (attempts > maxAttempts) {
clearInterval(pollTimer);
statusDiv.textContent = '支付超时,请刷新重试';
return;
}
try {
const res = await fetch(`/api/payment/check/${out_trade_no}`);
const data = await res.json();
if (data.success && data.trade_state === 'SUCCESS') {
clearInterval(pollTimer);
statusDiv.textContent = '支付成功!正在跳转...';
statusDiv.style.color = '#28a745';
setTimeout(() => {
window.location.href = '/success';
}, 1000);
}
} catch (e) {
console.error("Polling error", e);
}
}, 3000);
}
function showMessage(text, type) {
const msg = document.getElementById('message');
msg.textContent = text;
msg.className = type;
msg.style.display = 'block';
}
async function sendSmsCode() {
const phone = document.getElementById('phone').value.trim();
if (!phone || !/^1[3-9]\d{9}$/.test(phone)) {
showMessage('请输入有效的手机号码', 'error');
return;
}
const btn = document.getElementById('send-code-btn');
const codeInput = document.getElementById('verification_code');
if (!btn) return;
btn.disabled = true;
const originalText = "发送验证码";
// 添加loading效果
btn.innerHTML = '<span class="loading" style="width: 14px; height: 14px; border-width: 2px; margin-right: 6px;"></span>发送中';
let count = 60;
try {
const res = await fetch('/api/send-sms', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({phone: phone})
});
const data = await res.json();
if (data.success) {
showMessage('验证码已发送', 'success');
// 成功后才允许输入验证码
if (codeInput) {
codeInput.disabled = false;
codeInput.placeholder = "请输入验证码";
codeInput.focus();
}
btn.innerText = `${count}s`;
const timer = setInterval(() => {
count--;
btn.innerText = `${count}s`;
if (count <= 0) {
clearInterval(timer);
btn.disabled = false;
btn.innerText = originalText;
}
}, 1000);
} else {
showMessage(data.message || '发送失败', 'error');
btn.disabled = false;
btn.innerText = originalText;
}
} catch (e) {
console.error(e);
showMessage('网络错误', 'error');
btn.disabled = false;
btn.innerText = originalText;
}
}
</script>
</body>
</html>