/* 机构动向 */
let curType = '';
async function loadInsts() {
try {
const d = await api('/api/institutions?type=' + curType);
const items = d.items || [];
$('#tb').innerHTML = items.map(it => `
| ${escapeHtml(it.name)} |
${escapeHtml(it.type)} |
${escapeHtml(it.description)} |
… |
… |
|
`).join('');
items.forEach(it => fillCounts(it.id, it.name));
} catch (e) {
$('#tb').innerHTML = '| 加载失败 |
';
}
}
async function fillCounts(id, name) {
try {
const d = await api('/api/ratings/upgrades');
const rc = d.items.filter(x => x.inst_name === name).length;
$('#rc-' + id).textContent = rc;
} catch (e) {}
}
async function showInst(id) {
try {
const d = await api('/api/institutions/' + id);
const inst = d.institution;
const ratings = (d.ratings || []).map(r => `
| ${r.name}(${r.stock_code}) |
${r.rating} |
${r.target_price} | ${r.rating_date} |
`).join('');
const holdings = (d.holdings || []).map(h => `
| ${h.name}(${h.stock_code}) | ${h.quarter} |
${fmtNum(h.hold_value)} |
${fmtPct(h.change_pct)} |
`).join('');
openModal(`
${escapeHtml(inst.name)} ${escapeHtml(inst.type)}
${escapeHtml(inst.description)}
近期评级
基金持仓
`);
} catch (e) { toast('加载失败'); }
}
async function loadMoves() {
try {
const d = await api('/api/holdings/moves');
const q = d.quarter || '';
const inc = (d.increase || []).map(h => `
| ${h.name} | ${escapeHtml(h.inst_name)} |
${fmtPct(h.change_pct)} |
`).join('');
const dec = (d.decrease || []).map(h => `
| ${h.name} | ${escapeHtml(h.inst_name)} |
${fmtPct(h.change_pct)} |
`).join('');
$('#holdBox').innerHTML = `最新季度:${q}
| 增持榜 | 机构 | 环比 |
${inc || '| 暂无 |
'}
|
| 减持榜 | 机构 | 环比 |
${dec || '| 暂无 |
'}
`;
} catch (e) {}
}
async function loadUpgrades() {
try {
const d = await api('/api/ratings/upgrades');
$('#upgradeBox').innerHTML = `
| 股票 | 机构 | 评级 | 日期 |
${(d.items || []).slice(0, 14).map(r => `
| ${r.name} ${r.stock_code} |
${escapeHtml(r.inst_name)} |
${r.rating} → 目标${r.target_price} |
${r.rating_date} |
`).join('')}
`;
} catch (e) {}
}
$$('#typePills .pill').forEach(p => {
p.onclick = () => {
$$('#typePills .pill').forEach(x => x.classList.remove('active'));
p.classList.add('active');
curType = p.dataset.t;
loadInsts();
};
});
loadMoves();
loadUpgrades();
loadInsts();