Преглед на файлове

新增报工时间的判断

695593266@qq.com преди 2 месеца
родител
ревизия
5bef9351c8
променени са 2 файла, в които са добавени 170 реда и са изтрити 5 реда
  1. 169 4
      src/views/produce/components/jobBooking/index.vue
  2. 1 1
      src/views/produce/components/workOrderHandover/index.vue

+ 169 - 4
src/views/produce/components/jobBooking/index.vue

@@ -222,6 +222,7 @@
               placeholder="选择日期"
               placeholder="选择日期"
               style="margin-right: 25px; width: 190px"
               style="margin-right: 25px; width: 190px"
               :picker-options="pickerOptions"
               :picker-options="pickerOptions"
+              @change="onSingleExecutorTimeChange(index)"
             >
             >
             </el-date-picker>
             </el-date-picker>
 
 
@@ -791,10 +792,24 @@
       },
       },
       handleCreate(e) {
       handleCreate(e) {
         if (e) {
         if (e) {
+          let anyAdjusted = false;
           const list = JSON.parse(JSON.stringify(this.List));
           const list = JSON.parse(JSON.stringify(this.List));
-          list.map((item) => {
-            item.workReportInfo.executorTime = e;
+          list.forEach((item) => {
+            let t = e;
+            if (
+              item.feedLastTime &&
+              this.isTimeBeforeFeedLastTime(e, item.feedLastTime)
+            ) {
+              t = item.feedLastTime;
+              anyAdjusted = true;
+            }
+            item.workReportInfo.executorTime = t;
           });
           });
+          if (anyAdjusted) {
+            this.$message?.warning?.(
+              '报工时间不能小于最后投料时间,已调整为对应工单的最后投料时间'
+            );
+          }
           this.$set(this, 'List', list);
           this.$set(this, 'List', list);
         }
         }
       },
       },
@@ -868,8 +883,44 @@
           return;
           return;
         }
         }
 
 
+        let adjustedStart = start;
+        let maxFeedMs = null;
+        for (const item of this.List) {
+          if (item.feedLastTime) {
+            const f = this.parseDateTime(item.feedLastTime);
+            if (f && !isNaN(f.getTime())) {
+              maxFeedMs =
+                maxFeedMs == null
+                  ? f.getTime()
+                  : Math.max(maxFeedMs, f.getTime());
+            }
+          }
+        }
+
+        if (
+          maxFeedMs != null &&
+          startDate &&
+          startDate.getTime() < maxFeedMs
+        ) {
+          adjustedStart = this.formatDateTimeString(new Date(maxFeedMs));
+          this.$message?.warning?.(
+            '批量开始时间不能小于最后投料时间,已调整为最晚投料时间'
+          );
+        }
+
+        let adjustedEnd = end;
+        const adjStartD = this.parseDateTime(adjustedStart);
+        const endD = this.parseDateTime(adjustedEnd);
+        if (adjStartD && endD && adjStartD > endD) {
+          adjustedEnd = adjustedStart;
+          this.$set(this.reportTime, 1, adjustedEnd);
+        }
+        if (adjustedStart !== start) {
+          this.$set(this.reportTime, 0, adjustedStart);
+        }
+
         // 保持原有批量逻辑不变:仍然走 changeBatchReportTime(array)
         // 保持原有批量逻辑不变:仍然走 changeBatchReportTime(array)
-        this.changeBatchReportTime([start, end]);
+        this.changeBatchReportTime([adjustedStart, adjustedEnd]);
       },
       },
 
 
       async getTeamList(id) {
       async getTeamList(id) {
@@ -1062,6 +1113,43 @@
         return new Date(val);
         return new Date(val);
       },
       },
 
 
+      formatDateTimeString(date) {
+        if (!date || !(date instanceof Date) || isNaN(date.getTime())) {
+          return null;
+        }
+        const p = (n) => String(n).padStart(2, '0');
+        return `${date.getFullYear()}-${p(date.getMonth() + 1)}-${p(
+          date.getDate()
+        )} ${p(date.getHours())}:${p(date.getMinutes())}:${p(
+          date.getSeconds()
+        )}`;
+      },
+
+      /** 所选时间是否早于最后投料时间(早则不允许,须不早于投料时间) */
+      isTimeBeforeFeedLastTime(selected, feedLastTime) {
+        if (!feedLastTime || !selected) return false;
+        const t = this.parseDateTime(selected);
+        const f = this.parseDateTime(feedLastTime);
+        if (!t || !f || isNaN(t.getTime()) || isNaN(f.getTime())) return false;
+        return t.getTime() < f.getTime();
+      },
+
+      onSingleExecutorTimeChange(index) {
+        if (this.isReportTime) return;
+        const item = this.List?.[index];
+        const info = item?.workReportInfo;
+        if (!item || !info) return;
+        if (
+          item.feedLastTime &&
+          this.isTimeBeforeFeedLastTime(info.executorTime, item.feedLastTime)
+        ) {
+          this.$set(info, 'executorTime', item.feedLastTime);
+          this.$message?.warning?.(
+            '报工时间不能小于最后投料时间,已调整为最后投料时间'
+          );
+        }
+      },
+
       onExecutorStartTimeChange(index) {
       onExecutorStartTimeChange(index) {
         const info = this.List?.[index]?.workReportInfo;
         const info = this.List?.[index]?.workReportInfo;
         if (!info) return;
         if (!info) return;
@@ -1076,6 +1164,27 @@
           return;
           return;
         }
         }
 
 
+        const rowItem = this.List?.[index];
+        if (
+          rowItem?.feedLastTime &&
+          this.isTimeBeforeFeedLastTime(
+            info.executorStartTime,
+            rowItem.feedLastTime
+          )
+        ) {
+          this.$set(info, 'executorStartTime', rowItem.feedLastTime);
+          this.$message?.warning?.(
+            '开始时间不能小于最后投料时间,已调整为最后投料时间'
+          );
+          const start2 = this.parseDateTime(info.executorStartTime);
+          const end2 = this.parseDateTime(info.executorTime);
+          if (start2 && end2 && start2 > end2) {
+            this.$set(info, 'executorTime', info.executorStartTime);
+          }
+          this.calculateWorkTimeByStartEnd(index);
+          return;
+        }
+
         if (start && end && start > end) {
         if (start && end && start > end) {
           info.executorStartTime = null;
           info.executorStartTime = null;
           info.workTime = '';
           info.workTime = '';
@@ -1714,7 +1823,9 @@
           //   return this.$message.warning('请选择执行时间');
           //   return this.$message.warning('请选择执行时间');
           // }
           // }
 
 
-          for (let item of this.List) {
+          let feedStartAdjusted = false;
+          for (let i = 0; i < this.List.length; i++) {
+            const item = this.List[i];
             if (!item.workReportInfo.executorStartTime) {
             if (!item.workReportInfo.executorStartTime) {
               this.loading.close();
               this.loading.close();
               return this.$message.warning('请选择开始时间');
               return this.$message.warning('请选择开始时间');
@@ -1723,6 +1834,37 @@
               this.loading.close();
               this.loading.close();
               return this.$message.warning('请选择结束时间');
               return this.$message.warning('请选择结束时间');
             }
             }
+            if (
+              item.feedLastTime &&
+              this.isTimeBeforeFeedLastTime(
+                item.workReportInfo.executorStartTime,
+                item.feedLastTime
+              )
+            ) {
+              this.$set(
+                item.workReportInfo,
+                'executorStartTime',
+                item.feedLastTime
+              );
+              const s2 = this.parseDateTime(
+                item.workReportInfo.executorStartTime
+              );
+              const e2 = this.parseDateTime(item.workReportInfo.executorTime);
+              if (s2 && e2 && s2 > e2) {
+                this.$set(
+                  item.workReportInfo,
+                  'executorTime',
+                  item.workReportInfo.executorStartTime
+                );
+              }
+              this.calculateWorkTimeByStartEnd(i);
+              feedStartAdjusted = true;
+            }
+          }
+          if (feedStartAdjusted) {
+            this.$message.warning(
+              '开始时间不能小于最后投料时间,已调整为最后投料时间'
+            );
           }
           }
 
 
           // this.List.forEach((item) => {
           // this.List.forEach((item) => {
@@ -1738,6 +1880,29 @@
             this.loading.close();
             this.loading.close();
             return this.$message.warning('请选择执行时间');
             return this.$message.warning('请选择执行时间');
           }
           }
+          let execTimeAdjusted = false;
+          for (let item of this.List) {
+            if (!item.workReportInfo.executorTime) continue;
+            if (
+              item.feedLastTime &&
+              this.isTimeBeforeFeedLastTime(
+                item.workReportInfo.executorTime,
+                item.feedLastTime
+              )
+            ) {
+              this.$set(
+                item.workReportInfo,
+                'executorTime',
+                item.feedLastTime
+              );
+              execTimeAdjusted = true;
+            }
+          }
+          if (execTimeAdjusted) {
+            this.$message.warning(
+              '报工时间不能小于最后投料时间,已调整为最后投料时间'
+            );
+          }
         }
         }
 
 
         let bol2;
         let bol2;

+ 1 - 1
src/views/produce/components/workOrderHandover/index.vue

@@ -131,7 +131,7 @@
                 style="width: 100%"
                 style="width: 100%"
               >
               >
                 <el-option label="物品移交" :value="1" />
                 <el-option label="物品移交" :value="1" />
-                <el-option label="班次交接" :value="2" />
+                <!-- <el-option label="班次交接" :value="2" /> -->
               </el-select>
               </el-select>
             </el-form-item>
             </el-form-item>
             <el-form-item
             <el-form-item