|
|
@@ -1,13 +1,16 @@
|
|
|
import React, { useEffect } from 'react'
|
|
|
-import { Button, message, Tree, TreeSelect, Form } from 'antd'
|
|
|
-import { PlusOutlined } from '@ant-design/icons'
|
|
|
+import { Button, message, Tree, TreeSelect, Form, Popconfirm } from 'antd'
|
|
|
+import { DeleteOutlined, PlusOutlined } from '@ant-design/icons'
|
|
|
import consts from '@/consts'
|
|
|
-import { apiaddDepartment } from '@/services/hr'
|
|
|
+import { addDepartment, delDepartment } from '@/services/hr'
|
|
|
import { connect, useAccess } from 'umi'
|
|
|
import { ModalForm, ProFormText } from '@ant-design/pro-form'
|
|
|
+import './index.less'
|
|
|
+const { DirectoryTree } = Tree
|
|
|
|
|
|
const RoleMenu = props => {
|
|
|
const { dispatch, departments = [], onSelect } = props
|
|
|
+ const hasPerm = useAccess()?.validatePermByType('employee_del_department')
|
|
|
const newList = [...departments]
|
|
|
newList.unshift({
|
|
|
children: [],
|
|
|
@@ -17,15 +20,51 @@ const RoleMenu = props => {
|
|
|
name: '总全公司',
|
|
|
title: '总全公司'
|
|
|
})
|
|
|
- const { DirectoryTree } = Tree
|
|
|
|
|
|
const initData = () => {
|
|
|
dispatch({
|
|
|
type: 'staff/fetchDepartments'
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ const handleDelDepartment = async id => {
|
|
|
+ const { code = -1 } = await delDepartment(id)
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ message.success('删除成功')
|
|
|
+ initData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function renderTreeNode(tree) {
|
|
|
+ if (!hasPerm) return tree
|
|
|
+ return tree.map(item => {
|
|
|
+ const newItem = {
|
|
|
+ ...item,
|
|
|
+ title: (
|
|
|
+ <div className="department-node">
|
|
|
+ <div>{item.title}</div>
|
|
|
+ <div className="extra">
|
|
|
+ <Popconfirm
|
|
|
+ title="确认删除吗?"
|
|
|
+ onText="确认"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => handleDelDepartment(item.id)}
|
|
|
+ >
|
|
|
+ <DeleteOutlined />
|
|
|
+ </Popconfirm>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (newItem.children.length) {
|
|
|
+ newItem.children = renderTreeNode(newItem.children)
|
|
|
+ }
|
|
|
+ return newItem
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
const handleAddDepartment = async values => {
|
|
|
- const { code = -1 } = await apiaddDepartment({ ...values })
|
|
|
+ const { code = -1 } = await addDepartment({ ...values })
|
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
|
initData()
|
|
|
}
|
|
|
@@ -43,10 +82,6 @@ const RoleMenu = props => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const onExpand = () => {}
|
|
|
-
|
|
|
- const hasPerm = useAccess()?.validatePermByType('employee_add_department')
|
|
|
-
|
|
|
return (
|
|
|
<div className="h-full w-12rem rounded-4px">
|
|
|
<div className="p-4 pb-3 border-b-1 border-solid border-black border-opacity-10 bg-[#f7f9fa] flex justify-around items-center">
|
|
|
@@ -78,12 +113,6 @@ const RoleMenu = props => {
|
|
|
allowClear
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- {/* <ProFormTreeSelect
|
|
|
- width="md"
|
|
|
- options={departments.map(item => ({ label: item.name, value: item.id }))}
|
|
|
- name="parentId"
|
|
|
- label="上级部门"
|
|
|
- /> */}
|
|
|
</ModalForm>
|
|
|
)}
|
|
|
</div>
|
|
|
@@ -94,9 +123,8 @@ const RoleMenu = props => {
|
|
|
defaultExpandAll
|
|
|
defaultSelectedKeys={['0']}
|
|
|
onSelect={keys => saveActiveId(keys[0])}
|
|
|
- onExpand={onExpand}
|
|
|
showIcon={false}
|
|
|
- treeData={newList}
|
|
|
+ treeData={renderTreeNode(newList)}
|
|
|
/>
|
|
|
) : null}
|
|
|
</div>
|
|
|
@@ -104,7 +132,6 @@ const RoleMenu = props => {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-// export default RoleMenu
|
|
|
export default connect(({ staff }) => ({
|
|
|
departments: staff.departments
|
|
|
}))(RoleMenu)
|