|
@@ -300,6 +300,29 @@ function getCurrentScope() {
|
|
|
return "";
|
|
return "";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function getSelectedNames(list) {
|
|
|
|
|
+ return new Set((list || []).map((item) => item?.name).filter(Boolean));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function getFruitItemsByFieldNames(fieldItems) {
|
|
|
|
|
+ const names = getSelectedNames(fieldItems);
|
|
|
|
|
+ if (!names.size) return [];
|
|
|
|
|
+ return FRUIT_GROUPS.flatMap((group) =>
|
|
|
|
|
+ group.items
|
|
|
|
|
+ .filter((item) => names.has(item.name))
|
|
|
|
|
+ .map((item) => ({ ...item, scope: "fruit", groupName: group.name }))
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function mergeEquipmentById(existing, extra) {
|
|
|
|
|
+ const map = new Map();
|
|
|
|
|
+ [...(existing || []), ...(extra || [])].forEach((item) => {
|
|
|
|
|
+ if (item?.id == null) return;
|
|
|
|
|
+ map.set(String(item.id), item);
|
|
|
|
|
+ });
|
|
|
|
|
+ return Array.from(map.values());
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function restoreSelection() {
|
|
function restoreSelection() {
|
|
|
const cached = readJson(EQUIPMENT_KEY);
|
|
const cached = readJson(EQUIPMENT_KEY);
|
|
|
const scope = getCurrentScope();
|
|
const scope = getCurrentScope();
|
|
@@ -319,6 +342,19 @@ function restoreSelection() {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function applyFieldOverlapToFruit() {
|
|
|
|
|
+ if (!props.isService || getCurrentScope() !== "fruit") return;
|
|
|
|
|
+ const fieldNames = getSelectedNames(getScopeList(readJson(EQUIPMENT_KEY), "field"));
|
|
|
|
|
+ if (!fieldNames.size) return;
|
|
|
|
|
+ let changed = false;
|
|
|
|
|
+ allEquipmentItems.value.forEach((item) => {
|
|
|
|
|
+ if (!fieldNames.has(item.name) || selectedIds.has(String(item.id))) return;
|
|
|
|
|
+ selectedIds.add(String(item.id));
|
|
|
|
|
+ changed = true;
|
|
|
|
|
+ });
|
|
|
|
|
+ if (changed) saveSelectionDraft();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function saveSelectionDraft() {
|
|
function saveSelectionDraft() {
|
|
|
const scope = getCurrentScope();
|
|
const scope = getCurrentScope();
|
|
|
const selected = allEquipmentItems.value
|
|
const selected = allEquipmentItems.value
|
|
@@ -338,8 +374,12 @@ function saveSelectionDraft() {
|
|
|
field: Array.isArray(cached) ? cached : cached?.field || [],
|
|
field: Array.isArray(cached) ? cached : cached?.field || [],
|
|
|
fruit: Array.isArray(cached) ? [] : cached?.fruit || [],
|
|
fruit: Array.isArray(cached) ? [] : cached?.fruit || [],
|
|
|
};
|
|
};
|
|
|
- if (scope === "fruit") next.fruit = selected;
|
|
|
|
|
- else next.field = selected;
|
|
|
|
|
|
|
+ if (scope === "fruit") {
|
|
|
|
|
+ next.fruit = selected;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ next.field = selected;
|
|
|
|
|
+ next.fruit = mergeEquipmentById(next.fruit, getFruitItemsByFieldNames(selected));
|
|
|
|
|
+ }
|
|
|
sessionStorage.setItem(EQUIPMENT_KEY, JSON.stringify(next));
|
|
sessionStorage.setItem(EQUIPMENT_KEY, JSON.stringify(next));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -538,6 +578,7 @@ const handleSubmit = () => {
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
fetchEquipmentList();
|
|
fetchEquipmentList();
|
|
|
restoreSelection();
|
|
restoreSelection();
|
|
|
|
|
+ applyFieldOverlapToFruit();
|
|
|
});
|
|
});
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|