<template>
|
<basic-container>
|
<el-form ref="queryParamsRef" :model="searchParams" class="command-page-history-search">
|
<el-form-item label="部门名称" prop="deptName">
|
<el-input
|
class="command-input"
|
v-model="searchParams.deptName"
|
placeholder="请输入"
|
clearable
|
@clear="handleSearch"
|
/>
|
</el-form-item>
|
|
<el-form-item label="部门全称" prop="fullName">
|
<el-input
|
class="command-input"
|
v-model="searchParams.fullName"
|
placeholder="请输入"
|
clearable
|
@clear="handleSearch"
|
/>
|
</el-form-item>
|
|
<el-form-item class="history-search-actions">
|
<el-button :icon="RefreshRight" @click="resetForm"></el-button>
|
<el-button class="search-btn" :icon="Search" @click="handleSearch"></el-button>
|
</el-form-item>
|
</el-form>
|
|
<div class="command-table-toolbar">
|
<el-button :icon="Plus" color="#284FE3" type="primary" @click="handleAdd">新增</el-button>
|
<el-button :icon="Delete" color="#1A2652" type="primary" :disabled="!selectedIds.length" @click="handleDelete()">
|
删除
|
</el-button>
|
</div>
|
|
<div class="command-table-container" v-loading="loading" element-loading-background="rgba(5, 5, 15, 0.6)">
|
<div class="command-table-content command-table-content-bg">
|
<el-table
|
class="command-table"
|
:data="list"
|
row-key="id"
|
lazy
|
:load="loadChildren"
|
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
|
@selection-change="handleSelectionChange"
|
>
|
<el-table-column type="selection" width="46" />
|
<el-table-column type="index" show-overflow-tooltip width="64" label="序号" />
|
<el-table-column prop="deptName" show-overflow-tooltip label="部门名称" />
|
<el-table-column prop="fullName" show-overflow-tooltip label="部门全称" />
|
<el-table-column prop="deptCategory" show-overflow-tooltip label="部门类型">
|
<template v-slot="{ row }">
|
{{ getDictLabel(row.deptCategory, dictObj.org_category) }}
|
</template>
|
</el-table-column>
|
<el-table-column prop="deptNature" show-overflow-tooltip label="部门性质">
|
<template v-slot="{ row }">
|
{{ getDictLabel(row.deptNature, dictObj.org_nature) }}
|
</template>
|
</el-table-column>
|
<el-table-column prop="sort" show-overflow-tooltip width="80" label="排序" />
|
<el-table-column prop="bingId" show-overflow-tooltip width="80" label="组织id" />
|
<el-table-column prop="areaName" show-overflow-tooltip label="行政区划" />
|
|
<el-table-column label="操作" class-name="operation-btns">
|
<template v-slot="{ row }">
|
<el-link @click="handleView(row)">查看</el-link>
|
<el-link @click="handleEdit(row)">编辑</el-link>
|
<el-link @click="handleAddChild(row)">新增子项</el-link>
|
<el-link type="danger" @click="handleDelete(row)">删除</el-link>
|
<el-link type="danger" @click="handleShare(row)" v-if="hasSharing">共享</el-link>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
|
<div class="command-table-pagination">
|
<el-pagination
|
popper-class="command-select-popper"
|
v-model:current-page="searchParams.current"
|
v-model:page-size="searchParams.size"
|
layout="total, prev, pager, next, sizes"
|
:total="total"
|
@change="getList"
|
/>
|
</div>
|
</div>
|
|
<FormDiaLog ref="dialogRef" @success="handleFormSuccess" v-model="visible" v-if="visible" />
|
<ShareDiaLog ref="shareDialogRef" @success="getList" v-model="shareVisible" v-if="shareVisible" />
|
</basic-container>
|
</template>
|
|
<script setup>
|
import { Delete, Plus, RefreshRight, Search } from '@element-plus/icons-vue'
|
import { nextTick, onMounted, provide, ref } from 'vue'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { getDictionary } from '@/api/system/dict'
|
import { getChildLazyTree, getDeptTree, getLazyList, remove } from '@/api/system/dept'
|
import { getDictLabel } from '@ztzf/utils'
|
import FormDiaLog from './FormDiaLog.vue'
|
import ShareDiaLog from './ShareDiaLog.vue'
|
import { saveOperationLog } from '@ztzf/apis'
|
import { useRoute } from 'vue-router'
|
import { useStore } from 'vuex'
|
|
const store = useStore()
|
const permission = computed(() => store.state.user.permission)
|
const ancestors = computed(() => store.state.user.userInfo?.detail?.ancestors)
|
// 市级部门并且有权限才能看到共享按钮
|
const hasSharing = computed(() => permission.value.department_share && ancestors.value.split(',')?.length === 2)
|
const initSearchParams = () => ({
|
deptName: '',
|
fullName: '',
|
current: 1,
|
size: 10,
|
})
|
|
const searchParams = ref(initSearchParams())
|
const loading = ref(true)
|
const visible = ref(false)
|
const list = ref([])
|
const total = ref(0)
|
const selectedIds = ref([])
|
const selectedRows = ref([])
|
const lastActionParentRow = ref(null)
|
const queryParamsRef = ref(null)
|
const dialogRef = ref(null)
|
const shareDialogRef = ref(null)
|
const shareVisible = ref(false)
|
const dictObj = ref({
|
org_category: [],
|
org_nature: [],
|
})
|
const deptTree = ref([])
|
const route = useRoute()
|
const treeResolveMap = new Map()
|
|
provide('dictObj', dictObj)
|
provide('deptTree', deptTree)
|
|
async function getList() {
|
loading.value = true
|
try {
|
const res = await getLazyList(0, searchParams.value)
|
list.value = res?.data?.data ?? []
|
total.value = list.value.length
|
} finally {
|
loading.value = false
|
}
|
}
|
|
function handleSearch() {
|
searchParams.value.current = 1
|
getList()
|
}
|
|
function resetForm() {
|
queryParamsRef.value?.resetFields()
|
searchParams.value.current = 1
|
getList()
|
}
|
|
function handleAdd() {
|
visible.value = true
|
nextTick(() => {
|
dialogRef.value?.open({ mode: 'add' })
|
})
|
}
|
|
function handleAddChild(row) {
|
lastActionParentRow.value = row
|
visible.value = true
|
nextTick(() => {
|
dialogRef.value?.open({ mode: 'add', parent: row })
|
})
|
}
|
|
function handleView(row) {
|
visible.value = true
|
nextTick(() => {
|
dialogRef.value?.open({ mode: 'view', row: { ...row } })
|
})
|
}
|
|
function handleEdit(row) {
|
visible.value = true
|
nextTick(() => {
|
dialogRef.value?.open({ mode: 'edit', row: { ...row } })
|
})
|
}
|
|
function handleShare(row) {
|
shareVisible.value = true
|
nextTick(() => {
|
shareDialogRef.value?.open({ row })
|
})
|
}
|
|
async function handleDelete(row) {
|
const tips = row ? '该条' : '选中的项'
|
await ElMessageBox.confirm(`确认删除${tips}吗?`, '提示', {
|
type: 'warning',
|
customClass: 'command-page-view-message-box',
|
confirmButtonClass: 'command-message-box-confirm',
|
cancelButtonClass: 'command-message-box-cancel',
|
})
|
const ids = row ? row.id : selectedIds.value.join(',')
|
const rows = row ? [row] : selectedRows.value
|
await remove(ids)
|
saveOperationLog({
|
requestUri: route.path,
|
title: `${route.name || '部门管理'}-删除`,
|
type: 1,
|
})
|
ElMessage.success('删除成功')
|
selectedIds.value = []
|
selectedRows.value = []
|
const parentIds = Array.from(new Set(rows.map(item => item.parentId).filter(Boolean)))
|
const hasRoot = rows.some(item => !item.parentId)
|
if (hasRoot) {
|
getList()
|
}
|
parentIds.forEach(parentId => refreshChildNodes(parentId))
|
}
|
|
function handleSelectionChange(rows) {
|
selectedIds.value = rows.map(item => item.id)
|
selectedRows.value = rows
|
}
|
|
function getDictList() {
|
Promise.all([getDictionary({ code: 'org_category' }), getDictionary({ code: 'org_nature' })]).then(
|
([categoryRes, natureRes]) => {
|
dictObj.value = {
|
org_category: categoryRes?.data?.data ?? [],
|
org_nature: natureRes?.data?.data ?? [],
|
}
|
}
|
)
|
}
|
|
function getDeptTreeList() {
|
getDeptTree().then(res => {
|
deptTree.value = res.data.data
|
})
|
}
|
|
function loadChildren(row, treeNode, resolve) {
|
treeResolveMap.set(row.id, { resolve, row })
|
getChildLazyTree({ parentId: row.id })
|
.then(res => {
|
const children = res?.data?.data ?? []
|
row.hasChildren = children.length > 0
|
resolve(children)
|
})
|
.catch(() => {
|
row.hasChildren = false
|
resolve([])
|
})
|
}
|
|
function refreshChildNodes(parentId) {
|
const cache = treeResolveMap.get(parentId)
|
if (!cache?.resolve) return
|
getChildLazyTree({ parentId })
|
.then(res => {
|
const children = res?.data?.data ?? []
|
if (cache.row) {
|
cache.row.hasChildren = children.length > 0
|
}
|
cache.resolve(children)
|
})
|
.catch(() => {
|
if (cache.row) {
|
cache.row.hasChildren = false
|
}
|
cache.resolve([])
|
})
|
}
|
|
function handleFormSuccess(payload = {}) {
|
if (payload?.parentId) {
|
refreshChildNodes(payload.parentId)
|
if (payload.isAddChild && lastActionParentRow.value?.id === payload.parentId) {
|
lastActionParentRow.value.hasChildren = true
|
}
|
lastActionParentRow.value = null
|
return
|
}
|
lastActionParentRow.value = null
|
getList()
|
}
|
|
onMounted(() => {
|
getList()
|
getDictList()
|
getDeptTreeList()
|
})
|
</script>
|
|
<style scoped lang="scss"></style>
|