[FIX] 合併 hotfix:修正員工卡編輯彈窗 Preline getInstance 取錯物件導致公司未回填

This commit is contained in:
sky121113 2026-06-23 11:40:09 +08:00
commit 7b6dc3cb8e

View File

@ -444,15 +444,19 @@
}
this.isStaffModalOpen = true;
// Re-init Preline select or set value after modal opens
// 回填所屬公司下拉:
// 1. Preline v3 getInstance(target, true) 回傳的是 collection wrapper 而非實例,
// 其上沒有 setValue 會丟錯導致回填失靈,故不可帶第二個參數。
// 2. Preline 的 option value 為字串company_id 為數字時嚴格比對會失配,統一轉字串;空值用 ' ' 對應 placeholder。
// 同步先設原生 <select>.value 再呼叫 setValue對齊 welcome-gifts / pickup-codes 既有可運作寫法)。
this.$nextTick(() => {
const select = HSSelect.getInstance('#modal-company-id', true);
if (select) {
// Preline 的 option value 為字串company_id 為數字時嚴格比對會失配導致回填失敗,
// 故統一轉成字串;空值則以 ' ' 對應 placeholder 選項
const el = document.getElementById('modal-company-id');
if (el) {
const cid = this.staffFormFields.company_id;
const valStr = (cid !== undefined && cid !== null && cid.toString().trim() !== '') ? cid.toString() : ' ';
select.setValue(valStr);
el.value = valStr;
const inst = window.HSSelect && window.HSSelect.getInstance(el);
if (inst) inst.setValue(valStr);
}
});
},