Browse Source

@
fix: 费控编辑页回显适用范围和规则数据

编辑时调用 listScope 获取实际员工/部门ID回填表单,
调用 listRule 获取规则 max_amount 回填 single_limit。
@

alphaH 7 hours ago
parent
commit
deb3d168a7

+ 37 - 2
frontend/src/views/module_payment/institution/components/InstitutionForm.vue

@@ -228,6 +228,7 @@ import {
   InstitutionDetail,
 } from "@/api/module_payment/institution";
 import InstitutionAPI from "@/api/module_payment/institution";
+import RuleAPI from "@/api/module_payment/rule";
 import DepartmentAPI from "@/api/module_payment/department";
 import { useEnterpriseStore } from "@/store/modules/enterprise.store";
 import { reactive, ref, watch, computed, onMounted } from "vue";
@@ -377,8 +378,42 @@ watch(
         formData.amount = data.amount;
         formData.single_limit = data.single_limit;
         formData.effective_time_type = data.effective_time_type || "unlimited";
-        formData.employee_ids = data.employee_ids || [];
-        formData.department_id = data.department_id;
+
+        // 回显适用范围:调用 scope 接口获取实际员工/部门ID
+        const eid = data.enterprise_id || props.enterpriseId;
+        if (eid && data.applicable_scope && data.applicable_scope !== "none") {
+          try {
+            const scopeRes = await InstitutionAPI.listScope(newVal, {
+              enterprise_id: eid,
+              page_num: 1,
+              page_size: 200,
+            });
+            const scopeData = scopeRes.data.data;
+            if (scopeData) {
+              const adapterType = scopeData.adapter_type;
+              const ownerIds: string[] = scopeData.owner_id_list || [];
+              if (adapterType === "EMPLOYEE_SELECT") {
+                formData.employee_ids = ownerIds;
+              } else if (adapterType === "EMPLOYEE_DEPARTMENT") {
+                formData.department_id = ownerIds[0];
+              }
+              // EMPLOYEE_ALL: 无需具体ID
+            }
+          } catch (_) { /* scope 查询失败不影响主流程 */ }
+        }
+
+        // 回显使用规则:加载规则的 max_amount 回填 single_limit
+        try {
+          const ruleRes = await RuleAPI.listRule({
+            institution_id: newVal,
+            page_no: 1,
+            page_size: 100,
+          });
+          const rules = ruleRes.data.data?.items || ruleRes.data.data?.list || [];
+          if (rules.length > 0 && formData.single_limit == null) {
+            formData.single_limit = rules[0].max_amount ?? rules[0].single_limit;
+          }
+        } catch (_) { /* rule 查询失败不影响主流程 */ }
       }
     }
   },