203 lines
6.5 KiB
JavaScript
203 lines
6.5 KiB
JavaScript
/*
|
||
* Author: 黎永顺
|
||
* name: 工资单发放撤回弹框列表
|
||
* Description:
|
||
* Date: 2022/12/2
|
||
*/
|
||
import React, { Component } from "react";
|
||
import { Button, message, Modal } from "antd";
|
||
import { WeaButtonIcon, WeaDialog, WeaInputSearch, WeaTable, WeaLocaleProvider } from "ecCom";
|
||
import { sendRangeDelete, sendRangeList } from "../../../apis/payroll";
|
||
import { calcPageNo } from "../../../util";
|
||
import PayrollPartModal from "./payrollPartModal";
|
||
|
||
const getLabel = WeaLocaleProvider.getLabel;
|
||
class PayrollPartTable extends Component {
|
||
constructor(props) {
|
||
super(props);
|
||
this.state = {
|
||
searchValue: "",
|
||
dialogVisible: false,
|
||
loading: {
|
||
query: false
|
||
},
|
||
dataSource: [],
|
||
columns: [],
|
||
selectedRowKeys: [],
|
||
pageInfo: {
|
||
current: 1,
|
||
pageSize: 10,
|
||
total: 0
|
||
}
|
||
};
|
||
}
|
||
|
||
componentWillReceiveProps(nextProps, nextContext) {
|
||
if (nextProps.visible !== this.props.visible) {
|
||
nextProps.visible && this.sendRangeList(nextProps);
|
||
this.setState({ selectedRowKeys: [] });
|
||
}
|
||
}
|
||
|
||
sendRangeList = (props) => {
|
||
const { grantType, salarySendId, pageCurrent = {} } = props;
|
||
const { pageInfo, loading, searchValue: targetName } = this.state;
|
||
const payload = {
|
||
grantType,
|
||
salarySendId,
|
||
targetName,
|
||
...pageInfo,
|
||
...pageCurrent
|
||
};
|
||
this.setState({ loading: { ...loading, query: true } });
|
||
sendRangeList(payload).then(({ status, data }) => {
|
||
this.setState({ loading: { ...loading, query: false } });
|
||
if (status) {
|
||
const { pageNum: current, pageSize, total, columns, list: dataSource } = data;
|
||
this.setState({
|
||
pageInfo: { ...pageInfo, current, pageSize, total },
|
||
dataSource: _.map(dataSource, it => ({
|
||
...it,
|
||
includeObj: _.map(it.includeObj, child => child.targetName || child.targetTypeName).join(","),
|
||
excludeObj: _.map(it.excludeObj, child => child.targetName || child.targetTypeName).join(",")
|
||
})),
|
||
columns
|
||
});
|
||
}
|
||
});
|
||
};
|
||
sendRangeDelete = () => {
|
||
const { selectedRowKeys, pageInfo } = this.state;
|
||
const { grantType, salarySendId } = this.props;
|
||
Modal.confirm({
|
||
title: getLabel(111, "信息确认"),
|
||
content: getLabel(111, "确认要删除吗?"),
|
||
onOk: () => {
|
||
sendRangeDelete(selectedRowKeys).then(({ status, errormsg }) => {
|
||
if (status) {
|
||
message.success(getLabel(111, "刪除成功"));
|
||
this.setState({ selectedRowKeys: [] }, () => {
|
||
this.sendRangeList({
|
||
grantType, salarySendId,
|
||
pageCurrent: {
|
||
current: calcPageNo(pageInfo.total, pageInfo.current, 10, selectedRowKeys.length)
|
||
}
|
||
});
|
||
});
|
||
} else {
|
||
message.error(errormsg || getLabel(111, "刪除失败"));
|
||
}
|
||
});
|
||
},
|
||
onCancel: () => {
|
||
}
|
||
});
|
||
};
|
||
handleOperate = () => {
|
||
const { grantType, salarySendId, onWithdraw, onGrant } = this.props;
|
||
const { selectedRowKeys } = this.state;
|
||
if (_.isEmpty(selectedRowKeys)) {
|
||
message.warning(getLabel(111, "您没有需要处理的对象!"));
|
||
return;
|
||
}
|
||
Modal.confirm({
|
||
title: getLabel(111, "信息确认"),
|
||
content: `${getLabel(111, "您共选择")}${selectedRowKeys.length}${getLabel(111, "个对象")},${getLabel(111, "确定要")}${grantType === "grant" ? getLabel(111, "发放") : getLabel(111, "撤回")}?`,
|
||
onCancel: () => {
|
||
},
|
||
onOk: () => {
|
||
if (grantType === "grant") {
|
||
onGrant({ ids: [salarySendId], salarySendRangeIds: selectedRowKeys });
|
||
} else if (grantType === "withdraw") {
|
||
onWithdraw({ ids: [salarySendId], salarySendRangeIds: selectedRowKeys });
|
||
}
|
||
}
|
||
});
|
||
};
|
||
|
||
render() {
|
||
const { dataSource, columns, pageInfo, loading, selectedRowKeys, dialogVisible, searchValue } = this.state;
|
||
const { onCancel, visible, grantType, salarySendId, title } = this.props;
|
||
const pagination = {
|
||
...pageInfo,
|
||
showTotal: total => `${getLabel(83698, "共")} ${total} ${getLabel(18256, "条")}`,
|
||
showQuickJumper: true,
|
||
pageSizeOptions: ["10", "20", "50", "100"],
|
||
onChange: current => {
|
||
this.setState({
|
||
pageInfo: { ...pageInfo, current }
|
||
}, () => {
|
||
});
|
||
}
|
||
};
|
||
const rowSelection = {
|
||
selectedRowKeys,
|
||
onChange: (selectedRowKeys) => this.setState({ selectedRowKeys })
|
||
};
|
||
return (
|
||
<WeaDialog
|
||
initLoadCss
|
||
className="payrollPartTableModalWrapper"
|
||
onCancel={() => this.setState({ selectedRowKeys: [] }, () => onCancel())}
|
||
title={
|
||
<RenderTitle
|
||
title={title}
|
||
selectedRowKeys={selectedRowKeys}
|
||
onAdd={() => this.setState({ dialogVisible: true })}
|
||
onDelete={this.sendRangeDelete}
|
||
onSave={this.handleOperate}
|
||
/>
|
||
}
|
||
visible={visible}
|
||
style={{ width: 700, height: 600 }}
|
||
hasScroll
|
||
>
|
||
<div style={{ display: "flex", justifyContent: "flex-end", margin: "10px 10px 10px 0" }}>
|
||
<WeaInputSearch
|
||
style={{ width: 220 }}
|
||
searchValue={searchValue}
|
||
onChange={(searchValue) => this.setState({ searchValue })}
|
||
onSearch={() => this.sendRangeList({ grantType, salarySendId })}
|
||
placeholder={getLabel(111, "请输入方案名称")}
|
||
/>
|
||
</div>
|
||
<WeaTable
|
||
rowKey="id"
|
||
rowSelection={rowSelection}
|
||
dataSource={dataSource}
|
||
pagination={pagination}
|
||
loading={loading.query}
|
||
columns={columns}
|
||
/>
|
||
<PayrollPartModal
|
||
grantType={grantType}
|
||
salarySendId={salarySendId}
|
||
visible={dialogVisible}
|
||
onCancel={() => this.setState({ dialogVisible: false }, () => {
|
||
this.sendRangeList({ grantType, salarySendId });
|
||
})}
|
||
/>
|
||
</WeaDialog>
|
||
);
|
||
}
|
||
}
|
||
|
||
export default PayrollPartTable;
|
||
|
||
const RenderTitle = (props) => {
|
||
const { title, selectedRowKeys, onAdd, onDelete, onSave } = props;
|
||
return <div className="titleWrapper">
|
||
<div>{title}</div>
|
||
<div className="rightBtnlist">
|
||
<Button type="primary" onClick={onSave}>{title.slice(-2)}</Button>
|
||
<WeaButtonIcon
|
||
buttonType="del"
|
||
type="primary"
|
||
disabled={_.isEmpty(selectedRowKeys)}
|
||
onClick={onDelete}
|
||
/>
|
||
<WeaButtonIcon buttonType="add" type="primary" onClick={onAdd}/>
|
||
</div>
|
||
</div>;
|
||
};
|