From f3195be73291effc55c3e35e623b82953cf1fc02 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期五, 11 八月 2023 17:59:10 +0800
Subject: [PATCH] update 优化 整体代码结构

---
 src/views/system/dept/index.vue |   84 ++++++++++++++++++++++++------------------
 1 files changed, 48 insertions(+), 36 deletions(-)

diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue
index a1dcb9f..ab7ecbb 100644
--- a/src/views/system/dept/index.vue
+++ b/src/views/system/dept/index.vue
@@ -97,7 +97,9 @@
           </el-col>
           <el-col :span="12">
             <el-form-item label="璐熻矗浜�" prop="leader">
-              <el-input v-model="form.leader" placeholder="璇疯緭鍏ヨ礋璐d汉" maxlength="20" />
+              <el-select v-model="form.leader" placeholder="璇烽�夋嫨璐熻矗浜�">
+                <el-option v-for="item in deptUserList" :key="item.userId" :label="item.userName" :value="item.userId" />
+              </el-select>
             </el-form-item>
           </el-col>
           <el-col :span="12">
@@ -133,6 +135,8 @@
 <script setup name="Dept" lang="ts">
 import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept"
 import { DeptForm, DeptQuery, DeptVO } from "@/api/system/dept/types";
+import {UserVO} from "@/api/system/user/types";
+import {listUserByDeptId} from "@/api/system/user";
 
 interface DeptOptionsType {
   deptId: number | string;
@@ -149,7 +153,7 @@
 const showSearch = ref(true)
 const deptOptions = ref<DeptOptionsType[]>([])
 const isExpandAll = ref(true)
-
+const deptUserList = ref<UserVO[]>([]);
 
 const dialog = reactive<DialogOption>({
   visible: false,
@@ -199,6 +203,15 @@
   }
   loading.value = false
 }
+
+/** 鏌ヨ褰撳墠閮ㄩ棬鐨勬墍鏈夌敤鎴� */
+async function getDeptAllUser(deptId: any) {
+  if (deptId !== null && deptId !== "" && deptId !== undefined) {
+    const res = await listUserByDeptId(deptId);
+    deptUserList.value = res.data;
+  }
+}
+
 /** 鍙栨秷鎸夐挳 */
 const cancel = () => {
   reset()
@@ -219,23 +232,7 @@
   queryFormRef.value?.resetFields();
   handleQuery()
 }
-/** 鏂板鎸夐挳鎿嶄綔 */
-const handleAdd = (row?: DeptVO) => {
-  listDept().then(res => {
-    const data = proxy?.handleTree<DeptOptionsType>(res.data, "deptId");
-    if (data) {
-      deptOptions.value = data
-      dialog.visible = true;
-      dialog.title = "娣诲姞閮ㄩ棬";
-      nextTick(() => {
-        reset();
-        if (row && row.deptId) {
-          form.value.parentId = row?.deptId;
-        }
-      })
-    }
-  })
-}
+
 /** 灞曞紑/鎶樺彔鎿嶄綔 */
 const handleToggleExpandAll = () => {
   isExpandAll.value = !isExpandAll.value;
@@ -249,28 +246,43 @@
   })
 }
 
+/** 鏂板鎸夐挳鎿嶄綔 */
+const handleAdd = async (row?: DeptVO) => {
+  reset();
+  const res = await listDept();
+  const data = proxy?.handleTree<DeptOptionsType>(res.data, "deptId");
+  if (data) {
+    deptOptions.value = data
+    if (row && row.deptId) {
+      form.value.parentId = row?.deptId;
+    }
+    dialog.visible = true;
+    dialog.title = "娣诲姞閮ㄩ棬";
+  }
+}
+
 /** 淇敼鎸夐挳鎿嶄綔 */
 const handleUpdate = async (row: DeptVO) => {
+  reset();
+  //鏌ヨ褰撳墠閮ㄩ棬鎵�鏈夌敤鎴�
+  getDeptAllUser(row.deptId);
   const res = await getDept(row.deptId);
+  form.value = res.data
+  const response = await listDeptExcludeChild(row.deptId);
+  const data = proxy?.handleTree<DeptOptionsType>(response.data, "deptId")
+  if (data) {
+    deptOptions.value = data;
+    if (data.length === 0) {
+      const noResultsOptions: DeptOptionsType = {
+        deptId: res.data.parentId,
+        deptName: res.data.parentName,
+        children: []
+      };
+      deptOptions.value.push(noResultsOptions);
+    }
+  }
   dialog.visible = true;
   dialog.title = "淇敼閮ㄩ棬";
-  await nextTick(async () => {
-    reset();
-    form.value = res.data
-    const response = await listDeptExcludeChild(row.deptId);
-    const data = proxy?.handleTree<DeptOptionsType>(response.data, "deptId")
-    if (data) {
-      deptOptions.value = data;
-      if (data.length === 0) {
-        const noResultsOptions: DeptOptionsType = {
-          deptId: res.data.parentId,
-          deptName: res.data.parentName,
-          children: []
-        };
-        deptOptions.value.push(noResultsOptions);
-      }
-    }
-  })
 }
 /** 鎻愪氦鎸夐挳 */
 const submitForm = () => {

--
Gitblit v1.9.3