/* Copyright (c) 2025-2026 马建军. All rights reserved. * 交易记录核对修改 — 与币安实例一致:开关启用后,逐条弹窗核对 */ (function () { var switchEl = document.getElementById('trade-edit-switch'); if (!switchEl) return; function syncReviewEditButtons() { var on = !!switchEl.checked; document.querySelectorAll('.review-edit-btn').forEach(function (btn) { btn.disabled = !on; }); } function normalizeDatetime(v) { var raw = String(v || '').trim().replace('T', ' '); var m = raw.match(/^(\d{4}-\d{2}-\d{2})[ ](\d{2}:\d{2})(:\d{2})?/); if (!m) return raw.slice(0, 19); return m[1] + ' ' + m[2] + ':' + (m[3] ? m[3].slice(1) : '00'); } function fmtPrice(v) { if (v === null || v === undefined || v === '') return ''; return String(v); } function editTradeRecordReview(t) { if (!t || !t.id) return; var opened = prompt('开仓时间(YYYY-MM-DD HH:MM:SS)', normalizeDatetime(t.open_time)); if (opened === null) return; var closed = prompt('平仓时间(YYYY-MM-DD HH:MM:SS)', normalizeDatetime(t.close_time)); if (closed === null) return; var entry = prompt('开仓价(核对后用于统计)', fmtPrice(t.entry_price)); if (entry === null) return; var closePx = prompt('平仓价(跨日持仓请以柜台成交为准)', fmtPrice(t.close_price)); if (closePx === null) return; var stopLoss = prompt('止损价格(核对后用于统计)', fmtPrice(t.stop_loss)); if (stopLoss === null) return; var takeProfit = prompt('止盈价格(核对后用于统计)', fmtPrice(t.take_profit)); if (takeProfit === null) return; var pnl = prompt('盈亏(元,可手工核对后填写)', String(t.pnl != null ? t.pnl : '')); if (pnl === null) return; var result = prompt( '结果(止盈/止损/保本止盈/移动止盈/手动平仓/CTP同步)', String(t.result || '手动平仓') ); if (result === null) return; var form = document.createElement('form'); form.method = 'POST'; form.action = '/update_trade/' + t.id; var fields = { symbol_name: t.symbol_name || t.symbol || '', monitor_type: t.monitor_type || '', direction: t.direction || 'long', entry_price: entry, close_price: closePx, stop_loss: stopLoss, take_profit: takeProfit, lots: t.lots != null ? t.lots : '', margin: t.margin != null ? t.margin : '', holding_minutes: t.holding_minutes != null ? t.holding_minutes : 0, open_time: normalizeDatetime(opened), close_time: normalizeDatetime(closed), pnl: pnl, result: String(result || '').trim() || '手动平仓', }; Object.keys(fields).forEach(function (name) { var input = document.createElement('input'); input.type = 'hidden'; input.name = name; input.value = fields[name]; form.appendChild(input); }); document.body.appendChild(form); form.submit(); } window.editTradeRecordReview = editTradeRecordReview; window.toggleTradeReviewMode = syncReviewEditButtons; switchEl.addEventListener('change', syncReviewEditButtons); switchEl.addEventListener('input', syncReviewEditButtons); syncReviewEditButtons(); window.addEventListener('pageshow', syncReviewEditButtons); document.addEventListener('click', function (e) { var btn = e.target.closest('.review-edit-btn'); if (!btn || btn.disabled) return; e.preventDefault(); e.stopPropagation(); var raw = btn.getAttribute('data-trade-edit'); if (!raw) return; try { editTradeRecordReview(JSON.parse(raw)); } catch (err) { /* ignore */ } }); })();