|
@@ -1,13 +1,14 @@
|
|
|
<script setup lang="ts">
|
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
|
-import { ElInput, ElCard, ElTree, ElTreeSelect } from 'element-plus'
|
|
|
+import { ElInput, ElCard, ElTree, ElTreeSelect, ElSelect, ElOption } from 'element-plus'
|
|
|
import { handleTree } from '@/utils/tree'
|
|
|
import { onMounted, ref, unref, watch } from 'vue'
|
|
|
import * as DeptApi from '@/api/system/dept'
|
|
|
import { Form, FormExpose } from '@/components/Form'
|
|
|
-import { modelSchema } from './dept.data'
|
|
|
+import { modelSchema, rules } from './dept.data'
|
|
|
import { DeptVO } from '@/api/system/dept/types'
|
|
|
import { useMessage } from '@/hooks/web/useMessage'
|
|
|
+import { getListSimpleUsersApi } from '@/api/system/user'
|
|
|
const message = useMessage()
|
|
|
interface Tree {
|
|
|
id: number
|
|
@@ -34,7 +35,7 @@ const filterText = ref('')
|
|
|
const deptOptions = ref() // 树形结构
|
|
|
const treeRef = ref<InstanceType<typeof ElTree>>()
|
|
|
const getTree = async () => {
|
|
|
- const res = await DeptApi.getDeptPageApi(null)
|
|
|
+ const res = await DeptApi.listSimpleDeptApi()
|
|
|
deptOptions.value = handleTree(res)
|
|
|
}
|
|
|
const filterNode = (value: string, data: Tree) => {
|
|
@@ -44,6 +45,13 @@ const filterNode = (value: string, data: Tree) => {
|
|
|
watch(filterText, (val) => {
|
|
|
treeRef.value!.filter(val)
|
|
|
})
|
|
|
+// 用户列表
|
|
|
+const userOption = ref()
|
|
|
+const leaderUserId = ref()
|
|
|
+const getUserList = async () => {
|
|
|
+ const res = await getListSimpleUsersApi()
|
|
|
+ userOption.value = res
|
|
|
+}
|
|
|
// 新增
|
|
|
const handleAdd = (data: { id: number }) => {
|
|
|
// 重置表单
|
|
@@ -54,11 +62,12 @@ const handleAdd = (data: { id: number }) => {
|
|
|
}
|
|
|
// 编辑
|
|
|
const handleUpdate = async (data: { id: number }) => {
|
|
|
- showForm.value = true
|
|
|
const res = await DeptApi.getDeptApi(data.id)
|
|
|
formTitle.value = '修改- ' + res?.name
|
|
|
deptParentId.value = res.parentId
|
|
|
+ leaderUserId.value = res.leaderUserId
|
|
|
unref(formRef)?.setValues(res)
|
|
|
+ showForm.value = true
|
|
|
}
|
|
|
// 删除
|
|
|
const handleDelete = async (data: { id: number }) => {
|
|
@@ -78,7 +87,7 @@ const submitForm = async () => {
|
|
|
try {
|
|
|
const data = unref(formRef)?.formModel as DeptVO
|
|
|
data.parentId = deptParentId.value
|
|
|
- // TODO: 表单提交待完善
|
|
|
+ data.leaderUserId = leaderUserId.value
|
|
|
if (formTitle.value.startsWith('新增')) {
|
|
|
await DeptApi.createDeptApi(data)
|
|
|
} else if (formTitle.value.startsWith('修改')) {
|
|
@@ -92,6 +101,7 @@ const submitForm = async () => {
|
|
|
}
|
|
|
onMounted(async () => {
|
|
|
await getTree()
|
|
|
+ await getUserList()
|
|
|
})
|
|
|
</script>
|
|
|
<template>
|
|
@@ -123,14 +133,29 @@ onMounted(async () => {
|
|
|
<span class="custom-tree-node">
|
|
|
<span>{{ node.label }}</span>
|
|
|
<span>
|
|
|
- <el-button link v-hasPermi="['system:dept:create']" @click="handleAdd(data)">
|
|
|
- <Icon icon="ep:plus" class="mr-1px" />
|
|
|
+ <el-button
|
|
|
+ link
|
|
|
+ type="primary"
|
|
|
+ v-hasPermi="['system:dept:create']"
|
|
|
+ @click="handleAdd(data)"
|
|
|
+ >
|
|
|
+ <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
|
|
|
</el-button>
|
|
|
- <el-button link v-hasPermi="['system:dept:update']" @click="handleUpdate(data)">
|
|
|
- <Icon icon="ep:edit" class="mr-1px" />
|
|
|
+ <el-button
|
|
|
+ link
|
|
|
+ type="primary"
|
|
|
+ v-hasPermi="['system:dept:update']"
|
|
|
+ @click="handleUpdate(data)"
|
|
|
+ >
|
|
|
+ <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
|
|
|
</el-button>
|
|
|
- <el-button link v-hasPermi="['system:dept:delete']" @click="handleDelete(data)">
|
|
|
- <Icon icon="ep:delete" class="mr-1px" />
|
|
|
+ <el-button
|
|
|
+ link
|
|
|
+ type="primary"
|
|
|
+ v-hasPermi="['system:dept:delete']"
|
|
|
+ @click="handleDelete(data)"
|
|
|
+ >
|
|
|
+ <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
|
|
|
</el-button>
|
|
|
</span>
|
|
|
</span>
|
|
@@ -149,7 +174,7 @@ onMounted(async () => {
|
|
|
</div>
|
|
|
<div v-if="showForm">
|
|
|
<!-- 操作工具栏 -->
|
|
|
- <Form :schema="modelSchema" ref="formRef">
|
|
|
+ <Form ref="formRef" :schema="modelSchema" :rules="rules">
|
|
|
<template #parentId>
|
|
|
<el-tree-select
|
|
|
node-key="id"
|
|
@@ -159,6 +184,16 @@ onMounted(async () => {
|
|
|
check-strictly
|
|
|
/>
|
|
|
</template>
|
|
|
+ <template #leaderUserId>
|
|
|
+ <el-select v-model="leaderUserId">
|
|
|
+ <el-option
|
|
|
+ v-for="item in userOption"
|
|
|
+ :key="parseInt(item.id)"
|
|
|
+ :label="item.nickname"
|
|
|
+ :value="parseInt(item.id)"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
</Form>
|
|
|
<!-- 操作按钮 -->
|
|
|
<el-button
|