feat(advice): 添加药品库存过滤功能

- 在搜索结果中过滤掉无库存的药品项目
- 仅对药品类型(adviceType === 1)进行库存检查
- 计算库存总数量并过滤库存大于0的项目
- 保持非药品类型的原有搜索逻辑不变
- 优化代码缩进格式以提高可读性
This commit is contained in:
2026-03-02 11:38:34 +08:00
parent 6add091a7b
commit 04ad139eae

View File

@@ -182,14 +182,27 @@ const filteredAdviceBaseList = computed(() => {
if (!props.adviceQueryParams.searchKey) {
result = adviceBaseList.value.slice(0, 50); // 返回前50个常用项目
} else {
const searchKey = props.adviceQueryParams.searchKey.toLowerCase();
const searchKey = props.adviceQueryParams.searchKey.toLowerCase();
result = adviceBaseList.value.filter(item =>
item.adviceName.toLowerCase().includes(searchKey) ||
item.py_str?.toLowerCase().includes(searchKey) ||
item.wb_str?.toLowerCase().includes(searchKey)
).slice(0, 100); // 限制返回数量
item.adviceName.toLowerCase().includes(searchKey) ||
item.py_str?.toLowerCase().includes(searchKey) ||
item.wb_str?.toLowerCase().includes(searchKey)
).slice(0, 100); // 限制返回数量
}
// 过滤无库存的药品(只针对药品类型 adviceType === 1
result = result.filter(item => {
if (item.adviceType === 1) {
// 检查是否有库存
if (item.inventoryList && item.inventoryList.length > 0) {
const totalQuantity = item.inventoryList.reduce((sum, inv) => sum + (inv.quantity || 0), 0);
return totalQuantity > 0;
}
return false; // 无库存列表或库存为空,视为无库存
}
return true; // 非药品类型不过滤
});
return result;
});