getSelectionParams function
根据传入的原始数据,返回用户选中的筛选数据
Implementation
Map<String, String> getSelectionParams(List<SelectionEntity>? selectedResults) {
Map<String, String> params = Map();
if (selectedResults == null) return params;
for (SelectionEntity menuItemEntity in selectedResults) {
if (menuItemEntity.filterType == SelectionFilterType.more) {
params.addAll(getSelectionParams(menuItemEntity.children));
} else {
/// 1、首先找出 自定义范围的筛选项参数。
SelectionEntity? selectedCustomInputItem =
SelectionUtil.getFilledCustomInputItem(menuItemEntity.children);
if (selectedCustomInputItem != null &&
!PhoenixTools.isEmpty(selectedCustomInputItem.customMap)) {
String? key = selectedCustomInputItem.parent?.key;
if (!PhoenixTools.isEmpty(key)) {
params[key!] =
'${selectedCustomInputItem.customMap!["min"] ?? ''}:${selectedCustomInputItem.customMap!["max"] ?? ''}';
}
}
/// 2、一次找出层级为 1、2、3 的选中项的参数,递归不好阅读,直接写成 for 嵌套遍历。
int levelCount = SelectionUtil.getTotalLevel(menuItemEntity);
if (levelCount == 1) {
params.addAll(getCurrentSelectionEntityParams(menuItemEntity));
} else if (levelCount == 2) {
params.addAll(getCurrentSelectionEntityParams(menuItemEntity));
menuItemEntity.children.forEach((firstLevelItem) =>
params.addAll(getCurrentSelectionEntityParams(firstLevelItem)));
} else if (levelCount == 3) {
params.addAll(getCurrentSelectionEntityParams(menuItemEntity));
menuItemEntity.children.forEach((firstLevelItem) {
params.addAll(getCurrentSelectionEntityParams(firstLevelItem));
firstLevelItem.children.forEach((secondLevelItem) {
params.addAll(getCurrentSelectionEntityParams(secondLevelItem));
});
});
}
}
}
return params;
}