diff --git a/static/cond_orders.js b/static/cond_orders.js index 54e8e16..bf97ac7 100644 --- a/static/cond_orders.js +++ b/static/cond_orders.js @@ -251,7 +251,7 @@ if (fundEl) fundEl.textContent = "资金 " + fmtTradingU(fundingUsdt); } - function transferFundingToTrading(instanceId) { + function transferInternal(instanceId, direction) { const id = String(instanceId || ""); const it = candidatesById[id]; if (!it) return; @@ -263,31 +263,39 @@ window.alert(it.transfer_block_msg || "当前不可划转"); return; } - const fund = Number(it.funding_usdt); + const toTrading = direction !== "to_funding"; + const fromAcct = toTrading ? "funding" : "trading"; + const toAcct = toTrading ? "trading" : "funding"; + const srcBal = Number(toTrading ? it.funding_usdt : it.trading_usdt); const defAmt = - !Number.isNaN(fund) && fund > 0 ? String(Math.round(fund * 10000) / 10000) : ""; - const raw = window.prompt("资金户 → 交易户(USDT)。本页划转,条件单表单不会丢失。", defAmt); + !Number.isNaN(srcBal) && srcBal > 0 + ? String(Math.round(srcBal * 10000) / 10000) + : ""; + const label = toTrading ? "资金户 → 交易户" : "交易户 → 资金户"; + const raw = window.prompt(label + "(USDT)。本页划转,条件单表单不会丢失。", defAmt); if (raw == null) return; const amount = Number(String(raw).trim()); if (!(amount > 0)) { window.alert("请输入大于 0 的数量"); return; } - const btn = document.querySelector( + const btns = document.querySelectorAll( '.cond-inst-xfer[data-inst-id="' + id.replace(/"/g, "") + '"]' ); - if (btn) { + const labels = []; + btns.forEach(function (btn) { + labels.push(btn.textContent); btn.disabled = true; btn.textContent = "划转中…"; - } + }); fetch("/api/instances/" + encodeURIComponent(id) + "/transfer", { method: "POST", credentials: "same-origin", headers: { "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify({ amount: amount, - from: "funding", - to: "trading", + from: fromAcct, + to: toAcct, ccy: "USDT", }), }) @@ -307,10 +315,14 @@ if (st) { st.textContent = (it.name || id) + - " 已划入交易 " + + " " + + label + + " " + fmtTradingU(amount) + "(交易 " + fmtTradingU(d.trading_usdt) + + " / 资金 " + + fmtTradingU(d.funding_usdt) + ")"; } }) @@ -318,10 +330,11 @@ window.alert("划转请求失败"); }) .finally(function () { - if (btn) { - btn.disabled = !!(it.transfer_blocked || !it.online); - btn.textContent = "划入交易"; - } + const blocked = !!(it.transfer_blocked || !it.online); + btns.forEach(function (btn, i) { + btn.disabled = blocked; + btn.textContent = labels[i] || btn.getAttribute("data-label") || "划转"; + }); }); } @@ -341,16 +354,18 @@ const xferBlocked = !!(it.transfer_blocked || !it.online); const xferTitle = xferBlocked ? it.transfer_block_msg || (!it.online ? "离线" : "不可划转") - : "资金户→交易户,本页完成不丢表单"; + : "本页双向划转,表单不丢"; + const dis = xferBlocked ? " disabled" : ""; return ( '