zhangqi 1 rok temu
rodzic
commit
e72b737328
1 zmienionych plików z 48 dodań i 30 usunięć
  1. 48 30
      src/DRP/SDrpManagement/productGroup/detail/index.vue

+ 48 - 30
src/DRP/SDrpManagement/productGroup/detail/index.vue

@@ -69,7 +69,7 @@
             </div>
           </div> -->
           
-          <div v-if="group.item[0].iscustomsize == 1">
+          <div v-if="group.item[0].iscustomsize == 1 && data.spec == 'custom'">
             <p style="color:#999;margin-top:30px">定制信息</p>
             <a-divider/>
             <div class="mt-30 input-number-panel">
@@ -78,7 +78,7 @@
                 <div v-if="lengthscheme.type == '自定义'">
                   <a-input-number style="width: 150px;" :controls="false" :step="1" v-model:value="schemeData.length" @blur="inputValid('length')" placeholder="输入区间内长度"/><span style="color:#666">&emsp;输入范围:{{lengthscheme.min}}mm - {{lengthscheme.max}}mm,不保留小数</span>
                 </div>
-                <div>
+                <div v-else>
                   <a-button class="mr-10 mt-10" v-for="(item,index) in lengthscheme.rowsdetail" :key="index" :disabled="schemeData.length != item.num && (schemeData.length != null && schemeData.length != '')" :type="schemeData.length == item.num?'primary':'default'" @click="customClick2('length',item.num)">{{item.num}}</a-button>
                 </div>
               </div>
@@ -87,7 +87,7 @@
               <p class="label"><span class="mr-10">宽度</span></p>
               <div>
                 <div v-if="widthscheme.type == '自定义'">
-                <a-input-number style="width: 150px;" :controls="false" :step="1" v-model:value="schemeData.width" @blur="inputValid('width')" placeholder="输入区间内宽度"/><span style="color:#666">&emsp;输入范围:{{widthscheme.min}}mm - {{widthscheme.max}}mm,不保留小数</span>
+                  <a-input-number style="width: 150px;" :controls="false" :step="1" v-model:value="schemeData.width" @blur="inputValid('width')" placeholder="输入区间内宽度"/><span style="color:#666">&emsp;输入范围:{{widthscheme.min}}mm - {{widthscheme.max}}mm,不保留小数</span>
                 </div>
                 <div v-else>
                   <a-button class="mr-10 mt-10"  v-for="(item,index) in widthscheme.rowsdetail" :key="index" :disabled="schemeData.width != item.num && (schemeData.width != null && schemeData.width != '')" :type="schemeData.width == item.num?'primary':'default'" @click="customClick2('width',item.num)">{{item.num}}</a-button>
@@ -173,7 +173,11 @@
     group.value.specRows = group.value.specRows.reverse()
     
     if(group.value.specRows.filter(item => item.parm != '自定义').every(item => !item.flag) && group.value.item[0].iscustomsize) data.value.spec = '自定义'
+    
     qty.value = res.data.item[0].orderminqty
+
+    validOnlySelect(res.data)
+
     // 获取可定制项
     let arr = ['cheekRows','colorRows','materialRows','specRows']
     let reg2 = new RegExp("Rows")
@@ -182,45 +186,59 @@
         custom.value.push(key.replace(reg2,""))
       }
     })
+
+
     customschemeItems.value = res.data.customschemeItems
 
     callback ? callback():""
-
     getCustomsizeData()
   }
-  const updateSingleRowProperty = (group, data, properties,type) => {  
-    // 遍历所有需要更新的属性  
-    properties.forEach(property => {  
-        // 构造从 group 中获取值的路径  
-        const rowsPath = `${property}Rows`;  
-        const targetPath = property;  
-        if (type == 'uncheck' && group.value[rowsPath].length === 1) {
-          data.value[targetPath] = '';  
-        }
-        // 如果对应的 rows 数组只有一个元素  
-        if (group.value[rowsPath].length === 1 && type == 'check') {  
-            // 从该数组的第一个元素中获取 parm 属性,并更新到 data 中  
-            data.value[targetPath] = group.value[rowsPath][0].parm;  
+  const validOnlySelect = (rsdata,type) => { 
+    console.log(rsdata) 
+    if (!rsdata || typeof rsdata !== 'object') {  
+        console.error('Invalid data or data.value structure');  
+        return;  
+    }  
+  
+    const keys = ['cheekRows', 'colorRows', 'materialRows', 'specRows'];  
+    const reg2 = /Rows$/; // 使用正则表达式来匹配结尾的"Rows"  
+  
+    keys.forEach((key) => {  
+        const items = rsdata[key];  
+        if (Array.isArray(items) && items.some(item => item.flag === true)) {  
+            // 查找第一个标记为true的项  
+            const filteredItems = items.filter(item => item.flag === true);  
+            if (filteredItems.length === 1) {  
+                // 假设我们总是取第一个匹配的项  
+                const selectedItem = filteredItems[0];  
+                if (selectedItem && selectedItem.parm !== undefined) {  
+                    // 更新data.value中的相应属性  
+                    if (type && type == 'uncheck') {
+                      data.value[key.replace(reg2, '')] = ''
+                    } else {
+                      data.value[key.replace(reg2, '')] = selectedItem.parm;
+                    }
+                } else {  
+                    console.error(`No valid parm found for key: ${key}`);
+                }  
+            }
+            if (filteredItems.length > 1 && type && type == 'uncheck') {
+              data.value[key.replace(reg2, '')] = ''
+            }
         }  
     });  
-  }  
+  };
   const customClick = (key,value)=>{
     if (data.value[key] == value) {
       data.value[key] = ''
-      
-      groupDetail(()=>{
-        const propertiesToUpdate = ['material', 'color', 'cheek', 'spec'];  
-        updateSingleRowProperty(group, data,propertiesToUpdate,'uncheck')
-      })
+      validOnlySelect(group.value,'uncheck')
+      schemeData.value.length = ''
+      schemeData.value.width = ''
+      groupDetail()
+
     } else {
       data.value[key] = value
-      groupDetail(()=>{
-        // 定义需要更新的属性列表  
-          const propertiesToUpdate = ['material', 'color', 'cheek', 'spec'];  
-        
-        // 调用函数,传入必要的参数  
-        updateSingleRowProperty(group, data, propertiesToUpdate,'check'); 
-      })
+      groupDetail()
     }
   }
   const customClick2 = (key,value)=>{