/* * Author: 黎永顺 * name: 设置项目 * Description: * Date: 2023/3/6 */ import React, { Component } from "react"; import { WeaCheckbox, WeaSearchGroup } from "ecCom"; class SelectItemsWrapper extends Component { constructor(props) { super(props); this.state = { searchVal: "", selectItem: [], groupItem: [], showOnlyChecked: false }; } componentDidMount() { const { dataSource } = this.props this.setState({ selectItem: _.map(_.filter(_.reduce(dataSource, (pre, cur) => { return [...pre, ...cur.items]; }, []), item => !!item.checked), it => it.id) }); } handleSearchItemSet = (searchVal) => this.setState({ searchVal }); handleShowOnlyChecked = (showOnlyChecked) => this.setState({ showOnlyChecked: !!Number(showOnlyChecked) }); handleSelectGroupAll = (groupId, checked) => { const { selectItem, groupItem } = this.state; const { dataSource } = this.props; _.map(dataSource, item => { if (item.groupId === groupId) { if (!!Number(checked)) { this.setState({ groupItem: [...groupItem, ..._.map(item.items, child => child.id)] }, () => this.setState({ selectItem: [...selectItem, ...this.state.groupItem] })); } else { this.setState({ groupItem: _.differenceWith(groupItem, _.map(item.items, child => child.id), _.isEqual) }, () => this.setState({ selectItem: this.state.groupItem })); } } }); }; handleSelectItem = (id, checked) => { const { selectItem } = this.state; this.setState({ selectItem: !!Number(checked) ? [...selectItem, id] : _.xorWith(selectItem, [id], _.isEqual) }); }; renderTitle = (item) => { const { onSelectGroupAll } = this.props; const { groupName, groupId, items } = item; const number = _.filter(items, it => !!it.checked).length; const value = _.every(items, it => !!it.checked) ? "1" : "0"; return