/* * Author: 黎永顺 * name: 社保福利方案-自定义福利表格 * Description: * Date: 2023/3/2 */ import React, { Component } from "react"; import { WeaCheckbox, WeaLocaleProvider, WeaTable } from "ecCom"; import { message, Modal } from "antd"; import { deleteCustomCategory, getCustomCategoryList, updateCustomCategoryStatus } from "../../../apis/welfareScheme"; const { getLabel } = WeaLocaleProvider; 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 ( this.handleCustomBenefitsSwitch(record, value)} /> ); case "welfareType": return {record.welfareTypeSpan}; case "paymentScopt": return {record.paymentScopeSpan}; default: return
; } } })), { title: "操作", width: 120, dataIndex: "operate", render: (_, record) => { return (
{showOperateBtn && onCustomEdit(record)} style={{ marginRight: 10 }}>编辑 this.deleteCustomCategory(record.id)}>{getLabel(535052, "删除")} }
); } }]; }; 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 || "操作失败"); } }); }, onCancel: () => { this.setState({ dataSource: _.map(this.state.dataSource, item => { if (item.id === id) { return { ...item, isUse: item.isUse }; } return { ...item }; }) }); } }); }; deleteCustomCategory = (id) => { Modal.confirm({ title: getLabel(131329, "信息确认"), content: getLabel(543231, "确认删除本条数据吗?"), onOk: () => { message.destroy(); message.loading(getLabel(529063, "正在删除中..."), 0); const payload = { id }; deleteCustomCategory(payload).then(({ status, errormsg }) => { message.destroy(); if (status) { message.success(getLabel(502230, "删除成功")); this.getCustomCategoryList(); } else { message.error(errormsg || getLabel(30651, "操作失败")); } }).catch(() => message.destroy()); } }); }; 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 ( ); } } export default CustomBenefitsTable;