aaa
doum
2026-06-08 3ac279c9df7181c9f21d35a689a321b990b87b22
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
44
45
46
47
/**
 * 本地商品/品牌过滤(基于全量缓存)
 */
 
export function matchKeyword(item, keyword) {
    if (!keyword) return true
    const kw = String(keyword).trim()
    if (!kw) return true
    const kwLower = kw.toLowerCase()
    const name = item.name != null ? String(item.name).toLowerCase() : ''
    const pinyin = item.pinyin != null ? String(item.pinyin).toLowerCase() : ''
    const shortPinyin = item.shortPinyin != null ? String(item.shortPinyin).toLowerCase() : ''
    return name.includes(kwLower) ||
        pinyin.includes(kwLower) ||
        shortPinyin.includes(kwLower)
}
 
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)))
}