zhangqi 1 год назад
Родитель
Сommit
bc146febf7

+ 21 - 7
src/DRP/HDrpManagement/orderManage/detail/index.vue

@@ -195,6 +195,7 @@ import saleOutBill from './tabs/saleOutBill.vue'
 import logisticsOrder from './tabs/logisticsOrder.vue'
 import IncomeMx from './tabs/income.vue'
 import print from '@/components/print/index.vue'
+import Product from '@/class/Product.js'
 
 import { Modal } from 'ant-design-vue'
 import { message } from 'ant-design-vue';
@@ -370,14 +371,27 @@ const updateProd = async (data,msg,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
+  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 {
-    record[type] = record[type]
-  }
+    // 如果所有检查都通过  
+    return true;
+  } 
+  // 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 addProductToBody = async (val) =>{
   let param = {

+ 23 - 8
src/DRP/SDrpManagement/order/detail/index.vue

@@ -488,6 +488,7 @@ import { Modal } from "ant-design-vue";
 import { message } from "ant-design-vue";
 import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
 import { useRouter } from "vue-router";
+import Product from '@/class/Product'
 import {
   onMounted,
   ref,
@@ -651,14 +652,28 @@ const updateProd = async (data, msg, 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];
-  }
+  // 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 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;
 };
 const qtyModal = ref(false)
 const promotionQty  = ref(null)

+ 26 - 20
src/DRP/SDrpManagement/productGroup/detail/index.vue

@@ -39,26 +39,26 @@
       <div v-if="group.materialRows.length > 0" class="mt-30 input-number-panel">
         <p class="label"><span class="mr-10">{{siteInfo.siteid == 'DLB'?'选项':'基材'}}</span></p>
         <div>
-          <a-button class="mr-10 mt-10" v-for="(item,index) in group.materialRows" :key="index" :disabled="!item.flag" :type="data.material == item.parm?'primary':'default'" @click="customClick('material',item.parm)">{{item.parm}}</a-button>
+          <a-button class="mr-10 mt-10" v-for="(item,index) in group.materialRows" :key="index" :disabled="!item.flag || load" :type="data.material == item.parm?'primary':'default'" @click="customClick('material',item.parm)">{{item.parm}}</a-button>
         </div>
       </div>
       <div v-if="group.colorRows.length > 0" class="mt-30 input-number-panel">
         <p class="label"><span class="mr-10">颜色</span></p>
         <div>
-          <a-button class="mr-10 mt-10" v-for="(item,index) in group.colorRows" :key="index" :disabled="!item.flag" :type="data.color == item.parm?'primary':'default'" @click="customClick('color',item.parm)">{{item.parm}}</a-button>
+          <a-button class="mr-10 mt-10" v-for="(item,index) in group.colorRows" :key="index" :disabled="!item.flag || load" :type="data.color == item.parm?'primary':'default'" @click="customClick('color',item.parm)">{{item.parm}}</a-button>
         </div>
       </div>
      
       <div v-if="group.cheekRows.length > 0" class="mt-30 input-number-panel">
         <p class="label"><span class="mr-10">{{siteInfo.siteid == 'DLB'?'工艺':'边框'}}</span></p>
         <div>
-          <a-button class="mr-10" v-for="(item,index) in group.cheekRows" :key="index" :disabled="!item.flag" :type="data.cheek == item.parm?'primary':'default'" @click="customClick('cheek',item.parm)">{{item.parm}}</a-button>
+          <a-button class="mr-10" v-for="(item,index) in group.cheekRows" :key="index" :disabled="!item.flag || load" :type="data.cheek == item.parm?'primary':'default'" @click="customClick('cheek',item.parm)">{{item.parm}}</a-button>
         </div>
       </div>
       <div v-if="group.specRows.length > 0" class="mt-30 input-number-panel">
         <p style="flex:1 0 auto;max-width:38px;margin-bottom:10px" class="label"><span class="mr-10">尺寸</span></p>
         <div>
-          <a-button  class="mr-10 mt-10" v-for="(item,index) in group.specRows" :key="index" :disabled="!item.flag" :type="data.spec == item.parm?'primary':'default'" @click="customClick('spec',item.parm)">{{item.parm == 'custom'?'自定义':item.parm}}</a-button>
+          <a-button  class="mr-10 mt-10" v-for="(item,index) in group.specRows" :key="index" :disabled="!item.flag || load" :type="data.spec == item.parm?'primary':'default'" @click="customClick('spec',item.parm)">{{item.parm == 'custom'?'自定义':item.parm}}</a-button>
         </div>
       </div>
       
@@ -131,6 +131,8 @@
   import utils from '@/utils/utils'
   import { useBaseStore } from '@/stores/modules/base'
   import { storeToRefs } from 'pinia'
+  import Product from '@/class/product'
+
   const base = useBaseStore()
   let { siteInfo } = storeToRefs(base)
 
@@ -148,13 +150,17 @@
   const imgIndex = ref(0)
   const custom = ref([])
   const qty = ref(0)
+  const load = ref(false)
   const groupDetail = async (init)=>{
+    load.value = true
     data.value.sa_itemgroupid = router.currentRoute.value.query.id
     const res = await Api.requested({
       "id": "20221223165503",
       "content": data.value
     })
+    load.value = false
     group.value = res.data
+
     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
@@ -175,7 +181,6 @@
     if (res.data.rows.length == 1) {
       // 遍历对象
       for (let key in res.data.rows[0]) {
-        console.log(key,'--')
         data.value[key] = res.data.rows[0][key]
       }
     }
@@ -292,7 +297,6 @@
     return res.data
   }
   const onInputChange = ((type)=>{
-    console.log(schemeData.value)
     function hasDecimal(num) {
       const str = num.toString();
       const decimalIndex = str.indexOf('.');
@@ -301,11 +305,14 @@
     if (schemeData.value.width && hasDecimal(schemeData.value.width)){
       message.warning('请输入整数')
       schemeData.value.width = widthscheme.value.min
+      return false
     }
     if (schemeData.value.length && hasDecimal(schemeData.value.length)) {
       message.warning('请输入整数')
       schemeData.value.length = lengthscheme.value.min
+      return false
     }
+    if (!validCustomSize()) return false
   })
   const getCustomsizeData =  async ()=>{
     let lengthschemeid = group.value.item[0].lengthschemeid
@@ -326,22 +333,21 @@
       }
   }
   const validCustomSize = ()=>{
-    let lengthValidData = {min:lengthscheme.value.min,max:lengthscheme.value.max}
-    let widthValData = {min:widthscheme.value.min,max:widthscheme.value.max}
-    if (!schemeData.value.width || !schemeData.value.length) {
-      message.error({content:'定制选项不能为空!',key:1})
-      return false
-    } else if ((schemeData.value.width < widthValData.min || schemeData.value.width > widthValData.max) && widthscheme.value.type == '自定义') {
-      message.error({content:'自定义宽度超出可选范围!',key:1})
-      return false
-    } else if ((schemeData.value.length < lengthValidData.min || schemeData.value.length > lengthValidData.max) && lengthscheme.value.type == '自定义') {
-      message.error({content:'自定义长度超出可选范围!',key:1})
-      return false
+    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;  
+    } else if (!pd.checkDimension(lengthValidData, schemeData.value, 'length', '自定义长度超出可选范围!')) {  
+      return false;  
     } else {
-      return true
-    }
-    
+      // 如果所有检查都通过  
+      return true;
+    } 
   }
+    
   const onCollection = (data)=>{
     let collection = async (bool)=>{
       const res = await Api.requested({

+ 1 - 4
src/DRP/SDrpManagement/productGroup/index.vue

@@ -86,12 +86,9 @@
   import Api from '@/api/api'
   import utils from '@/utils/utils'
   import FieldAndClass from './modules/fieldAndClass.vue'
-  import {ref,onMounted,getCurrentInstance} from 'vue'
+  import {ref,onMounted} from 'vue'
   import { ShoppingCartOutlined,StarOutlined,StarFilled} from '@ant-design/icons-vue';
-  import { message } from 'ant-design-vue';
   import { useBaseStore } from '@/stores/modules/base'
-  import { storeToRefs } from 'pinia'
-
   import { useRouter } from "vue-router"
   const base = useBaseStore()
   const router = useRouter()

+ 0 - 2
src/api/request.js

@@ -4,8 +4,6 @@ import axios from 'axios'
 import { useAuthStore } from '@/stores/modules/auth'
 import { useBaseStore } from '@/stores/modules/base'
 import { message } from 'ant-design-vue';
-import NProgress from 'nprogress' // nprogress插件 
-import 'nprogress/nprogress.css' // nprogress样式
 import utils from '@/utils/utils'
 import router from '@/router'
 let CancelToken = axios.CancelToken;

+ 65 - 0
src/class/product.js

@@ -0,0 +1,65 @@
+import { message } from 'ant-design-vue';
+class Product {  
+  constructor(attributes = {}) {  
+    // 初始化一个空对象来存储商品的所有属性  
+    this.attributes = {};  
+  
+    // 如果传入了属性,则将它们添加到attributes对象中  
+    Object.assign(this.attributes, attributes);  
+  }  
+  
+  // 定义一个方法来获取商品属性  
+  getAttribute(key) {  
+    return this.attributes[key];  
+  }  
+  
+  // 定义一个方法来设置商品属性  
+  setAttribute(key, value) {  
+    this.attributes[key] = value;  
+  }  
+  
+  // 定义一个方法来列出所有商品属性  
+  listAttributes() {  
+    return Object.keys(this.attributes).map(key => `${key}: ${this.attributes[key]}`).join(', ');  
+  }  
+
+  // 验证商品订制属性是否符合规则
+  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;  
+    }  
+    
+    // 检查值是否为空  
+    if (!dimensionValue) {  
+      message.error({ content: '定制选项不能为空!', key: 1 });  
+      return false;  
+    }  
+    
+    return true;  
+  }  
+}  
+  
+// const product1 = new Product({  
+//   name: 'Apple iPhone 12',  
+//   price: 999.99,  
+//   category: 'Smartphone'  
+// });  
+  
+// console.log(product1.getAttribute('name')); // 输出: Apple iPhone 12  
+// console.log(product1.listAttributes()); // 输出: name: Apple iPhone 12, price: 999.99, category: Smartphone  
+  
+// // 动态添加属性  
+// product1.setAttribute('stock', 100);  
+// console.log(product1.listAttributes()); // 输出: name: Apple iPhone 12, price: 999.99, category: Smartphone, stock: 100  
+  
+// // 创建另一个商品实例,不传入任何属性  
+// const product2 = new Product();  
+// product2.setAttribute('name', 'Samsung Galaxy S21');  
+// product2.setAttribute('price', 899.99);  
+// console.log(product2.listAttributes()); // 输出: name: Samsung Galaxy S21, price: 899.99
+export default Product