Przeglądaj źródła

fix: 部门选项改真实API数据替代硬编码

alphah 2 tygodni temu
rodzic
commit
08fbf03847

+ 18 - 6
frontend/src/views/module_payment/institution/components/InstitutionForm.vue

@@ -229,6 +229,7 @@ import {
   InstitutionDetail,
 } from "@/api/module_payment/institution";
 import InstitutionAPI from "@/api/module_payment/institution";
+import DepartmentAPI from "@/api/module_payment/department";
 import { reactive, ref, watch, computed } from "vue";
 import EmployeeSelector from "./EmployeeSelector.vue";
 
@@ -284,12 +285,22 @@ function togglePeriodCollapse() {
   isPeriodCollapsed.value = !isPeriodCollapsed.value;
 }
 
-const departmentOptions = ref([
-  { value: "dept1", label: "研发部" },
-  { value: "dept2", label: "产品部" },
-  { value: "dept3", label: "运营部" },
-  { value: "dept4", label: "财务部" },
-]);
+const departmentOptions = ref<{ value: string; label: string }[]>([]);
+
+// 从后端加载真实部门数据
+async function loadDepartments() {
+  if (!formData.enterprise_id) return;
+  try {
+    const res = await DepartmentAPI.listDepartment({ enterprise_id: formData.enterprise_id, page_no: 1, page_size: 200 });
+    const items = res?.data?.data?.items || [];
+    departmentOptions.value = items.map((d: any) => ({
+      value: d.department_id,
+      label: d.department_name,
+    }));
+  } catch (e) {
+    console.error("加载部门列表失败", e);
+  }
+}
 
 const tagOptions = ref([
   { value: "tag1", label: "管理层" },
@@ -338,6 +349,7 @@ watch(
   (newVal) => {
     if (newVal && props.type === "create") {
       formData.enterprise_id = newVal;
+      loadDepartments();
     }
   },
   { immediate: true }