fix(ticket): 修复票务勾选时下拉框不刷新的 JS 报错

fix/ticket-select-refresh
Council 2026-06-12 13:51:24 +08:00
parent e282a5af2b
commit 39230958a0
2 changed files with 24 additions and 2 deletions

View File

@ -82,7 +82,7 @@ class AdminGoodsIndex
// 触发chosen组件更新如果已初始化
if ($.fn.chosen && select.classList.contains('chosen-init-success')) {
select.trigger('chosen:updated');
$(select).trigger('chosen:updated');
}
return true;

View File

@ -364,11 +364,19 @@ class AdminGoodsSave
});
};
// 备份原始的 produce_region 选项 HTML
let originalRegionOptionsHtml = '';
// ── 动态替换 produce_region 下拉选项为 level=2 城市 ──
const replaceCityOptions = () => {
const select = document.querySelector('select[name="produce_region"]');
if (!select) return;
// 备份原始选项 HTML仅在第一次被替换前备份
if (!originalRegionOptionsHtml) {
originalRegionOptionsHtml = select.innerHTML;
}
// 优先使用 PHP 传递的保存值(城市 ID这是最可靠的数据源
const savedValue = AppData.savedProduceRegion || 0;
@ -391,7 +399,18 @@ class AdminGoodsSave
// 触发chosen组件更新如果使用了chosen插件
if ($.fn.chosen) {
select.trigger('chosen:updated');
$(select).trigger('chosen:updated');
}
};
const restoreCityOptions = () => {
const select = document.querySelector('select[name="produce_region"]');
if (!select || !originalRegionOptionsHtml) return;
select.innerHTML = originalRegionOptionsHtml;
if ($.fn.chosen) {
$(select).trigger('chosen:updated');
}
};
@ -400,6 +419,9 @@ class AdminGoodsSave
if (val) {
// 票务商品模式:替换城市下拉选项
replaceCityOptions();
} else {
// 恢复原始选项
restoreCityOptions();
}
}, { immediate: true });