zhangqi 1 год назад
Родитель
Сommit
3c2c4cd1b2
1 измененных файлов с 17 добавлено и 7 удалено
  1. 17 7
      src/class/product.js

+ 17 - 7
src/class/product.js

@@ -24,23 +24,33 @@ class Product {
   }  
 
   // 验证商品订制属性是否符合规则
-  checkDimension (dimensionData, schemeData) { 
-    console.log(dimensionData,schemeData)
-    const requiredProperties = ['length', 'width'];  
+  checkDimension (dimensionData, schemeData) {
+    let requiredProperties = ['length', 'width'];  
+    if (schemeData.lengthschemedetails.length > 0) {
+      requiredProperties = requiredProperties.filter(prop => prop !== 'length');  
+
+    }
+    if(schemeData.widthschemedetails.length > 0) {
+      requiredProperties = requiredProperties.filter(prop => prop !== 'width');  
+    }
+    for (const prop of ['length', 'width']) { 
+      if (!schemeData[prop]) {  
+        message.error({ content: `${prop == 'length'?'长度':'宽度'}定制选项不能为空!`, key: 1 });  
+        return false;  
+      } 
+    }
     for (const prop of requiredProperties) {  
       if ((schemeData[prop] < dimensionData[prop].min || schemeData[prop] > dimensionData[prop].max)) {  
         message.error({ content: `自定义${prop == 'length'?'长度':'宽度'}超出可选范围!`, key: 1 });  
         return false;  
       }
-      if (!schemeData[prop]) {  
-        message.error({ content: `${prop == 'length'?'长度':'宽度'}定制选项不能为空!`, key: 1 });  
-        return false;  
-      }
       if (!this.hasDecimal(schemeData[prop],prop)) {  
         return false;  
       }
     }
+    
     return true
+    
   }
 
   hasDecimal(num,prop) {