salary-management-front/pc4mobx/hrmSalary/pages/socialSecurityBenefits/programme/customBenefitsTable.js

136 lines
3.9 KiB
JavaScript

/*
* Author: 黎永顺
* name: 社保福利方案-自定义福利表格
* Description:
* Date: 2023/3/2
*/
import React, { Component } from "react";
import { WeaCheckbox, WeaTable } from "ecCom";
import { message, Modal } from "antd";
import { getCustomCategoryList, updateCustomCategoryStatus } from "../../../apis/welfareScheme";
class CustomBenefitsTable extends Component {
constructor(props) {
super(props);
this.state = {
loading: {
query: false
},
dataSource: [],
columns: [],
pageInfo: {
current: 1,
pageSize: 10,
total: 0
}
};
}
componentDidMount() {
this.getCustomCategoryList();
}
getCustomCategoryList = (extraPayload) => {
const { loading, pageInfo } = this.state;
const { welfareTypeEnum } = this.props;
const module = { welfareTypeEnum, ...pageInfo, ...extraPayload };
this.setState({ loading: { ...loading, query: true } });
getCustomCategoryList(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 } }));
};
getColumns = () => {
const { columns } = this.state;
const { showOperateBtn, onCustomEdit } = this.props;
return [..._.map(_.filter(columns, item => !!item.display), child => ({
...child,
render: (text, record) => {
switch (child.dataIndex) {
case "isUse":
return (
<WeaCheckbox
value={text} display="switch" disabled={!showOperateBtn}
onChange={value => this.handleCustomBenefitsSwitch(record, value)}
/>
);
case "welfareType":
return <span>{record.welfareTypeSpan}</span>;
case "paymentScopt":
return <span>{record.paymentScopeSpan}</span>;
default:
return <div dangerouslySetInnerHTML={{ __html: text }}/>;
}
}
})), {
title: "操作",
width: 120,
dataIndex: "operate",
render: (_, record) => {
return (
<div className="linkWapper">
{showOperateBtn &&
<a href="javascript: void(0);" onClick={() => onCustomEdit(record)}>编辑</a>
}
</div>
);
}
}];
};
handleCustomBenefitsSwitch = ({ id }, isUse) => {
Modal.confirm({
title: "信息确认",
content: `确认要${isUse === "1" ? "启用" : "停用"}`,
onOk: () => {
const payload = { id, isUse };
updateCustomCategoryStatus(payload).then(({ status, errormsg }) => {
if (status) {
message.success("操作成功");
this.getCustomCategoryList();
} else {
message.error(errormsg || "操作失败");
}
});
}
});
};
render() {
const { dataSource, 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.getCustomCategoryList());
},
onChange: current => {
this.setState({
pageInfo: { ...pageInfo, current }
}, () => this.getCustomCategoryList());
}
};
return (
<WeaTable
columns={this.getColumns()}
dataSource={dataSource}
pagination={pagination}
loading={loading.query}
/>
);
}
}
export default CustomBenefitsTable;