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

379 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,
2024-06-05 16:01:37 +08:00
notification,
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');
2024-06-05 16:01:37 +08:00
import { getLabel } from '../../util/i18n.js';
import { SmileOutlined } from '@ant-design/icons';
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: [], //根节点异步树
2023-12-19 16:28:37 +08:00
treeLoadedKeys: [],
2023-06-27 14:12:42 +08:00
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;
2024-06-05 16:01:37 +08:00
const { labelData } = this.props;
2023-06-28 17:38:16 +08:00
if (description.length == 0) {
2024-06-05 16:01:37 +08:00
return message.error(`${getLabel(547512, labelData)}`);
2023-06-28 17:38:16 +08:00
}
this.setState({ confirmLoading: true });
2023-07-14 14:46:14 +08:00
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,
});
2024-06-05 16:01:37 +08:00
message.success(`${getLabel(547513, labelData)}`, 2, 3);
2023-07-14 14:46:14 +08:00
} else {
2024-06-05 16:01:37 +08:00
message.error(`${getLabel(547514, labelData)}`, 2, 3);
2023-07-14 14:46:14 +08:00
}
});
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) => {
2023-12-19 16:28:37 +08:00
const { id } = treeNode;
2023-06-27 14:12:42 +08:00
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={[
{
2024-06-05 16:01:37 +08:00
label: `${getLabel(547315, this.props.labelData)}`,
2022-09-06 13:46:56 +08:00
key: '1',
},
2023-07-14 14:46:14 +08:00
// {
// label: '导出PDF',
// key: '2',
// },
2022-09-06 13:46:56 +08:00
]}
/>
);
render() {
2024-06-05 16:01:37 +08:00
const { disabled, type, labelData } = this.props;
2023-12-19 16:28:37 +08:00
const { rootTreeData, open, confirmLoading, treeExpandedKeys } = 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}>
2024-06-05 16:01:37 +08:00
{getLabel(547293, labelData)}
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-12-19 16:28:37 +08:00
this.setState({
rootTreeData: [],
});
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}>
2024-06-05 16:01:37 +08:00
{getLabel(547294, labelData)}
2023-06-27 14:12:42 +08:00
<TreeSelect
treeDataSimpleMode
allowClear
2024-06-05 16:01:37 +08:00
style={{ width: '65%' }}
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' }}
2024-06-05 16:01:37 +08:00
placeholder={getLabel(547298, labelData)}
2023-06-27 14:12:42 +08:00
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
>
2024-06-05 16:01:37 +08:00
{getLabel(547296, labelData)}
2023-06-27 14:12:42 +08:00
</Checkbox>
2023-06-28 17:38:16 +08:00
<Tooltip
2024-06-05 16:01:37 +08:00
title={getLabel(547303, labelData)}
2023-08-17 18:12:40 +08:00
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}>
2024-06-05 16:01:37 +08:00
{getLabel(547299, labelData)}
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 })}
>
2024-06-05 16:01:37 +08:00
<Option value="1">{getLabel(547301, labelData)}</Option>
<Option value="2">{getLabel(547463, labelData)}</Option>
<Option value="3">{getLabel(547464, labelData)}</Option>
<Option value="4">{getLabel(547465, labelData)}</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',
})
}
>
2024-06-05 16:01:37 +08:00
{getLabel(547302, labelData)}
2023-08-17 18:12:40 +08:00
</Checkbox>
<Tooltip
2024-06-05 16:01:37 +08:00
title={getLabel(547304, labelData)}
2023-08-17 18:12:40 +08:00
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}>
2024-07-04 09:44:19 +08:00
{this.state.requestData.fclass == '0' && (
<span>
<Button
type="primary"
style={{ marginRight: '10px' }}
disabled={disabled}
onClick={() => {
this.setState({ open: true });
}}
>
{getLabel(547305, labelData)}
</Button>
<Button
type="primary"
style={{ marginRight: '10px' }}
onClick={() => {
window.open('#/dragtree', 'blank');
}}
>
{getLabel(547310, labelData)}
</Button>
<Button
type="primary"
style={{ marginRight: '10px' }}
onClick={() => {
window.open('#/statistics', 'blank');
}}
>
{getLabel(547313, labelData)}
</Button>{' '}
</span>
)}
2023-07-06 16:23:45 +08:00
2022-09-06 13:46:56 +08:00
<Button
type="primary"
style={{ marginRight: '10px' }}
onClick={() => {
this.props.onSearch(this.state.requestData);
}}
>
2024-06-05 16:01:37 +08:00
{getLabel(547307, labelData)}
2022-09-06 13:46:56 +08:00
</Button>
2024-07-04 09:44:19 +08:00
2023-06-27 14:12:42 +08:00
<Dropdown overlay={this.menu}>
2024-06-05 16:01:37 +08:00
<Button type="primary">{getLabel(547314, labelData)}</Button>
2022-09-06 13:46:56 +08:00
</Dropdown>
</Col>
</Row>
2023-06-28 17:38:16 +08:00
<Modal
2024-06-05 16:01:37 +08:00
title={getLabel(547305, labelData)}
cancelText={getLabel(547318, labelData)}
okText={getLabel(547319, labelData)}
2023-06-28 17:38:16 +08:00
open={open}
onOk={this.handleOk}
confirmLoading={confirmLoading}
onCancel={() => this.setState({ open: false })}
>
2024-06-05 16:01:37 +08:00
<p style={{ color: 'red' }}>{getLabel(547316, labelData)}</p>
<p>{getLabel(547317, labelData)}:</p>
2023-06-28 17:38:16 +08:00
<TextArea
showCount
2024-06-05 16:01:37 +08:00
maxLength={20}
2023-06-28 17:38:16 +08:00
style={{ height: 120, resize: 'none' }}
onChange={this.onChange}
placeholder="please enter"
/>
</Modal>
2022-09-06 13:46:56 +08:00
</div>
);
}
}