import React, { Component } from "react";
import { WeaLocaleProvider } from "ecCom";
import moment from "moment";
import "./index.less";
const getLabel = WeaLocaleProvider.getLabel;
class Index extends Component {
render() {
const { theme, background, tip, tipPosi, itemTypeList } = this.props;
const { onlyOneGrup, showData } = dealTemplate(itemTypeList, "pc");
return (
{theme || ""}
{moment().format("YYYY-MM-DD HH:mm:ss")}
{
background &&
}
{
!onlyOneGrup && tipPosi === "1" && tip &&
{tip}
}
{
showData.map((groupItem, index) => {
// 如果当前组下没有条目 当前组直接不展示。
if (!groupItem) return null;
const { groupId, groupName, items = [] } = groupItem;
return (
{
groupName ?
{groupName}
: null
}
{
(onlyOneGrup && tipPosi === "1" && tip) && (
{getLabel(111, "发放说明")}
{tip}
)
}
{
items.map((templatItem, index) => {
const { salaryItemValue, name } = templatItem || {};
return
{name || ""}
{salaryItemValue || ""}
;
})
}
{
(onlyOneGrup && tipPosi === "2" && tip) && (
{getLabel(111, "发放说明")}
{tip}
)
}
);
})
}
{
!onlyOneGrup && tipPosi === "2" && tip &&
{tip}
}
);
}
}
export default Index;
export const dealTemplate = (itemTypeList, type) => {
let cloneItemTypeList = _.cloneDeep(itemTypeList);
let showData = [], onlyOneGrup = false;
cloneItemTypeList.forEach((group) => {
const { items, groupName, groupId } = group;
if (items.length !== 0) {
items.forEach((item) => {
item.salaryItemValue = "100";
});
if (items.length % 2 && type === "pc") items.push({});
// 未分类不展示标题
if (!groupId.includes("222222222222222222")) {
showData.push({ groupId, groupName, items });
} else {
showData.push({ items });
}
}
});
if (cloneItemTypeList.length === 1) {
onlyOneGrup = true;
// 只有一个分组的时候不展示分组名
cloneItemTypeList[0].name = "";
}
return { onlyOneGrup, showData };
};