/* 股票池 */ let page = 1, total = 0, industries = []; async function loadIndustries() { try { const d = await api('/api/overview'); industries = d.heat.map(h => h.industry); const sel = $('#industry'); industries.forEach(i => { const o = document.createElement('option'); o.textContent = i; sel.appendChild(o); }); } catch (e) {} } async function load(p) { if (p) page = p; const q = new URLSearchParams({ keyword: $('#kw').value.trim(), industry: $('#industry').value, board: $('#board').value, rating: $('#rating').value, sort: $('#sort').value, order: $('#sort').value === 'score' ? 'desc' : 'desc', page: page, per: 20 }); try { const d = await api('/api/stocks?' + q.toString()); total = d.total; render(d.items); $('#pageInfo').textContent = `第 ${page} / ${Math.max(1, Math.ceil(total / 20))} 页 · 共 ${total} 只`; $('#stCount').textContent = `共 ${total} 只`; $('#prevBtn').disabled = page <= 1; $('#nextBtn').disabled = page * 20 >= total; } catch (e) { $('#tb').innerHTML = '加载失败'; } } function render(items) { if (!items.length) { $('#tb').innerHTML = '无匹配股票'; return; } $('#tb').innerHTML = items.map(it => ` ${it.name}
${it.code}
${escapeHtml(it.industry)} ${it.board} ${it.close} ${fmtPct(it.change_pct)} ${fmtPct(it.chg_5d)} ${it.vol_ratio} ${fmtAmountYi(it.amount)} ${Number(it.market_cap).toFixed(0)}亿 ${it.score} ${it.rating} `).join(''); } async function addWatch(code) { try { await api('/api/watchlist/' + code, { method: 'POST' }); toast('已加入自选'); } catch (e) { toast('操作失败'); } } $('#kw').addEventListener('keydown', e => { if (e.key === 'Enter') load(1); }); $('#kw').addEventListener('input', debounce(() => load(1), 400)); $('#industry').onchange = () => load(1); $('#board').onchange = () => load(1); $('#rating').onchange = () => load(1); $('#sort').onchange = () => load(1); loadIndustries(); load(1);