Browse Source

修改内容

ext.liuqiwen3 1 day ago
parent
commit
232cf62e47
2 changed files with 8 additions and 21 deletions
  1. 6 19
      components/CategorySelector/index.vue
  2. 2 2
      pages/goods/goods_details/index.vue

+ 6 - 19
components/CategorySelector/index.vue

@@ -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)

+ 2 - 2
pages/goods/goods_details/index.vue

@@ -65,7 +65,7 @@
                   </view>
                   <view class="label acea-row">
                     <view>工费:{{ attr.productSelect.price || 0 }}元/g</view>
-<!--                    <view>重量:{{ attr.productSelect.weight }}g</view>-->
+                    <view>重量:{{ attr.productSelect.weight }}g</view>
                     <view>
                       附加费:{{ attr.productSelect.additionalAmount || "" }}
                     </view>
@@ -2127,7 +2127,7 @@ action-sheet-item {
 }
 .label{
   display: flex;
-  gap: 30rpx;
+  gap: 20rpx;
   color: #666;
 }
 </style>