瀏覽代碼

feat(inspectionWork): 报工执行人默认为报工人

- 班组模式下换班组后清空执行人并默认报工人(须在新班组成员内)

- 默认执行人逻辑不再跳过检验方案模式,指定班组模式仍跳过

- workOrderReport 报工模式执行人未指定时默认报工人,异常场景输出 warn 提示
lihaiting 4 天之前
父節點
當前提交
6a586be817

+ 42 - 8
src/views/inspectionWork/components/baseInfo.vue

@@ -594,6 +594,17 @@
       changeExecuteJob(item) {
         this.$set(this.form, 'executeJobName', item.name);
         this.$set(this.form, 'executeUserId', '');
+        // 换班组后执行人清空, 重新默认报工人(当前登录用户, 须在新班组成员内)
+        this.$set(this.form, 'executeUserIdList', []);
+        const userInfo = this.$store?.state?.user?.info;
+        const reporter = (item.userVOList || []).find(
+          (u) => u.id == userInfo?.userId
+        );
+        if (reporter) {
+          this.$set(this.form, 'executeUserIdList', [userInfo.userId]);
+          this.$set(this.form, 'executeUserName', userInfo.name);
+          this.$set(this.form, 'executeUserId', String(userInfo.userId));
+        }
       },
       getCode() {
         parameterGetByCode({
@@ -786,14 +797,14 @@
           this.executorList = (res && res.list) || [];
         } catch (error) {}
       },
-      /* 默认执行部门=当前登录用户所属公司, 默认执行人=当前登录用户 */
+      /* 默认执行部门=当前登录用户所属公司, 默认执行人=当前登录用户(报工人) */
       async setDefaultExecuteInfo() {
         const userInfo = this.$store?.state?.user?.info;
         if (!userInfo || !userInfo.userId) {
           return;
         }
-        // 班组模式下执行人由班组决定, 检验方案模式下没有执行部门, 均不处理
-        if (this.form.assignType == 1 || this.form.qualityType == 2) {
+        // 指定班组模式(assignType==1)执行人是禁用回显字段, 不做默认
+        if (this.form.assignType == 1) {
           return;
         }
         // 执行人: 未指定时默认当前登录用户
@@ -802,12 +813,35 @@
           !this.form.executeUserIdList ||
           !this.form.executeUserIdList.length
         ) {
-          this.$set(this.form, 'executeUserIdList', [userInfo.userId]);
-          this.$set(this.form, 'executeUserName', userInfo.name);
-          this.$set(this.form, 'executeUserId', String(userInfo.userId));
+          if (this.form.qualityType == 2) {
+            /* 检验方案模式: 执行人候选项 = 所选执行班组的成员,
+               默认人必须在班组成员列表里, 否则多选框回显不出来 */
+            const job = (this.form.jobList || []).find(
+              (item) => item.id == this.form.executeJobId
+            );
+            const teamUsers = (job && job.userVOList) || [];
+            const reporter = teamUsers.find(
+              (item) => item.id == userInfo.userId
+            );
+            if (reporter) {
+              this.$set(this.form, 'executeUserIdList', [userInfo.userId]);
+              this.$set(this.form, 'executeUserName', userInfo.name);
+              this.$set(this.form, 'executeUserId', String(userInfo.userId));
+            } else {
+              console.warn(
+                '[报工] 当前登录人不在执行班组成员中, 执行人无法默认为报工人',
+                '执行班组:', job && job.name,
+                '班组成员:', teamUsers.map((i) => ({ id: i.id, name: i.name }))
+              );
+            }
+          } else {
+            this.$set(this.form, 'executeUserIdList', [userInfo.userId]);
+            this.$set(this.form, 'executeUserName', userInfo.name);
+            this.$set(this.form, 'executeUserId', String(userInfo.userId));
+          }
         }
-        // 执行部门: 未指定时默认当前登录用户所属公司
-        if (!this.form.executeDeptId) {
+        // 执行部门: 未指定时默认当前登录用户所属公司(检验方案模式没有执行部门, 不处理)
+        if (this.form.qualityType != 2 && !this.form.executeDeptId) {
           let company = null;
           try {
             company = await getCurrentUserCompany(userInfo);

+ 27 - 11
src/views/inspectionWork/components/inspectionProjectReport.vue

@@ -955,12 +955,16 @@
             this.form.sampleQuantity
           );
         } else {
+          /* 与 watch tableData 同规则:明细不合格数总和 > 样品数取样品数(封顶),否则取总和 */
+          const sumNoQualified = this.tableData.reduce(
+            (sum, item) => sum + (Number(item.noQualifiedQuantity) || 0),
+            0
+          );
+          const sampleQuantity = Number(this.form.sampleQuantity) || 0;
           this.form.sampleNoQualifiedNumber = this.tableData.length
-            ? this.tableData.reduce(
-                (max, item) =>
-                  Math.max(max, Number(item.noQualifiedQuantity) || 0),
-                0
-              )
+            ? sumNoQualified > sampleQuantity
+              ? sampleQuantity
+              : sumNoQualified
             : 0;
         }
         this.form.sampleQualifiedNumber =
@@ -1111,13 +1115,25 @@
               this.$set(this.form, 'sampleQualifiedNumber', qualifiedNumber);
             }
           } else {
-            const maxNoQualified = newVal.reduce((max, item) => {
-              const val = Number(item.noQualifiedQuantity) || 0;
-              return val > max ? val : max;
-            }, 0);
-            this.$set(this.form, 'sampleNoQualifiedNumber', maxNoQualified);
+            /* 样品不合格数规则(2026-11-10 二次确认):
+               下方明细不合格数总和 > 样品数 → 取样品数(封顶);
+               总和 <= 样品数 → 取明细不合格数总和 */
+            const sumNoQualified = newVal.reduce(
+              (sum, item) => sum + (Number(item.noQualifiedQuantity) || 0),
+              0
+            );
+            const sampleQuantity = Number(this.form.sampleQuantity) || 0;
+            const sampleNoQualifiedNumber =
+              sumNoQualified > sampleQuantity
+                ? sampleQuantity
+                : sumNoQualified;
+            this.$set(
+              this.form,
+              'sampleNoQualifiedNumber',
+              sampleNoQualifiedNumber
+            );
             const qualifiedNumber =
-              (Number(this.form.sampleQuantity) || 0) - maxNoQualified;
+              sampleQuantity - sampleNoQualifiedNumber;
             if (qualifiedNumber < 0) {
               this.$message.warning('样品合格数不能小于0');
               this.$set(this.form, 'sampleQualifiedNumber', 0);

+ 55 - 19
src/views/recordComponents/workOrderReport.vue

@@ -577,7 +577,10 @@
               i.checkUsersIds = i.checkUsers.map((j) => j.userId);
             }
 
-            if (i.checkUsersIds?.length == 0 && data.executeUsers.length > 0) {
+            if (
+              i.checkUsersIds?.length == 0 &&
+              (data.executeUsers || []).length > 0
+            ) {
               // 默认执行人作为检查人
               i.checkUsersIds = data.executeUsers
                 .filter((i) => i.userId)
@@ -599,8 +602,8 @@
           Object.assign(this.addForm, data);
           console.log('this.addForm', this.addForm);
 
-          // 处理数据
-          this.addForm.executeUsersIds = this.addForm.executeUsers
+          // 处理数据(executeUsers 可能为 null,需判空,否则后续默认执行人逻辑不会执行)
+          this.addForm.executeUsersIds = (this.addForm.executeUsers || [])
             .map((i) => i.userId)
             .filter((i) => i); // 过滤掉 undefined
 
@@ -609,7 +612,10 @@
           //     ? this.addForm.executeUsers[0].teamId
           //     : '';
 
-          if (this.addForm.executeUsers.length > 0 && !this.addForm.type) {
+          if (
+            (this.addForm.executeUsers || []).length > 0 &&
+            !this.addForm.type
+          ) {
             let groupIds = this.addForm.executeUsers
               .map((i) => i.groupId)
               .filter(
@@ -634,24 +640,54 @@
 
           this.addForm.recordRulesClassify += '';
 
-          // 加载班组人员列表
+          // 加载班组人员列表(工单班组可能不在班组分页里,判空防止抛异常中断后续逻辑)
           if (this.addForm.teamId) {
-            const index = this.allTeamList.findIndex(
+            const team = this.allTeamList.find(
               (item) => item.id == this.addForm.teamId
             );
-            console.log(this.allTeamList[index], 'dsadas');
-            this.teamUserList = this.allTeamList[index].userVOList;
-
-            this.productLineList = this.allTeamList[
-              index
-            ].factoryWorkstationVOList.map((item) => {
-              return {
-                name: item.productionLineName,
-                id: item.productionLineId
-              };
-            });
+            if (team && team.userVOList) {
+              this.teamUserList = team.userVOList;
 
-            console.log('this.teamUserList', this.teamUserList);
+              this.productLineList = (team.factoryWorkstationVOList || []).map(
+                (item) => {
+                  return {
+                    name: item.productionLineName,
+                    id: item.productionLineId
+                  };
+                }
+              );
+            }
+          }
+
+          /* 报工模式下执行人未指定时, 默认报工人(当前登录用户)。
+             后端 executeUsers 有值时保持后端默认, 不覆盖 */
+          if (
+            this.addForm.type &&
+            !(this.addForm.executeUsersIds || []).length
+          ) {
+            const userInfo = this.$store?.state?.user?.info;
+            const reporter = this.teamUserList.find(
+              (item) => item.id == userInfo?.userId
+            );
+            if (reporter) {
+              this.addForm.executeUsersIds = [reporter.id];
+              this.addForm.executeUsers = [
+                {
+                  teamId: this.addForm.teamId,
+                  teamName: this.teamList.find(
+                    (team) => team.id == this.addForm.teamId
+                  )?.name,
+                  userId: reporter.id,
+                  userName: reporter.name
+                }
+              ];
+            } else {
+              console.warn(
+                '[报工] 当前登录人不在工单班组人员列表中, 执行人无法默认为报工人',
+                '登录人 userId:', userInfo?.userId,
+                '班组人员:', this.teamUserList.map((i) => ({ id: i.id, name: i.name }))
+              );
+            }
           }
 
           this.$nextTick(() => {
@@ -660,7 +696,7 @@
             this.loading = false;
           });
         } catch (error) {
-          console.log('error', error);
+          console.error('[报工] 工单详情处理异常(会导致默认执行人等后续逻辑中断):', error);
           this.loading = false;
         }
       },