/* 荐股中心 */
let curRating = 'all';
async function load() {
try {
const d = await api('/api/recommend?rating=' + curRating + '&limit=80');
render(d.items);
} catch (e) {
$('#tb').innerHTML = '
| 加载失败:' + escapeHtml(e.message) + ' |
';
}
}
function render(items) {
if (!items.length) { $('#tb').innerHTML = '| 该评级暂无股票 |
'; return; }
$('#tb').innerHTML = items.map((it, i) => {
const sc = it.score;
return `
| ${i + 1} |
${it.name} ${it.code} · ${escapeHtml(it.industry)} |
${it.close} |
${fmtPct(it.change_pct)} |
${fmtPct(it.chg_5d)} |
|
${sc.rating} |
${scoreBars(sc.score_parts)}
|
${escapeHtml((it.reasons || []).join(';'))} |
|
`;
}).join('');
$$('.score-ring', $('#tb')).forEach(el => scoreRing(el, el.dataset.score));
}
/* AI 深度分析:跳详情页并自动触发 */
function analyze(code, name) {
location.href = `/stock/${code}?analyze=1`;
}
$$('#ratingPills .pill').forEach(p => {
p.onclick = () => {
$$('#ratingPills .pill').forEach(x => x.classList.remove('active'));
p.classList.add('active');
curRating = p.dataset.r;
load();
};
});
load();