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/topBar/index.jsx

238 lines
5.6 KiB
React

import React from 'react';
import style from './index.less';
import {
DatePicker,
Select,
Button,
Checkbox,
Row,
Col,
Dropdown,
Menu,
TreeSelect,
} from 'antd';
const { Option } = Select;
import moment from 'moment';
import 'moment/locale/zh-cn';
import locale from 'antd/lib/date-picker/locale/zh_CN';
moment.locale('zh-cn');
export class TopBar extends React.Component {
constructor(props) {
super(props);
this.state = {
fclasslist: [],
rootTreeData: [], //根节点异步树
treeExpandedKeys: [],
requestData: {
fclass: '0',
root: undefined,
level: '3',
fisvitual: '0',
},
};
}
/**
* 表单值改变
* @param {*} payload
*/
handleFormChange(payload) {
let requestData = { ...this.state.requestData, ...payload };
this.setState({ requestData });
}
/**
* 组织维度改变
*/
changeFclass() {
debugger;
this.getSeatchCondition(this.props.url);
}
handleExportMenuClick(e) {
this.props.onExport(e.key == '1' ? 'png' : 'pdf');
}
handleExportButtonClick() {
this.props.onExport('png');
}
/**
* 根节点树数据
* @param {} parentId
* @returns
*/
getNodeTreeNode = (parentId) => {
const { fclass } = this.state.requestData;
let api =
'/api/bs/hrmorganization/orgchart/getSubCompanyTree?subcompany=' +
parentId +
'&fclass=' +
fclass;
fetch(api)
.then((res) => res.json())
.then((data) => {
if (data.api_status) {
let arr = [...this.state.rootTreeData, ...data.companyTree];
this.setState({
rootTreeData: arr,
});
}
});
};
/**
* 根节点树异步加载
* @param {} parentId
* @returns
*/
onRootLoadData = (treeNode) =>
new Promise((resolve) => {
const { id } = treeNode.props;
setTimeout(() => {
this.getNodeTreeNode(id);
resolve(undefined);
}, 1000);
});
onRootChange = (value) => {
debugger;
let requestData = { ...this.state.requestData, root: value };
this.setState({ requestData });
};
onTreeExpand = (expandedKeys) => {
this.setState({
treeExpandedKeys: expandedKeys,
});
};
componentDidMount() {
this.getSeatchCondition(this.props.url);
}
getSeatchCondition = (url) => {
fetch(url)
.then((res) => res.json())
.then((data) => {
this.setState({
fclasslist: data.fclasslist,
rootTreeData: data.companyTree,
});
});
};
menu = (
<Menu
onClick={this.handleExportMenuClick.bind(this)}
items={[
{
label: '导出图片',
key: '1',
},
{
label: '导出PDF',
key: '2',
},
]}
/>
);
render() {
2 years ago
const { disabled } = this.props;
debugger;
const { rootTreeData } = this.state;
2 years ago
return (
<div className={style.topbarWrapper}>
<Row>
2 years ago
<Col span={6}>
维度
<Select
defaultValue="0"
style={{ width: 140 }}
value={this.state.requestData.fclass}
onChange={(value) => {
this.handleFormChange({ fclass: value });
this.props.onSearch(this.state.requestData);
}}
>
{this.state.fclasslist.map((item) => (
<Option key={item.key} value={item.id}>
{item.companyname}
</Option>
))}
</Select>
</Col>
2 years ago
<Col span={6}>
根节点
<TreeSelect
treeDataSimpleMode
allowClear
style={{ width: '80%' }}
value={this.state.requestData.root}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
placeholder="请选择根节点"
onChange={this.onRootChange}
loadData={this.onRootLoadData}
treeData={rootTreeData}
/>
</Col>
<Col span={6}>
<Checkbox
style={{ marginTop: '5px', marginLeft: 100 }}
onChange={(e) =>
this.handleFormChange({
fisvitual: e.target.checked ? '1' : '0',
})
}
>
显示虚拟组织
</Checkbox>
</Col>
2 years ago
<Col span={6}>
显示层级
<Select
defaultValue="3"
style={{ width: 140 }}
value={this.state.requestData.level}
onChange={(value) => this.handleFormChange({ level: value })}
>
<Option value="1">一级</Option>
<Option value="2">二级</Option>
<Option value="3">三级</Option>
</Select>
</Col>
2 years ago
</Row>
<Row style={{ marginTop: '15px' }}>
<Col span={8}>
2 years ago
<Button
type="primary"
style={{ marginRight: '10px' }}
2 years ago
disabled={disabled}
2 years ago
onClick={() => {
this.props.onSynchronous(this.state.requestData);
}}
>
版本记录
2 years ago
</Button>
<Button
type="primary"
style={{ marginRight: '10px' }}
onClick={() => {
this.props.onSearch(this.state.requestData);
}}
>
查询
</Button>
<Dropdown overlay={this.menu}>
<Button>导出</Button>
</Dropdown>
</Col>
</Row>
</div>
);
}
}