Commit 6f321ec5 authored by GuanHua's avatar GuanHua

fix: 商品属性分类筛选问题

parent b932ee57
......@@ -30,14 +30,14 @@ const Category: React.FC<CategoryPropsType> = (props) => {
const [initSelectAttributeList, setInitSelectAttributeList] = useState<any>([])
useEffect(() => {
console.log(JSON.stringify(filterList))
if (isEmpty(filterList)) {
setSelectedKeys([])
setLastCategoryId(null)
setSelectAttrbuteList([])
} else {
const initKeys = []
// let initAttrKeys = []
let attrInitKeys = []
for (const item of filterList) {
if (item.type === FILTER_TYPE.category) {
initKeys.push(String(item.key))
......@@ -45,9 +45,15 @@ const Category: React.FC<CategoryPropsType> = (props) => {
initKeys.push(String(item.key))
}
if (item.type === FILTER_TYPE.attribute) {
setInitSelectAttributeList(item.key)
attrInitKeys = item.key
}
}
setInitSelectAttributeList(attrInitKeys)
if(isEmpty(attrInitKeys)) {
setSelectAttrbuteList([])
}
setSelectedKeys(initKeys)
}
}, [filterList])
......@@ -197,15 +203,10 @@ const Category: React.FC<CategoryPropsType> = (props) => {
setLastCategoryId(selectedKeys[0])
}
} else {
setLastCategoryId(null)
setAttributeList([])
if(filterList.some(item => item.type === FILTER_TYPE.attribute)) {
onFilter({
type: FILTER_TYPE.attribute,
key: null,
title: ``
})
}
initAttribute()
}
if(selectedKeys.length === 0) {
initAttribute()
}
switch(layoutType) {
case LAYOUT_TYPE.mall:
......@@ -226,6 +227,18 @@ const Category: React.FC<CategoryPropsType> = (props) => {
}
const initAttribute = () => {
setLastCategoryId(null)
setAttributeList([])
if(filterList.some(item => item.type === FILTER_TYPE.attribute)) {
onFilter({
type: FILTER_TYPE.attribute,
key: null,
title: ``
})
}
}
const handleExpand = (expandedKeys) => {
setExpandedKeys(expandedKeys)
}
......
......@@ -136,7 +136,9 @@ class FilterStore {
for (const filterItem of newFilterList) {
switch (filterItem.type) {
case FILTER_TYPE.category:
tempFilterParam.categoryId = Number(filterItem.key[0])
if(Number(filterItem.key[0])) {
tempFilterParam.categoryId = Number(filterItem.key[0])
}
break
case FILTER_TYPE.customerCategory:
tempFilterParam.customerCategoryId = Number(filterItem.key[0])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment