import { defineComponent } from 'vue'; import styles from './index.module.less'; import { Cell, Collapse, CollapseItem } from 'vant'; import iconNoCheck from './image/icon-nocheck.png'; import iconImm from './image/icon-imm.png'; import iconCheck from './image/icon-check.png'; import iconCheckDisabled from './image/icon-check-disabled.png'; export const onMenuChange = (item: any, status?: string) => { if (item.status === 'disabled') { return; } // 判断父级元素 if (status) { item.status = status; } else { if (item.status === 'disabled') { return; } if (item.status === 'checked') { item.status = 'nochecked'; } else { item.status = 'checked'; } } if (Array.isArray(item.materialList)) { // console.log(item.status, 'item.status', status); item.materialList.forEach((material: any) => { if (material.status === 'disabled') { return; } if (item.status === 'nochecked') { material.status = 'nochecked'; } else { material.status = 'checked'; } }); } if (Array.isArray(item.children)) { item.children.forEach((child: any) => { onMenuChange(child, item.status); }); } }; export const onParentChangeStatus = (parent: any, childName = 'children') => { let arrLength = 0; let checkedLength = 0; let indeterminateLength = 0; if (parent.materialList && parent.materialList.length > 0) { parent.materialList.forEach((item: any) => { if (item.status !== 'disabled') { arrLength += 1; } if (item.status === 'checked') { checkedLength += 1; } }); } if (Array.isArray(parent[childName])) { parent[childName].forEach((item: any) => { if (item.status !== 'disabled') { arrLength += 1; } if (item.status === 'checked') { checkedLength += 1; } if (item.status === 'indeterminate') { indeterminateLength += 1; } }); } if (checkedLength >= arrLength) { parent.status = 'checked'; } else if (checkedLength > 0) { parent.status = 'indeterminate'; } else { parent.status = 'nochecked'; } // 只能目录才会大于0,素材是不会有 if (indeterminateLength > 0) { parent.status = 'indeterminate'; } }; const ChildNode = defineComponent({ name: 'child-node', props: { list: { type: Array, default: () => [] }, collapse: { type: String, default: '' } }, emits: ['update:collapse', 'menuChange', 'materialChange'], setup(props, { emit }) { return () => ( { emit('update:collapse', val); }} border={false} accordion> {props.list?.map((point: any) => ( {{ title: () => (
{point.name}
), default: () => ( <> {Array.isArray(point?.materialList) && point.materialList.map((n: any) => ( {{ title: () => n.name, value: () => ( { e.stopPropagation(); if (n.status === 'disabled') { return; } if (n.status === 'checked') { n.status = 'nochecked'; } else { n.status = 'checked'; } onParentChangeStatus(point); emit('menuChange'); }} /> ) }} ))} {Array.isArray(point?.children) && ( { point.collapse = val; }} onMenuChange={() => { onParentChangeStatus(point); emit('menuChange'); }} /> )} ), 'right-icon': () => ( { e.stopPropagation(); onMenuChange(point); emit('menuChange'); }} /> ) }}
))}
); } }); export default ChildNode;