|
@@ -1,37 +1,46 @@
|
|
|
<script lang="ts" setup name="GroupSelector">
|
|
<script lang="ts" setup name="GroupSelector">
|
|
|
-import { getGroupCatByList } from '@/api/system/groupCatApi'
|
|
|
|
|
|
|
+import { getGroupByList } from '@/api/system/groupApi'
|
|
|
|
|
+import { packageTreeData } from '@/utils/tool'
|
|
|
|
|
+
|
|
|
const emit = defineEmits(['update:modelValue'])
|
|
const emit = defineEmits(['update:modelValue'])
|
|
|
-interface Group {
|
|
|
|
|
- groupCatId: number
|
|
|
|
|
- groupCatTitle: number
|
|
|
|
|
|
|
+interface TreeNode {
|
|
|
|
|
+ label: string
|
|
|
|
|
+ groupId: number
|
|
|
|
|
+ children?: TreeNode[]
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
const state = reactive({
|
|
const state = reactive({
|
|
|
loading: false,
|
|
loading: false,
|
|
|
- groupCatId: 0,
|
|
|
|
|
- dataList: [] as Group[],
|
|
|
|
|
|
|
+ groupId: 0,
|
|
|
|
|
+ dataList: [] as TreeNode[],
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const getData = async () => {
|
|
const getData = async () => {
|
|
|
state.loading = true
|
|
state.loading = true
|
|
|
- const { data } = await getGroupCatByList()
|
|
|
|
|
- state.loading = false
|
|
|
|
|
- state.dataList = data
|
|
|
|
|
-}
|
|
|
|
|
-const onChange = () => {
|
|
|
|
|
- emit('update:modelValue', state.groupCatId)
|
|
|
|
|
|
|
+ const { data } = await getGroupByList()
|
|
|
|
|
+
|
|
|
|
|
+ state.dataList = packageTreeData({
|
|
|
|
|
+ data,
|
|
|
|
|
+ id: 'groupId',
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+watch(() => state.groupId, (newValue) => {
|
|
|
|
|
+ emit('update:modelValue', newValue)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
getData ()
|
|
getData ()
|
|
|
})
|
|
})
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
<template>
|
|
|
- <el-select v-model="state.groupCatId" v-loading="state.loading" style="width: 100%" filterable placeholder="请选择部门类别" value-key="groupCatId" @change="onChange">
|
|
|
|
|
- <el-option
|
|
|
|
|
- v-for="item in state.dataList"
|
|
|
|
|
- :key="item.groupCatId"
|
|
|
|
|
- :label="item.groupCatTitle"
|
|
|
|
|
- :value="item.groupCatId"
|
|
|
|
|
- />
|
|
|
|
|
- </el-select>
|
|
|
|
|
|
|
+ <el-tree-select
|
|
|
|
|
+ v-model="state.groupId"
|
|
|
|
|
+ :data="state.dataList"
|
|
|
|
|
+ style="width: 100%"
|
|
|
|
|
+ filterable
|
|
|
|
|
+ placeholder="请选择部门"
|
|
|
|
|
+ :render-after-expand="false"
|
|
|
|
|
+ />
|
|
|
</template>
|
|
</template>
|