diff --git a/src/components/BudgetSourcePickerField.vue b/src/components/BudgetSourcePickerField.vue index e479eb3..e1caa79 100644 --- a/src/components/BudgetSourcePickerField.vue +++ b/src/components/BudgetSourcePickerField.vue @@ -606,9 +606,9 @@ export default { } if (!this.yearId && this.yearOptions.length > 0) { - // 尝试根据当前 value 反查 year_id(可选),否则默认第一项 + // 尝试根据当前 value 反查 year_id;未命中时优先回退到当前自然年,再回退到第一项 const fromValue = await this.tryResolveYearIdByValue(); - this.yearId = fromValue || this.yearOptions[0].value; + this.yearId = fromValue || this.getCurrentYearOptionValue() || this.yearOptions[0].value; } if (this.yearId) { @@ -629,6 +629,13 @@ export default { this.yearLoading = false; } }, + getCurrentYearOptionValue() { + const currentYear = new Date().getFullYear(); + const matched = (this.yearOptions || []).find( + (y) => String(y.year) === String(currentYear) + ); + return matched ? matched.value : null; + }, async tryResolveYearIdByValue() { if (!this.hasValue) return null; const idFromValue = this.budgetDataId || (this.budgetItems[0] && this.budgetItems[0].budget_data_id); @@ -1135,7 +1142,10 @@ export default { // 尝试获取年份ID if (!this.yearId) { const fromValue = await this.tryResolveYearIdByValue(); - this.yearId = fromValue || (this.yearOptions.length > 0 ? this.yearOptions[0].value : null); + this.yearId = + fromValue || + this.getCurrentYearOptionValue() || + (this.yearOptions.length > 0 ? this.yearOptions[0].value : null); } // 如果没有年份ID,无法生成显示文本