Explorar el Código

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

695593266@qq.com hace 7 meses
padre
commit
804bcbd8b1

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

@@ -311,6 +311,23 @@
                 ></el-input>
               </el-form-item>
             </el-col>
+            <el-col :span="8">
+              <el-form-item label="产出物">
+                <el-select
+                  v-model="form.outputType"
+                  placeholder="请选择产出物类型"
+                  filterable
+                  style="width: 100%"
+                >
+                  <el-option
+                    v-for="item in outputTypeList"
+                    :key="item.value"
+                    :label="item.label"
+                    :value="item.value"
+                  />
+                </el-select>
+              </el-form-item>
+            </el-col>
             <el-col :span="8">
               <el-form-item label="结论" required prop="conclusion">
                 <el-radio-group v-model="form.conclusion">
@@ -453,75 +470,24 @@
           </el-col>
         </el-row>
 
-        <header-title
+        <material
           v-if="
-            form.reportWorkType == '2' &&
-            form.produceTaskId &&
-            reportWorkType == 2 &&
-            form.itemType == 2
+            form.produceTaskId && form.produceTaskInstanceId && workOrderInfo
           "
-          title="物品清单"
-          style="margin-top: 20px"
-        ></header-title>
-
-        <ele-pro-table
-          v-if="
-            form.reportWorkType == '2' &&
-            form.produceTaskId &&
-            reportWorkType == 2 &&
-            form.itemType == 2
-          "
-          ref="table"
-          row-key="id"
-          :columns="materialColumns"
-          :datasource="form.pickDetails"
-          cache-key="prenatal-examination-material-list-table-2510231107"
-          autoAmendPage
-          :needPage="false"
+          ref="materialRef"
+          :pickDetails.sync="form.pickDetails"
+          :outputDetails.sync="form.outputDetails"
+          :preOutputDetails="preOutputDetails"
+          :workOrderId="form.workOrderId"
+          :ruleId="form.ruleId"
+          :produceTaskId="form.produceTaskId"
+          :produceTaskName="form.produceTaskName"
+          :produceTaskInstanceId="form.produceTaskInstanceId"
+          :bomCategoryId="workOrderInfo.bomCategoryId"
+          :outputType="form.outputType"
+          :categoryId="workOrderInfo.categoryId"
           @refresh="getListByWorkOrderId"
-        >
-          <!-- <template v-slot:toolbar>
-            <el-button type="primary" @click="openMaterialModal"
-              >添加物料</el-button
-            >
-          </template> -->
-
-          <template v-slot:reportQuantity="{ row }">
-            <el-input-number
-              size="small"
-              v-model.number="row.reportQuantity"
-              controls-position="right"
-              :min="0"
-              :max="row.feedQuantity"
-            ></el-input-number>
-          </template>
-          <template v-slot:qualifiedQuantity="{ row }">
-            <el-input-number
-              size="small"
-              v-model.number="row.qualifiedQuantity"
-              controls-position="right"
-              :min="0"
-              :max="qualifiedQuantityMax(row)"
-            ></el-input-number>
-          </template>
-          <template v-slot:noQualifiedQuantity="{ row }">
-            <el-input-number
-              size="small"
-              v-model.number="row.noQualifiedQuantity"
-              controls-position="right"
-              :min="0"
-              :max="noQualifiedQuantityMax(row)"
-            ></el-input-number>
-          </template>
-          <template v-slot:msg="{ row }">
-            <el-input
-              v-model="row.msg"
-              type="textarea"
-              rows="1"
-              autosize
-            ></el-input>
-          </template>
-        </ele-pro-table>
+        ></material>
 
         <header-title
           v-if="form.itemType == 2"
@@ -779,6 +745,7 @@
   import bpmTask from '@/components/bpmTask/bpmTask.vue';
   import { getFactoryarea } from '@/api/aps/index';
   import { getTeam } from '@/api/produce/job.js';
+  import material from '@/views/produce/components/prenatalExamination/material.vue';
 
   export default {
     name: 'editModal',
@@ -795,7 +762,8 @@
       SelectUser,
       toolModal,
       bpmDetail,
-      bpmTask
+      bpmTask,
+      material
     },
     props: {
       // 1-产前准备,2-过程监测,3-产后检查
@@ -876,6 +844,8 @@
         details: [],
         // 物品清单
         pickDetails: [],
+        // 本次产出明细
+        outputDetails: [],
         executeUsersIds: [],
         workshopAreaId: null,
         workshopArea: '',
@@ -889,7 +859,8 @@
         checkValidityUnit: '',
         recordRulesExecuteMethodName: '',
         recordRulesExecuteMethodId: null,
-        conclusion: null
+        conclusion: null,
+        outputType: 1
       };
 
       return {
@@ -1039,144 +1010,17 @@
           { key: 'bpm', name: '流程详情' }
         ],
         activeComp: 'main',
-        // 物料清单表头
-        materialColumns: [
-          {
-            width: 45,
-            type: 'index',
-            columnKey: 'index',
-            align: 'center'
-          },
-          {
-            label: '类型',
-            prop: 'categoryLevelNamePath',
-            minWidth: 120
-          },
-          {
-            label: '编码',
-            prop: 'categoryCode',
-            minWidth: 120
-          },
-          {
-            label: '名称',
-            prop: 'categoryName',
-            minWidth: 120
-          },
-          {
-            prop: 'modelType',
-            label: '型号',
-            align: 'center',
-            showOverflowTooltip: true
-          },
-          {
-            prop: 'specification',
-            label: '规格',
-            align: 'center',
-            width: 160,
-            showOverflowTooltip: true
-          },
-          {
-            prop: 'brandNum',
-            label: '牌号',
-            align: 'center'
-          },
-          {
-            label: '工序名称',
-            prop: 'produceTaskName',
-            minWidth: 120
-          },
-          {
-            label: '数量',
-            prop: 'feedQuantity',
-            minWidth: 120,
-            formatter: (row) => {
-              return (row.feedQuantity || 0) + (row.feedUnit || '');
-            }
-          },
-          {
-            label: '当次报工数量',
-            prop: 'reportQuantity',
-            minWidth: 160,
-            slot: 'reportQuantity',
-            formatter: (row) => {
-              return (
-                (row.reportQuantity == null ? '' : row.reportQuantity) +
-                (row.feedUnit || '')
-              );
-            }
-          },
-          {
-            label: '当次合格数量',
-            prop: 'qualifiedQuantity',
-            minWidth: 160,
-            slot: 'qualifiedQuantity',
-            formatter: (row) => {
-              return (
-                (row.qualifiedQuantity == null ? '' : row.qualifiedQuantity) +
-                (row.feedUnit || '')
-              );
-            }
-          },
-          {
-            label: '当次不合格数量',
-            prop: 'noQualifiedQuantity',
-            minWidth: 160,
-            slot: 'noQualifiedQuantity',
-            formatter: (row) => {
-              return (
-                (row.noQualifiedQuantity == null
-                  ? ''
-                  : row.noQualifiedQuantity) + (row.feedUnit || '')
-              );
-            }
-          },
-          {
-            label: '不合格原因',
-            prop: 'msg',
-            minWidth: 160,
-            slot: 'msg'
-          },
-          {
-            label: '已报工数量',
-            prop: 'sumReportQuantity',
-            minWidth: 120,
-            formatter(row) {
-              return (row.sumReportQuantity || 0) + row.feedUnit;
-            }
-          },
-          {
-            label: '未报工数量',
-            prop: 'noReportQuantity',
-            minWidth: 120,
-            formatter(row) {
-              if (row.sumReportQuantity != null) {
-                return row.feedQuantity - row.sumReportQuantity + row.feedUnit;
-              }
-              return `${row.feedQuantity}${row.feedUnit || ''}`;
-            }
-          },
-          {
-            label: '合格总数',
-            prop: 'sumQualifiedQuantity',
-            minWidth: 120,
-            formatter(row) {
-              return (row.sumQualifiedQuantity || 0) + (row.feedUnit || '');
-            }
-          },
-          {
-            label: '不合格总数',
-            prop: 'sumNoQualifiedQuantity',
-            minWidth: 120,
-            formatter(row) {
-              return (row.sumNoQualifiedQuantity || 0) + (row.feedUnit || '');
-            }
-          }
-        ],
         workshopAreaList: [],
         checked: false,
         teamUserList: [],
         teamList: [],
-        teamAllList: []
+        teamAllList: [],
+        preOutputDetails: [],
+        outputTypeList: [
+          { label: '原材料', value: 1 },
+          { label: '在制品', value: 2 },
+          { label: 'BOM标准产出', value: 3 }
+        ]
       };
     },
     computed: {
@@ -1479,7 +1323,13 @@
       async getProductTaskList(id) {
         const data = await getTaskInstanceList(id);
         console.log('data 工序列表', data);
-        this.produceTaskList = data;
+        this.produceTaskList = data.filter(
+          (i) => i.taskId != '-2' && i.taskId != '-1'
+        );
+        // 赋值工序实例id
+        this.form.produceTaskInstanceId = data.find(
+          (i) => i.sourceTaskId == this.form.produceTaskId
+        )?.taskId;
       },
       // 选择工序
       produceTaskIdChange() {
@@ -1525,6 +1375,11 @@
               }
             );
           } else if (this.form.executeMethod == 2) {
+            // 验证产出物数量;
+            const valid = this.$refs.materialRef.validateOutputQuantities();
+            if (!valid) {
+              return;
+            }
             this.releaseRulesSaveOrSubmit('submit');
           } else {
             // 任务确认
@@ -1543,6 +1398,12 @@
 
           try {
             if (this.form.itemType == 2) {
+              // 验证产出物数量;
+              const valid = this.$refs.materialRef.validateOutputQuantities();
+              if (!valid) {
+                return;
+              }
+
               // 记录规则保存
               return this.releaseRulesSaveOrSubmit('save');
             }
@@ -1699,18 +1560,26 @@
         row.tools = [];
         row.toolNames = '';
       },
-      async getListByWorkOrderId() {
+      async getListByWorkOrderId(type = '') {
         if (!this.form.produceTaskId || this.reportWorkType != 2) return;
         // 查询物料信息
-        const materialList = await queryListByWorkOrderId({
+        const materialObject = await queryListByWorkOrderId({
           workOrderId: this.form.workOrderId,
           recordId: this.form.id,
           produceTaskId: this.form.produceTaskId,
           ruleId: this.form.ruleId
         });
 
-        console.log('materialList 物料信息', materialList);
-        this.form.pickDetails = materialList || [];
+        console.log('materialObject 物料信息', materialObject);
+        if (type == '') {
+          this.form.pickDetails = materialObject.pickDetails;
+          this.form.outputDetails = materialObject.outputDetails;
+          this.preOutputDetails = materialObject.preOutputDetails;
+        }
+
+        if (type == 'output') {
+          this.form.outputDetails = materialObject.outputDetails;
+        }
       },
       // qualifiedQuantityMax 最大合格数量
       qualifiedQuantityMax(row) {

+ 10 - 2
src/views/batchRecord/components/list.vue

@@ -56,7 +56,7 @@
             编辑
           </el-link>
 
-          <el-popconfirm
+          <!-- <el-popconfirm
             v-if="
               row.executeStatus == 0 ||
               (row.executeStatus == 1 && row.itemType == 2) ||
@@ -69,7 +69,15 @@
             <template v-slot:reference>
               <el-link type="primary" :underline="false"> 报工 </el-link>
             </template>
-          </el-popconfirm>
+          </el-popconfirm> -->
+
+          <el-link
+            type="primary"
+            :underline="false"
+            @click="openEdit('edit', row)"
+          >
+            报工
+          </el-link>
 
           <el-link
             v-if="row.approvalStatus === 0"

+ 302 - 50
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>
@@ -114,13 +118,23 @@
       // 规则id
       ruleId: {
         type: [String, Number],
-        required: true
+        required: false
       },
       // 工序id
       produceTaskId: {
         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);
@@ -177,6 +204,27 @@
             this.getMaterialQuotaInfo();
           }
         }
+      },
+      ruleId: {
+        handler() {
+          // 更新物料明细的ruleId
+          this.localPickDetails = this.localPickDetails.map((item) => {
+            return {
+              ...item,
+              ruleId: this.ruleId
+            };
+          });
+          // 更新产出明细的ruleId
+          this.localOutputDetails = this.localOutputDetails.map((item) => {
+            return {
+              ...item,
+              ruleId: this.ruleId
+            };
+          });
+          // 通知父组件更新
+          this.$emit('update:pickDetails', this.localPickDetails);
+          this.$emit('update:outputDetails', this.localOutputDetails);
+        }
       }
     },
     computed: {
@@ -238,6 +286,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 +333,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 +387,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 +431,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 +464,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 +489,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 +536,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 +565,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;
       }
     }
   };

+ 28 - 4
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;
@@ -936,10 +959,11 @@
           this.addForm.checkValidityUnit = '';
           this.addForm.conclusion = null;
           this.addForm.id = null;
-          this.addForm.pickDetails = [];
           this.addForm.duration = 0;
           this.addForm.executeUsers = [];
-          thia.addForm.executeUsersIds = [];
+          this.addForm.executeUsersIds = [];
+          this.addForm.pickDetails = [];
+          this.addForm.outputDetails = [];
 
           this.getRuleList();
           this.$message.success('缓存清空成功!');