salary-management-front/pc4mobx/hrmSalary/pages/dataAcquisition/dataTables.js

166 lines
5.1 KiB
JavaScript
Raw Normal View History

2023-02-17 17:21:05 +08:00
/*
* Author: 黎永顺
* name: 数据采集-列表
* Description:
* Date: 2023/2/17
*/
import React, { Component } from "react";
import UnifiedTable from "../../components/UnifiedTable";
import { getTableDate } from "../../apis/cumDeduct";
import { Menu, Popover } from "antd";
class DataTables extends Component {
constructor(props) {
super(props);
this.state = {
loading: {
query: false
},
dataSource: [],
columns: [],
selectedRowKeys: [],
pageInfo: {
current: 1, pageSize: 10, total: 0
}
};
}
componentDidMount() {
this.getTableDate();
}
2023-02-20 14:28:08 +08:00
getTableDate = (extraPayload = {}) => {
2023-02-17 17:21:05 +08:00
const { loading, pageInfo } = this.state;
const { url, payload } = this.props;
2023-02-20 14:28:08 +08:00
const module = { ...pageInfo, url, ...payload, ...extraPayload };
2023-02-17 17:21:05 +08:00
this.setState({ loading: { ...loading, query: true } });
getTableDate(module).then(({ status, data }) => {
this.setState({ loading: { ...loading, query: false } });
if (status) {
const { columns, list: dataSource, pageNum: current, pageSize, total } = data;
this.setState({
pageInfo: { ...pageInfo, current, pageSize, total },
dataSource,
columns
});
}
}).catch(() => this.setState({ loading: { ...loading, query: false } }));
};
2023-02-20 10:24:40 +08:00
/*
* Author: 黎永顺
* Description: 清空所选
* Params:
* Date: 2023/2/20
*/
handleClearRows = () => this.setState({ selectedRowKeys: [] });
2023-02-17 17:21:05 +08:00
render() {
2023-02-20 09:41:36 +08:00
const { columns, dataSource, loading, selectedRowKeys, pageInfo } = this.state;
2023-02-23 15:59:28 +08:00
const { showOperateBtn, onTableOperate, onViewDetails, isSpecial = false, form } = this.props;
2023-02-20 09:41:36 +08:00
const rowSelection = {
selectedRowKeys,
onChange: (selectedRowKeys) => this.setState({ selectedRowKeys })
};
const pagination = {
...pageInfo,
showTotal: (total) => `${total}`,
pageSizeOptions: ["10", "20", "50", "100"],
showSizeChanger: true,
showQuickJumper: true,
onShowSizeChange: (current, pageSize) => {
this.setState({
pageInfo: { ...pageInfo, current, pageSize }
}, () => {
2023-02-23 15:59:28 +08:00
this.getTableDate({ ...form.getFormParams() });
2023-02-20 09:41:36 +08:00
});
},
onChange: (current) => {
this.setState({
pageInfo: { ...pageInfo, current }
}, () => {
2023-02-23 15:59:28 +08:00
this.getTableDate({ ...form.getFormParams() });
2023-02-20 09:41:36 +08:00
});
}
};
2023-03-20 18:00:36 +08:00
const getColumns = _.map(columns, item => {
const { dataIndex } = item;
if (dataIndex === "username") {
return {
...item,
render: (text, record) => {
return <a
className="ellipsis"
href={`javaScript:openhrm(${record.employeeId});`}
onClick={e => window.pointerXY(e)}
title={text}
>
{text}
</a>;
}
};
} else if (dataIndex === "operate") {
return {
...item,
2023-07-03 15:42:11 +08:00
width: 150,
2023-03-20 18:00:36 +08:00
render: (text, record) => (
<div className="linkWapper">
{
!isSpecial &&
<React.Fragment>
2023-07-03 15:42:11 +08:00
<a href="javaScript:void(0);" style={{ marginRight: 12 }}
onClick={() => onTableOperate({ key: "handleAddData" }, record)}>编辑</a>
<a href="javaScript:void(0);" style={{ marginRight: 12 }}
onClick={() => onViewDetails(record)}>查看明细</a>
2023-03-20 18:00:36 +08:00
{
showOperateBtn &&
<Popover
overlayClassName="moreIconWrapper"
placement="bottomRight"
content={<Menu onClick={(e) => onTableOperate(e, record)}>
<Menu.Item key="deleteSelectAddUpDeduction">删除</Menu.Item>
</Menu>} title="">
<i className="icon-coms-more"/>
</Popover>
}
</React.Fragment>
}
{
isSpecial &&
<React.Fragment>
{
showOperateBtn &&
<React.Fragment>
2023-07-03 15:42:11 +08:00
<a href="javaScript:void(0);" style={{ marginRight: 12 }}
2023-03-20 18:00:36 +08:00
onClick={() => onTableOperate({ key: "handleAddData" }, record)}>编辑</a>
<a href="javaScript:void(0);"
onClick={() => onTableOperate({ key: "deleteSelectAddUpDeduction" }, record)}>删除</a>
</React.Fragment>
}
</React.Fragment>
}
</div>
)
};
} else {
return {
...item,
render: (text) => {
return <span className="ellipsis" title={text}> {text} </span>;
}
};
}
});
2023-02-17 17:21:05 +08:00
return <UnifiedTable
rowKey="id"
2023-02-20 09:41:36 +08:00
rowSelection={rowSelection}
2023-03-20 18:00:36 +08:00
columns={getColumns}
2023-02-17 17:21:05 +08:00
dataSource={dataSource}
2023-02-20 09:41:36 +08:00
pagination={pagination}
2023-02-17 17:21:05 +08:00
loading={loading.query}
xWidth={getColumns.length * 160}
2023-02-17 17:21:05 +08:00
/>;
}
}
export default DataTables;