fix(withdrawal): wire the channel hint to the actual withdrawal modal

The previous commit put the channel-switching code in the wrong init block.
credits.js initializes two modals side by side — the points recharge dialog and
the withdrawal dialog — and the snippet landed in the recharge one, which has
no [data-jio-withdraw-method] element at all. Both symptoms followed from that:
methodField resolved to null so no change listener was ever bound, and the
initial sync never ran, leaving the note paragraph permanently hidden.

The block now lives inside initWithdraw(), and the stray copy is gone. The
behaviour itself was already correct — switching channels swaps the account
placeholder and shows or hides the channel note — it just never executed.

Verified in a headless browser against the real markup and stylesheet: the
placeholder starts as the first channel's hint and the note is hidden; switching
to the second channel swaps the placeholder and reveals the note as
display:block; switching back hides it again as display:none.

The contract test previously only checked that the code existed, which is why
it missed a placement bug that made the whole block dead. It now asserts
syncChannelHint appears exactly once, sits after initWithdraw(), and does not
run past the next function definition. 873 tests pass.
This commit is contained in:
kate522 committed 2026-11-04 19:37:56 +08:00
1 parent dcd306b428
commit 8c4aabb9a4
2 files changed
+28 -22

No files matched your search

+20 -20
View File
@@ -392,26 +392,6 @@
});
applyMethodVisibility((modal.querySelector('input[name="payment_method"]') || {}).value || '');
if (!form) return;
// 收款渠道由后台拖拽结构定义:切换时同步收款信息提示与渠道说明。
var methodField = form.querySelector('[data-jio-withdraw-method]');
var accountField = form.querySelector('[data-jio-withdraw-account]');
var noteField = form.querySelector('[data-jio-withdraw-note]');
function syncChannelHint() {
if (!methodField) return;
var option = methodField.options[methodField.selectedIndex];
if (!option) return;
var hint = option.getAttribute('data-hint') || '';
var note = option.getAttribute('data-note') || '';
if (accountField) accountField.setAttribute('placeholder', hint || '姓名 + 账户 / 卡号');
if (noteField) {
noteField.textContent = note;
noteField.hidden = note === '';
}
}
if (methodField) {
methodField.addEventListener('change', syncChannelHint);
syncChannelHint();
}
resetOperationKeyOnChange(form);
form.addEventListener('submit', function (e) {
e.preventDefault();
@@ -826,6 +806,26 @@
btn.addEventListener('click', function () { closeModal(modal); });
});
if (!form) return;
// 收款渠道由后台拖拽结构定义:切换时同步收款信息提示与渠道说明。
var methodField = form.querySelector('[data-jio-withdraw-method]');
var accountField = form.querySelector('[data-jio-withdraw-account]');
var noteField = form.querySelector('[data-jio-withdraw-note]');
function syncChannelHint() {
if (!methodField) return;
var option = methodField.options[methodField.selectedIndex];
if (!option) return;
var hint = option.getAttribute('data-hint') || '';
var note = option.getAttribute('data-note') || '';
if (accountField) accountField.setAttribute('placeholder', hint || '姓名 + 账户 / 卡号');
if (noteField) {
noteField.textContent = note;
noteField.hidden = note === '';
}
}
if (methodField) {
methodField.addEventListener('change', syncChannelHint);
syncChannelHint();
}
resetOperationKeyOnChange(form);
form.addEventListener('submit', function (e) {
e.preventDefault();
@@ -58,8 +58,14 @@ test('前台弹窗与后端校验都按渠道 key 工作', () => {
assert.match(modal, /data-note="<\?php echo esc_attr/);
assert.match(modal, /data-jio-withdraw-note/);
// 切换渠道时同步提示文案。
assert.match(client, /function syncChannelHint\(\)/);
// 切换渠道时同步提示文案,且必须挂在提现弹窗的初始化里
// (同一文件还有充值弹窗,挂错块会让整段逻辑变成死代码)。
assert.equal((client.match(/function syncChannelHint\(\)/g) || []).length, 1);
const initAt = client.indexOf('function initWithdraw()');
const syncAt = client.indexOf('function syncChannelHint()');
const nextFnAt = client.indexOf(String.fromCharCode(10) + String.fromCharCode(9) + 'function ', syncAt + 1);
assert.ok(initAt >= 0 && syncAt > initAt, 'syncChannelHint must live inside initWithdraw()');
assert.ok(nextFnAt === -1 || syncAt < nextFnAt, 'syncChannelHint must not leak past initWithdraw()');
assert.match(client, /methodField\.addEventListener\('change', syncChannelHint\)/);
// 后端只校验渠道存在且启用,不再限定内置两项。