统一样式

This commit is contained in:
2026-04-26 10:28:58 +08:00
Unverified
parent ef001c7460
commit c54e5209af
7 changed files with 1813 additions and 1024 deletions
+106 -212
View File
@@ -4,239 +4,133 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>单据详情</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600;700&family=Orbitron:wght@500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../css/tech-query.css">
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<style>
body {
background: #f0f2f5;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto;
}
.detail-container {
max-width: 900px;
margin: 60px auto;
padding: 32px;
background: #fff;
border-radius: 12px;
box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}
.back-link {
display: inline-block;
margin-bottom: 20px;
color: #4CAF50;
text-decoration: none;
}
.detail-header {
border-bottom: 2px solid #4CAF50;
padding-bottom: 15px;
margin-bottom: 30px;
}
.detail-title {
font-size: 22px;
margin: 0;
}
.section-title {
font-size: 16px;
color: #4CAF50;
margin-bottom: 15px;
}
.info-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 15px;
}
.info-item {
padding: 14px;
background: #fafafa;
border-radius: 6px;
}
.info-label {
font-size: 12px;
color: #888;
}
.info-value {
font-size: 15px;
font-weight: 500;
}
.status {
padding: 4px 10px;
border-radius: 4px;
font-size: 12px;
}
.done {
background: #e8f5e9;
color: #2e7d32;
}
.pending {
background: #fff3e0;
color: #ef6c00;
}
.action-buttons {
margin-top: 30px;
display: flex;
gap: 10px;
}
.btn {
padding: 10px 20px;
border-radius: 6px;
border: none;
cursor: pointer;
}
.btn-primary {
background: #4CAF50;
color: white;
}
.btn-secondary {
background: #6c757d;
color: white;
}
.loading, .error-message {
text-align: center;
padding: 40px;
}
.error-message {
color: #c33;
background: #fee;
border-radius: 6px;
}
</style>
</head>
<body>
<main class="detail-shell">
<div class="top-actions">
<a href="./index.html" class="tech-link-button secondary">返回查询页</a>
<div class="top-actions-group">
<button class="tech-button secondary" type="button" onclick="history.back()">返回上一页</button>
<button class="tech-button" type="button" onclick="goPrint()">打印单据</button>
</div>
</div>
<div class="detail-container">
<a href="./index.html" class="back-link">← 返回查询页面</a>
<div id="detailContent" class="detail-panel feedback-card">
正在加载单据详情...
</div>
</main>
<div id="detailContent">
<div class="loading">正在加载详情...</div>
</div>
</div>
<footer class="page-footer">
<p>© 2026 BI Intelligent Query Interface</p>
</footer>
<script>
const SUPABASE_URL = 'https://chixssrphfgxvqqigkzo.supabase.co';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNoaXhzc3JwaGZneHZxcWlna3pvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ2OTE0OTEsImV4cCI6MjA5MDI2NzQ5MX0.Az_Ew2J2zdOMcSV0UNAjBS-LPqGpqhsaN4IyZ5R7iqU';
<script>
const SUPABASE_URL = 'https://chixssrphfgxvqqigkzo.supabase.co';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNoaXhzc3JwaGZneHZxcWlna3pvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ2OTE0OTEsImV4cCI6MjA5MDI2NzQ5MX0.Az_Ew2J2zdOMcSV0UNAjBS-LPqGpqhsaN4IyZ5R7iqU';
// 防重复初始化(关键修复)
if (!window._sbClient) {
window._sbClient = window.supabase.createClient(
SUPABASE_URL,
SUPABASE_ANON_KEY
);
}
const sbClient = window._sbClient;
async function loadTicketDetail() {
const urlParams = new URLSearchParams(window.location.search);
const ticketId = urlParams.get('id');
if (!ticketId) {
showError('未提供单据 ID');
return;
if (!window._sbClient) {
window._sbClient = window.supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
}
const sbClient = window._sbClient;
try {
const { data: ticket, error } = await sbClient
.from('tickets')
.select('*')
.eq('id', ticketId)
.single();
async function loadTicketDetail() {
const urlParams = new URLSearchParams(window.location.search);
const ticketId = urlParams.get('id');
if (error) throw error;
if (!ticket) {
showError('未找到该单据');
if (!ticketId) {
showError('未提供单据 ID。');
return;
}
displayTicketDetail(ticket);
try {
const { data: ticket, error } = await sbClient
.from('tickets')
.select('*')
.eq('id', ticketId)
.single();
} catch (error) {
showError(error.message);
if (error) throw error;
if (!ticket) {
showError('未找到该单据。');
return;
}
displayTicketDetail(ticket);
} catch (error) {
showError(error.message || '加载失败');
}
}
}
function displayTicketDetail(ticket) {
const el = document.getElementById('detailContent');
function displayTicketDetail(ticket) {
const el = document.getElementById('detailContent');
const processedLabel = ticket.processed ? '已处理' : '未处理';
const completionLabel = ticket.status ? '已办结' : '未办结';
const amount = Number(ticket.amount || 0).toLocaleString('zh-CN', {
style: 'currency',
currency: 'CNY'
});
el.innerHTML = `
<div class="detail-header">
<h1 class="detail-title">
${ticket.ticket_number || ''} / ${ticket.customer_name || ''}
</h1>
</div>
el.classList.remove('feedback-card');
el.innerHTML = `
<div class="ticket-header">
<div>
<div class="section-kicker">Ticket Detail</div>
<h1 class="ticket-title">${ticket.ticket_number || '-'} / ${ticket.customer_name || '-'}</h1>
<p class="ticket-subtitle">单据全量信息、处理状态与打印操作在此统一展示。</p>
</div>
<div class="top-actions-group">
<span class="status-pill ${ticket.processed ? 'done' : 'pending'}">${processedLabel}</span>
<span class="status-pill ${ticket.status ? 'done' : 'pending'}">${completionLabel}</span>
</div>
</div>
<div class="info-grid">
${item('编号', ticket.ticket_number)}
${item('姓名', ticket.customer_name)}
${item('事由', ticket.reason)}
${item('处理结果', ticket.result)}
${item('金额', '¥' + Number(ticket.amount || 0).toFixed(2))}
${item('开具人', ticket.issuer)}
${item('日期', formatDate(ticket.created_at))}
${item('状态', `
<span class="status ${ticket.processed ? 'done' : 'pending'}">
${ticket.status ? '已处理' : '待处理'}
</span>
`, true)}
${item('办结否', `
<span class="status ${ticket.status ? 'TRUE' : 'FALSE'}">
${ticket.processed ? '已办结' : '未办结'}
</span>
`, true)}
${item('办结日期', formatDate(ticket.processed_at) || '暂无')}
${item('备注', ticket.remarks || '无')}
</div>
<div class="ticket-detail-grid">
${item('编号', ticket.ticket_number)}
${item('姓名', ticket.customer_name)}
${item('事由', ticket.reason)}
${item('处理结果', ticket.result)}
${item('金额', amount, 'money')}
${item('开具人', ticket.issuer)}
${item('创建时间', formatDate(ticket.created_at))}
${item('办结日期', formatDate(ticket.processed_at))}
${item('处理状态', `<span class="status-pill ${ticket.processed ? 'done' : 'pending'}">${processedLabel}</span>`, '', true)}
${item('办结状态', `<span class="status-pill ${ticket.status ? 'done' : 'pending'}">${completionLabel}</span>`, '', true)}
${item('备注', ticket.remarks || '无', '', false, true)}
</div>
`;
}
<div class="action-buttons">
<button class="btn btn-primary" onclick="goPrint()">打印</button>
<button class="btn btn-secondary" onclick="history.back()">返回</button>
</div>
`;
}
function goPrint() {
window.open(`print.html?id=${new URLSearchParams(location.search).get('id')}`, '_blank');
}
function item(label, value, extraClass = '', isHTML = false, isWide = false) {
return `
<div class="detail-item${isWide ? ' wide' : ''}">
<span class="detail-label">${label}</span>
<div class="detail-value${extraClass ? ` ${extraClass}` : ''}">${isHTML ? value : (value || '无')}</div>
</div>
`;
}
function item(label, value, isHTML = false) {
return `
<div class="info-item">
<div class="info-label">${label}</div>
<div class="info-value">${isHTML ? value : (value || '无')}</div>
</div>
`;
}
function goPrint() {
window.open(`print.html?id=${new URLSearchParams(location.search).get('id')}`, '_blank');
}
function formatDate(dateString) {
if (!dateString) return '暂无';
return new Date(dateString).toLocaleString('zh-CN');
}
function formatDate(dateString) {
if (!dateString) return '暂无';
return new Date(dateString).toLocaleString('zh-CN');
}
function showError(msg) {
document.getElementById('detailContent').innerHTML =
`<div class="error-message">${msg}</div>`;
}
function showError(msg) {
const el = document.getElementById('detailContent');
el.classList.add('feedback-card');
el.innerHTML = `<div class="error-state">${msg}</div>`;
}
document.addEventListener('DOMContentLoaded', loadTicketDetail);
</script>
<script src="https://cdn.jsdmirror.cn/gh/bishshi/wechat-detect@main/wechat-detect.js"></script>
document.addEventListener('DOMContentLoaded', loadTicketDetail);
</script>
<script src="https://cdn.jsdmirror.cn/gh/bishshi/wechat-detect@main/wechat-detect.js"></script>
</body>
</html>
</html>
+185 -213
View File
@@ -4,234 +4,206 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>单据查询系统</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600;700&family=Orbitron:wght@500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../css/tech-query.css">
<script src="https://cdn.jsdmirror.cn/gh/bishshi/wechat-detect@main/wechat-detect.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<script src="https://unpkg.com/html5-qrcode"></script>
<style>
:root {
--bg-color: #f0f2f5;
--card-bg: #ffffff;
--text-main: #1e293b;
--text-muted: #64748b;
--border-color: #e2e8f0;
--primary: #1a73e8;
--success: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
}
html, body { margin: 0; padding: 0; height: 100%; overflow-x: hidden; -webkit-font-smoothing: antialiased; }
body { background: var(--bg-color); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--text-main); box-sizing: border-box; }
.ticket-container {
max-width: 1000px; margin: 30px auto; padding: 28px;
background: var(--card-bg); border-radius: 16px;
box-shadow: 0 4px 20px rgba(0,0,0,0.08); box-sizing: border-box;
}
h1 { text-align: center; font-size: clamp(22px, 5vw, 28px); font-weight: 600; margin-bottom: 12px; }
.page-desc { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }
/* 搜索卡片 */
.search-card {
background: #fafbfc; border-radius: 10px; padding: 16px; border: 1px solid var(--border-color);
margin-bottom: 24px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 12px; align-items: end;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.input-with-icon { position: relative; display: flex; align-items: center; }
.form-control {
padding: 6px 12px; border: 1px solid var(--border-color); border-radius: 6px;
font-size: 14px; height: 36px; flex: 1; box-sizing: border-box;
}
.scan-trigger {
position: absolute; right: 8px; cursor: pointer; color: var(--primary);
padding: 4px; display: flex; align-items: center; background: none; border: none; z-index: 10;
}
.btn {
height: 36px; padding: 0 24px; background: var(--primary); border: none;
border-radius: 6px; color: #fff; font-weight: 600; cursor: pointer; white-space: nowrap;
}
/* 表格样式恢复 */
.table-wrapper { overflow-x: auto; margin-top: 16px; border-radius: 8px; border: 1px solid var(--border-color); }
.result-table { width: 100%; border-collapse: collapse; min-width: 700px; font-size: 14px; }
.result-table th { background: #f8fafc; text-align: left; padding: 12px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid var(--border-color); font-size: 13px; }
.result-table td { padding: 12px; border-bottom: 1px solid var(--border-color); color: var(--text-main); vertical-align: middle; }
/* 状态标签样式 */
.status { padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; display: inline-block; white-space: nowrap; }
.status.done { background: linear-gradient(135deg, #dcfce7, #bbf7d0); color: #166534; }
.status.pending { background: linear-gradient(135deg, #ffedd5, #fed7aa); color: #c2410c; }
.loading, .no-result { text-align: center; padding: 40px; color: var(--text-muted); font-size: 15px; }
/* --- 扫码正方形 UI --- */
#scanner-overlay {
display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.9); z-index: 9999;
flex-direction: column; justify-content: center; align-items: center; touch-action: none;
}
.scanner-wrapper {
position: relative; width: 280px; height: 280px;
border-radius: 12px; overflow: hidden; background: #000;
border: 2px solid rgba(255,255,255,0.2);
}
#reader { width: 100% !important; height: 100% !important; }
.scan-line {
position: absolute; width: 100%; height: 2px;
background: linear-gradient(to right, transparent, var(--primary), transparent);
top: 0; left: 0; z-index: 10; animation: scanMove 2s infinite linear;
}
@keyframes scanMove { 0% { top: 0; } 100% { top: 100%; } }
.btn-cancel { margin-top: 30px; padding: 10px 40px; background: #ef4444; color: white; border: none; border-radius: 20px; font-size: 14px; }
@media (max-width: 768px) {
.ticket-container { margin: 15px; padding: 20px; width: calc(100% - 30px); }
.search-card { grid-template-columns: 1fr; }
.hide-mobile { display: none; }
}
</style>
</head>
<body>
<div class="ticket-container">
<h1>单据查询</h1>
<p class="page-desc">请输入查询条件,可查询 2024 年至今的单据</p>
<div class="search-card">
<div class="form-group">
<label for="searchTerm">编号 / 姓名</label>
<div class="input-with-icon">
<input type="text" id="searchTerm" class="form-control" placeholder="请输入编号或姓名">
<div class="scan-trigger" id="startScanBtn">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 7V5a2 2 0 0 1 2-2h2m10 0h2a2 2 0 0 1 2 2v2m0 10v2a2 2 0 0 1-2 2h-2M7 21H5a2 2 0 0 1-2-2v-2M7 7h10v10H7z"/></svg>
<main class="page-shell">
<section class="page-header">
<div class="hero-card">
<span class="eyebrow">Ticket Search</span>
<h1>单据状态追踪中心</h1>
<p>支持按单据编号、姓名和时间范围查询,扫码可直接识别单据信息并进入检索流程。</p>
<div class="hero-meta">
<span class="meta-chip">覆盖范围:2024 年至今</span>
<span class="meta-chip">输出内容:金额 / 状态 / 详情入口</span>
</div>
</div>
<aside class="stat-card">
<div>
<div class="stat-label">Module</div>
<div class="stat-value">TICKET</div>
</div>
<p></p>
</aside>
</section>
<section class="panel-card">
<div class="panel-title-row">
<div>
<h2 class="panel-title">检索条件</h2>
<div class="panel-subtitle">支持文本检索与扫码录入</div>
</div>
</div>
<div class="search-grid">
<div class="form-group">
<label class="form-label" for="searchTerm">编号 / 姓名</label>
<div class="input-with-action">
<input type="text" id="searchTerm" class="tech-input" placeholder="请输入单据编号或姓名">
<button type="button" class="icon-action" id="startScanBtn" title="扫码查询" aria-label="扫码查询">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 7V5a2 2 0 0 1 2-2h2m10 0h2a2 2 0 0 1 2 2v2m0 10v2a2 2 0 0 1-2 2h-2M7 21H5a2 2 0 0 1-2-2v-2M7 7h10v10H7z"/></svg>
</button>
</div>
</div>
<div class="form-group">
<label class="form-label" for="dateFrom">开始日期</label>
<input type="date" id="dateFrom" class="tech-input">
</div>
<div class="form-group">
<label class="form-label" for="dateTo">结束日期</label>
<input type="date" id="dateTo" class="tech-input">
</div>
<button id="searchBtn" class="tech-button">执行查询</button>
</div>
</section>
<section class="panel-card results-card">
<div class="panel-title-row">
<div>
<h2 class="panel-title">查询结果</h2>
<div class="panel-subtitle">金额、状态与详情一屏展示</div>
</div>
</div>
<div id="searchResults" class="results-shell">
<div class="empty-state">输入查询条件后开始检索,或使用扫码功能快速定位单据。</div>
</div>
</section>
</main>
<div id="scanner-overlay" class="scanner-overlay">
<div class="scanner-frame">
<div id="reader"></div>
<div class="scanner-line"></div>
</div>
<div class="form-group">
<label for="dateFrom">开始日期</label>
<input type="date" id="dateFrom" class="form-control">
</div>
<div class="form-group">
<label for="dateTo">结束日期</label>
<input type="date" id="dateTo" class="form-control">
</div>
<button id="searchBtn" class="btn">立即查询</button>
<div class="scanner-text">请将二维码保持在扫描框内</div>
<button class="tech-button secondary" id="stopScanBtn" type="button">退出扫描</button>
</div>
<div id="searchResults"></div>
</div>
<footer class="page-footer">
<p>© 2026 BI Intelligent Query Interface</p>
</footer>
<div id="scanner-overlay">
<div class="scanner-wrapper">
<div id="reader"></div>
<div class="scan-line"></div>
</div>
<div style="color:white; margin-top:15px; font-size:14px; opacity:0.8">请将二维码置于框内</div>
<button class="btn-cancel" id="stopScanBtn">退出扫描</button>
</div>
<script>
const SUPABASE_URL = 'https://chixssrphfgxvqqigkzo.supabase.co';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNoaXhzc3JwaGZneHZxcWlna3pvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ2OTE0OTEsImV4cCI6MjA5MDI2NzQ5MX0.Az_Ew2J2zdOMcSV0UNAjBS-LPqGpqhsaN4IyZ5R7iqU';
const sbClient = supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
<script>
const SUPABASE_URL = 'https://chixssrphfgxvqqigkzo.supabase.co';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNoaXhzc3JwaGZneHZxcWlna3pvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ2OTE0OTEsImV4cCI6MjA5MDI2NzQ5MX0.Az_Ew2J2zdOMcSV0UNAjBS-LPqGpqhsaN4IyZ5R7iqU';
const sbClient = supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
let html5QrCode = null;
let html5QrCode = null;
// 扫码逻辑
document.getElementById('startScanBtn').addEventListener('click', async () => {
document.getElementById('scanner-overlay').style.display = 'flex';
if (html5QrCode) { try { await html5QrCode.stop(); } catch(e) {} }
html5QrCode = new Html5Qrcode("reader");
const config = { fps: 15, qrbox: { width: 250, height: 250 }, aspectRatio: 1.0 };
try {
await html5QrCode.start({ facingMode: "environment" }, config, (text) => {
document.getElementById('searchTerm').value = text;
closeScanner();
handleSearch();
});
} catch (err) { alert("摄像头启动失败"); closeScanner(); }
});
async function closeScanner() {
if (html5QrCode && html5QrCode.isScanning) { await html5QrCode.stop(); }
document.getElementById('scanner-overlay').style.display = 'none';
}
document.getElementById('stopScanBtn').addEventListener('click', closeScanner);
// 查询与结果渲染逻辑(完整找回)
async function handleSearch() {
const searchTerm = document.getElementById('searchTerm').value.trim();
const dateFrom = document.getElementById('dateFrom').value;
const dateTo = document.getElementById('dateTo').value;
const resultsDiv = document.getElementById('searchResults');
resultsDiv.innerHTML = '<div class="loading">正在查询...</div>';
try {
let query = sbClient.from('tickets').select('*');
if (searchTerm) {
query = query.or(`ticket_number.ilike.%${searchTerm}%,customer_name.ilike.%${searchTerm}%`);
document.getElementById('startScanBtn').addEventListener('click', async () => {
document.getElementById('scanner-overlay').style.display = 'flex';
if (html5QrCode) {
try {
await html5QrCode.stop();
} catch (e) {}
}
html5QrCode = new Html5Qrcode("reader");
const config = { fps: 15, qrbox: { width: 250, height: 250 }, aspectRatio: 1.0 };
try {
await html5QrCode.start({ facingMode: "environment" }, config, (text) => {
document.getElementById('searchTerm').value = text;
closeScanner();
handleSearch();
});
} catch (err) {
alert("摄像头启动失败。");
closeScanner();
}
if (dateFrom) query = query.gte('created_at', dateFrom);
if (dateTo) query = query.lte('created_at', dateTo);
const { data, error } = await query.order('created_at', { ascending: false });
if (error) throw error;
displayResults(data);
} catch (error) {
resultsDiv.innerHTML = `<div style="color:red;padding:20px;">查询失败:${error.message}</div>`;
}
}
function displayResults(tickets) {
const resultsDiv = document.getElementById('searchResults');
if (!tickets || tickets.length === 0) {
resultsDiv.innerHTML = '<div class="no-result">🔍 未找到符合条件的单据</div>';
return;
}
let html = `
<div class="table-wrapper">
<table class="result-table">
<thead>
<tr>
<th>编号</th><th>姓名</th><th>事由</th><th>金额</th><th class="hide-mobile">日期</th><th>状态</th><th>操作</th>
</tr>
</thead>
<tbody>
`;
tickets.forEach(ticket => {
const amount = (ticket.amount || 0).toLocaleString('zh-CN', { style: 'currency', currency: 'CNY' });
const reason = ticket.reason || '';
const displayReason = reason.length > 15 ? `<span title="${reason}">${reason.substring(0, 15)}...</span>` : reason;
html += `
<tr>
<td><strong>${ticket.ticket_number || ''}</strong></td>
<td>${ticket.customer_name || ''}</td>
<td>${displayReason}</td>
<td style="font-weight: 600; color: var(--primary);">${amount}</td>
<td class="hide-mobile">${new Date(ticket.created_at).toLocaleDateString('zh-CN')}</td>
<td><span class="status ${ticket.processed ? 'done' : 'pending'}">${ticket.processed ? '✓ 已处理' : '⏳ 未处理'}</span></td>
<td><button class="btn" onclick="location.href='detail.html?id=${ticket.id}'" style="padding: 6px 12px; font-size: 13px;">查看详情</button></td>
</tr>
`;
});
html += '</tbody></table></div>';
resultsDiv.innerHTML = html;
}
async function closeScanner() {
if (html5QrCode && html5QrCode.isScanning) {
await html5QrCode.stop();
}
document.getElementById('scanner-overlay').style.display = 'none';
}
document.getElementById('searchBtn').addEventListener('click', handleSearch);
</script>
document.getElementById('stopScanBtn').addEventListener('click', closeScanner);
async function handleSearch() {
const searchTerm = document.getElementById('searchTerm').value.trim();
const dateFrom = document.getElementById('dateFrom').value;
const dateTo = document.getElementById('dateTo').value;
const resultsDiv = document.getElementById('searchResults');
resultsDiv.innerHTML = '<div class="loading-state">正在连接单据数据库并执行检索...</div>';
try {
let query = sbClient.from('tickets').select('*');
if (searchTerm) {
query = query.or(`ticket_number.ilike.%${searchTerm}%,customer_name.ilike.%${searchTerm}%`);
}
if (dateFrom) query = query.gte('created_at', dateFrom);
if (dateTo) query = query.lte('created_at', dateTo);
const { data, error } = await query.order('created_at', { ascending: false });
if (error) throw error;
displayResults(data);
} catch (error) {
resultsDiv.innerHTML = `<div class="error-state">查询失败:${error.message}</div>`;
}
}
function displayResults(tickets) {
const resultsDiv = document.getElementById('searchResults');
if (!tickets || tickets.length === 0) {
resultsDiv.innerHTML = '<div class="empty-state">未找到符合条件的单据记录。</div>';
return;
}
let html = `
<div class="table-wrapper">
<table class="result-table">
<thead>
<tr>
<th>编号</th>
<th>姓名</th>
<th>事由</th>
<th>金额</th>
<th>日期</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
`;
tickets.forEach(ticket => {
const amount = (ticket.amount || 0).toLocaleString('zh-CN', { style: 'currency', currency: 'CNY' });
const reason = ticket.reason || '';
const displayReason = reason.length > 18
? `<span class="text-truncate" title="${reason}">${reason}</span>`
: reason;
html += `
<tr>
<td class="table-highlight">${ticket.ticket_number || ''}</td>
<td>${ticket.customer_name || ''}</td>
<td>${displayReason}</td>
<td class="table-highlight">${amount}</td>
<td>${ticket.created_at ? new Date(ticket.created_at).toLocaleDateString('zh-CN') : '-'}</td>
<td>
<span class="status-pill ${ticket.processed ? 'done' : 'pending'}">
${ticket.processed ? '已处理' : '未处理'}
</span>
</td>
<td><button class="tech-link-button secondary" type="button" onclick="location.href='detail.html?id=${ticket.id}'">查看详情</button></td>
</tr>
`;
});
html += '</tbody></table></div>';
resultsDiv.innerHTML = html;
}
document.getElementById('searchBtn').addEventListener('click', handleSearch);
</script>
</body>
</html>
</html>