Przeglądaj źródła

设置分销设置传参变更完善

祁鹏飞 1 miesiąc temu
rodzic
commit
ec472f1a5d
1 zmienionych plików z 23 dodań i 20 usunięć
  1. 23 20
      src/views/sale/settings.vue

+ 23 - 20
src/views/sale/settings.vue

@@ -92,8 +92,9 @@
         </ElFormItem>
 
         <!-- 已选机构列表 -->
-        <el-table :data="selectData" style="width: 611px; margin-left: 130px; margin-top: 16px;"
-          header-cell-class-name="custom-header-cell" v-if="form.excludeDeptScope == '2'">
+        <el-table :data="selectData" height="calc(100vh - 620px);"
+          style="width: 611px; margin-left: 130px; margin-top: 16px;" header-cell-class-name="custom-header-cell"
+          v-if="form.excludeDeptScope == '2'">
           <el-table-column prop="name" label="机构" width="517" align="center" />
           <el-table-column label="操作" width="">
             <template #default="scope">
@@ -293,9 +294,10 @@ onMounted(() => {
 
 // 获取协议授权机构
 const agreementAuth = () => {
-  api.saleApi.agreementdeptTree({ name: "", system: "", isDistribution: 0 }).then((res: any) => {
+  api.saleApi.agreementdeptTree({ name: "", system: "" }).then((res: any) => {
     if (res.code == "200") {
       deptTreeData.value = res.data;
+      allDeptTreeData.value = findNodesById(deptTreeData.value, []);
     }
   });
 };
@@ -312,25 +314,26 @@ const handleDrawerCancel = () => {
   showDeptDrawer.value = false;
 };
 
+const allDeptTreeData = ref([])
+const findNodesById = (nodes: TreeOption[], ids: string[]): TreeOption[] => {
+  const result: TreeOption[] = [];
+  for (const node of nodes) {
+    if (ids.includes(node.id) || !ids.length) {
+      result.push(node);
+    }
+    if (node.children && node.children.length > 0) {
+      const childMatches = findNodesById(node.children, ids);
+      result.push(...childMatches);
+    }
+  }
+  return result;
+};
 // 保存选中的机构
 const handleDrawerSave = (selectedIds: string[]) => {
   showDeptDrawer.value = false;
   selectData.value = [];
 
   // 从机构树中查找选中的节点
-  const findNodesById = (nodes: TreeOption[], ids: string[]): TreeOption[] => {
-    const result: TreeOption[] = [];
-    for (const node of nodes) {
-      if (ids.includes(node.id)) {
-        result.push(node);
-      }
-      if (node.children && node.children.length > 0) {
-        const childMatches = findNodesById(node.children, ids);
-        result.push(...childMatches);
-      }
-    }
-    return result;
-  };
 
   selectData.value = findNodesById(deptTreeData.value, selectedIds);
 };
@@ -414,8 +417,8 @@ const handleSubmit = async () => {
       commissionRatioLevel1: form.commissionRatioLevel1 || 0,
       commissionRatioLevel2: form.commissionRatioLevel2 || 0,
       commissionRatioLevel3: form.commissionRatioLevel3 || 0,
-      excludeDeptIds: form.excludeDeptScope == '1' ? [] : selectData.value.map((item) => item.id),
-      systemCode: localStorage.getItem('login_system')
+      systemCode: localStorage.getItem('login_system'),
+      excludeDepts: allDeptTreeData.value.map(v => ({ id: v.id, isDistribution: selectData.value.map(k => k.id).includes(v.id) ? '0' : '1' }))
     };
     await api.saleApi.saveSetting(formData);
 
@@ -435,8 +438,8 @@ const handleUpdate = async () => {
     commissionRatioLevel1: form.commissionRatioLevel1 || 0,
     commissionRatioLevel2: form.commissionRatioLevel2 || 0,
     commissionRatioLevel3: form.commissionRatioLevel3 || 0,
-    excludeDeptIds: form.excludeDeptScope == '1' ? [] : selectData.value.map((item) => item.id),
-    systemCode: localStorage.getItem('login_system')
+    systemCode: localStorage.getItem('login_system'),
+    excludeDepts: allDeptTreeData.value.map(v => ({ id: v.id, isDistribution: selectData.value.map(k => k.id).includes(v.id) ? '0' : '1' }))
   };
   await api.saleApi.update(formData).then((res: any) => {
     if (res.code == 200) {