693 lines
17 KiB
Vue
693 lines
17 KiB
Vue
<template>
|
|
<div class="organization-page">
|
|
<div class="page-header">
|
|
<div>
|
|
<h2>组织架构</h2>
|
|
<p>管理企业组织架构、部门设置和人员信息</p>
|
|
</div>
|
|
<div class="header-actions">
|
|
<el-button :icon="Setting" @click="openOrgSettings">组织设置</el-button>
|
|
<el-button type="primary" :icon="Plus" @click="openCreateOrg">新建组织</el-button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="organization-container">
|
|
<!-- 左侧树形结构 -->
|
|
<div class="org-tree-container">
|
|
<div class="tree-header">
|
|
<h3>组织架构图</h3>
|
|
<div class="tree-actions">
|
|
<el-button :icon="Refresh" @click="loadOrgTree" circle />
|
|
<el-button :icon="Expand" @click="expandAll" circle />
|
|
<el-button :icon="Fold" @click="collapseAll" circle />
|
|
</div>
|
|
</div>
|
|
<div class="org-tree">
|
|
<el-tree
|
|
ref="orgTreeRef"
|
|
:data="orgTreeData"
|
|
:props="treeProps"
|
|
node-key="id"
|
|
default-expand-all
|
|
highlight-current
|
|
@node-click="handleNodeClick"
|
|
@node-expand="handleNodeExpand"
|
|
@node-collapse="handleNodeCollapse"
|
|
>
|
|
<template #default="{ data }">
|
|
<div class="tree-node">
|
|
<div class="node-content">
|
|
<span
|
|
class="node-status-dot"
|
|
:class="data.status === 1 ? 'is-active' : 'is-inactive'"
|
|
:title="data.status === 1 ? '启用' : '停用'"
|
|
/>
|
|
<span class="node-label">{{ data.org_name }}</span>
|
|
</div>
|
|
<div class="node-actions">
|
|
<el-button
|
|
link
|
|
type="primary"
|
|
size="small"
|
|
title="编辑"
|
|
@click.stop="editOrg(data)"
|
|
>
|
|
<el-icon><Edit /></el-icon>
|
|
</el-button>
|
|
<el-button
|
|
link
|
|
type="primary"
|
|
size="small"
|
|
title="添加子组织"
|
|
@click.stop="addChildOrg(data)"
|
|
>
|
|
<el-icon><Plus /></el-icon>
|
|
</el-button>
|
|
<el-button
|
|
link
|
|
type="danger"
|
|
size="small"
|
|
@click.stop="deleteOrg(data)"
|
|
>
|
|
删除
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</el-tree>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 右侧详情面板 -->
|
|
<div class="org-detail-container">
|
|
<div class="detail-header">
|
|
<h3>组织详情</h3>
|
|
<div class="detail-actions">
|
|
<el-button
|
|
v-if="selectedOrg"
|
|
type="primary"
|
|
:icon="Plus"
|
|
@click="openCreateEmployee"
|
|
>
|
|
添加员工
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="selectedOrg" class="org-detail">
|
|
<!-- 基本信息 -->
|
|
<div class="detail-section">
|
|
<h4>基本信息</h4>
|
|
<el-descriptions :column="2" border>
|
|
<el-descriptions-item label="组织名称">{{ selectedOrg.org_name }}</el-descriptions-item>
|
|
<el-descriptions-item label="组织编码">{{ selectedOrg.org_code }}</el-descriptions-item>
|
|
<el-descriptions-item label="上级组织">{{ selectedOrg.parent_name || '无' }}</el-descriptions-item>
|
|
<el-descriptions-item label="排序">{{ selectedOrg.sort }}</el-descriptions-item>
|
|
<el-descriptions-item label="组织类型">
|
|
<el-tag :type="selectedOrg.is_company ? 'primary' : 'success'">
|
|
{{ selectedOrg.is_company ? '企业单位' : '部门' }}
|
|
</el-tag>
|
|
</el-descriptions-item>
|
|
<el-descriptions-item label="状态">
|
|
<el-tag :type="selectedOrg.status === 1 ? 'success' : 'danger'">
|
|
{{ selectedOrg.status === 1 ? '启用' : '禁用' }}
|
|
</el-tag>
|
|
</el-descriptions-item>
|
|
<el-descriptions-item label="负责人" v-if="selectedOrg.leader_name">
|
|
{{ selectedOrg.leader_name }}
|
|
</el-descriptions-item>
|
|
<el-descriptions-item label="创建时间">
|
|
{{ formatDate(selectedOrg.create_time) }}
|
|
</el-descriptions-item>
|
|
</el-descriptions>
|
|
</div>
|
|
|
|
<!-- 备注信息 -->
|
|
<div class="detail-section">
|
|
<h4>备注信息</h4>
|
|
<div class="remark-content">
|
|
{{ selectedOrg.remark || '无备注' }}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 员工列表 -->
|
|
<div class="detail-section">
|
|
<h4>员工列表</h4>
|
|
<div class="employee-list">
|
|
<el-table :data="employeeList" stripe>
|
|
<el-table-column prop="name" label="姓名" width="120" />
|
|
<el-table-column prop="account" label="账号" width="150" />
|
|
<el-table-column prop="department" label="部门" width="150" />
|
|
<el-table-column prop="position" label="职位" width="150" />
|
|
<el-table-column prop="phone" label="电话" width="120" />
|
|
<el-table-column prop="email" label="邮箱" />
|
|
<el-table-column label="状态" width="80">
|
|
<template #default="{ row }">
|
|
<el-tag :type="row.account_status === 1 ? 'success' : 'danger'" size="small">
|
|
{{ row.account_status === 1 ? '正常' : '禁用' }}
|
|
</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="操作" width="150">
|
|
<template #default="{ row }">
|
|
<el-button link type="primary" @click="editEmployee(row)">编辑</el-button>
|
|
<el-button link type="danger" @click="deleteEmployee(row)">删除</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-else class="empty-detail">
|
|
<el-empty description="请选择一个组织查看详情" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 组织编辑对话框 -->
|
|
<OrgEditDialog
|
|
v-model="orgEditVisible"
|
|
:form-data="orgFormData"
|
|
:is-edit="orgEditMode"
|
|
@save="saveOrg"
|
|
/>
|
|
|
|
<!-- 员工编辑对话框 -->
|
|
<EmployeeEditDialog
|
|
v-model="employeeEditVisible"
|
|
:form-data="employeeFormData"
|
|
:is-edit="employeeEditMode"
|
|
@save="saveEmployee"
|
|
/>
|
|
|
|
<!-- 组织设置对话框 -->
|
|
<OrgSettingsDialog
|
|
v-model="orgSettingsVisible"
|
|
@changed="loadOrgTree"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed, onMounted, reactive, ref } from "vue";
|
|
import { ElMessage, ElMessageBox } from "element-plus";
|
|
import {
|
|
Plus,
|
|
Refresh,
|
|
Setting,
|
|
Expand,
|
|
Fold,
|
|
Edit
|
|
} from "@element-plus/icons-vue";
|
|
import OrgEditDialog from "./components/orgEditDialog.vue";
|
|
import EmployeeEditDialog from "./components/employeeEditDialog.vue";
|
|
import OrgSettingsDialog from "./components/orgSettingsDialog.vue";
|
|
import {
|
|
getOrganizationList,
|
|
getOrganizationDetail,
|
|
createOrganization,
|
|
updateOrganization,
|
|
deleteOrganization,
|
|
getEmployeeList,
|
|
createEmployee,
|
|
updateEmployee,
|
|
deleteEmployee as apiDeleteEmployee,
|
|
getOrgSettings
|
|
} from "@/api/organization";
|
|
|
|
const orgTreeRef = ref();
|
|
const orgTreeData = ref([]);
|
|
const selectedOrg = ref(null);
|
|
const employeeList = ref([]);
|
|
const orgEditVisible = ref(false);
|
|
const employeeEditVisible = ref(false);
|
|
const orgSettingsVisible = ref(false);
|
|
const orgEditMode = ref(false);
|
|
const employeeEditMode = ref(false);
|
|
|
|
const treeProps = {
|
|
children: 'children',
|
|
label: 'org_name'
|
|
};
|
|
|
|
const emptyOrgForm = () => ({
|
|
org_name: '',
|
|
org_code: '',
|
|
parent_id: 0,
|
|
leader_id: null,
|
|
is_company: 0,
|
|
sort: 0,
|
|
status: 1,
|
|
remark: ''
|
|
});
|
|
|
|
const orgFormData = reactive(emptyOrgForm());
|
|
|
|
const emptyEmployeeForm = () => ({
|
|
name: '',
|
|
account: '',
|
|
gender: 0,
|
|
birthday: '',
|
|
affiliate_unit: '',
|
|
department: '',
|
|
position: '',
|
|
education: '',
|
|
nation: '',
|
|
phone: '',
|
|
wechat: '',
|
|
email: '',
|
|
home_address: '',
|
|
account_status: 1
|
|
});
|
|
|
|
const employeeFormData = reactive(emptyEmployeeForm());
|
|
|
|
const loadOrgTree = async () => {
|
|
try {
|
|
const res = await getOrganizationList();
|
|
const data = res?.data || res || [];
|
|
orgTreeData.value = buildTreeData(Array.isArray(data) ? data : []);
|
|
if (orgTreeData.value.length > 0 && !selectedOrg.value) {
|
|
selectedOrg.value = orgTreeData.value[0];
|
|
await loadEmployeeList(selectedOrg.value.id);
|
|
}
|
|
} catch (error) {
|
|
ElMessage.error(error?.message || '加载组织架构失败');
|
|
}
|
|
};
|
|
|
|
const buildTreeData = (data) => {
|
|
const tree = [];
|
|
const map = {};
|
|
|
|
// 创建映射
|
|
data.forEach(item => {
|
|
map[item.id] = { ...item, children: [] };
|
|
});
|
|
|
|
// 构建树形结构
|
|
data.forEach(item => {
|
|
const node = map[item.id];
|
|
if (item.parent_id === 0) {
|
|
tree.push(node);
|
|
} else {
|
|
const parent = map[item.parent_id];
|
|
if (parent) {
|
|
parent.children.push(node);
|
|
}
|
|
}
|
|
});
|
|
|
|
return tree;
|
|
};
|
|
|
|
const handleNodeClick = async (data) => {
|
|
selectedOrg.value = data;
|
|
await loadEmployeeList(data.id);
|
|
};
|
|
|
|
const handleNodeExpand = (data) => {
|
|
console.log('Node expanded:', data);
|
|
};
|
|
|
|
const handleNodeCollapse = (data) => {
|
|
console.log('Node collapsed:', data);
|
|
};
|
|
|
|
const expandAll = () => {
|
|
orgTreeRef.value?.expandAll();
|
|
};
|
|
|
|
const collapseAll = () => {
|
|
orgTreeRef.value?.collapseAll();
|
|
};
|
|
|
|
const loadEmployeeList = async (orgId) => {
|
|
try {
|
|
const res = await getEmployeeList({ org_id: orgId });
|
|
const data = res?.data || res || [];
|
|
employeeList.value = Array.isArray(data) ? data : [];
|
|
} catch (error) {
|
|
ElMessage.error(error?.message || '加载员工列表失败');
|
|
}
|
|
};
|
|
|
|
const openCreateOrg = () => {
|
|
orgEditMode.value = false;
|
|
Object.assign(orgFormData, emptyOrgForm());
|
|
orgFormData.parent_id = selectedOrg.value ? selectedOrg.value.id : 0;
|
|
orgFormData.is_company = selectedOrg.value ? 0 : 1;
|
|
orgEditVisible.value = true;
|
|
};
|
|
|
|
const editOrg = (data) => {
|
|
orgEditMode.value = true;
|
|
Object.assign(orgFormData, {
|
|
id: data.id,
|
|
org_name: data.org_name,
|
|
org_code: data.org_code,
|
|
parent_id: data.parent_id,
|
|
leader_id: data.leader_id,
|
|
is_company: data.is_company,
|
|
sort: data.sort,
|
|
status: data.status,
|
|
remark: data.remark
|
|
});
|
|
orgEditVisible.value = true;
|
|
};
|
|
|
|
const addChildOrg = (data) => {
|
|
orgEditMode.value = false;
|
|
Object.assign(orgFormData, emptyOrgForm());
|
|
orgFormData.parent_id = data.id;
|
|
orgFormData.is_company = 0;
|
|
orgEditVisible.value = true;
|
|
};
|
|
|
|
const deleteOrg = async (data) => {
|
|
try {
|
|
await ElMessageBox.confirm('确认删除这个组织吗?删除后将无法恢复。', '删除确认', {
|
|
type: 'warning',
|
|
});
|
|
await deleteOrganization(data.id);
|
|
ElMessage.success('删除成功');
|
|
await loadOrgTree();
|
|
} catch (error) {
|
|
if (error !== 'cancel' && error !== 'close') {
|
|
ElMessage.error(error?.message || '删除失败');
|
|
}
|
|
}
|
|
};
|
|
|
|
const saveOrg = async (payload) => {
|
|
try {
|
|
if (orgEditMode.value) {
|
|
await updateOrganization(orgFormData.id, payload);
|
|
ElMessage.success('更新成功');
|
|
} else {
|
|
await createOrganization(payload);
|
|
ElMessage.success('创建成功');
|
|
}
|
|
orgEditVisible.value = false;
|
|
await loadOrgTree();
|
|
} catch (error) {
|
|
ElMessage.error(error?.message || '保存失败');
|
|
}
|
|
};
|
|
|
|
const openCreateEmployee = () => {
|
|
employeeEditMode.value = false;
|
|
Object.assign(employeeFormData, emptyEmployeeForm());
|
|
employeeFormData.affiliate_unit = selectedOrg.value ? selectedOrg.value.id.toString() : '';
|
|
employeeFormData.department = selectedOrg.value ? selectedOrg.value.id.toString() : '';
|
|
employeeEditVisible.value = true;
|
|
};
|
|
|
|
const editEmployee = (data) => {
|
|
employeeEditMode.value = true;
|
|
Object.assign(employeeFormData, {
|
|
id: data.id,
|
|
name: data.name,
|
|
account: data.account,
|
|
gender: data.gender,
|
|
birthday: data.birthday,
|
|
affiliate_unit: data.affiliate_unit,
|
|
department: data.department,
|
|
position: data.position,
|
|
education: data.education,
|
|
nation: data.nation,
|
|
phone: data.phone,
|
|
wechat: data.wechat,
|
|
email: data.email,
|
|
home_address: data.home_address,
|
|
account_status: data.account_status
|
|
});
|
|
employeeEditVisible.value = true;
|
|
};
|
|
|
|
const deleteEmployee = async (data) => {
|
|
try {
|
|
await ElMessageBox.confirm('确认删除这个员工吗?删除后将无法恢复。', '删除确认', {
|
|
type: 'warning',
|
|
});
|
|
await apiDeleteEmployee(data.id);
|
|
ElMessage.success('删除成功');
|
|
await loadEmployeeList(selectedOrg.value.id);
|
|
} catch (error) {
|
|
if (error !== 'cancel' && error !== 'close') {
|
|
ElMessage.error(error?.message || '删除失败');
|
|
}
|
|
}
|
|
};
|
|
|
|
const saveEmployee = async (payload) => {
|
|
try {
|
|
if (employeeEditMode.value) {
|
|
await updateEmployee(employeeFormData.id, payload);
|
|
ElMessage.success('更新成功');
|
|
} else {
|
|
await createEmployee(payload);
|
|
ElMessage.success('创建成功');
|
|
}
|
|
employeeEditVisible.value = false;
|
|
await loadEmployeeList(selectedOrg.value.id);
|
|
} catch (error) {
|
|
ElMessage.error(error?.message || '保存失败');
|
|
}
|
|
};
|
|
|
|
const openOrgSettings = () => {
|
|
orgSettingsVisible.value = true;
|
|
};
|
|
|
|
const formatDate = (value) => {
|
|
if (!value) return '-';
|
|
return new Date(value).toLocaleString('zh-CN', { hour12: false });
|
|
};
|
|
|
|
onMounted(() => {
|
|
loadOrgTree();
|
|
});
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.organization-page {
|
|
min-height: calc(100vh - 84px);
|
|
background: #f5f7fa;
|
|
padding: 20px;
|
|
}
|
|
|
|
.page-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.header-actions {
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.page-header h2 {
|
|
margin: 0 0 8px;
|
|
color: #303133;
|
|
font-size: 22px;
|
|
}
|
|
|
|
.page-header p {
|
|
margin: 0;
|
|
color: #909399;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.organization-container {
|
|
display: flex;
|
|
gap: 16px;
|
|
height: calc(100vh - 140px);
|
|
background: #fff;
|
|
border-radius: 6px;
|
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
|
|
}
|
|
|
|
.org-tree-container {
|
|
width: 350px;
|
|
border-right: 1px solid #e4e7ed;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.tree-header {
|
|
padding: 16px;
|
|
border-bottom: 1px solid #e4e7ed;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.tree-header h3 {
|
|
margin: 0;
|
|
color: #303133;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.tree-actions {
|
|
display: flex;
|
|
gap: 8px;
|
|
}
|
|
|
|
.org-tree {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 16px;
|
|
}
|
|
|
|
.tree-node {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
width: 100%;
|
|
padding: 4px 8px;
|
|
border-radius: 4px;
|
|
transition: background-color 0.2s;
|
|
}
|
|
|
|
.tree-node:hover {
|
|
background-color: #f5f7fa;
|
|
}
|
|
|
|
.node-content {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
flex: 1;
|
|
}
|
|
|
|
.node-label {
|
|
font-weight: 500;
|
|
color: #303133;
|
|
}
|
|
|
|
.node-status-dot {
|
|
flex-shrink: 0;
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
|
|
&.is-active {
|
|
background-color: #67c23a;
|
|
}
|
|
|
|
&.is-inactive {
|
|
background-color: #c0c4cc;
|
|
}
|
|
}
|
|
|
|
.node-actions {
|
|
display: flex;
|
|
gap: 4px;
|
|
opacity: 0;
|
|
transition: opacity 0.2s;
|
|
}
|
|
|
|
.tree-node:hover .node-actions {
|
|
opacity: 1;
|
|
}
|
|
|
|
.org-detail-container {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.detail-header {
|
|
padding: 16px;
|
|
border-bottom: 1px solid #e4e7ed;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.detail-header h3 {
|
|
margin: 0;
|
|
color: #303133;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.detail-actions {
|
|
display: flex;
|
|
gap: 8px;
|
|
}
|
|
|
|
.org-detail {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 16px;
|
|
}
|
|
|
|
.detail-section {
|
|
margin-bottom: 24px;
|
|
}
|
|
|
|
.detail-section h4 {
|
|
margin: 0 0 16px 0;
|
|
color: #303133;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.remark-content {
|
|
padding: 12px;
|
|
background: #f5f7fa;
|
|
border-radius: 4px;
|
|
color: #606266;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.employee-list {
|
|
margin-top: 16px;
|
|
}
|
|
|
|
.empty-detail {
|
|
flex: 1;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.organization-page {
|
|
padding: 12px;
|
|
}
|
|
|
|
.organization-container {
|
|
flex-direction: column;
|
|
height: auto;
|
|
}
|
|
|
|
.org-tree-container {
|
|
width: 100%;
|
|
height: 300px;
|
|
border-right: none;
|
|
border-bottom: 1px solid #e4e7ed;
|
|
}
|
|
|
|
.org-tree {
|
|
height: 200px;
|
|
}
|
|
|
|
.page-header {
|
|
flex-direction: column;
|
|
align-items: flex-start;
|
|
gap: 12px;
|
|
}
|
|
|
|
.header-actions {
|
|
width: 100%;
|
|
flex-wrap: wrap;
|
|
}
|
|
}
|
|
</style>
|