Przeglądaj źródła

Merge branch 'dev' of http://110.41.163.243:9980/kd-aiot/kd-aiot-frontend-mes into dengfei

695593266@qq.com 7 miesięcy temu
rodzic
commit
04304285e3

+ 21 - 0
src/api/producetaskrecordrulesrecord/index.js

@@ -109,3 +109,24 @@ export async function resetSubmit(body) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+// /mes/workorder/inStoreageRecord
+export async function inStoreageRecord(body) {
+  const res = await request.post('/mes/workorder/inStoreageRecord', body);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+// /mes/workorder/listProduceTaskAndFormNum
+export async function listProduceTaskAndFormNum(body) {
+  const res = await request.post(
+    '/mes/workorder/listProduceTaskAndFormNum',
+    body
+  );
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 76 - 10
src/views/batchRecord/components/editModal.vue

@@ -523,7 +523,6 @@
           :bomCategoryId="workOrderInfo.bomCategoryId"
           :outputType="form.outputType"
           :categoryId="workOrderInfo.categoryId"
-          :record-id="form.id"
           @refresh="getListByWorkOrderId"
         ></material>
         <header-title
@@ -1077,7 +1076,8 @@
           { label: '物料统计', value: '2' },
           { label: '工序统计', value: '3' }
         ],
-        rulesDetailList: []
+        rulesDetailList: [],
+        rulesDetail: null
       };
     },
     computed: {
@@ -1341,6 +1341,7 @@
       // 选择记录规则
       chooseReleaseRules(rules) {
         console.log('rules', rules);
+        this.rulesDetail = rules;
         this.form.ruleId = rules?.id;
         this.form.ruleName = rules?.name;
         this.form.recordRulesClassify = rules?.classify + '';
@@ -1388,10 +1389,24 @@
         this.produceTaskList = data.filter(
           (i) => i.taskId != '-2' && i.taskId != '-1'
         );
-        // 赋值工序实例id
-        this.form.produceTaskInstanceId = data.find(
-          (i) => i.sourceTaskId == this.form.produceTaskId
-        )?.taskId;
+        if (this.form.produceTaskId) {
+          // 赋值工序实例id
+          this.form.produceTaskInstanceId = data.find(
+            (i) => i.sourceTaskId == this.form.produceTaskId
+          )?.taskId;
+        }
+
+        if (this.rulesDetail) {
+          const item = this.produceTaskList.find(
+            (i) => i.sourceTaskId == this.rulesDetail.produceTaskId
+          );
+          if (item) {
+            this.form.produceTaskId = item.sourceTaskId;
+            this.form.produceTaskName = item.taskTypeName;
+            this.form.produceTaskInstanceId = item.taskId;
+          }
+        }
+
       },
       // 选择工序
       produceTaskIdChange() {
@@ -1505,6 +1520,12 @@
           }
         }
 
+        //
+        if (this.reportWorkType == 4) {
+          // 延迟 500ms 等待公式计算
+          await new Promise((resolve) => setTimeout(resolve, 700));
+        }
+
         if (
           this.$refs.statisticsRef &&
           type != 'cache' &&
@@ -1648,13 +1669,17 @@
           i.reportQuantityCopy = i.reportQuantity;
 
           const sumItem = materialObject.sumOutputDetails.find(
-            (i) => i.categoryId === i.categoryId
+            (i) => i.categoryCode === i.categoryCode
           );
 
           if (sumItem) {
-            i.reportQuantity = sumItem.reportQuantity;
+            i.sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+            i.sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+            i.sumReportQuantity = sumItem.sumReportQuantity;
           } else {
-            i.reportQuantity = i.reportQuantity || 0;
+            i.sumQualifiedQuantity = 0;
+            i.sumNoQualifiedQuantity = 0;
+            i.sumReportQuantity = 0;
           }
 
           return i;
@@ -1662,20 +1687,61 @@
         const pickDetails = materialObject.pickDetails.map((i) => {
           // 物料清单中如果存在则 selected 设置为 true
           const any = this.form.outputDetails.find(
-            (j) => j.categoryId === i.categoryId
+            (j) => j.categoryCode === i.categoryCode
           );
           if (any) {
             i.selected = true;
           } else {
             i.selected = false;
           }
+
+          const sumItem = materialObject.sumOutputDetails.find(
+            (item) => i.categoryCode === item.categoryCode
+          );
+
+          if (sumItem) {
+            i.sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+            i.sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+            i.sumReportQuantity = sumItem.sumReportQuantity;
+          } else {
+            i.sumQualifiedQuantity = 0;
+            i.sumNoQualifiedQuantity = 0;
+            i.sumReportQuantity = 0;
+          }
+
           return i;
         });
 
         const preOutputDetails = materialObject.preOutputDetails.map((i) => {
           i.quantity = i.qualifiedQuantity;
+
+          // 物料清单中如果存在则 selected 设置为 true
+          const any = this.addForm.outputDetails.find(
+            (j) => j.categoryCode === i.categoryCode
+          );
+          if (any) {
+            i.selected = true;
+          } else {
+            i.selected = false;
+          }
+
+          const sumItem = materialObject.sumOutputDetails.find(
+            (item) => i.categoryCode === item.categoryCode
+          );
+
+          if (sumItem) {
+            i.sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+            i.sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+            i.sumReportQuantity = sumItem.sumReportQuantity;
+          } else {
+            i.sumQualifiedQuantity = 0;
+            i.sumNoQualifiedQuantity = 0;
+            i.sumReportQuantity = 0;
+          }
+
           return i;
         });
+
         this.preOutputDetails = preOutputDetails.filter(
           (i) => i.outputType != 1
         );

+ 16 - 1
src/views/batchRecord/components/list.vue

@@ -417,13 +417,28 @@
       openApproval(row) {
         console.log('row', row);
         this.processSubmitDialogFlag = true;
+
+        // 类型
+        let businessType = '';
+        if (this.reportWorkType == 1) {
+          businessType = '产前准备';
+        } else if (this.reportWorkType == 2) {
+          businessType = '过程监测';
+        } else if (this.reportWorkType == 3) {
+          businessType = '产后检查';
+        } else {
+          businessType = '生产统计';
+        }
+
         this.$nextTick(() => {
           let params = {
             businessId: row.id,
             businessKey: 'mes_produce_task_record_rule_check',
             formCreateUserId: row.createUserId,
             variables: {
-              businessCode: row.code
+              businessCode: row.code,
+              businessName: '批记录',
+              businessType: businessType
             }
           };
           this.$refs.processSubmitDialogRef.init(params);

+ 92 - 17
src/views/batchRecord/components/statistics.vue

@@ -45,7 +45,7 @@
                 "
                 :disabled="Boolean(row[index].formula)"
                 :controls="false"
-                @input="handleDataChange(row)"
+                @change="handleDataChange(row)"
               ></el-input-number>
               <div style="width: 80px; height: 100%; flex-shrink: 0">
                 <DictSelection
@@ -155,7 +155,7 @@
                 "
                 :disabled="Boolean(row[index].formula)"
                 :controls="false"
-                @input="handleDataChange(row)"
+                @change="handleDataChange(row)"
               ></el-input-number>
               <div style="width: 80px; height: 100%; flex-shrink: 0">
                 <DictSelection
@@ -258,7 +258,7 @@
                 "
                 :disabled="Boolean(row[index].formula)"
                 :controls="false"
-                @input="handleDataChange(row)"
+                @change="handleDataChange(row)"
               ></el-input>
               <div style="width: 80px; height: 100%; flex-shrink: 0">
                 <DictSelection
@@ -273,7 +273,7 @@
           <!-- 公式 -->
           <template v-else-if="row[index].paramType == 9">
             <div style="display: flex">
-              <el-input-number
+              <el-input
                 v-model="row[index].value"
                 :placeholder="
                   row[index].formula
@@ -282,7 +282,7 @@
                 "
                 disabled
                 @input="handleDataChange(row)"
-              ></el-input-number>
+              ></el-input>
               <div style="width: 80px; height: 100%; flex-shrink: 0">
                 <DictSelection
                   v-model="row[index].unit"
@@ -316,10 +316,10 @@
 
 <script>
   import {
-    getAllRoutingTaskList,
-    getPickAndFeed
+    listProduceTaskAndFormNum,
+    getPickAndFeed,
+    inStoreageRecord
   } from '@/api/producetaskrecordrulesrecord/index';
-  import fix from 'highlight.js/lib/languages/fix';
 
   export default {
     props: {
@@ -623,15 +623,59 @@
 
         if (this.workOrderId) {
           // 并发获取工序任务列表和物料数据
-          let [routingTaskObj, pickAndFeedList] = await Promise.all([
-            getAllRoutingTaskList({ routingId: this.routingId }),
-            getPickAndFeed({
-              workOrderId: this.workOrderId,
-              bomCategoryId: this.bomCategoryId
-            })
-          ]);
+          let [routingTaskReslut, pickAndFeedList, inStoreageRecordList] =
+            await Promise.all([
+              listProduceTaskAndFormNum({ workOrderId: this.workOrderId }),
+              getPickAndFeed({
+                workOrderId: this.workOrderId,
+                bomCategoryId: this.bomCategoryId
+              }),
+              inStoreageRecord({
+                workOrderId: this.workOrderId
+              })
+            ]);
           pickAndFeed = pickAndFeedList || [];
-          routingTaskList = routingTaskObj?.list || [];
+          routingTaskList = routingTaskReslut || [];
+          console.log('inStoreageRecordList', inStoreageRecordList);
+          if (inStoreageRecordList && inStoreageRecordList.length > 0) {
+            // 成品入库一行的记录
+            const rows = this.rulesDetailList
+              .filter((i) => i.statisticsType == 1)
+              .map((i) => {
+                return {
+                  title: i.paramValue,
+                  value: i.defaultValue,
+                  formula: i.formula,
+                  unit: i.unitName || this.unit,
+                  paramType: i.paramType
+                };
+              });
+
+            if (this.rulesDetailList.length > 0) {
+              const list = inStoreageRecordList.map((record) => {
+                const rowsCopy = JSON.parse(JSON.stringify(rows));
+                rowsCopy.forEach((item) => {
+                  if (item.title.includes('成品入库数')) {
+                    item.value = record.totalCount;
+                  } else if (
+                    item.title === '成品入库时间' ||
+                    item.title === '入库时间' ||
+                    item.title === '生产日期'
+                  ) {
+                    item.value = record.executorTime;
+                  }
+                  item.unit = record.measuringUnit || this.unit;
+                });
+                return rowsCopy;
+              });
+              // 赋值
+              this.localDetails[0].statisticsValue = list;
+              console.log(
+                'this.localDetails[0].statisticsValue 重新',
+                this.localDetails[0].statisticsValue
+              );
+            }
+          }
         }
 
         console.log('routingTaskList 工序数据', routingTaskList);
@@ -696,6 +740,36 @@
               paramType: 7
             });
 
+            // 接收
+            if (!isNaN(pick.formedNum)) {
+              const item = data.find(
+                (i) => i.title === '接收量' || i.title === '接收数量'
+              );
+              if (item) {
+                item.value = pick.formedNum;
+              }
+            }
+
+            // 不合格品
+            if (!isNaN(pick.noQualifiedSum)) {
+              const item = data.find(
+                (i) => i.title == '不合格品量' || i.title == '不合格品数量'
+              );
+              if (item) {
+                item.value = pick.noQualifiedSum;
+              }
+            }
+
+            // 合格品量
+            if (!isNaN(pick.qualified)) {
+              const item = data.find(
+                (i) => i.title == '合格品数' || i.title == '合格品数量'
+              );
+              if (item) {
+                item.value = pick.qualified;
+              }
+            }
+
             return data;
           })
         };
@@ -719,7 +793,7 @@
 
             data.unshift({
               title: '工序名称',
-              value: task.taskInstanceName,
+              value: task.name || task.produceTaskName,
               formula: '',
               unit: '',
               // 仅展示不计算和输入
@@ -739,6 +813,7 @@
       },
       // 当数据变化时计算公式
       handleDataChange(row) {
+        console.log('row 触发', row);
         // todo 计算公式
         // 寻找当前行的所有可计算项,进行计算更新
         const formulaItmes = row.filter((i) => i.formula);

+ 2 - 2
src/views/produce/components/footBtn.vue

@@ -274,11 +274,11 @@
             buts: ['过程监测', '产后检查', '报工'],
             msg: '请先完成投料'
           },
-          processResult: {
+          postResult: {
             buts: ['产后检查', '报工'],
             msg: '请先完成过程监测'
           },
-          postResult: {
+          finalResult: {
             buts: ['报工'],
             msg: '请先完成产后检查'
           }

+ 182 - 181
src/views/produce/components/prenatalExamination/material.vue

@@ -39,14 +39,16 @@
       @refresh="localOutputDetailsRefresh"
     >
       <template v-slot:reportQuantity="{ row }">
-        <el-input-number
-          size="small"
-          v-model.number="row.reportQuantity"
-          controls-position="right"
-          :min="0"
-          :max="reportQuantitymax(row)"
-          @change="reportQuantityChange(row)"
-        ></el-input-number>
+        <div>
+          <el-input-number
+            size="small"
+            v-model.number="row.reportQuantity"
+            controls-position="right"
+            :min="0"
+            :max="reportQuantitymax(row)"
+            @change="reportQuantityChange(row)"
+          ></el-input-number>
+        </div>
       </template>
       <template v-slot:qualifiedQuantity="{ row }">
         <el-input-number
@@ -154,10 +156,10 @@
         type: [String, Number],
         required: false
       },
-      // recordId 是否保存过数据
-      recordId: {
-        type: [String, Number],
-        default: ''
+      // 执行状态
+      executeStatus: {
+        type: [Number],
+        required: false
       }
     },
     watch: {
@@ -305,7 +307,7 @@
               if (this.outputType == 1) {
                 // 取值产出清单
                 const outputItem = this.localOutputDetails.find(
-                  (item) => item.categoryId === row.categoryId
+                  (item) => item.categoryCode === row.categoryCode
                 );
                 return (
                   (outputItem ? outputItem.reportQuantity : 0) +
@@ -318,7 +320,7 @@
                   return '0' + (row.unit || '');
                 }
                 const materialItem = this.materialQuotaInfo.materialQuota.find(
-                  (item) => item.id === row.categoryId
+                  (item) => item.categoryCode === row.categoryCode
                 );
                 if (!materialItem) {
                   return '0' + (row.unit || '');
@@ -344,57 +346,59 @@
             formatter: (row) => {
               if (this.outputType == 1) {
                 const outputItem = this.localOutputDetails.find(
-                  (item) => item.categoryId === row.categoryId
+                  (item) => item.categoryCode == row.categoryCode
                 );
                 if (!outputItem) {
-                  return '0' + (row.unit || '');
+                  return row.sumReportQuantity + (row.unit || '');
                 }
-                if (this.recordId) {
-                  let count =
-                    outputItem.sumReportQuantity +
-                    outputItem.reportQuantity -
-                    outputItem.reportQuantityCopy;
-                  return count + (row.unit || '');
+                let count = 0;
+                if (this.executeStatus === 2) {
+                  // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
+                  count =
+                    row.sumReportQuantity -
+                    (outputItem.reportQuantityCopy - outputItem.reportQuantity);
                 } else {
-                  let count =
-                    outputItem.sumReportQuantity + outputItem.reportQuantity;
-                  return count + (row.unit || '');
+                  count = row.sumReportQuantity + outputItem.reportQuantity;
                 }
+
+                return count + (row.unit || '');
               } else {
-                // 产出为在制品 或 BOM标准产出
-                // 查询基数
+                // 产出为在制品 或 BOM标准产出 累计消耗数量
                 if (!this.materialQuotaInfo) {
-                  return '0' + (row.unit || '');
+                  return row.sumReportQuantity + (row.unit || '');
                 }
                 const materialItem = this.materialQuotaInfo.materialQuota.find(
-                  (item) => item.id === row.categoryId
+                  (item) => item.categoryCode === row.categoryCode
                 );
                 if (!materialItem) {
-                  return '0' + (row.unit || '');
+                  return row.sumReportQuantity + (row.unit || '');
                 }
-                // 需要的物料数量比例
-                let count =
-                  materialItem.count / this.materialQuotaInfo.baseCount;
-                // 产出清单的报工数量 当次报工+累计报工
                 const outputItem = this.localOutputDetails[0];
                 if (!outputItem) {
-                  return '0' + (row.unit || '');
+                  return row.sumReportQuantity + (row.unit || '');
                 }
-                if (this.recordId) {
-                  // 累计消耗
-                  let needQuantity =
-                    (outputItem.sumReportQuantity +
-                      outputItem.reportQuantity -
-                      outputItem.reportQuantityCopy) *
-                    count;
-                  return needQuantity + (row.unit || '');
+                // 单位产出所需物料比例
+                const proportion =
+                  materialItem.count / this.materialQuotaInfo.baseCount;
+
+                let cumulativeOutputQuantity = 0;
+
+                if (this.executeStatus === 2) {
+                  // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
+                  cumulativeOutputQuantity =
+                    outputItem.sumReportQuantity -
+                    (outputItem.reportQuantityCopy - outputItem.reportQuantity);
                 } else {
-                  // 累计消耗
-                  let needQuantity =
-                    (outputItem.sumReportQuantity + outputItem.reportQuantity) *
-                    count;
-                  return needQuantity + (row.unit || '');
+                  cumulativeOutputQuantity =
+                    outputItem.sumReportQuantity + outputItem.reportQuantity;
                 }
+                const needQuantity = cumulativeOutputQuantity * proportion;
+
+                // 已消耗数量转换
+                // const sumReportQuantity = row.sumReportQuantity * proportion;
+                const sumReportQuantity = row.sumReportQuantity;
+
+                return needQuantity + sumReportQuantity + (row.unit || '');
               }
             }
           }
@@ -529,6 +533,7 @@
             ruleId: this.ruleId,
             produceTaskId: this.produceTaskId
           },
+          // ...this.localPickDetails, ...this.preOutputDetails
           []
         );
       },
@@ -538,34 +543,39 @@
 
         data.forEach((newItem) => {
           const index = this.localPickDetails.findIndex(
-            (item) =>
-              item.categoryCode === newItem.categoryCode &&
-              item.produceTaskInstanceId === newItem.produceTaskInstanceId
+            (item) => item.categoryCode === newItem.categoryCode
           );
           if (index !== -1) {
             // 存在则替换数量
             this.localPickDetails[index].quantity = newItem.quantity;
           } else {
             const sumItem = this.sumOutputDetails.find(
-              (i) => i.categoryId === i.categoryId
+              (item) => item.categoryCode === newItem.categoryCode
             );
 
-            let reportQuantity = newItem.reportQuantity || 0;
+            let sumQualifiedQuantity = 0;
+            let sumNoQualifiedQuantity = 0;
+            let sumReportQuantity = 0;
 
             if (sumItem) {
-              reportQuantity = sumItem.reportQuantity;
+              sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+              sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+              sumReportQuantity = sumItem.sumReportQuantity;
             }
 
             // 不存在则添加
             this.localPickDetails.push({
               ...newItem,
-              reportQuantity,
+              reportQuantity: 0,
               ruleId: this.ruleId,
               bomCategoryId: this.bomCategoryId,
               produceTaskId: this.produceTaskId,
               produceTaskInstanceId: this.produceTaskInstanceId,
               produceTaskName: this.produceTaskName,
-              workOrderId: this.workOrderId
+              workOrderId: this.workOrderId,
+              sumQualifiedQuantity,
+              sumNoQualifiedQuantity,
+              sumReportQuantity
             });
           }
         });
@@ -574,16 +584,22 @@
       },
       setMaterialQuotaInfo() {
         console.log('this.materialQuotaInfo', this.materialQuotaInfo);
+
         if (this.materialQuotaInfo && this.materialQuotaInfo.standardOutput) {
           const sumItem = this.sumOutputDetails.find(
             (i) =>
-              i.categoryId === this.materialQuotaInfo.standardOutput.categoryId
+              i.categoryCode ===
+              this.materialQuotaInfo.standardOutput.categoryCode
           );
 
-          let reportQuantity = 0;
+          let sumQualifiedQuantity = 0;
+          let sumNoQualifiedQuantity = 0;
+          let sumReportQuantity = 0;
 
           if (sumItem) {
-            reportQuantity = sumItem.reportQuantity;
+            sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+            sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+            sumReportQuantity = sumItem.sumReportQuantity;
           }
 
           // 赋值产出
@@ -591,13 +607,14 @@
             {
               ...this.materialQuotaInfo.standardOutput,
               id: null,
-              reportQuantity,
+              reportQuantity: 0,
+              reportQuantityCopy: 0,
               qualifiedQuantity: 0,
               noQualifiedQuantity: 0,
               msg: '',
-              sumReportQuantity: 0,
-              sumQualifiedQuantity: 0,
-              sumNoQualifiedQuantity: 0,
+              sumReportQuantity,
+              sumQualifiedQuantity,
+              sumNoQualifiedQuantity,
               ruleId: this.ruleId,
               outputType: this.outputType,
               produceTaskId: this.produceTaskId,
@@ -607,6 +624,8 @@
             }
           ];
           this.$emit('update:outputDetails', this.localOutputDetails);
+        } else {
+          this.$message.warning('未配置BOM标准产出信息');
         }
       },
       // 获取bom的产出清单
@@ -617,6 +636,10 @@
             this.produceTaskId
           );
           console.log('this.materialQuotaInfo', data);
+          if (JSON.stringify(data) === '{}') {
+            this.materialQuotaInfo = null;
+            return;
+          }
           this.materialQuotaInfo = data;
         }
       },
@@ -634,23 +657,36 @@
         if (row.selected) {
           // 判断是否存在
           const index = this.localOutputDetails.findIndex(
-            (item) =>
-              item.categoryId === row.categoryId &&
-              item.produceTaskInstanceId === row.produceTaskInstanceId
+            (item) => item.categoryId === row.categoryId
           );
 
           if (index === -1) {
+            const sumItem = this.sumOutputDetails.find(
+              (i) => i.categoryCode === row.categoryCode
+            );
+
+            let sumQualifiedQuantity = 0;
+            let sumNoQualifiedQuantity = 0;
+            let sumReportQuantity = 0;
+
+            if (sumItem) {
+              sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+              sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+              sumReportQuantity = sumItem.sumReportQuantity;
+            }
+
             // 不存在则添加
             this.localOutputDetails.push({
               ...row,
               id: null,
               reportQuantity: 0,
+              reportQuantityCopy: 0,
               qualifiedQuantity: 0,
               noQualifiedQuantity: 0,
               msg: '',
-              sumReportQuantity: 0,
-              sumQualifiedQuantity: 0,
-              sumNoQualifiedQuantity: 0,
+              sumReportQuantity,
+              sumQualifiedQuantity,
+              sumNoQualifiedQuantity,
               ruleId: this.ruleId,
               outputType: this.outputType,
               bomCategoryId: this.bomCategoryId,
@@ -676,26 +712,31 @@
         const data = await getCategoryAndLevelByCategoryId(this.categoryId);
         if (data) {
           const sumItem = this.sumOutputDetails.find(
-            (i) => i.categoryId == data.categoryId
+            (i) => i.categoryCode == data.categoryCode
           );
 
-          let reportQuantity = 0;
+          let sumQualifiedQuantity = 0;
+          let sumNoQualifiedQuantity = 0;
+          let sumReportQuantity = 0;
 
           if (sumItem) {
-            reportQuantity = sumItem.reportQuantity;
+            sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+            sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+            sumReportQuantity = sumItem.sumReportQuantity;
           }
 
           this.localOutputDetails = [
             {
               ...data,
               id: null,
-              reportQuantity,
+              reportQuantity: 0,
+              reportQuantityCopy: 0,
               qualifiedQuantity: 0,
               noQualifiedQuantity: 0,
               msg: '',
-              sumReportQuantity: 0,
-              sumQualifiedQuantity: 0,
-              sumNoQualifiedQuantity: 0,
+              sumReportQuantity,
+              sumQualifiedQuantity,
+              sumNoQualifiedQuantity,
               ruleId: this.ruleId,
               outputType: this.outputType,
               produceTaskId: this.produceTaskId,
@@ -714,18 +755,64 @@
       // 计算报工数量最大值
       reportQuantitymax(row) {
         if (this.outputType == 1) {
-          // 物料本身 不能超过已报工数量减领料数量
-          return row.quantity - row.sumReportQuantity;
-        }
-        if (row.outputType == 2) {
-          // 在物料中查询对应的物料
-          const pickitem = this.preOutputDetails.find(
-            (pick) => pick.categoryId == row.categoryId
+          // 查询物料本身
+          const pickItem = this.localPickDetails.find(
+            (item) => item.categoryCode === row.categoryCode
           );
-          if (pickitem) {
-            return pickitem.qualifiedQuantity;
+          // 物料本身 不能超过已报工数量减领料数量
+
+          // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
+          if (this.executeStatus === 2) {
+            return (
+              pickItem.quantity -
+              (pickItem.sumReportQuantity - row.reportQuantityCopy)
+            );
+          } else {
+            return pickItem.quantity - pickItem.sumReportQuantity;
           }
         }
+        if (row.outputType == 2 || row.outputType == 3) {
+          // 基于物料配额限制最大可报工数量(兼容已缓存/已保存一次的编辑场景,并区分已执行状态)
+          if (!this.materialQuotaInfo) return Infinity;
+          const quota = this.materialQuotaInfo.materialQuota || [];
+          if (!quota.length) return Infinity;
+
+          const isExecuted = this.executeStatus === 2;
+
+          const { baseCount } = this.materialQuotaInfo;
+          if (!baseCount) return Infinity;
+
+          // 计算每个物料的最大可报工数量
+          const maxQuantities = quota.map((item) => {
+            const pickItem = this.localPickDetails.find(
+              (p) => p.categoryCode === item.categoryCode
+            );
+            if (!pickItem) {
+              return Infinity;
+            }
+
+            // 单位产出所需物料比例
+            const proportion = item.count / baseCount;
+
+            // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
+            let consumedQuantity = isExecuted
+              ? row.sumReportQuantity - row.reportQuantityCopy
+              : row.sumReportQuantity;
+
+            // 已执行的比例换算,换算为需要多少物料数量
+            const consumedProportion = consumedQuantity * proportion;
+
+            // 最大可报工数量
+            const maxQuantity =
+              (pickItem.quantity - consumedProportion) / proportion;
+
+            // 向下取整
+            return Math.floor(maxQuantity);
+          });
+
+          // 返回最小的那个物料的最大可报工数量
+          return Math.min(...maxQuantities);
+        }
         return Infinity;
       },
       // 判断生成产出清单的物料数量是合格
@@ -753,19 +840,24 @@
         }
 
         if (this.outputType == 1) {
-          if (this.localPickDetails.length == 0) {
+          if (
+            this.localPickDetails.length == 0 &&
+            this.preOutputDetails.length == 0
+          ) {
             this.$message.warning(`物料清单不能为空`);
             return false;
           }
 
           for (const item of this.localOutputDetails) {
             const pickitem = this.localPickDetails.find(
-              (pick) =>
-                pick.categoryId == item.categoryId &&
-                pick.produceTaskInstanceId == item.produceTaskInstanceId
+              (pick) => pick.categoryCode == item.categoryCode
+            );
+
+            const prePickitem = this.preOutputDetails.find(
+              (pick) => pick.categoryCode == item.categoryCode
             );
 
-            if (pickitem == null) {
+            if (pickitem == null && prePickitem == null) {
               this.$message.warning(
                 `所需物料【${item.categoryName}】未在物料清单中找到`
               );
@@ -781,97 +873,6 @@
           }
         }
 
-        if (this.outputType == 2) {
-          let val = true;
-
-          if (!this.materialQuotaInfo) {
-            await this.getMaterialQuotaInfo();
-          }
-
-          // 没有配置产出清单 、没有原材料 不检查
-          if (!this.materialQuotaInfo || this.localPickDetails.length == 0) {
-            return true;
-          }
-
-          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;
       },
       // 当次报工修改

+ 3 - 4
src/views/produce/components/prenatalExamination/materialModal.vue

@@ -20,7 +20,7 @@
         :datasource="datasource"
         :selection.sync="selection"
         :need-page="false"
-        row-key="index"
+        row-key="categoryCode"
       >
       </ele-pro-table>
     </el-card>
@@ -62,9 +62,7 @@
             selectable: (row, index) => {
               // 已选物料不可再选
               return !this.pickDetails.some(
-                (item) =>
-                  item.categoryCode === row.categoryCode &&
-                  item.produceTaskInstanceId === row.produceTaskInstanceId
+                (item) => item.categoryCode === row.categoryCode
               );
             }
           },
@@ -165,6 +163,7 @@
       },
       open(params = {}, pickDetails = []) {
         this.params = params;
+        this.pickDetails = pickDetails;
         this.visible = true;
       },
       selected() {

+ 51 - 14
src/views/produce/components/prenatalExamination/releaseRulesDialog.vue

@@ -251,7 +251,7 @@
       :bomCategoryId="workOrderInfo.bomCategoryId"
       :outputType="addForm.outputType"
       :categoryId="workOrderInfo.categoryId"
-      :record-id="productionInfo.recordId"
+      :executeStatus="productionInfo.executeStatus"
       @refresh="getListByWorkOrderId"
     ></material>
 
@@ -887,34 +887,80 @@
           i.reportQuantityCopy = i.reportQuantity;
 
           const sumItem = materialObject.sumOutputDetails.find(
-            (i) => i.categoryId === i.categoryId
+            (item) => i.categoryCode === item.categoryCode
           );
 
           if (sumItem) {
-            i.reportQuantity = sumItem.reportQuantity;
+            i.sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+            i.sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+            i.sumReportQuantity = sumItem.sumReportQuantity;
           } else {
-            i.reportQuantity = i.reportQuantity || 0;
+            i.sumQualifiedQuantity = 0;
+            i.sumNoQualifiedQuantity = 0;
+            i.sumReportQuantity = 0;
           }
 
           return i;
         });
+
         const pickDetails = materialObject.pickDetails.map((i) => {
           // 物料清单中如果存在则 selected 设置为 true
           const any = this.addForm.outputDetails.find(
-            (j) => j.categoryId === i.categoryId
+            (j) => j.categoryCode === i.categoryCode
           );
           if (any) {
             i.selected = true;
           } else {
             i.selected = false;
           }
+
+          const sumItem = materialObject.sumOutputDetails.find(
+            (item) => i.categoryCode === item.categoryCode
+          );
+
+          if (sumItem) {
+            i.sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+            i.sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+            i.sumReportQuantity = sumItem.sumReportQuantity;
+          } else {
+            i.sumQualifiedQuantity = 0;
+            i.sumNoQualifiedQuantity = 0;
+            i.sumReportQuantity = 0;
+          }
+
           return i;
         });
 
         const preOutputDetails = materialObject.preOutputDetails.map((i) => {
           i.quantity = i.qualifiedQuantity;
+
+          // 物料清单中如果存在则 selected 设置为 true
+          const any = this.addForm.outputDetails.find(
+            (j) => j.categoryCode === i.categoryCode
+          );
+          if (any) {
+            i.selected = true;
+          } else {
+            i.selected = false;
+          }
+
+          const sumItem = materialObject.sumOutputDetails.find(
+            (item) => i.categoryCode === item.categoryCode
+          );
+
+          if (sumItem) {
+            i.sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
+            i.sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
+            i.sumReportQuantity = sumItem.sumReportQuantity;
+          } else {
+            i.sumQualifiedQuantity = 0;
+            i.sumNoQualifiedQuantity = 0;
+            i.sumReportQuantity = 0;
+          }
+
           return i;
         });
+
         this.preOutputDetails = preOutputDetails.filter(
           (i) => i.outputType != 1
         );
@@ -987,15 +1033,6 @@
       // 提交
       submit(type) {
         console.log('this.addForm', this.addForm);
-        if (type == 'submit') {
-          if (this.$refs.materialRef) {
-            // 验证产出物数量
-            const valid = this.$refs.materialRef.validateOutputQuantities();
-            if (!valid) {
-              return;
-            }
-          }
-        }
         // 验证表单
         this.$refs.ruleFormRef.validate(async (valid) => {
           if (!valid) {

+ 2 - 2
vue.config.js

@@ -36,7 +36,7 @@ module.exports = {
         // target: 'http://192.168.1.125:18086',
         // target: 'http://192.168.1.251:18086',
         // target: 'http://192.168.1.251:18086',
-        target: 'http://192.168.1.125:18086',
+        // target: 'http://192.168.1.125:18086',
         // target: 'http://192.168.1.116:18086', // 赵沙金
         // target: 'http://192.168.1.251:18086', // 开发环境
         // target: 'http://192.168.1.103:18086',192.168.1.116
@@ -44,7 +44,7 @@ module.exports = {
         // target: 'http://192.168.1.30:18086',
         // target: 'http://192.168.1.211:18086',
         // target: 'http://192.168.1.33:18086',
-        // target: 'http://192.168.1.251:18186',
+        target: 'http://192.168.1.251:18186', // 测试环境
         // target: 'http://192.168.1.251:18087',
         // target: 'http://116.163.22.90:86/api', // 嘉实生产
         changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域