Commit 1c5e6a6d authored by 张烨's avatar 张烨

feat: 更新选择器组件

parent 5de6c68c
......@@ -5,8 +5,16 @@ import styles from './itemCard.less';
const CheckGroup = Checkbox.Group;
const ListCardItem = props => {
const { getValueCallback, itemid, userList, OUName, searchWord } = props;
const {
getValueCallback,
itemid,
userList,
OUName,
searchWord,
Child,
} = props;
const [indeterminate, setIndeterminate] = useState(false);
const [childValues, setChildValues] = useState({});
const [allChecked, setAllChecked] = useState(false); // 全选状态
const [checkList, setCheckList] = useState([]); // 复选框列表选中的值
const [defaultList, setDefaultList] = useState([]); // 默认的选项
......@@ -67,11 +75,36 @@ const ListCardItem = props => {
setCheckList(e);
setAllChecked(e.length === defaultList.length);
setIndeterminate(!!e.length && e.length < defaultList.length);
if (Child) {
const childValArr = Object.values(childValues).flat();
getValueCallback([...e, childValArr], itemid);
} else {
getValueCallback(e, itemid);
}
};
if (defaultList.length === 0) {
return null;
}
const handleChildValueCallback = (arr, childIndex) => {
childValues[childIndex] = arr;
const childValArr = Object.values(childValues).flat();
setChildValues({ ...childValues });
getValueCallback([...checkList, childValArr]);
};
const renderChild = () =>
Child &&
Child.map((c, i) => (
<ListCardItem
{...c}
itemid={i}
key={`item${i}key`}
getValueCallback={handleChildValueCallback}
searchWord={searchWord}
/>
));
return (
<>
<div className={`${styles.divBox}`}>
......@@ -97,6 +130,7 @@ const ListCardItem = props => {
options={defaultList}
/>
)}
{renderChild()}
</div>
</div>
</>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment