lucw 7 месяцев назад
Родитель
Сommit
b82bda1135

+ 280 - 49
src/views/produce/components/prenatalExamination/material.vue

@@ -44,7 +44,8 @@
           v-model.number="row.reportQuantity"
           controls-position="right"
           :min="0"
-          :max="row.feedQuantity"
+          :max="reportQuantitymax(row)"
+          @change="$emit('update:outputDetails', localOutputDetails)"
         ></el-input-number>
       </template>
       <template v-slot:qualifiedQuantity="{ row }">
@@ -54,6 +55,7 @@
           controls-position="right"
           :min="0"
           :max="qualifiedQuantityMax(row)"
+          @change="$emit('update:outputDetails', localOutputDetails)"
         ></el-input-number>
       </template>
       <template v-slot:noQualifiedQuantity="{ row }">
@@ -63,6 +65,7 @@
           controls-position="right"
           :min="0"
           :max="noQualifiedQuantityMax(row)"
+          @change="$emit('update:outputDetails', localOutputDetails)"
         ></el-input-number>
       </template>
       <template v-slot:msg="{ row }">
@@ -71,6 +74,7 @@
           type="textarea"
           rows="1"
           autosize
+          @change="$emit('update:outputDetails', localOutputDetails)"
         ></el-input>
       </template>
     </ele-pro-table>
@@ -121,6 +125,16 @@
         type: [String, Number],
         required: true
       },
+      // 工序实例id
+      produceTaskInstanceId: {
+        type: [String, Number],
+        required: true
+      },
+      // 工序名称
+      produceTaskName: {
+        type: String,
+        required: true
+      },
       // BOM产品分类id
       bomCategoryId: {
         type: [String, Number],
@@ -140,31 +154,44 @@
     watch: {
       pickDetails: {
         handler(newVal) {
-          this.localPickDetails = JSON.parse(JSON.stringify(newVal));
+          this.localPickDetails = JSON.parse(JSON.stringify(newVal)).map(
+            (i) => {
+              i.ruleId = this.ruleId;
+              i.bomCategoryId = this.bomCategoryId;
+              return i;
+            }
+          );
         },
-        deep: true
+        deep: true,
+        immediate: true
       },
       outputDetails: {
         handler(newVal) {
-          this.localOutputDetails = JSON.parse(JSON.stringify(newVal));
+          this.localOutputDetails = JSON.parse(JSON.stringify(newVal)).map(
+            (i) => {
+              i.ruleId = this.ruleId;
+              i.outputType = this.outputType;
+              i.bomCategoryId = this.bomCategoryId;
+              i.id = null;
+              return i;
+            }
+          );
         },
-        deep: true
-      },
-      bomCategoryId: {
-        handler() {
-          this.getMaterialQuotaInfo();
-        }
-      },
-      produceTaskId: {
-        handler() {
-          this.getMaterialQuotaInfo();
-        }
+        deep: true,
+        immediate: true
       },
       outputType: {
         handler() {
           // 重置产出明细
           this.localOutputDetails = [];
 
+          this.localPickDetails = this.localPickDetails.map((item) => {
+            return {
+              ...item,
+              selected: false
+            };
+          });
+
           // 根据不同的类型,重置物料明细
           if (this.outputType == 1) {
             this.$emit('update:outputDetails', this.localOutputDetails);
@@ -238,6 +265,36 @@
             formatter: (row) => {
               return (row.quantity || '') + (row.unit || '');
             }
+          },
+          {
+            label: '当次消耗数量',
+            prop: '',
+            minWidth: 120,
+            formatter: (row) => {
+              // 取值产出清单
+              const outputItem = this.localOutputDetails.find(
+                (item) => item.categoryId === row.categoryId
+              );
+              return (
+                (outputItem ? outputItem.reportQuantity : 0) + (row.unit || '')
+              );
+            }
+          },
+          {
+            label: '累计消耗数量',
+            prop: '',
+            minWidth: 120,
+            formatter: (row) => {
+              const outputItem = this.localOutputDetails.find(
+                (item) => item.categoryId === row.categoryId
+              );
+              if (!outputItem) {
+                return '0' + (row.unit || '');
+              }
+              let count =
+                outputItem.sumReportQuantity + outputItem.reportQuantity;
+              return count + (row.unit || '');
+            }
           }
         ];
         if (this.outputType == 1) {
@@ -255,8 +312,9 @@
 
     data() {
       return {
-        localPickDetails: JSON.parse(JSON.stringify(this.pickDetails)),
-        localOutputDetails: JSON.parse(JSON.stringify(this.outputDetails)),
+        localPickDetails: [],
+        localOutputDetails: [],
+        // bom配置的 标准产出信息
         materialQuotaInfo: null,
         // 产出清单表头
         outputDetailsColumns: [
@@ -308,34 +366,19 @@
             label: '当次报工数量',
             prop: 'reportQuantity',
             minWidth: 160,
-            slot: 'reportQuantity',
-            formatter: (row) => {
-              return (
-                (row.reportQuantity == null ? '' : row.unit) +
-                (row.feedUnit || '')
-              );
-            }
+            slot: 'reportQuantity'
           },
           {
             label: '当次合格数量',
             prop: 'qualifiedQuantity',
             minWidth: 160,
-            slot: 'qualifiedQuantity',
-            formatter: (row) => {
-              return (
-                (row.qualifiedQuantity == null ? '' : row.unit) +
-                (row.feedUnit || '')
-              );
-            }
+            slot: 'qualifiedQuantity'
           },
           {
             label: '当次不合格数量',
             prop: 'noQualifiedQuantity',
             minWidth: 160,
-            slot: 'noQualifiedQuantity',
-            formatter: (row) => {
-              return (row.noQualifiedQuantity || 0) + (row.unit || '');
-            }
+            slot: 'noQualifiedQuantity'
           },
           {
             label: '不合格原因',
@@ -367,17 +410,12 @@
               return (row.sumNoQualifiedQuantity || 0) + (row.unit || '');
             }
           }
-        ]
+        ],
+        // bomInfo
+        materialQuotaInfo: null
       };
     },
-    mounted() {
-      if (this.outputType == 2) {
-        this.getCategoryAndLevelByCategoryId();
-      }
-      if (this.outputType == 3) {
-        this.getMaterialQuotaInfo();
-      }
-    },
+    mounted() {},
     methods: {
       // 选择物料
       openMaterialModal() {
@@ -405,13 +443,21 @@
             this.localPickDetails[index].quantity = newItem.quantity;
           } else {
             // 不存在则添加
-            this.localPickDetails.push({ ...newItem });
+            this.localPickDetails.push({
+              ...newItem,
+              ruleId: this.ruleId,
+              bomCategoryId: this.bomCategoryId,
+              produceTaskId: this.produceTaskId,
+              produceTaskInstanceId: this.produceTaskInstanceId,
+              produceTaskName: this.produceTaskName,
+              workOrderId: this.workOrderId
+            });
           }
         });
 
         this.$emit('update:pickDetails', this.localPickDetails);
       },
-      // 获取bom的产出
+      // 获取bom的产出清单
       async getMaterialQuotaInfo() {
         if (this.bomCategoryId && this.produceTaskId) {
           const data = await getMaterialQuotaInfo(
@@ -422,17 +468,25 @@
           if (!data.standardOutput) {
             return this.$message.warning('未配置标准产出物料');
           }
+          this.materialQuotaInfo = data;
           // 赋值产出
           this.localOutputDetails = [
             {
               ...data.standardOutput,
+              id: null,
               reportQuantity: 0,
               qualifiedQuantity: 0,
               noQualifiedQuantity: 0,
               msg: '',
               sumReportQuantity: 0,
               sumQualifiedQuantity: 0,
-              sumNoQualifiedQuantity: 0
+              sumNoQualifiedQuantity: 0,
+              ruleId: this.ruleId,
+              outputType: this.outputType,
+              produceTaskId: this.produceTaskId,
+              produceTaskInstanceId: this.produceTaskInstanceId,
+              produceTaskName: this.produceTaskName,
+              workOrderId: this.workOrderId
             }
           ];
           this.$emit('update:outputDetails', this.localOutputDetails);
@@ -461,13 +515,21 @@
             // 不存在则添加
             this.localOutputDetails.push({
               ...row,
+              id: null,
               reportQuantity: 0,
               qualifiedQuantity: 0,
               noQualifiedQuantity: 0,
               msg: '',
               sumReportQuantity: 0,
               sumQualifiedQuantity: 0,
-              sumNoQualifiedQuantity: 0
+              sumNoQualifiedQuantity: 0,
+              ruleId: this.ruleId,
+              outputType: this.outputType,
+              bomCategoryId: this.bomCategoryId,
+              produceTaskId: this.produceTaskId,
+              produceTaskInstanceId: this.produceTaskInstanceId,
+              produceTaskName: this.produceTaskName,
+              workOrderId: this.workOrderId
             });
           } else {
             this.$message.warning('该物料已存在于产出清单中');
@@ -482,17 +544,186 @@
         this.localOutputDetails = [
           {
             ...data,
+            id: null,
             reportQuantity: 0,
             qualifiedQuantity: 0,
             noQualifiedQuantity: 0,
             msg: '',
             sumReportQuantity: 0,
             sumQualifiedQuantity: 0,
-            sumNoQualifiedQuantity: 0
+            sumNoQualifiedQuantity: 0,
+            ruleId: this.ruleId,
+            outputType: this.outputType,
+            produceTaskId: this.produceTaskId,
+            produceTaskInstanceId: this.produceTaskInstanceId,
+            produceTaskName: this.produceTaskName,
+            workOrderId: this.workOrderId
           }
         ];
         this.$emit('update:outputDetails', this.localOutputDetails);
+
+        const bomInfo = await getMaterialQuotaInfo(
+          this.bomCategoryId,
+          this.produceTaskId
+        );
+        this.materialQuotaInfo = bomInfo;
         console.log('this.localOutputDetails', this.localOutputDetails);
+        console.log('this.materialQuotaInfo', this.materialQuotaInfo);
+      },
+      // 计算报工数量最大值
+      reportQuantitymax(row) {
+        if (this.outputType == 1) {
+          // 物料本身 不能超过已报工数量减领料数量
+          return row.quantity - row.sumReportQuantity;
+        }
+        return Infinity;
+      },
+      // 判断生成产出清单的物料数量是合格
+      async validateOutputQuantities() {
+        if (this.localPickDetails.length == 0) {
+          this.$message.warning(`物料清单不能为空`);
+          return false;
+        }
+
+        if (this.localOutputDetails.length == 0) {
+          this.$message.warning(`产出清单不能为空`);
+          return false;
+        }
+
+        for (const item of this.localOutputDetails) {
+          if (!item.reportQuantity) {
+            this.$message.warning(
+              `请填写产出清单【${item.categoryName}】的当次报工数量`
+            );
+            return false;
+          }
+
+          // 判断当次合格数量 和 不合格数量 之和需要等于 报工数量
+          if (
+            item.reportQuantity !==
+            item.qualifiedQuantity + item.noQualifiedQuantity
+          ) {
+            this.$message.warning(
+              `物料【${item.categoryName}】的当次合格数量和不合格数量之和必须等于报工数量`
+            );
+            return false;
+          }
+        }
+
+        if (this.outputType == 1) {
+          for (const item of this.localOutputDetails) {
+            const pickitem = this.localPickDetails.find(
+              (pick) =>
+                pick.categoryId == item.categoryId &&
+                pick.produceTaskInstanceId == item.produceTaskInstanceId
+            );
+
+            if (pickitem == null) {
+              this.$message.warning(
+                `所需物料【${item.categoryName}】未在物料清单中找到`
+              );
+              return false;
+            }
+
+            if (item.reportQuantity > item.quantity) {
+              this.$message.error(
+                `物料【${item.categoryName}】的报工数量不能超过领料数量`
+              );
+              return false;
+            }
+          }
+        }
+
+        if (this.outputType == 2 || this.outputType == 3) {
+          let val = true;
+
+          if(!this.materialQuotaInfo){
+            this.materialQuotaInfo = await getMaterialQuotaInfo(
+              this.bomCategoryId,
+              this.produceTaskId
+            );
+          }
+
+          this.materialQuotaInfo.materialQuota.forEach((i) => {
+            // 避免重复提示
+            if (!val) {
+              return;
+            }
+            // 需要的物料数量比例
+            let count = i.count / this.materialQuotaInfo.baseCount;
+
+            // 产出清单的报工数量 当次报工+累计报工
+            const outputItem = this.localOutputDetails[0];
+
+            // 产出物料数量
+            const outputQuantity =
+              outputItem.reportQuantity + outputItem.sumReportQuantity;
+            const needQuantity = outputQuantity * count;
+
+            // 查询物料清单 是否满足数量
+            const pickitem = this.localPickDetails.find(
+              (pick) => pick.categoryId == i.id
+            );
+            // 查询preOutputDetails 上一道工序产出物
+            const preOutputItem = this.preOutputDetails.find(
+              (pre) => pre.categoryId == i.id
+            );
+
+            // 所需物料是 物料或者是上一道工序产出物
+            if (pickitem == null && preOutputItem == null) {
+              this.$message.warning(
+                `所需物料【${i.categoryName}】未在物料清单中找到`
+              );
+              val = false;
+              return false;
+            }
+
+            // 物料对象存在
+            if (pickitem) {
+              if (needQuantity > pickitem.quantity) {
+                this.$message.warning(
+                  `物料【${pickitem.categoryName}】领料数量不足,需${needQuantity}${pickitem.unit},当前仅有${pickitem.quantity}${pickitem.unit}`
+                );
+                val = false;
+                return false;
+              }
+              // 判断累计报工数量是否足够
+              let pickitemSumReportQuantity =
+                pickitem.sumReportQuantity + pickitem.reportQuantity;
+              if (needQuantity > pickitemSumReportQuantity) {
+                this.$message.warning(
+                  `物料【${pickitem.categoryName}】累计报工数量不足,需${needQuantity}${pickitem.unit},当前仅有${pickitemSumReportQuantity}${pickitem.unit}`
+                );
+                val = false;
+                return false;
+              }
+            }
+            // 上一道工序产出物存在
+            if (preOutputItem) {
+              if (needQuantity > preOutputItem.quantity) {
+                this.$message.warning(
+                  `物料【${preOutputItem.categoryName}】领料数量不足,需${needQuantity}${preOutputItem.unit},当前仅有${preOutputItem.quantity}${preOutputItem.unit}`
+                );
+                val = false;
+                return false;
+              }
+              // 判断累计报工数量是否足够
+              let preOutputItemSumReportQuantity =
+                preOutputItem.sumReportQuantity + preOutputItem.reportQuantity;
+              if (needQuantity > preOutputItemSumReportQuantity) {
+                this.$message.warning(
+                  `物料【${preOutputItem.categoryName}】累计报工数量不足,需${needQuantity}${preOutputItem.unit},当前仅有${preOutputItemSumReportQuantity}${preOutputItem.unit}`
+                );
+                val = false;
+                return false;
+              }
+            }
+          });
+
+          return val;
+        }
+
+        return true;
       }
     }
   };

+ 27 - 2
src/views/produce/components/prenatalExamination/releaseRulesDialog.vue

@@ -228,12 +228,15 @@
 
     <material
       v-if="addForm.produceTaskId"
+      ref="materialRef"
       :pickDetails.sync="addForm.pickDetails"
       :outputDetails.sync="addForm.outputDetails"
       :preOutputDetails="preOutputDetails"
       :workOrderId="addForm.workOrderId"
       :ruleId="addForm.ruleId"
       :produceTaskId="addForm.produceTaskId"
+      :produceTaskName="addForm.produceTaskName"
+      :produceTaskInstanceId="workOrderInfo.taskId"
       :bomCategoryId="workOrderInfo.bomCategoryId"
       :outputType="addForm.outputType"
       :categoryId="workOrderInfo.categoryId"
@@ -777,6 +780,10 @@
             this.teamUserList = this.teamAllList[index];
           }
 
+          if (this.addForm.outputType == null) {
+            this.addForm.outputType = 1;
+          }
+
           this.getListByWorkOrderId();
 
           this.loading = false;
@@ -858,6 +865,13 @@
       // 提交
       submit(type) {
         console.log('this.addForm', this.addForm);
+        if (type == 'submit') {
+          // 验证产出物数量
+          const valid = this.$refs.materialRef.validateOutputQuantities();
+          if (!valid) {
+            return;
+          }
+        }
         // 验证表单
         this.$refs.ruleFormRef.validate(async (valid) => {
           if (!valid) {
@@ -898,7 +912,12 @@
           body.duration = Number(body.duration);
           body.duration = body.duration * 60 * 60 * 1000;
 
-          // 处理执行人
+          // 验证产出物数量
+          const materialValid =
+            await this.$refs.materialRef.validateOutputQuantities();
+          if (!materialValid) {
+            return;
+          }
 
           // 提交
           this.butLoading = true;
@@ -923,11 +942,15 @@
         });
       },
       async clearCache() {
+        if (!this.productionInfo || !this.productionInfo.recordId) {
+          this.$message.warning('无缓存记录!');
+          return;
+        }
         try {
           this.butLoading = true;
           await logicDelete(this.productionInfo.recordId);
           this.butLoading = false;
-          this.productionInfo.recordId == null;
+          this.productionInfo.recordId = null;
           this.addForm.workshopArea = '';
           this.addForm.workshopAreaId = null;
           this.addForm.checkFinishTime = null;
@@ -940,6 +963,8 @@
           this.addForm.duration = 0;
           this.addForm.executeUsers = [];
           thia.addForm.executeUsersIds = [];
+          this.addForm.pickDetails = [];
+          this.addForm.outputDetails = [];
 
           this.getRuleList();
           this.$message.success('缓存清空成功!');