salary-management-oneself/src/pages/unitTable/renderColsOpts.tsx

505 lines
18 KiB
TypeScript
Raw Normal View History

2024-01-24 15:35:50 +08:00
import React from "react";
2024-02-22 15:06:29 +08:00
import { Button, Dropdown, MenuProps, Space, Tooltip, Typography } from "antd";
import { MoreOutlined, QuestionCircleFilled } from "@ant-design/icons";
2024-02-28 15:19:37 +08:00
import { extraType } from "@/pages/unitTable/index";
2024-01-24 15:35:50 +08:00
const { Text } = Typography;
/*
* Author: 黎永顺
* Description:社保福利台账列表项
* Params:
* Date: 2024/1/23
*/
2024-02-28 15:19:37 +08:00
export function renderCols(initialState: any[], type: string, i18n?: AnyObject, extraParams?: Partial<extraType>) {
2024-01-24 15:35:50 +08:00
return React.useMemo(() => {
if (type === "welfareRecord") {
2024-10-30 18:07:56 +08:00
return [
..._.map(
_.filter(initialState, (o) => o.dataIndex !== "id"),
(g) => {
let col = { ...g, ellipsis: true, fixed: g.dataIndex === "billMonth", width: 180 };
switch (g.dataIndex) {
case "billMonth":
col = {
...col,
width: 120,
render: (text: string, record: any) => {
const { billStatus } = record;
return (
<Button type="link" onClick={() => postMessageToParent(billStatus === "0" && extraParams?.permission ? "CALC" : "VIEW", record)}>
{text}
</Button>
);
}
};
break;
case "billStatus":
col = {
...col,
width: 100,
render: (text: string) => (
<Text style={{ maxWidth: "100%" }} ellipsis>
{text === "1" ? i18n?.["已归档"] : i18n?.["未归档"]}
</Text>
)
};
break;
case "paymentOrganization":
col = { ...col, width: 200 };
break;
case "socialNum":
case "otherNum":
case "fundNum":
col = { ...col, width: 118 };
break;
case "remarks":
col = { ...col, width: 200 };
break;
default:
col = { ...col };
break;
2024-01-24 15:35:50 +08:00
}
2024-10-30 18:07:56 +08:00
return col;
}
),
{
dataIndex: "operate",
title: i18n?.["操作"],
width: 185,
fixed: "right",
render: (__: string, record: any) => {
2024-11-05 15:26:05 +08:00
const { billStatus, customOptAuth } = record;
2024-10-30 18:07:56 +08:00
const items: MenuProps["items"] = [
{
key: "DeleteList",
label: i18n?.["删除"],
onClick: () => postMessageToParent("DELRC", record)
},
2024-01-24 15:35:50 +08:00
{
2024-10-30 18:07:56 +08:00
key: "Log",
label: i18n?.["操作日志"],
onClick: () => postMessageToParent("log", record)
}
];
return (
<Space>
{!extraParams?.permission ? (
2024-02-28 15:19:37 +08:00
<Space>
2024-10-30 18:07:56 +08:00
<Button type="link" onClick={() => postMessageToParent("VIEW", record)}>
{i18n?.["查看"]}
</Button>
<Dropdown
menu={{
items: [
{
key: "Log",
label: i18n?.["操作日志"],
onClick: () => postMessageToParent("log", record)
}
]
}}
placement="bottomRight"
>
<Button type="link" icon={<MoreOutlined />} />
2024-02-29 10:12:40 +08:00
</Dropdown>
2024-10-30 18:07:56 +08:00
</Space>
) : (
2024-01-24 15:35:50 +08:00
<>
2024-10-30 18:07:56 +08:00
{billStatus === "0" && (
2024-01-24 15:35:50 +08:00
<>
2024-10-30 18:07:56 +08:00
<Button type="link" onClick={() => postMessageToParent("CALC", record)}>
{i18n?.["核算"]}
</Button>
2024-11-05 15:26:05 +08:00
{(_.isEmpty(customOptAuth) || customOptAuth.FILE) && (
<Button type="link" onClick={() => postMessageToParent("FILE", record)}>
{i18n?.["归档"]}
</Button>
)}
2024-01-24 15:35:50 +08:00
<Dropdown menu={{ items }} placement="bottomRight">
2024-10-30 18:07:56 +08:00
<Button type="link" icon={<MoreOutlined />} />
2024-01-24 15:35:50 +08:00
</Dropdown>
</>
2024-10-30 18:07:56 +08:00
)}
{billStatus === "1" && (
2024-01-24 15:35:50 +08:00
<>
2024-10-30 18:07:56 +08:00
<Button type="link" onClick={() => postMessageToParent("VIEW", record)}>
{i18n?.["查看"]}
</Button>
2024-11-05 15:26:05 +08:00
{(_.isEmpty(customOptAuth) || customOptAuth.RECALC) && (
<Button type="link" onClick={() => postMessageToParent("RECALC", record)}>
{i18n?.["重新核算"]}
</Button>
)}
2024-10-30 18:07:56 +08:00
<Dropdown
menu={{
items: [
{
key: "Log",
label: i18n?.["操作日志"],
onClick: () => postMessageToParent("log", record)
}
]
}}
placement="bottomRight"
>
<Button type="link" icon={<MoreOutlined />} />
2024-02-28 15:19:37 +08:00
</Dropdown>
2024-01-24 15:35:50 +08:00
</>
2024-10-30 18:07:56 +08:00
)}
2024-01-24 15:35:50 +08:00
</>
2024-10-30 18:07:56 +08:00
)}
2024-02-22 15:06:29 +08:00
</Space>
2024-10-30 18:07:56 +08:00
);
}
2024-02-21 15:49:16 +08:00
}
2024-10-30 18:07:56 +08:00
];
} else if (type === "bonusplan") {
return [
..._.map(initialState, (g) => {
let col = { ...g, ellipsis: true, fixed: false, width: 150 };
switch (g.dataIndex) {
case "taxYear":
case "fileStatusDesc":
col = { ...col, width: 80 };
break;
case "billStatus":
col = {
...col,
width: 100,
render: (text: string) => (
<Text style={{ maxWidth: "100%" }} ellipsis>
{text === "1" ? i18n?.["已归档"] : i18n?.["未归档"]}
</Text>
)
};
break;
case "optimizedBonusSum":
col = { ...col, width: 220 };
break;
case "employeeCount":
col = {
...col,
title: (
<Space>
<Text>{g.title}</Text>
<Tooltip placement="top" title={i18n?.["若同一个人 在两个个税扣缴义务人下 同一纳税年度 同时发年终奖,统计为两个人"]}>
<QuestionCircleFilled />
</Tooltip>
</Space>
)
};
break;
default:
col = { ...col };
break;
}
return col;
}),
{
dataIndex: "operate",
title: i18n?.["操作"],
width: 185,
fixed: "right",
render: (__: string, record: any) => {
const { fileStatus } = record;
const items: MenuProps["items"] = [
2024-02-22 15:06:29 +08:00
{
2024-10-30 18:07:56 +08:00
key: "FileList",
label: fileStatus === 0 ? i18n?.["归档"] : i18n?.["取消归档"],
onClick: () => postMessageToParent("FILE", record)
},
{
key: "DeleteList",
label: i18n?.["删除"],
onClick: () => postMessageToParent("DEL", record)
},
{
key: "Log",
label: i18n?.["操作日志"],
onClick: () => postMessageToParent("log", record)
}
];
return (
<Space>
{!extraParams?.permission ? (
2024-02-28 15:19:37 +08:00
<Space>
2024-10-30 18:07:56 +08:00
<Button type="link" onClick={() => postMessageToParent("VIEW", record)}>
{i18n?.["查看详情"]}
</Button>
2024-02-29 17:05:59 +08:00
<Dropdown menu={{ items: items.slice(-1) }} placement="bottomRight">
2024-10-30 18:07:56 +08:00
<Button type="link" icon={<MoreOutlined />} />
2024-02-29 17:05:59 +08:00
</Dropdown>
2024-10-30 18:07:56 +08:00
</Space>
) : (
2024-02-22 15:06:29 +08:00
<>
2024-10-30 18:07:56 +08:00
<Button type="link" onClick={() => postMessageToParent("VIEW", record)}>
{i18n?.["查看详情"]}
</Button>
<Button type="link" onClick={() => postMessageToParent("EDIT", record)}>
{i18n?.["编辑"]}
</Button>
2024-02-22 15:06:29 +08:00
<Dropdown menu={{ items }} placement="bottomRight">
2024-10-30 18:07:56 +08:00
<Button type="link" icon={<MoreOutlined />} />
2024-02-22 15:06:29 +08:00
</Dropdown>
</>
2024-10-30 18:07:56 +08:00
)}
</Space>
);
}
2024-02-22 15:06:29 +08:00
}
2024-10-30 18:07:56 +08:00
];
2024-02-28 15:19:37 +08:00
} else if (type === "bonusStrategy") {
const { selectedKey } = extraParams as { selectedKey: string };
2024-10-30 18:07:56 +08:00
return [
..._.map(initialState, (g) => {
let col = { ...g, ellipsis: true, fixed: false, width: 120 };
switch (g.dataIndex) {
case "username":
col = { ...col, fixed: "left" };
break;
case "taxAgentName":
col = { ...col, width: 200, fixed: "left" };
break;
case "idNo":
col = { ...col, width: 150 };
break;
case "originalTaxTypeDesc":
case "originalBonus":
case "originalTax":
case "originalIncome":
col = {
...col,
render: (text: string) => <div style={{ color: "rgb(93, 156, 236)" }}>{text}</div>
};
break;
case "optimizedTaxTypeDesc":
case "optimizedBonus":
case "optimizedTax":
case "optimizedIncome":
col = { ...col, render: (text: string) => <Text type="success">{text}</Text> };
break;
case "companySave":
case "employeeGain":
col = { ...col, render: (text: string) => <Text type="warning">{text}</Text> };
break;
default:
col = { ...col };
break;
}
return col;
}),
{
dataIndex: "operate",
title: i18n?.["操作"],
width: 185,
fixed: "right",
render: (__: string, record: any) => {
let items: MenuProps["items"] = [
2024-02-28 15:19:37 +08:00
{
2024-10-30 18:07:56 +08:00
key: "DeleteList",
label: i18n?.["删除"],
onClick: () => postMessageToParent("DEL", record)
},
{
key: "Log",
label: i18n?.["操作日志"],
onClick: () => postMessageToParent("log", record)
}
];
selectedKey === "getAnnualbonusaddupList" && items.shift();
return (
<Space>
{!extraParams?.permission ? (
2024-02-28 15:19:37 +08:00
<Space>
2024-10-30 18:07:56 +08:00
{selectedKey === "getAnnualbonusstrategyList" && (
<Button type="link" onClick={() => postMessageToParent("VIEW", record)}>
{i18n?.["查看详情"]}
</Button>
)}
<Button type="link" onClick={() => postMessageToParent("log", record)}>
{i18n?.["操作日志"]}
</Button>
</Space>
) : (
2024-02-28 15:19:37 +08:00
<>
2024-10-30 18:07:56 +08:00
<Button type="link" onClick={() => postMessageToParent("EDIT", record)}>
{i18n?.["编辑"]}
</Button>
{selectedKey === "getAnnualbonusstrategyList" && (
<Button type="link" onClick={() => postMessageToParent("VIEW", record)}>
{i18n?.["查看详情"]}
</Button>
)}
{selectedKey === "getAnnualbonusaddupList" && (
<Button type="link" onClick={() => postMessageToParent("DEL", record)}>
{i18n?.["删除"]}
</Button>
)}
2024-02-28 15:19:37 +08:00
<Dropdown menu={{ items }} placement="bottomRight">
2024-10-30 18:07:56 +08:00
<Button type="link" icon={<MoreOutlined />} />
2024-02-28 15:19:37 +08:00
</Dropdown>
</>
2024-10-30 18:07:56 +08:00
)}
</Space>
);
}
2024-02-28 15:19:37 +08:00
}
2024-10-30 18:07:56 +08:00
];
2024-08-13 17:59:55 +08:00
} else if (type === "variableSalary") {
2024-10-30 18:07:56 +08:00
return [
..._.map(initialState, (g) => {
return { ...g, ellipsis: true, fixed: false, width: 150 };
}),
{
dataIndex: "operate",
title: i18n?.["操作"],
width: 185,
fixed: "right",
render: (__: string, record: any) => {
return (
<Space>
<Button type="link" onClick={() => postMessageToParent("EDIT", record)}>
{i18n?.["编辑"]}
</Button>
<Button type="link" onClick={() => postMessageToParent("DEL", record)}>
{i18n?.["删除"]}
</Button>
</Space>
);
}
2024-08-13 17:59:55 +08:00
}
2024-10-30 18:07:56 +08:00
];
} else if (type === "dataAcquisition") {
const { isSpecial } = extraParams as { isSpecial: boolean };
return [
..._.map(initialState, (g) => {
let col = { ...g, ellipsis: true, width: 110 };
switch (g.dataIndex) {
case "username":
case "departmentName":
col = { ...col, fixed: true };
break;
case "taxAgentName":
col = { ...col, fixed: true, width: 180 };
break;
case "mobile":
col = { ...col, width: 125 };
break;
case "operate":
col = {
...col,
width: 176,
fixed: "right",
render: (__: string, record: any) => {
let items: MenuProps["items"] = [
{
key: "DeleteList",
label: i18n?.["删除"],
onClick: () => postMessageToParent("DEL", record)
},
{
key: "Log",
label: i18n?.["操作日志"],
onClick: () => postMessageToParent("log", record)
}
];
isSpecial && items.shift();
return (
<Space>
<Button type="link" onClick={() => postMessageToParent("EDIT", record)}>
{i18n?.["编辑"]}
</Button>
{isSpecial ? (
<Button type="link" onClick={() => postMessageToParent("DEL", record)}>
{i18n?.["删除"]}
</Button>
) : (
<Button type="link" onClick={() => postMessageToParent("VIEW", record)}>
{i18n?.["查看明细"]}
</Button>
)}
<Dropdown menu={{ items }} placement="bottomRight">
<Button type="link" icon={<MoreOutlined />} />
</Dropdown>
</Space>
);
}
};
break;
default:
col = { ...col };
break;
}
return col;
})
];
2025-04-24 16:51:07 +08:00
} else if (type === "attendanceView") {
return [
..._.map(initialState, (g) => {
let col = { ...g, ellipsis: true };
2025-06-11 09:55:13 +08:00
switch (g.dataIndex) {
case "operate":
col = {
...col,
ellipsis: false,
width: 120,
render: (__: string, record: any) => {
return (
<Space>
{_.map(col?.operateType, (o) => (
<Button key={o.key} type="link" onClick={() => postMessageToParent(o.key, record)}>
{o.label}
</Button>
))}
</Space>
);
}
};
break;
default:
col = { ...col };
break;
}
return col;
})
];
} else if (type === "declare") {
return [
..._.map(initialState, (g) => {
let col = { ...g, ellipsis: true };
2025-04-24 16:51:07 +08:00
switch (g.dataIndex) {
case "operate":
col = {
...col,
2025-06-04 09:12:20 +08:00
ellipsis: false,
width: 120,
render: (__: string, record: any) => {
return (
<Space>
{_.map(col?.operateType, (o) => (
<Button key={o.key} type="link" onClick={() => postMessageToParent(o.key, record)}>
{o.label}
</Button>
))}
</Space>
);
}
2025-04-24 16:51:07 +08:00
};
break;
default:
col = { ...col };
break;
}
return col;
})
];
2024-01-24 15:35:50 +08:00
}
2024-04-16 18:17:31 +08:00
return initialState;
2024-02-28 15:19:37 +08:00
}, [initialState, type, i18n, extraParams]);
2024-01-24 15:35:50 +08:00
}
const postMessageToParent = (type: string, params: any) => {
window.parent.postMessage({ type: "turn", payload: { id: type, params } }, "*");
};