diff --git a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsIndex.php b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsIndex.php index e3a9fbe..41020d3 100644 --- a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsIndex.php +++ b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsIndex.php @@ -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; diff --git a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSave.php b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSave.php index a5951bf..60ccece 100644 --- a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSave.php +++ b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSave.php @@ -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 });