salary-management-front/pc4mobx/hrmSalary/components/selectItemsModal/selectItemsWrapper.js

133 lines
3.7 KiB
JavaScript
Raw Normal View History

2023-03-06 15:06:56 +08:00
/*
* Author: 黎永顺
* name: 设置项目
* Description:
* Date: 2023/3/6
*/
import React, { Component } from "react";
import { WeaCheckbox, WeaSearchGroup } from "ecCom";
2022-03-14 17:07:26 +08:00
2023-03-06 15:06:56 +08:00
class SelectItemsWrapper extends Component {
2023-03-07 14:47:47 +08:00
constructor(props) {
super(props);
this.state = {
list: [],
filterList: []
};
}
componentDidMount() {
this.setState({
list: this.props.dataSource
});
}
handleSearchItemSet = (val) => {
const { dataSource } = this.props;
this.setState({
filterList: _.map(dataSource, item => {
return {
...item,
items: _.filter(item.items || [], child => child.name.indexOf(val) !== -1)
};
})
});
};
handleShowOnlyChecked = (checked) => {
const { dataSource } = this.props;
const { list } = this.state;
if (!!Number(checked)) {
this.setState({
list: _.map(list, item => {
return {
...item,
items: _.filter(item.items || [], child => !!child.checked)
};
})
});
} else {
this.setState({ list: dataSource });
}
};
handleSelectGroupAll = (groupId, checked) => {
const { list, filterList } = this.state;
const key = !_.isEmpty(filterList) ? "filterList" : "list";
this.setState({
[key]: _.map(!_.isEmpty(filterList) ? filterList : list, item => {
if (groupId === item.groupId) {
return {
...item,
items: _.map(item.items || [], child => {
return { ...child, checked: !!Number(checked) };
})
};
}
return { ...item };
})
});
};
handleSelectItem = (id, checked) => {
const { list, filterList } = this.state;
const key = !_.isEmpty(filterList) ? "filterList" : "list";
this.setState({
[key]: _.map(!_.isEmpty(filterList) ? filterList : list, item => {
return {
...item,
items: _.map(item.items || [], child => {
if (id === child.id) {
return { ...child, checked: !!Number(checked) };
}
return { ...child };
})
};
})
});
};
2023-03-06 15:06:56 +08:00
renderTitle = (item) => {
2023-03-06 17:13:08 +08:00
const { onSelectGroupAll } = this.props;
const { groupName, groupId } = item;
2023-03-06 15:06:56 +08:00
return <div className="setGroupWrapper">
2023-03-06 17:13:08 +08:00
<WeaCheckbox content={groupName} onChange={(val) => onSelectGroupAll(groupId, val)}/>
2023-03-06 15:06:56 +08:00
<span className="checkedtitle">已选择0个字段</span>
</div>;
};
2022-03-23 13:11:01 +08:00
render() {
2023-03-07 14:47:47 +08:00
const { list, filterList } = this.state;
const { onSelectItem } = this.props;
console.log("filterList", filterList);
return (
2023-03-06 15:06:56 +08:00
<React.Fragment>
{
2023-03-07 14:47:47 +08:00
_.map(!_.isEmpty(filterList) ? filterList : list, item => {
2023-03-06 15:06:56 +08:00
const { items } = item;
return <WeaSearchGroup title={this.renderTitle(item)} showGroup>
<div className="itemsWrapper">
{
_.isEmpty(items) ?
<span className="empty">暂无数据</span> :
<ul className="itemContUl">
{
_.map(items, child => {
2023-03-06 17:13:08 +08:00
const { name, checked, id } = child;
2023-03-06 15:06:56 +08:00
return <li title={name}>
<WeaCheckbox
content={name} value={checked ? "1" : "0"}
2023-03-06 17:13:08 +08:00
onChange={(val) => onSelectItem(id, val)}
2023-03-06 15:06:56 +08:00
/>
</li>;
})
}
</ul>
}
</div>
</WeaSearchGroup>;
})
}
2023-03-06 15:06:56 +08:00
</React.Fragment>
);
}
}
2023-03-06 15:06:56 +08:00
export default SelectItemsWrapper;