org-chart-frant/src/components/topBar/index.jsx

372 lines
10 KiB
React
Raw Normal View History

2022-09-06 13:46:56 +08:00
import React from 'react';
2023-06-28 17:38:16 +08:00
import { QuestionCircleOutlined } from '@ant-design/icons';
2022-09-06 13:46:56 +08:00
import style from './index.less';
import {
DatePicker,
Select,
Button,
Checkbox,
Row,
Col,
Dropdown,
Menu,
2023-06-27 14:12:42 +08:00
TreeSelect,
2023-06-28 17:38:16 +08:00
Tooltip,
Modal,
Input,
message,
2022-09-06 13:46:56 +08:00
} from 'antd';
2022-07-12 17:10:03 +08:00
const { Option } = Select;
2023-06-28 17:38:16 +08:00
const { TextArea } = Input;
2022-07-12 17:10:03 +08:00
import moment from 'moment';
2022-09-06 13:46:56 +08:00
import 'moment/locale/zh-cn';
import locale from 'antd/lib/date-picker/locale/zh_CN';
2023-09-15 17:14:01 +08:00
import { HomeOutlined } from '@ant-design/icons';
2022-09-06 13:46:56 +08:00
moment.locale('zh-cn');
2022-07-12 17:10:03 +08:00
export class TopBar extends React.Component {
2022-09-06 13:46:56 +08:00
constructor(props) {
super(props);
this.state = {
fclasslist: [],
2023-06-27 14:12:42 +08:00
rootTreeData: [], //根节点异步树
treeExpandedKeys: [],
2022-09-06 13:46:56 +08:00
requestData: {
fclass: '0',
2023-06-27 14:12:42 +08:00
root: undefined,
2023-07-07 16:37:05 +08:00
level: '2',
2022-09-06 13:46:56 +08:00
fisvitual: '0',
2023-08-17 18:12:40 +08:00
hidedept: '0',
2022-09-06 13:46:56 +08:00
},
2023-06-28 17:38:16 +08:00
open: false,
confirmLoading: false,
description: '',
2022-09-06 13:46:56 +08:00
};
}
2023-06-27 14:12:42 +08:00
/**
* 表单值改变
* @param {*} payload
*/
2022-09-06 13:46:56 +08:00
handleFormChange(payload) {
let requestData = { ...this.state.requestData, ...payload };
this.setState({ requestData });
}
2023-06-27 14:12:42 +08:00
2023-06-28 17:38:16 +08:00
onChange = (e) => {
this.setState({ description: e.target.value });
};
2023-06-27 14:12:42 +08:00
/**
2023-06-28 17:38:16 +08:00
* 弹窗确认
2023-06-27 14:12:42 +08:00
*/
2023-06-28 17:38:16 +08:00
handleOk = () => {
const { description, requestData } = this.state;
if (description.length == 0) {
return message.error('请填写描述信息');
}
this.setState({ confirmLoading: true });
2023-07-14 14:46:14 +08:00
// setTimeout(() => {
// this.setState({ open: false, confirmLoading: false, description: '' });
// message.success('版本记录成功,请重新刷新页面');
// }, 2000);
let api =
'/api/bs/hrmorganization/orgchart/versionRecord?fclass=' +
requestData.fclass +
'&description=' +
description;
fetch(api)
.then((res) => res.json())
.then((data) => {
if (data.api_status) {
this.setState({
open: false,
confirmLoading: false,
});
message.success('版本记录成功,请重新刷新页面', 2, 3);
} else {
message.error('版本记录失败,请联系相关人员处理数据', 2, 3);
}
});
2023-06-28 17:38:16 +08:00
};
2022-09-06 13:46:56 +08:00
handleExportMenuClick(e) {
this.props.onExport(e.key == '1' ? 'png' : 'pdf');
}
handleExportButtonClick() {
this.props.onExport('png');
}
2023-06-27 14:12:42 +08:00
/**
* 根节点树数据
* @param {} parentId
* @returns
*/
2023-06-30 16:39:00 +08:00
getNodeTreeNode = (url, merge = true) => {
fetch(url)
2023-06-27 14:12:42 +08:00
.then((res) => res.json())
.then((data) => {
if (data.api_status) {
2023-06-30 16:39:00 +08:00
let arr = [];
if (merge) {
arr = [...this.state.rootTreeData, ...data.companyTree];
} else {
arr = [...data.companyTree];
}
2023-09-15 17:14:01 +08:00
arr.map((item, index) => {
item.icon = <HomeOutlined />;
});
2023-06-27 14:12:42 +08:00
this.setState({
rootTreeData: arr,
});
}
});
};
/**
* 根节点树异步加载
* @param {} parentId
* @returns
*/
onRootLoadData = (treeNode) =>
new Promise((resolve) => {
const { id } = treeNode.props;
setTimeout(() => {
2023-06-30 16:39:00 +08:00
const { fclass } = this.state.requestData;
let api =
'/api/bs/hrmorganization/orgchart/getSubCompanyTree?subcompany=' +
id +
'&fclass=' +
fclass;
this.getNodeTreeNode(api);
2023-06-27 14:12:42 +08:00
resolve(undefined);
2023-06-28 17:38:16 +08:00
}, 500);
2023-06-27 14:12:42 +08:00
});
onRootChange = (value) => {
let requestData = { ...this.state.requestData, root: value };
this.setState({ requestData });
};
onTreeExpand = (expandedKeys) => {
this.setState({
treeExpandedKeys: expandedKeys,
});
};
2022-09-06 13:46:56 +08:00
componentDidMount() {
2023-06-27 14:12:42 +08:00
this.getSeatchCondition(this.props.url);
}
getSeatchCondition = (url) => {
fetch(url)
2022-09-06 13:46:56 +08:00
.then((res) => res.json())
.then((data) => {
2023-09-15 17:14:01 +08:00
data.companyTree.map((item, index) => {
item.icon = <HomeOutlined />;
});
2022-09-06 13:46:56 +08:00
this.setState({
fclasslist: data.fclasslist,
2023-06-27 14:12:42 +08:00
rootTreeData: data.companyTree,
2022-09-06 13:46:56 +08:00
});
});
2023-06-27 14:12:42 +08:00
};
2022-09-06 13:46:56 +08:00
menu = (
<Menu
onClick={this.handleExportMenuClick.bind(this)}
items={[
{
label: '导出图片',
key: '1',
},
2023-07-14 14:46:14 +08:00
// {
// label: '导出PDF',
// key: '2',
// },
2022-09-06 13:46:56 +08:00
]}
/>
);
render() {
2023-06-28 17:38:16 +08:00
const { disabled, type } = this.props;
const { rootTreeData, open, confirmLoading } = this.state;
2023-02-01 13:42:38 +08:00
2022-09-06 13:46:56 +08:00
return (
<div className={style.topbarWrapper}>
<Row>
2022-12-16 18:10:49 +08:00
<Col span={6}>
2022-09-06 13:46:56 +08:00
维度
<Select
defaultValue="0"
2023-06-27 14:12:42 +08:00
style={{ width: 140 }}
2022-09-06 13:46:56 +08:00
value={this.state.requestData.fclass}
2023-06-27 14:12:42 +08:00
onChange={(value) => {
2023-06-28 17:38:16 +08:00
const requestData = {
fclass: value,
root: undefined,
2023-07-14 14:46:14 +08:00
level: '2',
2023-06-28 17:38:16 +08:00
fisvitual: '0',
2023-08-21 14:42:34 +08:00
hidedept: '0',
2023-06-28 17:38:16 +08:00
};
this.handleFormChange(requestData);
2023-06-30 16:39:00 +08:00
this.getNodeTreeNode(
`/api/bs/hrmorganization/orgchart/getSubCompanyTree?fclass=${value}`,
false,
2023-06-28 17:38:16 +08:00
);
2023-06-30 16:39:00 +08:00
this.props.changeFclass(requestData);
2023-06-27 14:12:42 +08:00
}}
2022-09-06 13:46:56 +08:00
>
{this.state.fclasslist.map((item) => (
2023-06-27 14:12:42 +08:00
<Option key={item.key} value={item.id}>
{item.companyname}
</Option>
2022-09-06 13:46:56 +08:00
))}
</Select>
</Col>
2022-12-16 18:10:49 +08:00
<Col span={6}>
2022-09-06 13:46:56 +08:00
根节点
2023-06-27 14:12:42 +08:00
<TreeSelect
treeDataSimpleMode
allowClear
2023-07-14 14:46:14 +08:00
style={{ width: '75%' }}
2022-09-06 13:46:56 +08:00
value={this.state.requestData.root}
2023-06-27 14:12:42 +08:00
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
placeholder="请选择根节点"
onChange={this.onRootChange}
loadData={this.onRootLoadData}
treeData={rootTreeData}
2023-09-15 17:14:01 +08:00
treeIcon
2023-06-27 14:12:42 +08:00
/>
</Col>
<Col span={6}>
<Checkbox
style={{ marginTop: '5px', marginLeft: 100 }}
2023-08-17 18:12:40 +08:00
checked={this.state.requestData.hidedept == '1'}
2023-06-27 14:12:42 +08:00
onChange={(e) =>
this.handleFormChange({
2023-08-17 18:12:40 +08:00
hidedept: e.target.checked ? '1' : '0',
2023-06-27 14:12:42 +08:00
})
}
2022-09-06 13:46:56 +08:00
>
2023-08-17 18:12:40 +08:00
隐藏部门
2023-06-27 14:12:42 +08:00
</Checkbox>
2023-06-28 17:38:16 +08:00
<Tooltip
2023-08-17 18:12:40 +08:00
title="提示:开启后将只显示分部组织架构!!!"
color="#0082fb"
2023-06-28 17:38:16 +08:00
placement="rightTop"
>
<QuestionCircleOutlined
2023-08-17 18:12:40 +08:00
style={{ color: '#0082fb', cursor: 'pointer', fontSize: 16 }}
2023-06-28 17:38:16 +08:00
/>
</Tooltip>
2022-09-06 13:46:56 +08:00
</Col>
2022-12-16 18:10:49 +08:00
<Col span={6}>
2023-07-07 16:37:05 +08:00
部门层级
2022-09-06 13:46:56 +08:00
<Select
defaultValue="3"
2023-06-27 14:12:42 +08:00
style={{ width: 140 }}
2022-09-06 13:46:56 +08:00
value={this.state.requestData.level}
onChange={(value) => this.handleFormChange({ level: value })}
>
2023-07-07 16:37:05 +08:00
<Option value="1">全部</Option>
<Option value="2">一级</Option>
<Option value="3">二级</Option>
<Option value="4">三级</Option>
2022-09-06 13:46:56 +08:00
</Select>
</Col>
2022-12-16 18:10:49 +08:00
</Row>
<Row style={{ marginTop: '15px' }}>
2023-08-17 18:12:40 +08:00
<Col span={6}>
<Checkbox
style={{ marginTop: '5px' }}
checked={this.state.requestData.fisvitual == '1'}
onChange={(e) =>
this.handleFormChange({
fisvitual: e.target.checked ? '1' : '0',
})
}
>
显示虚拟组织
</Checkbox>
<Tooltip
title="提示:若启用虚拟组织,需要在分部自定义表增加字段(名称 fblx) 字段类型 下拉框(0实体 1虚拟) 部门自定义表同上(字段名称 bmlx)。"
color="#0082fb"
placement="rightTop"
>
<QuestionCircleOutlined
style={{ color: '#0082fb', cursor: 'pointer', fontSize: 16 }}
/>
</Tooltip>
</Col>
2023-09-14 18:23:08 +08:00
<Col span={16}>
2023-07-06 16:23:45 +08:00
<Button
type="primary"
style={{ marginRight: '10px' }}
disabled={disabled}
onClick={() => {
this.setState({ open: true });
}}
>
版本记录
</Button>
2022-09-06 13:46:56 +08:00
<Button
type="primary"
style={{ marginRight: '10px' }}
onClick={() => {
this.props.onSearch(this.state.requestData);
}}
>
查询
</Button>
2023-08-03 10:45:54 +08:00
<Button
type="primary"
style={{ marginRight: '10px' }}
onClick={() => {
window.open('#/dragtree', 'blank');
}}
>
组织调整
</Button>
2023-09-14 18:23:08 +08:00
<Button
type="primary"
style={{ marginRight: '10px' }}
onClick={() => {
window.open('#/statistics', 'blank');
}}
>
人数统计
</Button>
2023-06-27 14:12:42 +08:00
<Dropdown overlay={this.menu}>
2023-06-28 17:38:16 +08:00
<Button type="primary">导出</Button>
2022-09-06 13:46:56 +08:00
</Dropdown>
</Col>
</Row>
2023-06-28 17:38:16 +08:00
<Modal
title="版本记录"
cancelText="取消"
okText="确定"
open={open}
onOk={this.handleOk}
confirmLoading={confirmLoading}
onCancel={() => this.setState({ open: false })}
>
<p style={{ color: 'red' }}>
2023-07-14 14:46:14 +08:00
提示:版本记录耗时较长请谨慎操作仅记录当前维度的数据版本
2023-06-28 17:38:16 +08:00
</p>
2023-07-07 16:37:05 +08:00
<p>主题:</p>
2023-06-28 17:38:16 +08:00
<TextArea
showCount
maxLength={10}
style={{ height: 120, resize: 'none' }}
onChange={this.onChange}
placeholder="please enter"
/>
</Modal>
2022-09-06 13:46:56 +08:00
</div>
);
}
}