salary-management-front/pc4mobx/hrmSalary/pages/ledgerPage/components/ledgerTable.js

94 lines
2.4 KiB
JavaScript

/*
* Author: 黎永顺
* name: 薪资账套列表
* Description:
* Date: 2022/12/7
*/
import React, { Component } from "react";
import { WeaCheckbox, WeaTable } from "ecCom";
import { getLedgerList } from "../../../apis/ledger";
class LedgerTable extends Component {
constructor(props) {
super(props);
this.state = {
loading: false,
dataSource: [],
columns: [],
pageInfo: {
current: 1,
pageSize: 10,
total: 0
}
};
}
componentDidMount() {
this.getLedgerList();
}
getLedgerList = () => {
const { name } = this.props;
const { pageInfo } = this.state;
const payload = { name, ...pageInfo };
this.setState({ loading: true });
getLedgerList(payload).then(({ status, data }) => {
this.setState({ loading: false });
if (status) {
const { pageNum: current, pageSize, total, columns, list: dataSource } = data;
this.setState({
pageInfo: { ...pageInfo, current, pageSize, total },
dataSource,
columns: _.map(columns, item => {
const { dataIndex } = item;
if (dataIndex === "disable") {
item.render = (text) => {
return <WeaCheckbox value={text === 0 ? "1" : "0"} display="switch"/>;
};
} else {
item.render = (text) => {
return <span className="tdEllipsis" title={text}>{text}</span>;
};
}
return { ...item };
})
});
}
});
};
render() {
const { dataSource, columns, pageInfo, loading } = this.state;
const pagination = {
...pageInfo,
showTotal: total => `${total}`,
showQuickJumper: true,
showSizeChanger: true,
pageSizeOptions: ["10", "20", "50", "100"],
onShowSizeChange: (current, pageSize) => {
this.setState({ pageInfo: { ...pageInfo, current, pageSize } }, () => {
this.getLedgerList();
});
},
onChange: current => {
this.setState({
pageInfo: { ...pageInfo, current }
}, () => {
this.getLedgerList();
});
}
};
return (
<WeaTable
rowKey="id"
dataSource={dataSource}
pagination={pagination}
loading={loading}
columns={columns}
/>
);
}
}
export default LedgerTable;