/* Copyright (c) 2025-2026 马建军. All rights reserved.
* 交易记录 — 手机/平板简洁列表与详情弹窗
*/
(function () {
function esc(v) {
if (v === null || v === undefined || v === '') return '-';
return String(v);
}
function fmtTime(v) {
if (!v) return '-';
return String(v).replace('T', ' ').slice(0, 16);
}
function showTradeModal(data) {
var mask = document.getElementById('trade-detail-modal');
var body = document.getElementById('trade-detail-modal-body');
if (!mask || !body) return;
var fields = [
{ label: '品种', value: esc(data.symbol), wide: false },
{ label: '合约', value: esc(data.symbol_code), wide: false },
{ label: '类型', value: esc(data.monitor_type) + ' · ' + esc(data.source), wide: false },
{ label: '方向', value: esc(data.direction), wide: false },
{ label: '开仓价', value: esc(data.entry_price), wide: false },
{ label: '平仓价', value: esc(data.close_price), wide: false },
{ label: '手数', value: esc(data.lots), wide: false },
{ label: '止损', value: esc(data.stop_loss), wide: false },
{ label: '止盈', value: esc(data.take_profit), wide: false },
{ label: '保证金', value: data.margin != null ? esc(data.margin) : '-', wide: false },
{ label: '保证金占比', value: data.margin_pct != null ? esc(data.margin_pct) + '%' : '-', wide: false },
{ label: '持仓分钟', value: esc(data.holding_minutes), wide: false },
{ label: '开仓时间', value: fmtTime(data.open_time), wide: false },
{ label: '平仓时间', value: fmtTime(data.close_time), wide: false },
{ label: '盈亏(元)', value: esc(data.pnl), wide: false },
{ label: '手续费', value: esc(data.fee), wide: false },
{ label: '净盈亏', value: esc(data.pnl_net), wide: false },
{ label: '最新资金', value: esc(data.equity_after), wide: false },
{ label: '结果', value: esc(data.result) + (data.verified ? ' · 已核对' : ''), wide: true }
];
var html = '
';
fields.forEach(function (f) {
html += '
';
html += '
' + f.value + '
';
});
html += '
';
html += '';
if (data.id) {
html += '
';
}
if (data.fill_review_url) {
html += '
填入复盘';
}
if (data.del_url) {
html += '
删除';
}
html += '
';
body.innerHTML = html;
var reviewBtn = body.querySelector('.review-edit-btn');
if (reviewBtn && data.id) {
reviewBtn.setAttribute('data-trade-edit', JSON.stringify({
id: data.id,
symbol_name: data.symbol_name || data.symbol,
monitor_type: data.monitor_type,
direction: data.direction_code || (data.direction === '做多' ? 'long' : 'short'),
entry_price: data.entry_price,
close_price: data.close_price,
stop_loss: data.stop_loss,
take_profit: data.take_profit,
lots: data.lots,
margin: data.margin,
holding_minutes: data.holding_minutes,
open_time: data.open_time,
close_time: data.close_time,
pnl: data.pnl,
result: data.result
}));
}
if (typeof window.toggleTradeReviewMode === 'function') {
window.toggleTradeReviewMode();
}
mask.classList.add('show');
}
function openRowDetail(row) {
if (!row) return;
try {
showTradeModal(JSON.parse(row.getAttribute('data-trade')));
} catch (err) { /* ignore */ }
}
function bindTradeModal() {
var mask = document.getElementById('trade-detail-modal');
if (!mask) return;
var closeBtn = mask.querySelector('.modal-close');
if (closeBtn) {
closeBtn.addEventListener('click', function () {
mask.classList.remove('show');
});
}
mask.addEventListener('click', function (e) {
if (e.target === mask) mask.classList.remove('show');
});
var phoneList = document.getElementById('records-trade-mobile');
if (phoneList) {
phoneList.addEventListener('click', function (e) {
openRowDetail(e.target.closest('.records-trade-row'));
});
}
var tabletWrap = document.querySelector('.records-trade-table-wrap');
if (tabletWrap) {
tabletWrap.addEventListener('click', function (e) {
if (!e.target.closest('.records-tablet-detail-btn')) return;
openRowDetail(e.target.closest('tr[data-trade]'));
});
}
}
function bootRecordsPage() {
if (!document.querySelector('.records-page')) return;
bindTradeModal();
}
if (window.qihuoPageBoot) window.qihuoPageBoot(bootRecordsPage, '.records-page');
else if (window.qihuoOnPageLoad) window.qihuoOnPageLoad(bootRecordsPage);
else document.addEventListener('DOMContentLoaded', bootRecordsPage);
})();