@@ -0,0 +1,119 @@
|
||||
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);
|
||||
|
||||
async function loadData() {
|
||||
const id = new URLSearchParams(window.location.search).get('id');
|
||||
if (!id) return;
|
||||
|
||||
try {
|
||||
const { data, error } = await sbClient
|
||||
.from('certificates')
|
||||
.select('*')
|
||||
.eq('id', id)
|
||||
.single();
|
||||
|
||||
if (error || !data) throw error || new Error('未找到证书信息');
|
||||
|
||||
const verifyTime = new Date().toLocaleString('zh-CN');
|
||||
document.getElementById('info-card').style.display = 'block';
|
||||
document.getElementById('d-cert-number').innerText = data.cert_number || '-';
|
||||
document.getElementById('d-holder-name').innerText = data.holder_name || '-';
|
||||
document.getElementById('d-honor-title').innerText = data.honor_title || '-';
|
||||
document.getElementById('d-issue-date').innerText = data.issue_date || '-';
|
||||
document.getElementById('d-issuer').innerText = data.issuer || '官方授权机构';
|
||||
document.getElementById('d-desc').innerText = data.description || '官方荣誉认证';
|
||||
document.getElementById('d-remarks').innerText = data.remarks || '无';
|
||||
document.getElementById('d-verify-time').innerText = verifyTime;
|
||||
|
||||
document.getElementById('summary-cert-number').innerText = data.cert_number || '-';
|
||||
document.getElementById('summary-holder-name').innerText = data.holder_name || '-';
|
||||
document.getElementById('summary-verify-time').innerText = verifyTime;
|
||||
|
||||
if (data.status === 'valid') {
|
||||
document.getElementById('display-status').innerHTML = '<span class="status-pill done">有效</span>';
|
||||
} else if (data.status === 'invalid') {
|
||||
document.getElementById('display-status').innerHTML = '<span class="status-pill pending">无效</span>';
|
||||
} else {
|
||||
document.getElementById('display-status').innerHTML = '<span class="status-pill pending">待核验</span>';
|
||||
}
|
||||
|
||||
window.currentCertNumber = data.cert_number;
|
||||
} catch (e) {
|
||||
console.error('加载失败:', e);
|
||||
alert('证书信息检索失败。');
|
||||
}
|
||||
}
|
||||
|
||||
function loadCertificateImage() {
|
||||
const certNumber = window.currentCertNumber;
|
||||
if (!certNumber) return;
|
||||
|
||||
const img = document.getElementById('cert-img');
|
||||
const hint = document.getElementById('click-hint');
|
||||
|
||||
if (img.src && img.complete && img.naturalWidth > 0) {
|
||||
img.style.display = 'block';
|
||||
if (hint) hint.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
if (hint) {
|
||||
hint.innerHTML = '<span class="hint-orb">载</span><strong>图片加载中</strong><span>正在读取证书原件,请稍候。</span>';
|
||||
}
|
||||
|
||||
img.src = `https://s3.biss.click/CERTS/${encodeURIComponent(certNumber)}.svg`;
|
||||
img.onload = () => {
|
||||
img.style.display = 'block';
|
||||
if (hint) hint.style.display = 'none';
|
||||
};
|
||||
img.onerror = () => {
|
||||
if (hint) {
|
||||
hint.innerHTML = '<span class="hint-orb">!</span><strong>图片加载失败</strong><span>未找到对应证书图片文件</span>';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function ensureCertificateImageLoaded() {
|
||||
const certNumber = window.currentCertNumber;
|
||||
const img = document.getElementById('cert-img');
|
||||
const hint = document.getElementById('click-hint');
|
||||
|
||||
if (!certNumber) {
|
||||
throw new Error('未找到证书编号');
|
||||
}
|
||||
|
||||
if (img.src && img.complete && img.naturalWidth > 0) {
|
||||
img.style.display = 'block';
|
||||
if (hint) hint.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
if (hint) {
|
||||
hint.innerHTML = '<span class="hint-orb">载</span><strong>图片加载中</strong><span>正在为打印准备证书原件,请稍候。</span>';
|
||||
}
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
img.onload = () => {
|
||||
img.style.display = 'block';
|
||||
if (hint) hint.style.display = 'none';
|
||||
resolve();
|
||||
};
|
||||
img.onerror = () => {
|
||||
reject(new Error('证书图片加载失败'));
|
||||
};
|
||||
img.src = `https://s3.biss.click/CERTS/${encodeURIComponent(certNumber)}.svg`;
|
||||
});
|
||||
}
|
||||
|
||||
async function printCertificate() {
|
||||
try {
|
||||
await ensureCertificateImageLoaded();
|
||||
window.print();
|
||||
} catch (error) {
|
||||
console.error('打印前加载证书失败:', error);
|
||||
alert('证书原件加载失败,无法打印。');
|
||||
}
|
||||
}
|
||||
|
||||
loadData();
|
||||
@@ -0,0 +1,246 @@
|
||||
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);
|
||||
|
||||
const html5QrCode = new Html5Qrcode("reader");
|
||||
const scannerOverlay = document.getElementById('scanner-overlay');
|
||||
|
||||
document.getElementById('startScanBtn').addEventListener('click', async () => {
|
||||
scannerOverlay.style.display = 'flex';
|
||||
|
||||
const config = {
|
||||
fps: 15,
|
||||
qrbox: { width: 320, height: 140 },
|
||||
aspectRatio: 1.0
|
||||
};
|
||||
|
||||
if (typeof Html5QrcodeSupportedFormats !== 'undefined') {
|
||||
config.formatsToSupport = [
|
||||
Html5QrcodeSupportedFormats.CODE_128,
|
||||
Html5QrcodeSupportedFormats.CODE_39,
|
||||
Html5QrcodeSupportedFormats.CODE_93,
|
||||
Html5QrcodeSupportedFormats.EAN_13,
|
||||
Html5QrcodeSupportedFormats.EAN_8,
|
||||
Html5QrcodeSupportedFormats.UPC_A,
|
||||
Html5QrcodeSupportedFormats.UPC_E,
|
||||
Html5QrcodeSupportedFormats.ITF,
|
||||
Html5QrcodeSupportedFormats.CODABAR
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
await html5QrCode.start(
|
||||
{ facingMode: "environment" },
|
||||
config,
|
||||
(decodedText) => {
|
||||
document.getElementById('searchTerm').value = decodedText;
|
||||
closeScanner();
|
||||
handleSearch();
|
||||
},
|
||||
() => {}
|
||||
);
|
||||
} catch (err) {
|
||||
alert("无法启动摄像头,请检查 HTTPS 权限或设备连接。");
|
||||
scannerOverlay.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
async function closeScanner() {
|
||||
if (html5QrCode.isScanning) {
|
||||
await html5QrCode.stop();
|
||||
}
|
||||
scannerOverlay.style.display = 'none';
|
||||
}
|
||||
|
||||
document.getElementById('stopScanBtn').addEventListener('click', closeScanner);
|
||||
|
||||
async function handleSearch() {
|
||||
const term = document.getElementById('searchTerm').value.trim();
|
||||
const start = document.getElementById('dateStart').value;
|
||||
const end = document.getElementById('dateEnd').value;
|
||||
const display = document.getElementById('resultsArea');
|
||||
|
||||
if (!term) {
|
||||
alert("请输入证书编号、持有人姓名或奖项名。");
|
||||
return;
|
||||
}
|
||||
|
||||
display.innerHTML = '<div class="loading-state">正在连接证书数据库并执行检索...</div>';
|
||||
|
||||
try {
|
||||
let query = sbClient.from('certificates').select('*');
|
||||
query = query.or(`cert_number.ilike.%${term}%,holder_name.ilike.%${term}%,honor_title.ilike.%${term}%`);
|
||||
|
||||
if (start) query = query.gte('issue_date', start);
|
||||
if (end) query = query.lte('issue_date', end);
|
||||
|
||||
const { data, error } = await query.order('issue_date', { ascending: false });
|
||||
if (error) throw error;
|
||||
|
||||
const awardRecipientCounts = await loadAwardRecipientCounts(data);
|
||||
renderResults(data, awardRecipientCounts);
|
||||
} catch (err) {
|
||||
display.innerHTML = `<div class="error-state">检索失败:${err.message}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAwardRecipientCounts(data) {
|
||||
const awardTitles = [...new Set((data || []).map(item => item.honor_title).filter(Boolean))];
|
||||
if (awardTitles.length === 0) return {};
|
||||
|
||||
const countPairs = await Promise.all(awardTitles.map(async title => {
|
||||
const { count, error } = await sbClient
|
||||
.from('certificates')
|
||||
.select('id', { count: 'exact', head: true })
|
||||
.eq('honor_title', title);
|
||||
|
||||
if (error) throw error;
|
||||
return [title, count || 0];
|
||||
}));
|
||||
|
||||
return Object.fromEntries(countPairs);
|
||||
}
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value ?? '').replace(/[&<>"']/g, char => ({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": '''
|
||||
}[char]));
|
||||
}
|
||||
|
||||
function renderAwardStats(data, awardRecipientCounts) {
|
||||
const holderCounts = (data || []).reduce((counts, item) => {
|
||||
const holderName = item.holder_name || '未填写';
|
||||
counts[holderName] = (counts[holderName] || 0) + 1;
|
||||
return counts;
|
||||
}, {});
|
||||
|
||||
const holderStats = Object.entries(holderCounts)
|
||||
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0], 'zh-CN'));
|
||||
const maxHolderCount = Math.max(...holderStats.map(([, count]) => count), 1);
|
||||
|
||||
const awardStats = [...new Set((data || []).map(item => item.honor_title).filter(Boolean))]
|
||||
.map(title => ({
|
||||
title,
|
||||
count: awardRecipientCounts[title] || 0
|
||||
}))
|
||||
.sort((a, b) => b.count - a.count || a.title.localeCompare(b.title, 'zh-CN'));
|
||||
|
||||
const holderBars = holderStats.map(([name, count]) => `
|
||||
<div class="chart-row">
|
||||
<div class="chart-row-label" title="${escapeHtml(name)}">${escapeHtml(name)}</div>
|
||||
<div class="chart-bar-track">
|
||||
<div class="chart-bar-fill" style="width: ${Math.max((count / maxHolderCount) * 100, 6)}%;"></div>
|
||||
</div>
|
||||
<div class="chart-row-value">${count} 项</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
const awardChips = awardStats.map(item => `
|
||||
<div class="award-count-chip">
|
||||
<span class="award-count-title" title="${escapeHtml(item.title)}">${escapeHtml(item.title)}</span>
|
||||
<strong>${item.count}</strong>
|
||||
<span>人获得</span>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
return `
|
||||
<div class="results-summary">
|
||||
<div class="summary-stat-tile">
|
||||
<span>查询结果</span>
|
||||
<strong>${data.length}</strong>
|
||||
</div>
|
||||
<div class="summary-stat-tile">
|
||||
<span>涉及人员</span>
|
||||
<strong>${holderStats.length}</strong>
|
||||
</div>
|
||||
<div class="summary-stat-tile">
|
||||
<span>奖项种类</span>
|
||||
<strong>${awardStats.length}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stats-grid">
|
||||
<section class="stats-panel">
|
||||
<div class="stats-panel-title">个人奖项数量</div>
|
||||
<div class="bar-chart">${holderBars}</div>
|
||||
</section>
|
||||
<section class="stats-panel">
|
||||
<div class="stats-panel-title">查询奖项获得人数</div>
|
||||
<div class="award-count-grid">${awardChips || '<div class="muted-note">暂无奖项名称</div>'}</div>
|
||||
</section>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function renderResults(data, awardRecipientCounts = {}) {
|
||||
const display = document.getElementById('resultsArea');
|
||||
if (!data || data.length === 0) {
|
||||
display.innerHTML = '<div class="empty-state">未找到匹配的证书记录。</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = `
|
||||
${renderAwardStats(data, awardRecipientCounts)}
|
||||
<div class="table-wrapper">
|
||||
<table class="result-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>证书编号</th>
|
||||
<th>持有人</th>
|
||||
<th>荣誉标题</th>
|
||||
<th>颁发日期</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`;
|
||||
|
||||
data.forEach(item => {
|
||||
html += `
|
||||
<tr>
|
||||
<td class="table-highlight">${escapeHtml(item.cert_number || '-')}</td>
|
||||
<td>${escapeHtml(item.holder_name || '-')}</td>
|
||||
<td>${escapeHtml(item.honor_title || '-')}</td>
|
||||
<td>${escapeHtml(item.issue_date || '-')}</td>
|
||||
<td><button class="tech-link-button secondary" type="button" onclick="goToDetail('${item.id}')">查看详情</button></td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
|
||||
html += '</tbody></table></div>';
|
||||
display.innerHTML = html;
|
||||
}
|
||||
|
||||
function goToDetail(id) {
|
||||
window.location.href = `certificate.html?id=${id}`;
|
||||
}
|
||||
|
||||
function initializeSearchTermFromUrl() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const presetTerm =
|
||||
params.get('searchTerm') ||
|
||||
params.get('term') ||
|
||||
params.get('keyword') ||
|
||||
params.get('cert_number') ||
|
||||
params.get('certNumber') ||
|
||||
params.get('number') ||
|
||||
params.get('awardName') ||
|
||||
params.get('honor_title') ||
|
||||
params.get('honorTitle') ||
|
||||
params.get('award') ||
|
||||
params.get('q') ||
|
||||
'';
|
||||
|
||||
if (presetTerm) {
|
||||
document.getElementById('searchTerm').value = presetTerm;
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('searchBtn').addEventListener('click', handleSearch);
|
||||
document.getElementById('searchTerm').addEventListener('keypress', e => {
|
||||
if (e.key === 'Enter') handleSearch();
|
||||
});
|
||||
initializeSearchTermFromUrl();
|
||||
@@ -0,0 +1,70 @@
|
||||
(function () {
|
||||
fetch("../notices.json?v=" + Math.floor(Date.now() / 300000), { cache: "no-store" })
|
||||
.then(function (response) {
|
||||
if (!response.ok) {
|
||||
throw new Error("notice source unavailable");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(function (payload) {
|
||||
var notices = Array.isArray(payload) ? payload : payload.notices;
|
||||
var notice = Array.isArray(notices) && notices.find(function (item) {
|
||||
return item && item.enabled !== false;
|
||||
});
|
||||
|
||||
if (notice) {
|
||||
renderNotice(notice);
|
||||
}
|
||||
})
|
||||
.catch(function () {});
|
||||
|
||||
function renderNotice(notice) {
|
||||
setText("noticeTitle", notice.title || "重要通知");
|
||||
setText("noticeSummary", notice.message || "");
|
||||
setText("noticeBadge", notice.badge || "通知");
|
||||
setText("noticeLevel", String(notice.level || "info").toUpperCase());
|
||||
setText("articleTitle", notice.title || "重要通知");
|
||||
setText("articleMessage", notice.message || "");
|
||||
setText("noticeDate", formatDate(notice.startsAt) || "未设置开始时间");
|
||||
setText("noticeWindow", formatWindow(notice.startsAt, notice.endsAt));
|
||||
}
|
||||
|
||||
function setText(id, text) {
|
||||
var node = document.getElementById(id);
|
||||
if (node) {
|
||||
node.textContent = text;
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(value) {
|
||||
if (!value) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return date.toLocaleDateString("zh-CN", {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit"
|
||||
});
|
||||
}
|
||||
|
||||
function formatWindow(start, end) {
|
||||
var startText = formatDate(start);
|
||||
var endText = formatDate(end);
|
||||
|
||||
if (startText && endText) {
|
||||
return startText + " 至 " + endText;
|
||||
}
|
||||
|
||||
if (startText) {
|
||||
return startText + " 起生效";
|
||||
}
|
||||
|
||||
return "长期有效";
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,100 @@
|
||||
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;
|
||||
}
|
||||
|
||||
try {
|
||||
const { data: ticket, error } = await sbClient
|
||||
.from('tickets')
|
||||
.select('*')
|
||||
.eq('id', ticketId)
|
||||
.single();
|
||||
|
||||
if (error) throw error;
|
||||
if (!ticket) {
|
||||
showError('未找到该单据。');
|
||||
return;
|
||||
}
|
||||
|
||||
displayTicketDetail(ticket);
|
||||
} catch (error) {
|
||||
showError(error.message || '加载失败');
|
||||
}
|
||||
}
|
||||
|
||||
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.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="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>
|
||||
`;
|
||||
}
|
||||
|
||||
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 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 showError(msg) {
|
||||
const el = document.getElementById('detailContent');
|
||||
el.classList.add('feedback-card');
|
||||
el.innerHTML = `<div class="error-state">${msg}</div>`;
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', loadTicketDetail);
|
||||
@@ -0,0 +1,132 @@
|
||||
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;
|
||||
|
||||
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-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;
|
||||
}
|
||||
|
||||
function initializeSearchTermFromUrl() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const presetTerm =
|
||||
params.get('searchTerm') ||
|
||||
params.get('term') ||
|
||||
params.get('keyword') ||
|
||||
params.get('ticket_number') ||
|
||||
params.get('ticketNumber') ||
|
||||
params.get('number') ||
|
||||
params.get('q') ||
|
||||
'';
|
||||
|
||||
if (presetTerm) {
|
||||
document.getElementById('searchTerm').value = presetTerm;
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('searchBtn').addEventListener('click', handleSearch);
|
||||
initializeSearchTermFromUrl();
|
||||
@@ -0,0 +1,47 @@
|
||||
const SUPABASE_URL = 'https://chixssrphfgxvqqigkzo.supabase.co';
|
||||
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNoaXhzc3JwaGZneHZxcWlna3pvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ2OTE0OTEsImV4cCI6MjA5MDI2NzQ5MX0.Az_Ew2J2zdOMcSV0UNAjBS-LPqGpqhsaN4IyZ5R7iqU';
|
||||
|
||||
const sb = window.supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
|
||||
|
||||
function formatDate(d){
|
||||
return new Date(d).toLocaleString('zh-CN');
|
||||
}
|
||||
|
||||
function updateWatermark(customerName) {
|
||||
const now = new Date().toLocaleString('zh-CN');
|
||||
|
||||
const watermarkText = `BISS · ${customerName || 'Unknown'} · ${now}`;
|
||||
|
||||
document.getElementById('watermark').innerText = watermarkText;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
const id = new URLSearchParams(location.search).get('id');
|
||||
|
||||
const { data } = await sb.from('tickets').select('*').eq('id', id).single();
|
||||
|
||||
if (!data) return;
|
||||
|
||||
document.getElementById('ticket_number').innerText = data.ticket_number || '';
|
||||
document.getElementById('customer_name').innerText = data.customer_name || '';
|
||||
document.getElementById('reason').innerText = data.reason || '';
|
||||
document.getElementById('amount').innerText = '¥' + (data.amount || 0).toFixed(2);
|
||||
document.getElementById('issuer').innerText = data.issuer || '';
|
||||
document.getElementById('created_at').innerText = formatDate(data.created_at);
|
||||
document.getElementById('processed').innerText = data.processed ? '已办结' : '未办结';
|
||||
document.getElementById('processed_at').innerText = data.processed_at ? formatDate(data.processed_at) : '暂无';
|
||||
document.getElementById('remarks').innerText = data.remarks || '无';
|
||||
|
||||
// 打印时间
|
||||
document.getElementById('print_time').innerText =
|
||||
new Date().toLocaleString('zh-CN');
|
||||
|
||||
updateWatermark(data.customer_name);
|
||||
|
||||
// 自动打印
|
||||
setTimeout(() => {
|
||||
window.print();
|
||||
}, 300);
|
||||
}
|
||||
|
||||
load();
|
||||
@@ -0,0 +1,73 @@
|
||||
const SUPABASE_URL = 'https://chixssrphfgxvqqigkzo.supabase.co';
|
||||
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNoaXhzc3JwaGZneHZxcWlna3pvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ2OTE0OTEsImV4cCI6MjA5MDI2NzQ5MX0.Az_Ew2J2zdOMcSV0UNAjBS-LPqGpqhsaN4IyZ5R7iqU';
|
||||
const sb = supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
|
||||
|
||||
async function handleSearch() {
|
||||
const recipientTerm = document.getElementById('recipientTerm').value.trim();
|
||||
const contentTerm = document.getElementById('searchTerm').value.trim();
|
||||
const from = document.getElementById('dateFrom').value;
|
||||
const to = document.getElementById('dateTo').value;
|
||||
const out = document.getElementById('searchResults');
|
||||
|
||||
out.innerHTML = '<div class="loading-state">正在连接信函数据库并执行检索...</div>';
|
||||
|
||||
let q = sb.from('xinhan').select('*');
|
||||
if (recipientTerm) q = q.ilike('recipient', `%${recipientTerm}%`);
|
||||
if (contentTerm) q = q.ilike('content', `%${contentTerm}%`);
|
||||
if (from) q = q.gte('sent_date', from);
|
||||
if (to) q = q.lte('sent_date', to);
|
||||
|
||||
const { data, error } = await q.order('sent_date', { ascending: false });
|
||||
if (error) {
|
||||
out.innerHTML = `<div class="error-state">查询失败:${error.message}</div>`;
|
||||
return;
|
||||
}
|
||||
renderResults(data || []);
|
||||
}
|
||||
|
||||
function renderResults(rows) {
|
||||
const container = document.getElementById('searchResults');
|
||||
if (!rows.length) {
|
||||
container.innerHTML = '<div class="empty-state">未找到符合条件的信函记录。</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = `
|
||||
<div class="table-wrapper">
|
||||
<table class="result-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>收件人</th>
|
||||
<th>目的地</th>
|
||||
<th>寄出日期</th>
|
||||
<th>寄达日期</th>
|
||||
<th>内容摘要</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`;
|
||||
|
||||
rows.forEach(row => {
|
||||
const content = row.content || '';
|
||||
const summary = content.length > 60
|
||||
? `<span class="text-truncate" title="${content}">${content}</span>`
|
||||
: content;
|
||||
|
||||
html += `
|
||||
<tr>
|
||||
<td class="table-highlight">${row.id}</td>
|
||||
<td>${row.recipient || ''}</td>
|
||||
<td>${row.destination || ''}</td>
|
||||
<td>${row.sent_date || ''}</td>
|
||||
<td>${row.arrival_date || ''}</td>
|
||||
<td>${summary}</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
|
||||
html += '</tbody></table></div>';
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
document.getElementById('searchBtn').addEventListener('click', handleSearch);
|
||||
Reference in New Issue
Block a user