|
|
@@ -123,10 +123,6 @@ const toggleSecondLevel = (child) => {
|
|
|
|
|
|
// 获取所有选中的分类ID(根据规则:全选父类才包含父类ID,否则只包含子类ID)
|
|
|
const getSelectedIds = () => {
|
|
|
- console.log('当前选中状态:', {
|
|
|
- allCategories: props.categoryList,
|
|
|
- selectedChildren: selectedSecondLevel.value
|
|
|
- })
|
|
|
|
|
|
const result = []
|
|
|
|
|
|
@@ -137,19 +133,16 @@ const getSelectedIds = () => {
|
|
|
if (category.child && category.child.length > 0) {
|
|
|
// 有子分类的情况
|
|
|
const allChildIds = category.child.map(child => String(child.id))
|
|
|
- const isAllSelected = allChildIds.every(id =>
|
|
|
+ const selectedChildIds = allChildIds.filter(id =>
|
|
|
selectedSecondLevel.value.includes(id)
|
|
|
)
|
|
|
|
|
|
- if (isAllSelected) {
|
|
|
- // 全选子类,只添加父类ID
|
|
|
+ if (selectedChildIds.length > 0) {
|
|
|
+ // 只要有选中的子分类,就添加父类ID
|
|
|
result.push(parentId)
|
|
|
- } else {
|
|
|
- // 非全选,添加选中的子类
|
|
|
- allChildIds.forEach(id => {
|
|
|
- if (selectedSecondLevel.value.includes(id)) {
|
|
|
- result.push(id)
|
|
|
- }
|
|
|
+ // 添加选中的子类ID
|
|
|
+ selectedChildIds.forEach(id => {
|
|
|
+ result.push(id)
|
|
|
})
|
|
|
}
|
|
|
} else {
|
|
|
@@ -159,7 +152,6 @@ const getSelectedIds = () => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
console.log('计算出的选中IDs:', result)
|
|
|
return result
|
|
|
}
|
|
|
@@ -177,9 +169,6 @@ const setSelectedState = (ids) => {
|
|
|
selectedSecondLevel.value = []
|
|
|
currentFirstLevel.value = null
|
|
|
|
|
|
- console.log('设置选中IDs:', ids)
|
|
|
- console.log('可用分类数据:', props.categoryList)
|
|
|
-
|
|
|
if (!ids || !Array.isArray(ids) || ids.length === 0) {
|
|
|
initDefaultView()
|
|
|
return
|
|
|
@@ -280,12 +269,10 @@ const setSelectedIds = (ids) => {
|
|
|
|
|
|
// 监听props变化
|
|
|
watch(() => props.selectedIds, (newVal) => {
|
|
|
- console.log('props.selectedIds 变化:', newVal)
|
|
|
setSelectedState(newVal)
|
|
|
}, {immediate: true})
|
|
|
|
|
|
watch(() => props.categoryList, (newVal) => {
|
|
|
- console.log('分类数据变化:', newVal)
|
|
|
if (newVal && newVal.length > 0) {
|
|
|
// 重新应用选中状态
|
|
|
setSelectedState(props.selectedIds)
|