org-chart-frant/src/components/dialog/copyDialog.jsx

113 lines
2.7 KiB
React
Raw Normal View History

2023-08-02 09:26:28 +08:00
import { Form, Input, Modal, TreeSelect, message, Checkbox } from 'antd';
import React, {
useState,
useEffect,
useRef,
forwardRef,
useImperativeHandle,
} from 'react';
2023-08-01 10:40:41 +08:00
import * as d3 from 'd3';
import './index.less';
2023-08-02 09:26:28 +08:00
import { HomeOutlined } from '@ant-design/icons';
import './index.less';
2023-08-01 10:40:41 +08:00
const layout = {
2023-08-02 09:26:28 +08:00
labelCol: { span: 8 },
2023-08-01 10:40:41 +08:00
wrapperCol: { span: 14 },
};
2023-08-02 09:26:28 +08:00
const CopyDialog = forwardRef(({ open, onCreate, onCancel }, ref) => {
const [treeData, setData] = useState([]);
2023-08-01 10:40:41 +08:00
const [form] = Form.useForm();
2023-08-02 09:26:28 +08:00
const formRef = useRef(null);
2023-08-01 10:40:41 +08:00
2023-08-02 09:26:28 +08:00
useImperativeHandle(ref, () => ({
getTreeData() {
form.resetFields();
d3.json('/api/bs/hrmorganization/orgchart/getSubCompanyTree').then(
(data) => {
data.companyTree.map((item, index) => {
item.icon = <HomeOutlined />;
});
setData(data.companyTree);
},
);
},
}));
2023-08-01 10:40:41 +08:00
/**
* 根节点树异步加载
* @param {} parentId
* @returns
*/
const onRootLoadData = (treeNode) =>
new Promise((resolve) => {
const { id } = treeNode.props;
setTimeout(() => {
d3.json(
`/api/bs/hrmorganization/orgchart/getSubCompanyTree?subcompany=${id}`,
).then((data) => {
2023-08-02 09:26:28 +08:00
data.companyTree.map((item, index) => {
item.icon = <HomeOutlined />;
});
2023-08-01 10:40:41 +08:00
let arr = [...treeData, ...data.companyTree];
setData(arr);
});
resolve(undefined);
}, 200);
});
return (
<Modal
open={open}
2023-08-29 15:44:15 +08:00
title="部门复制"
2023-08-01 10:40:41 +08:00
okText="确认"
cancelText="取消"
onCancel={onCancel}
onOk={() => {
form
.validateFields()
.then((values) => {
onCreate(values);
})
.catch((info) => {
console.log('Validate Failed:', info);
});
}}
>
2023-08-02 09:26:28 +08:00
<Form ref={formRef} {...layout} form={form} name="form_in_modal">
2023-08-01 10:40:41 +08:00
<Form.Item
2023-08-02 09:26:28 +08:00
name="company"
label="复制到分部"
2023-08-01 10:40:41 +08:00
rules={[
{
required: true,
2023-08-02 09:26:28 +08:00
message: '【复制到分部】为必填项!',
2023-08-01 10:40:41 +08:00
},
]}
>
<TreeSelect
2023-08-02 09:26:28 +08:00
className="custom-tree-select"
2023-08-01 10:40:41 +08:00
treeDataSimpleMode
allowClear
style={{ width: '100%' }}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
loadData={onRootLoadData}
treeData={treeData}
2023-08-02 09:26:28 +08:00
treeIcon
2023-08-01 10:40:41 +08:00
/>
</Form.Item>
<Form.Item
2023-08-02 09:26:28 +08:00
name="copySubDept"
valuePropName="checked"
label="是否复制子部门信息"
2023-08-01 10:40:41 +08:00
>
2023-08-02 09:26:28 +08:00
<Checkbox />
2023-08-01 10:40:41 +08:00
</Form.Item>
</Form>
</Modal>
);
2023-08-02 09:26:28 +08:00
});
2023-08-01 10:40:41 +08:00
export default CopyDialog;