zhangqi vor 1 Jahr
Ursprung
Commit
d6e774a478

+ 8 - 20
src/DRP/HDrpManagement/orderManage/detail/index.vue

@@ -370,28 +370,14 @@ const updateProd = async (data,msg,fn) =>{
   })
  
 }
-const validInput = async (record,min,max,type)=>{
+const validInput = (record)=>{
   const pd = new Product(record)
-  let lengthValidData = {}
-  let widthValData = {}
-  type == 'length' ? lengthValidData = { min: min, max: max, type: '自定义' } : widthValData = { min: min, max: max, type: '自定义' };
-    
-  if (!pd.checkDimension(widthValData, record, 'width', '自定义宽度超出可选范围!')) {  
-    return false;  
-  } else if (!pd.checkDimension(lengthValidData, record, 'length', '自定义长度超出可选范围!')) {  
-    return false;  
-  } else {
-    // 如果所有检查都通过  
-    return true;
+  let lengthValidData = {min: record.lengthmin, max:record.lengthmax,}
+  let widthValData = {min: record.widthmin, max: record.widthmax,}
+  if (!pd.checkDimension({width:widthValData,length:lengthValidData}, record)) {
+    return false
   } 
-  // if (!record[type]) return
-  // if (record[type] > max) {
-  //   record[type] = max
-  // } else if (record[type] < min) {
-  //   record[type] = min
-  // } else {
-  //   record[type] = record[type]
-  // }
+  return true
 }
 const addProductToBody = async (val) =>{
   let param = {
@@ -727,6 +713,8 @@ const openCustom = (data)=>{
   prod.value = data
 }
 const handleOk = ()=>{
+  if (!validInput(prod.value.record)) 
+    return false
   prod.value.record.isselect = true
   prodlist.value.data.some((item)=>{
     if (item.itemid == prod.value.itemid) {

+ 12 - 12
src/DRP/SDrpManagement/collection/index.vue

@@ -105,6 +105,8 @@
   import { useRouter } from "vue-router"
   import { useBaseStore } from '@/stores/modules/base'
   import { storeToRefs } from 'pinia'
+  import Product from '@/class/Product'
+
   const base = useBaseStore()
   const router = useRouter()
   const prod = ref()
@@ -264,14 +266,14 @@
   //   })
   //   return bool
   // }
-  const validInput = async (record,min,max,type)=>{
-    if (record[type] > max) {
-      record[type] = max
-    } else if (record[type] < min) {
-      record[type] = min
-    } else {
-      record[type] = record[type]
-    }
+  const validInput = (record,min,max,type)=>{
+    const pd = new Product(record)
+    let lengthValidData = {min: record.lengthmin, max:record.lengthmax,}
+    let widthValData = {min: record.widthmin, max: record.widthmax,}
+    if (!pd.checkDimension({width:widthValData,length:lengthValidData}, record)) {
+      return false
+    } 
+    return true
   }
   const saveData = (data,type)=>{
     if(time.value !== null){
@@ -317,10 +319,8 @@
     prodData.value = data
   }
   const handleOk = ()=>{
-    if (prodData.value.record.cheekschemeid > 0 && !prodData.record.customcheek) return message.warning('请填写完整信息')
-    if (prodData.value.record.colorschemeid > 0 && !prodData.record.customcolors) return message.warning('请填写完整信息')
-    if (prodData.value.record.materialschemeid > 0 && !prodData.record.custommaterial) return message.warning('请填写完整信息')
-    if ((prodData.value.record.spec == '自定义' || prodData.value.record.spec == 'custom') && (!prodData.value.record.length || !prodData.value.record.width)) return message.warning('请填写完整信息')
+    if (!validInput(prodData.value.record)) 
+      return false
     prodData.value.record.isselect = true
     prod.value.data.some((item)=>{
       if (item.itemid == prodData.value.itemid) {

+ 9 - 22
src/DRP/SDrpManagement/order/detail/index.vue

@@ -651,29 +651,14 @@ const updateProd = async (data, msg, fn) => {
     fn ? fn() : "";
   });
 };
-const validInput = async (record, min, max, type) => {
-  // if (!record[type]) return;
-  // if (record[type] > max) {
-  //   record[type] = max;
-  // } else if (record[type] < min) {
-  //   record[type] = min;
-  // } else {
-  //   record[type] = record[type];
-  // }
+const validInput = (record) => {
   const pd = new Product(record)
-  let lengthValidData = { min: min, max: max, type: type };  
-  let widthValData = { min:min, max: max, type: type };  
-    
-  if (!pd.checkDimension(widthValData, record, 'width', '自定义宽度超出可选范围!')) {  
-    return false;  
-  }  
-    
-  if (!pd.checkDimension(lengthValidData, record, 'length', '自定义长度超出可选范围!')) {  
-    return false;  
-  }  
-    
-  // 如果所有检查都通过  
-  return true;
+  let lengthValidData = {min: record.lengthmin, max:record.lengthmax,}
+  let widthValData = {min: record.widthmin, max: record.widthmax,}
+  if (!pd.checkDimension({width:widthValData,length:lengthValidData}, record)) {
+    return false
+  } 
+  return true
 };
 const qtyModal = ref(false)
 const promotionQty  = ref(null)
@@ -932,6 +917,8 @@ const openCustom = (data) => {
   prod.value = data;
 };
 const handleOk = () => {
+  if (!validInput(prod.value.record)) 
+    return false
   prod.value.record.isselect = true;
   prodlist.value.data.some((item) => {
     if (item.itemid == prod.value.itemid) {

+ 6 - 14
src/DRP/SDrpManagement/productGroup/detail/index.vue

@@ -315,24 +315,16 @@
       }
   }
   const inputValid = (type)=>{
-    const pd = new Product(group.value.item[0])
-    pd.hasDecimal(schemeData.value[type])
+    validCustomSize()
   }
   const validCustomSize = (type)=>{
     const pd = new Product(group.value.item[0])
-    // 使用该函数来检查长度和宽度  
-    let lengthValidData = { min: lengthscheme.value.min, max: lengthscheme.value.max, type: lengthscheme.value.type };  
-    let widthValData = { min: widthscheme.value.min, max: widthscheme.value.max, type: widthscheme.value.type };  
-      
-    if (!pd.checkDimension(widthValData, schemeData.value, 'width', '自定义宽度超出可选范围!')) {  
-      return false;  
+    let lengthValidData = {min: lengthscheme.value.min, max:lengthscheme.value.max,}
+    let widthValData = {min: widthscheme.value.min, max: widthscheme.value.max,}
+    if (!pd.checkDimension({width:widthValData,length:lengthValidData}, schemeData.value)) {
+      return false
     }
-    
-    if (!pd.checkDimension(lengthValidData, schemeData.value, 'length', '自定义长度超出可选范围!')) {  
-      return false;  
-    }
-
-    return true;
+    return true
   }
     
   const onCollection = (data)=>{

+ 12 - 8
src/DRP/SDrpManagement/salerPromotion/detail/index.vue

@@ -279,6 +279,8 @@ import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
 import { Modal } from "ant-design-vue";
 import { message } from "ant-design-vue";
 import { useRouter } from "vue-router";
+import Product from '@/class/Product'
+
 const activeKey = ref(0)
 const router = useRouter();
 const prod = ref();
@@ -361,14 +363,14 @@ const onQtyChange = (val) => {
       val.qty = res;
     });
 };
-const validInput = async (record, min, max, type) => {
-  if (record[type] > max) {
-    record[type] = max;
-  } else if (record[type] < min) {
-    record[type] = min;
-  } else {
-    record[type] = record[type];
-  }
+const validInput = (record, min, max, type) => {
+  const pd = new Product(record)
+  let lengthValidData = {min: record.lengthmin, max:record.lengthmax,}
+  let widthValData = {min: record.widthmin, max: record.widthmax,}
+  if (!pd.checkDimension({width:widthValData,length:lengthValidData}, record)) {
+    return false
+  } 
+  return true
 };
 const checkIscustomsize = (val) => {
   let bool = true;
@@ -541,6 +543,8 @@ const openCustom = (data) => {
   prodData.value = data;
 };
 const handleOk = () => {
+  if (!validInput(prod.value.record)) 
+    return false
   prodData.value.record.isselect = true;
   prod.value.data.some((item) => {
     if (item.itemid == prodData.value.itemid) {

+ 13 - 4
src/DRP/SDrpManagement/shopCart/index.vue

@@ -90,6 +90,8 @@
   import { useRouter } from "vue-router"
   import { useBaseStore } from '@/stores/modules/base'
   import { storeToRefs } from 'pinia'
+  import Product from '@/class/Product'
+
   const base = useBaseStore()
   const router = useRouter()
   const prod = ref()
@@ -250,6 +252,15 @@
     })
     utils.message(res,'修改成功')
   }
+  const validInput = (record, min, max, type) => {
+    const pd = new Product(record)
+    let lengthValidData = {min: record.lengthmin, max:record.lengthmax,}
+    let widthValData = {min: record.widthmin, max: record.widthmax,}
+    if (!pd.checkDimension({width:widthValData,length:lengthValidData}, record)) {
+      return false
+    } 
+    return true
+  };
   const open = ref(false)
   const prodData = ref({})
   const openCustom = (data)=>{
@@ -257,10 +268,8 @@
     prodData.value = data
   }
   const handleOk = ()=>{
-    if (prodData.value.record.cheekschemeid > 0 && !prodData.record.customcheek) return message.warning('请填写完整信息')
-    if (prodData.value.record.colorschemeid > 0 && !prodData.record.customcolors) return message.warning('请填写完整信息')
-    if (prodData.value.record.materialschemeid > 0 && !prodData.record.custommaterial) return message.warning('请填写完整信息')
-    if ((prodData.value.record.spec == '自定义' || prodData.value.record.spec == 'custom') && (!prodData.value.record.length || !prodData.value.record.width)) return message.warning('请填写完整信息')
+    if (!validInput(prodData.value.record)) 
+      return false
     prodData.value.record.isselect = true
     prod.value.data.some((item)=>{
       if (item.itemid == prodData.value.itemid) {

+ 19 - 13
src/class/product.js

@@ -24,27 +24,33 @@ class Product {
   }  
 
   // 验证商品订制属性是否符合规则
-  checkDimension (dimensionData, schemeData, dimensionName, messageContent) {  
-    const { min, max, type } = dimensionData;  
-    const dimensionValue = schemeData[dimensionName];    
-    if (type === '自定义' && (dimensionValue < min || dimensionValue > max)) {  
-      message.error({ content: messageContent, key: 1 });  
-      return false;  
-    } else if (!dimensionValue) {  
-      message.error({ content: '定制选项不能为空!', key: 1 });  
-      return false;  
-    } else {
-      return true
+  checkDimension (dimensionData, schemeData) { 
+    console.log(schemeData)
+    const requiredProperties = ['length', 'width'];  
+    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) {
+  hasDecimal(num,prop) {
     const str = num.toString();
     const decimalIndex = str.indexOf('.');
     if (decimalIndex !== -1) {
-      message.warning(`请输入整数`)
+      message.error(`${prop == 'length'?'长度':'宽度'}请输入整数`)
       return false
     }
+    return true
   }
 }