aaa
doum
2026-06-04 08e9a67dd679f311e79a27b04cd0c53a30b4bccf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
 * 本地商品/品牌过滤(基于全量缓存)
 */
 
export function matchKeyword(item, keyword) {
    if (!keyword) return true
    const kw = String(keyword).trim()
    if (!kw) return true
    return (item.name && item.name.indexOf(kw) !== -1) ||
        (item.pinyin && item.pinyin.indexOf(kw) !== -1) ||
        (item.shortPinyin && item.shortPinyin.indexOf(kw) !== -1)
}
 
export function filterGoods(allGoods, options = {}) {
    const { categoryId, subCategoryId, brandId, keyword } = options
    const list = Array.isArray(allGoods) ? allGoods : []
    return list.filter(item => {
        if (categoryId != null && categoryId !== '' && String(item.categoryId) !== String(categoryId)) {
            return false
        }
        if (subCategoryId != null && subCategoryId !== '' && String(item.subCategoryId) !== String(subCategoryId)) {
            return false
        }
        if (brandId != null && brandId !== '' && String(item.brandId) !== String(brandId)) {
            return false
        }
        return matchKeyword(item, keyword)
    })
}
 
export function filterBrandsByCategory(allBrands, allGoods, categoryId) {
    if (!categoryId) {
        return Array.isArray(allBrands) ? allBrands : []
    }
    const goods = Array.isArray(allGoods) ? allGoods : []
    const brands = Array.isArray(allBrands) ? allBrands : []
    const brandIds = new Set(
        goods
            .filter(g => String(g.categoryId) === String(categoryId) && g.brandId != null && g.brandId !== '')
            .map(g => String(g.brandId))
    )
    return brands.filter(b => brandIds.has(String(b.id)))
}