Explorar o código

修改损耗数bug

695593266@qq.com hai 9 meses
pai
achega
5eb349fea7

+ 42 - 4
src/views/produce/components/feeding/components/batchProductsBom.vue

@@ -291,16 +291,22 @@
               dataList.push(this.deepCopy(item));
             });
 
-            this.refreshData(dataList);
+            if (dataList.length != 0) {
+              this.refreshData(dataList);
+            }
           });
         }
         this.dialogVisible = false;
       },
 
       refreshData(list) {
-        const number =
-          Number(this.list[this.itemIndex].feedQuantity) -
-          Number(this.form.quantity);
+        // const number =
+        //   Number(this.list[this.itemIndex].feedQuantity) -
+        //   Number(this.form.quantity);
+        const number = this.sub(
+          Number(this.list[this.itemIndex].feedQuantity),
+          Number(this.batchForm.quantity)
+        );
         this.list[this.itemIndex].extInfo.sourceQuantity = number;
         this.list[this.itemIndex].feedQuantity = number;
         this.list[this.itemIndex].extInfo.newWeight =
@@ -324,6 +330,38 @@
         this.$set(this.itemObj, 'product', this.list);
       },
 
+      toInteger(num) {
+        const len = this.getDecimalLength(num);
+        return {
+          int: Math.round(num * Math.pow(10, len)),
+          factor: Math.pow(10, len)
+        };
+      },
+
+      add(a, b) {
+        const { int: aInt, factor: aFactor } = this.toInteger(a);
+        const { int: bInt, factor: bFactor } = this.toInteger(b);
+        const maxFactor = Math.max(aFactor, bFactor);
+        return (
+          (aInt * (maxFactor / aFactor) + bInt * (maxFactor / bFactor)) /
+          maxFactor
+        );
+      },
+
+      sub(a, b) {
+        const { int: aInt, factor: aFactor } = this.toInteger(a);
+        const { int: bInt, factor: bFactor } = this.toInteger(b);
+        const maxFactor = Math.max(aFactor, bFactor);
+        return (
+          (aInt * (maxFactor / aFactor) - bInt * (maxFactor / bFactor)) /
+          maxFactor
+        );
+      },
+
+      getDecimalLength(num) {
+        return (num.toString().split('.')[1] || '').length;
+      },
+
       deepCopy(obj, hash = new WeakMap()) {
         if (obj === null) return null;
         if (obj instanceof Date) return new Date(obj);

+ 80 - 16
src/views/produce/components/jobBooking/components/batchSemiProductJobBom.vue

@@ -1246,12 +1246,15 @@
       sumweight(arr) {
         let formedWeight = 0;
         let noFormedWeight = 0;
+        let lossWeight = 0;
         arr.map((s, i) => {
           if (s.extInfo.reportWeight) {
-            if (s.extInfo.isQualified == 1) {
+            if (s.extInfo.isQualified == 1 && !s.extInfo.isLoss) {
               formedWeight += s.extInfo.reportWeight * 1;
-            } else {
+            } else if (!s.extInfo.isLoss) {
               noFormedWeight += s.extInfo.reportWeight * 1;
+            } else if (s.extInfo.isLoss == 1) {
+              lossWeight += s.extInfo.reportWeight * 1;
             }
           } else {
             s.extInfo.reportWeight = null;
@@ -1270,7 +1273,12 @@
           this.item.workReportInfo.notFormedWeight = parseFloat(
             noFormedWeight.toFixed(2)
           );
+          this.item.workReportInfo.lossWeight = parseFloat(
+            lossWeight.toFixed(2)
+          );
         }
+
+        console.log(this.item.workReportInfo, 'this.item.workReportInfo');
       },
 
       async getCodeData() {
@@ -1407,6 +1415,18 @@
 
       async getQualityParam() {
         if (this.batchForm.quantity && this.batchForm.batchNo) {
+          // const reg = /^(\d+)(\.\d{0,4})?$/;
+          // if (
+          //   this.itemData.feedQuantity === '' ||
+          //   reg.test(this.itemData.feedQuantity)
+          // ) {
+          //   this.itemData.feedQuantity = val;
+          // } else {
+          //   // 如果用户输入非法字符,直接去掉非法部分
+          //   const match = val.match(/^(\d+)(\.\d{0,4})?/);
+          //   this.itemData.feedQuantity = match ? match[0] : '';
+          // }
+
           if (Number(this.itemData.feedQuantity) == 0) {
             this.$message.warning('拆批数不能等于0');
             return;
@@ -1445,9 +1465,13 @@
       },
 
       refreshData(list) {
-        const number =
-          Number(this.list[this.itemIndex].feedQuantity) -
-          Number(this.batchForm.quantity);
+        // const number =
+        //   Number(this.list[this.itemIndex].feedQuantity) -
+        //   Number(this.batchForm.quantity);
+        const number = this.sub(
+          Number(this.list[this.itemIndex].feedQuantity),
+          Number(this.batchForm.quantity)
+        );
         this.list[this.itemIndex].extInfo.sourceQuantity = number;
         this.list[this.itemIndex].feedQuantity = number;
         this.list[this.itemIndex].extInfo.newWeight =
@@ -1479,6 +1503,38 @@
         }, result);
       },
 
+      toInteger(num) {
+        const len = this.getDecimalLength(num);
+        return {
+          int: Math.round(num * Math.pow(10, len)),
+          factor: Math.pow(10, len)
+        };
+      },
+
+      add(a, b) {
+        const { int: aInt, factor: aFactor } = this.toInteger(a);
+        const { int: bInt, factor: bFactor } = this.toInteger(b);
+        const maxFactor = Math.max(aFactor, bFactor);
+        return (
+          (aInt * (maxFactor / aFactor) + bInt * (maxFactor / bFactor)) /
+          maxFactor
+        );
+      },
+
+      sub(a, b) {
+        const { int: aInt, factor: aFactor } = this.toInteger(a);
+        const { int: bInt, factor: bFactor } = this.toInteger(b);
+        const maxFactor = Math.max(aFactor, bFactor);
+        return (
+          (aInt * (maxFactor / aFactor) - bInt * (maxFactor / bFactor)) /
+          maxFactor
+        );
+      },
+
+      getDecimalLength(num) {
+        return (num.toString().split('.')[1] || '').length;
+      },
+
       openLoss(item, index) {
         this.lossForm.quantity = '';
         this.lossForm.unit = '';
@@ -1492,6 +1548,18 @@
 
       async getLossParam() {
         if (this.lossForm.quantity && this.lossForm.batchNo) {
+          // const reg = /^(\d+)(\.\d{0,4})?$/;
+          // if (
+          //   this.lossData.feedQuantity === '' ||
+          //   reg.test(this.lossData.feedQuantity)
+          // ) {
+          //   this.lossData.feedQuantity = val;
+          // } else {
+          //   // 如果用户输入非法字符,直接去掉非法部分
+          //   const match = val.match(/^(\d+)(\.\d{0,4})?/);
+          //   this.lossData.feedQuantity = match ? match[0] : '';
+          // }
+
           if (
             Number(this.lossData.feedQuantity) < Number(this.lossForm.quantity)
           ) {
@@ -1519,9 +1587,13 @@
       },
 
       refreshLossData(list) {
-        const number =
-          Number(this.list[this.lossIndex].feedQuantity) -
-          Number(this.lossForm.quantity);
+        // const number =
+        //   Number(this.list[this.lossIndex].feedQuantity) -
+        //   Number(this.lossForm.quantity);
+        const number = this.sub(
+          Number(this.list[this.lossIndex].feedQuantity),
+          Number(this.lossForm.quantity)
+        );
         this.list[this.lossIndex].extInfo.sourceQuantity = number;
         this.list[this.lossIndex].feedQuantity = number;
         this.list[this.lossIndex].extInfo.newWeight =
@@ -1534,14 +1606,6 @@
         });
 
         const newList = this.list.filter((item) => item.feedQuantity != 0);
-        console.log(newList, 'newList新数据');
-
-        // this.$set(
-        //   this.item,
-        //   'product',
-        //   this.list.filter((item) => item.feedQuantity != 0)
-        // );
-
         let _arr = [...newList, ...list];
 
         this.$set(this.item, 'product', _arr);

+ 70 - 18
src/views/produce/components/jobBooking/components/jobBom.vue

@@ -110,6 +110,47 @@
           </div> -->
         </div>
 
+        <div class="item rx-sc">
+          <div class="rx ww40">
+            <div class="lable lable100 rx-cc">损耗数</div>
+            <div class="content content_num rx-sc">
+              <el-input
+                size="mini"
+                v-model="item.workReportInfo.lossQuantity"
+                :disabled="isDetails"
+                placeholder=""
+                @input="changeNum"
+              >
+                <template slot="append">{{ item.unit }}</template>
+              </el-input>
+            </div>
+          </div>
+
+          <div class="rx ww40">
+            <div class="lable rx-cc">损耗数重量</div>
+            <div class="content content_num rx-sc">
+              <el-input
+                size="mini"
+                v-model="item.workReportInfo.lossWeight"
+                :disabled="isDetails"
+                placeholder=""
+              >
+                <template slot="append">{{ item.weightUnit }}</template>
+              </el-input>
+            </div>
+          </div>
+
+          <!-- <div class="rw ww20 rx-cc">
+            <div class="penalize" v-if="!isDetails" :style="{ background: not.warehouseId ? '#FFA07A' : '' }"
+              @click="penalize">
+              处置</div>
+            <div class="penalize" v-if="isDetails" :style="{ background: not.warehouseId ? '#FFA07A' : '' }" @click="
+              handleView(isDetails ? not.warehouseName : item.warehouseName)
+              ">
+              查看</div>
+          </div> -->
+        </div>
+
         <!-- 报工备注 -->
         <div class="item rx-sc">
           <div
@@ -257,6 +298,7 @@
           if (newVal.product && newVal.product.length != 0) {
             let formedNum = 0;
             let notFormedNum = 0;
+            let lossNum = 0;
 
             newVal.product.forEach((item) => {
               if (
@@ -267,28 +309,28 @@
               ) {
                 // formedNum = formedNum + Number(item.feedQuantity);
                 formedNum = this.add(formedNum, Number(item.feedQuantity));
-              } else {
-                if (
-                  (item.extInfo.notType == 5 || item.extInfo.notType == 8) &&
-                  !item.extInfo.isLoss
-                ) {
+              } else if (!item.extInfo.isLoss) {
+                if (item.extInfo.notType == 5 || item.extInfo.notType == 8) {
                   // formedNum = formedNum + Number(item.feedQuantity);
 
                   formedNum = this.add(formedNum, Number(item.feedQuantity));
                 } else {
                   // notFormedNum = notFormedNum + Number(item.feedQuantity);
-                  if (!item.extInfo.isLoss) {
-                    notFormedNum = this.add(
-                      notFormedNum,
-                      Number(item.feedQuantity)
-                    );
-                  }
+                  // if (!item.extInfo.isLoss) {
+                  notFormedNum = this.add(
+                    notFormedNum,
+                    Number(item.feedQuantity)
+                  );
+                  // }
                 }
+              } else if (item.extInfo.isLoss == 1) {
+                lossNum = this.add(lossNum, Number(item.feedQuantity));
               }
             });
 
             this.$set(this.item.workReportInfo, 'formedNum', formedNum);
             this.$set(this.item.workReportInfo, 'notFormedNum', notFormedNum);
+            this.$set(this.item.workReportInfo, 'lossQuantity', lossNum);
           }
 
           // if (
@@ -386,6 +428,16 @@
         );
       },
 
+      sub(a, b) {
+        const { int: aInt, factor: aFactor } = this.toInteger(a);
+        const { int: bInt, factor: bFactor } = this.toInteger(b);
+        const maxFactor = Math.max(aFactor, bFactor);
+        return (
+          (aInt * (maxFactor / aFactor) - bInt * (maxFactor / bFactor)) /
+          maxFactor
+        );
+      },
+
       getDecimalLength(num) {
         return (num.toString().split('.')[1] || '').length;
       },
@@ -410,13 +462,13 @@
       },
 
       blurNum() {
-        let total =
-          Number(this.item.workReportInfo.formedNum) +
-          Number(this.item.workReportInfo.notFormedNum);
-        if (total > this.item.formingNum) {
-          this.item.workReportInfo.formedNum = 0;
-          this.$message.warning('合格品数量加不合格数量不能大于要求生产数量');
-        }
+        // let total =
+        //   Number(this.item.workReportInfo.formedNum) +
+        //   Number(this.item.workReportInfo.notFormedNum);
+        // if (total > this.item.formingNum) {
+        //   this.item.workReportInfo.formedNum = 0;
+        //   this.$message.warning('合格品数量加不合格数量不能大于要求生产数量');
+        // }
 
         // let total =
         //   Number(this.item.workReportInfo.formedNum) +

+ 3 - 1
src/views/produce/components/jobBooking/index.vue

@@ -942,7 +942,9 @@
                   formedWeight: null,
                   taskId: this.taskObj.id,
                   notFormedNum: null,
-                  notFormedWeigh: null
+                  notFormedWeigh: null,
+                  lossNum: null,
+                  lossWeight: null
                 };
 
                 obj.notFormedList = [

+ 11 - 17
src/views/produce/components/outsourcing/index.vue

@@ -4,8 +4,6 @@
       <!-- <el-tabs type="card" v-model="activeName" @tab-click="handleClick">
         <el-tab-pane label="委外记录" name="1"></el-tab-pane>
         <el-tab-pane label="请托记录" name="2"></el-tab-pane> -->
-      <!-- <div class="c_title">委外记录</div>
-        <div class="c_title">委外记录</div> -->
       <!-- </el-tabs> -->
       <div class="c_title">委外记录</div>
     </div>
@@ -427,6 +425,10 @@
       outsourceFormVal: {
         type: Object,
         default: () => ({})
+      },
+      taskName: {
+        type: String,
+        default: ''
       }
     },
 
@@ -471,21 +473,13 @@
     mounted() {
       this.getContactList();
       this.getFactoryList();
-      // if (this.activeName == '1') {
-      //   // this.attributeData.name = this.outsourceFormVal.name + '委托';
-      //   this.$set(
-      //     this.outsourceFormVal,
-      //     'name',
-      //     this.outsourceFormVal.name + '委托'
-      //   );
-      // } else if (this.activeName == '2') {
-      //   // this.attributeData.name = this.outsourceFormVal.name + '请托';
-      //   this.$set(
-      //     this.outsourceFormVal,
-      //     'name',
-      //     this.outsourceFormVal.name + '请托'
-      //   );
-      // }
+      if (this.activeName == '1') {
+        // this.attributeData.name = this.outsourceFormVal.name + '委托';
+        this.$set(this.outsourceFormVal, 'name', this.taskName + '委托');
+      } else if (this.activeName == '2') {
+        // this.attributeData.name = this.outsourceFormVal.name + '请托';
+        this.$set(this.outsourceFormVal, 'name', this.taskName + '请托');
+      }
     },
 
     methods: {

+ 1 - 0
src/views/produce/index.vue

@@ -240,6 +240,7 @@
                 ></outsourcingDetails>
                 <outsourcing
                   :outsourceFormVal="outsourceForm"
+                  :taskName="taskObj.name"
                   @changePlugIn="changePlugIn"
                   @changeCancel="changeCancel"
                   v-if="isStep"