Browse Source

发送明细新增和编辑小数位数限制提醒

jbb 2 years ago
parent
commit
fe66644e48

+ 20 - 42
src/views/shipment-details/addShipDetDrawer.vue

@@ -121,7 +121,7 @@
               <!-- 发货数量 :rules="rules.shipQuantity"-->
               <template slot="shipmentQuantity" slot-scope="text, record, index">
                 <a-form-model-item prop="shipmentQuantity">
-                  <a-input style="width:100%" type="text" v-model="record.shipmentQuantity"   @blur="dataDefault('2',record)" />
+                  <a-input style="width:100%" type="text" v-model="record.shipmentQuantity"   @blur="dataDefault(record,record.shipmentQuantity,'发货数量',0)" />
                 </a-form-model-item>
               </template>
 
@@ -154,20 +154,20 @@
               <!-- 报关单价 :rules="rules.customsDeclarationUnitPrice"-->
               <template slot="customsDeclarationUnitPrice" slot-scope="text, record, index">
                 <a-form-model-item prop="customsDeclarationUnitPrice">
-                  <a-input style="width:100%" type="text" v-model="record.customsDeclarationUnitPrice"  @blur="dataDefault('1',record)"/>
+                  <a-input style="width:100%" type="text" v-model="record.customsDeclarationUnitPrice"  @blur="dataDefault(record,record.customsDeclarationUnitPrice,'报关单价',4)"/>
                 </a-form-model-item>
               </template>
               <!-- 套装件数 :rules="rules.numberOfSets"-->
               <template slot="numberOfSets" slot-scope="text, record, index">
                 <a-form-model-item prop="numberOfSets">
-                  <a-input style="width:100%" type="text" v-model="record.numberOfSets"  @blur="dataDefault('3',record)"/>
+                  <a-input style="width:100%" type="text" v-model="record.numberOfSets"  @blur="dataDefault(record,record.numberOfSets,'套装件数',0)"/>
                 </a-form-model-item>
               </template>
 
               <!-- 工厂单价 :rules="rules.factoryUnitPrice"-->
               <template slot="factoryUnitPrice" slot-scope="text, record, index">
                 <a-form-model-item prop="factoryUnitPrice">
-                  <a-input style="width:100%" type="text" v-model="record.factoryUnitPrice"  @blur="dataDefault('4',record)" />
+                  <a-input style="width:100%" type="text" v-model="record.factoryUnitPrice"  @blur="dataDefault(record,record.factoryUnitPrice,'工厂单价',0)" />
                 </a-form-model-item>
               </template>
 
@@ -192,7 +192,7 @@
               <!--手册纱单价 -->
               <template slot="manualYarnUnitPrice" slot-scope="text, record, index">
                 <a-form-model-item prop="manualYarnUnitPrice">
-                  <a-input style="width:100%" type="text" v-model="record.manualYarnUnitPrice" :disabled='manualYarnDisabled' @blur="dataDefault('5',record)" @change="changeManualYarn('Price',record.manualYarnUnitPrice)" />
+                  <a-input style="width:100%" type="text" v-model="record.manualYarnUnitPrice" :disabled='manualYarnDisabled' @blur="dataDefault(record,record.manualYarnUnitPrice,'手册纱单价',4)" @change="changeManualYarn('Price',record.manualYarnUnitPrice)" />
                 </a-form-model-item>
               </template>
 
@@ -796,48 +796,26 @@ export default {
 
 
     //输入框小数点位数限制
-    dataDefault(data,record){
-      this.syShippingDetailsItemList
-      var i = 0
-      for(;i<this.syShippingDetailsItemList.length;i++){
-        // if()
-      }
-      //报关单价
-      if(data === '1'){
-        var position = record.customsDeclarationUnitPrice.indexOf('.') + 1;   //小数点的位置
-        var digit = record.customsDeclarationUnitPrice.length - position;  //小数的位数
-        if(digit >= 4){this.$message.error('报关单价最多四位小数!');  record.customsDeclarationUnitPrice = ''}
-      }
-      //发货数量
-      if(data === '2'){
-        var position = record.shipmentQuantity.indexOf('.') + 1;   //小数点的位置
-        var digit = record.shipmentQuantity.length - position;  //小数的位数
-        if(digit !== 0){this.$message.error('发货数量必须是整数!'); record.shipmentQuantity = ''}
-      }
-      //套装件数 
-      if(data === '3'){
-        var position = record.numberOfSets.indexOf('.') + 1;   //小数点的位置
-        var digit = record.numberOfSets.length - position;  //小数的位数
-        if(digit !== 0){this.$message.error('套装件数必须是整数!');record.numberOfSets = ''}
-      }
-      //工厂单价
-      if(data === '4'){
-        var position = record.factoryUnitPrice.indexOf('.') + 1;   //小数点的位置
-        var digit = record.factoryUnitPrice.length - position;  //小数的位数
-        if(digit >= 4){this.$message.error('工厂单价最多四位小数!'); record.factoryUnitPrice = ''}
-      }
-      //手册纱单价
-      if(data === '5'){
-        var position = record.manualYarnUnitPrice.indexOf('.') + 1;   //小数点的位置
-        var digit = record.manualYarnUnitPrice.length - position;  //小数的位数
-        if(digit >= 4){
-          this.$message.error('手册纱最多四位小数!');
+    dataDefault(record,data,title,filed){
+      var position = data.indexOf('.') + 1;   //小数点的位置
+      var digit = data.length - position;  //小数的位数
+      if(digit > filed){
+        this.$message.error(title+'最多'+filed+'位小数!');  
+        if(title == '手册纱单价'){
           this.syShippingDetailsItemList.map(item => {
             item.manualYarnUnitPrice = ''
             })
             this.$forceUpdate()
+        }else if(title == '报关单价') {
+           record.customsDeclarationUnitPrice = ''
+        }else if(title == '发货数量') {
+          record.shipmentQuantity = ''
+        }else if(title == '套装件数'){
+          record.numberOfSets = ''
+        }else if(title == '工厂单价'){
+          record.factoryUnitPrice = ''
         }
-      }
+       }
     },
     // 操作 删除
     handleDelete(index) {

+ 20 - 37
src/views/shipment-details/editShipDetDrawer.vue

@@ -79,7 +79,7 @@
               <!-- 发货数量 :rules="rules.shipQuantity"-->
               <template slot="shipmentQuantity" slot-scope="text, record, index">
                 <a-form-model-item prop="shipmentQuantity">
-                  <a-input style="width:100%" type="text" v-model="record.shipmentQuantity"  @blur="dataDefault('2',record)" />
+                  <a-input style="width:100%" type="text" v-model="record.shipmentQuantity" @blur="dataDefault(record,record.shipmentQuantity,'发货数量',0)"  />
                 </a-form-model-item>
               </template>
 
@@ -112,20 +112,20 @@
               <!-- 报关单价 :rules="rules.customsDeclarationUnitPrice"-->
               <template slot="customsDeclarationUnitPrice" slot-scope="text, record, index">
                 <a-form-model-item prop="customsDeclarationUnitPrice">
-                  <a-input style="width:100%" type="text" v-model="record.customsDeclarationUnitPrice"  @blur="dataDefault('1',record)"/>
+                  <a-input style="width:100%" type="text" v-model="record.customsDeclarationUnitPrice"  @blur="dataDefault(record,record.customsDeclarationUnitPrice,'报关单价',4)"/>
                 </a-form-model-item>
               </template>
               <!-- 套装件数 :rules="rules.numberOfSets"-->
               <template slot="numberOfSets" slot-scope="text, record, index">
                 <a-form-model-item prop="numberOfSets">
-                  <a-input style="width:100%" type="text" v-model="record.numberOfSets" @blur="dataDefault('3',record)"/>
+                  <a-input style="width:100%" type="text" v-model="record.numberOfSets" @blur="dataDefault(record,record.numberOfSets,'套装件数',0)"/>
                 </a-form-model-item>
               </template>
 
               <!-- 工厂单价 :rules="rules.factoryUnitPrice"-->
               <template slot="factoryUnitPrice" slot-scope="text, record, index">
                 <a-form-model-item prop="factoryUnitPrice">
-                  <a-input style="width:100%" type="text" v-model="record.factoryUnitPrice"  @blur="dataDefault('4',record)"/>
+                  <a-input style="width:100%" type="text" v-model="record.factoryUnitPrice"  @blur="dataDefault(record,record.factoryUnitPrice,'工厂单价',0)"/>
                 </a-form-model-item>
               </template>
 
@@ -156,7 +156,7 @@
               <!--手册纱单价 -->
               <template slot="manualYarnUnitPrice" slot-scope="text, record, index">
                 <a-form-model-item prop="manualYarnUnitPrice">
-                  <a-input style="width:100%" type="text" v-model="record.manualYarnUnitPrice"  :disabled='manualYarnDisabled' @blur="dataDefault('5',record)" @change="changeManualYarn('Price',record.manualYarnUnitPrice)"/>
+                  <a-input style="width:100%" type="text" v-model="record.manualYarnUnitPrice"  :disabled='manualYarnDisabled' @blur="dataDefault(record,record.manualYarnUnitPrice,'手册纱单价',4)" @change="changeManualYarn('Price',record.manualYarnUnitPrice)"/>
                 </a-form-model-item>
               </template>
 
@@ -708,42 +708,25 @@ export default {
    },
 
     //输入框小数点位数限制
-    dataDefault(data,record){
-      //报关单价
-      if(data === '1'){
-        var position = record.customsDeclarationUnitPrice.indexOf('.') + 1;   //小数点的位置
-        var digit = record.customsDeclarationUnitPrice.length - position;  //小数的位数
-        if(digit >= 4){this.$message.error('报关单价最多四位小数!'); record.customsDeclarationUnitPrice =''}
-      }
-      //发货数量
-      if(data === '2'){
-        var position = record.shipmentQuantity.indexOf('.') + 1;   //小数点的位置
-        var digit = record.shipmentQuantity.length - position;  //小数的位数
-        if(digit !== 0){this.$message.error('发货数量必须是整数!'); record.shipmentQuantity =''}
-      }
-      //套装件数 
-      if(data === '3'){
-        var position = record.numberOfSets.indexOf('.') + 1;   //小数点的位置
-        var digit = record.numberOfSets.length - position;  //小数的位数
-        if(digit !== 0){this.$message.error('套装件数必须是整数!'); record.numberOfSets =''}
-      }
-      //工厂单价
-      if(data === '4'){
-        var position = record.factoryUnitPrice.indexOf('.') + 1;   //小数点的位置
-        var digit = record.factoryUnitPrice.length - position;  //小数的位数
-        if(digit >= 4){this.$message.error('工厂单价最多四位小数!'); record.factoryUnitPrice =''}
-      }
-      //手册纱单价
-      if(data === '5'){
-        var position = record.manualYarnUnitPrice.indexOf('.') + 1;   //小数点的位置
-        var digit = record.manualYarnUnitPrice.length - position;  //小数的位数
-        if(digit >= 4){
-          this.$message.error('手册纱最多四位小数!');
+    dataDefault(record,data,title,filed){
+      var position = data.indexOf('.') + 1;   //小数点的位置
+      var digit = data.length - position;  //小数的位数
+      if(digit > filed){
+        this.$message.error(title+'最多'+filed+'位小数!');  
+        if(title == '手册纱单价'){
           this.syShippingDetailsItemList.map(item => {
             item.manualYarnUnitPrice = ''
             })
             this.$forceUpdate()
-          }
+        }else if(title == '报关单价') {
+           record.customsDeclarationUnitPrice = ''
+        }else if(title == '发货数量') {
+          record.shipmentQuantity = ''
+        }else if(title == '套装件数'){
+          record.numberOfSets = ''
+        }else if(title == '工厂单价'){
+          record.factoryUnitPrice = ''
+        }
        }
     },