You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
org-chart-frant/src/components/dialog/copyDialog.jsx

113 lines
2.7 KiB
React

2 years ago
import { Form, Input, Modal, TreeSelect, message, Checkbox } from 'antd';
import React, {
useState,
useEffect,
useRef,
forwardRef,
useImperativeHandle,
} from 'react';
2 years ago
import * as d3 from 'd3';
import './index.less';
2 years ago
import { HomeOutlined } from '@ant-design/icons';
import './index.less';
2 years ago
const layout = {
2 years ago
labelCol: { span: 8 },
2 years ago
wrapperCol: { span: 14 },
};
2 years ago
const CopyDialog = forwardRef(({ open, onCreate, onCancel }, ref) => {
const [treeData, setData] = useState([]);
2 years ago
const [form] = Form.useForm();
2 years ago
const formRef = useRef(null);
2 years ago
2 years ago
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);
},
);
},
}));
2 years ago
/**
* 根节点树异步加载
* @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) => {
2 years ago
data.companyTree.map((item, index) => {
item.icon = <HomeOutlined />;
});
2 years ago
let arr = [...treeData, ...data.companyTree];
setData(arr);
});
resolve(undefined);
}, 200);
});
return (
<Modal
open={open}
2 years ago
title="部门合并"
2 years ago
okText="确认"
cancelText="取消"
onCancel={onCancel}
onOk={() => {
form
.validateFields()
.then((values) => {
onCreate(values);
})
.catch((info) => {
console.log('Validate Failed:', info);
});
}}
>
2 years ago
<Form ref={formRef} {...layout} form={form} name="form_in_modal">
2 years ago
<Form.Item
2 years ago
name="company"
label="复制到分部"
2 years ago
rules={[
{
required: true,
2 years ago
message: '【复制到分部】为必填项!',
2 years ago
},
]}
>
<TreeSelect
2 years ago
className="custom-tree-select"
2 years ago
treeDataSimpleMode
allowClear
style={{ width: '100%' }}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
loadData={onRootLoadData}
treeData={treeData}
2 years ago
treeIcon
2 years ago
/>
</Form.Item>
<Form.Item
2 years ago
name="copySubDept"
valuePropName="checked"
label="是否复制子部门信息"
2 years ago
>
2 years ago
<Checkbox />
2 years ago
</Form.Item>
</Form>
</Modal>
);
2 years ago
});
2 years ago
export default CopyDialog;