diff --git a/lib/common/static/hedge_plan.js b/lib/common/static/hedge_plan.js index 3095132..b815a78 100644 --- a/lib/common/static/hedge_plan.js +++ b/lib/common/static/hedge_plan.js @@ -882,6 +882,50 @@ }); } + function selectedOoLegMap() { + const map = {}; + if (state.legA && state.legA.inst_id) map[String(state.legA.inst_id)] = "A"; + if (state.legB && state.legB.inst_id) map[String(state.legB.inst_id)] = "B"; + return map; + } + + function syncOoPickHighlight() { + const tbody = $("hp-oo-tbody"); + if (!tbody) return; + const map = selectedOoLegMap(); + tbody.querySelectorAll(".hp-oo-pick").forEach(function (btn) { + const inst = String(btn.getAttribute("data-inst") || ""); + const leg = map[inst]; + const on = !!leg; + btn.classList.toggle("is-selected", on); + btn.classList.toggle("active", on); + btn.setAttribute("aria-pressed", on ? "true" : "false"); + const side = String(btn.getAttribute("data-side") || "").toUpperCase(); + const base = side === "P" ? "Put" : "Call"; + btn.textContent = on ? "腿" + leg + " · " + base : base; + btn.title = on ? "已选用为腿" + leg + "(再点其他合约可改选)" : "选用此 " + base; + }); + tbody.querySelectorAll("tr").forEach(function (tr) { + const callBtn = tr.querySelector('.hp-oo-pick[data-side="C"]'); + const putBtn = tr.querySelector('.hp-oo-pick[data-side="P"]'); + const callOn = !!(callBtn && map[String(callBtn.getAttribute("data-inst") || "")]); + const putOn = !!(putBtn && map[String(putBtn.getAttribute("data-inst") || "")]); + tr.classList.toggle("hp-oo-row-selected", callOn || putOn); + tr.querySelectorAll("td.opt-t-call").forEach(function (td) { + td.classList.toggle("hp-oo-side-selected", callOn); + }); + if (callBtn && callBtn.parentElement) { + callBtn.parentElement.classList.toggle("hp-oo-side-selected", callOn); + } + tr.querySelectorAll("td.opt-t-put").forEach(function (td) { + td.classList.toggle("hp-oo-side-selected", putOn); + }); + if (putBtn && putBtn.parentElement) { + putBtn.parentElement.classList.toggle("hp-oo-side-selected", putOn); + } + }); + } + function renderTStrikes() { const tbody = $("hp-oo-tbody"); if (!tbody) return; @@ -892,6 +936,7 @@ return; } const rows = buildStraddleRows(exp.contracts); + const selected = selectedOoLegMap(); rows.forEach(function (row) { const tr = document.createElement("tr"); const call = row.call; @@ -901,6 +946,8 @@ if (!callOk && !putOk) return; const callAsk = callOk ? fmtPxSz(call.ask, call.ask_sz, call.ask_estimated, call.tick_sz) : "—"; const putAsk = putOk ? fmtPxSz(put.ask, put.ask_sz, put.ask_estimated, put.tick_sz) : "—"; + const callLeg = callOk ? selected[String(call.inst_id)] : ""; + const putLeg = putOk ? selected[String(put.inst_id)] : ""; tr.innerHTML = '