|
|
@@ -231,7 +231,7 @@ import {
|
|
|
import InstitutionAPI from "@/api/module_payment/institution";
|
|
|
import DepartmentAPI from "@/api/module_payment/department";
|
|
|
import { useEnterpriseStore } from "@/store/modules/enterprise.store";
|
|
|
-import { reactive, ref, watch, computed } from "vue";
|
|
|
+import { reactive, ref, watch, computed, onMounted } from "vue";
|
|
|
import EmployeeSelector from "./EmployeeSelector.vue";
|
|
|
|
|
|
interface Props {
|
|
|
@@ -288,17 +288,41 @@ function togglePeriodCollapse() {
|
|
|
|
|
|
const departmentOptions = ref<{ value: string; label: string }[]>([]);
|
|
|
|
|
|
+// 获取当前企业ID(综合多种来源)
|
|
|
+function getEnterpriseId(): string | undefined {
|
|
|
+ // 1. 优先使用表单中的 enterprise_id
|
|
|
+ if (formData.enterprise_id) return formData.enterprise_id;
|
|
|
+ // 2. 从 store 获取
|
|
|
+ const store = useEnterpriseStore();
|
|
|
+ const current = store.getCurrentEnterprise;
|
|
|
+ if (current?.enterprise_id) return current.enterprise_id;
|
|
|
+ // 3. 从 store enterpriseList 列表第一个获取
|
|
|
+ if (store.enterpriseList?.length > 0) {
|
|
|
+ return store.enterpriseList[0].enterprise_id;
|
|
|
+ }
|
|
|
+ // 4. 尝试从 sessionStorage 直接读取
|
|
|
+ try {
|
|
|
+ const cache = sessionStorage.getItem('currentEnterprise');
|
|
|
+ if (cache) {
|
|
|
+ const parsed = JSON.parse(cache);
|
|
|
+ if (parsed?.enterprise_id) return parsed.enterprise_id;
|
|
|
+ }
|
|
|
+ } catch (_) { /* ignore */ }
|
|
|
+ return undefined;
|
|
|
+}
|
|
|
+
|
|
|
// 从后端加载真实部门数据
|
|
|
async function loadDepartments() {
|
|
|
- let eid = formData.enterprise_id;
|
|
|
+ const eid = getEnterpriseId();
|
|
|
+ console.log("[InstitutionForm] loadDepartments enterprise_id:", eid);
|
|
|
if (!eid) {
|
|
|
- const store = useEnterpriseStore();
|
|
|
- eid = store.getCurrentEnterprise?.enterprise_id || eid;
|
|
|
+ console.warn("[InstitutionForm] enterprise_id为空,无法加载部门");
|
|
|
+ return;
|
|
|
}
|
|
|
- if (!eid) return;
|
|
|
try {
|
|
|
const res = await DepartmentAPI.listDepartment({ enterprise_id: eid, page_no: 1, page_size: 200 });
|
|
|
const items = res?.data?.data?.items || [];
|
|
|
+ console.log("[InstitutionForm] 部门列表返回条数:", items.length);
|
|
|
departmentOptions.value = items.map((d: any) => ({
|
|
|
value: d.department_id,
|
|
|
label: d.department_name,
|
|
|
@@ -308,6 +332,17 @@ async function loadDepartments() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 组件挂载时主动加载部门数据(先立即加载,若失败则 500ms 后重试)
|
|
|
+onMounted(async () => {
|
|
|
+ await loadDepartments();
|
|
|
+ if (departmentOptions.value.length === 0) {
|
|
|
+ // 如果首次 enterprise_id 或 store 尚未就绪,延迟重试(兼容极端时序)
|
|
|
+ setTimeout(() => {
|
|
|
+ loadDepartments();
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
const tagOptions = ref([
|
|
|
{ value: "tag1", label: "管理层" },
|
|
|
{ value: "tag2", label: "技术骨干" },
|