695593266@qq.com 2 месяцев назад
Родитель
Сommit
92c5eae7bf
1 измененных файлов с 136 добавлено и 16 удалено
  1. 136 16
      src/views/produce/components/feeding/index.vue

+ 136 - 16
src/views/produce/components/feeding/index.vue

@@ -16,7 +16,6 @@
             value-format="yyyy-MM-dd HH:mm:ss"
             placeholder="选择日期"
             @change="handleCreate"
-            :picker-options="pickerOptions"
           >
           </el-date-picker>
         </div>
@@ -84,7 +83,7 @@
               value-format="yyyy-MM-dd HH:mm:ss"
               placeholder="选择日期"
               style="margin-right: 25px; width: 190px"
-              :picker-options="pickerOptions"
+              @change="onItemExecutorTimeChange(item, $event)"
             >
             </el-date-picker>
 
@@ -364,19 +363,7 @@
         teamName: '',
         isDefaultExecutor: false,
         checked: false,
-        useDefaultFeedDate: false,
-        pickerOptions: {
-          disabledDate(time) {
-            // 禁止选择大于当前时间的日期
-            return time.getTime() > Date.now();
-          }
-          // selectableRange: (() => {
-          //   const now = new Date();
-          //   const start = '00:00:00';
-          //   const end = now.toTimeString().split(' ')[0];
-          //   return `${start} - ${end}`;
-          // })()
-        }
+        useDefaultFeedDate: false
         // feedExistNum: '',
         // feedNeedAridRegion: '',
         // feedNeedAuxiliaryEquipment: '',
@@ -407,8 +394,108 @@
     },
 
     methods: {
+      parseReportLastTimeMs(val) {
+        if (val == null || val === '') return null;
+        if (typeof val === 'number' && !isNaN(val)) {
+          const ms = val < 1e12 ? val * 1000 : val;
+          const t = new Date(ms).getTime();
+          return isNaN(t) ? null : t;
+        }
+        const s = String(val).trim();
+        const m = s.match(
+          /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})/
+        );
+        if (m) {
+          const d = new Date(
+            Number(m[1]),
+            Number(m[2]) - 1,
+            Number(m[3]),
+            Number(m[4]),
+            Number(m[5]),
+            Number(m[6])
+          );
+          const t = d.getTime();
+          return isNaN(t) ? null : t;
+        }
+        const d = new Date(s.replace(/-/g, '/'));
+        const t = d.getTime();
+        return isNaN(t) ? null : t;
+      },
+
+      formatMsToExecutorTime(ms) {
+        const date = new Date(ms);
+        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()
+        )}`;
+      },
+
+      /** 提示文案中展示的上一工序报工时间 */
+      formatReportLastTimeDisplay(raw) {
+        const ms = this.parseReportLastTimeMs(raw);
+        if (ms != null) {
+          return this.formatMsToExecutorTime(ms);
+        }
+        const s = raw != null ? String(raw).trim() : '';
+        return s || '—';
+      },
+
+      getListMaxReportLastTimeMs() {
+        let max = null;
+        (this.List || []).forEach((item) => {
+          const ms = this.parseReportLastTimeMs(item.reportLastTime);
+          if (ms != null) {
+            max = max == null ? ms : Math.max(max, ms);
+          }
+        });
+        return max;
+      },
+
+      onItemExecutorTimeChange(item, val) {
+        if (!val || !item) return;
+        const minMs = this.parseReportLastTimeMs(item.reportLastTime);
+        if (minMs == null) return;
+        const t = this.parseReportLastTimeMs(val);
+        if (t == null) return;
+        if (t < minMs) {
+          const timeStr = this.formatReportLastTimeDisplay(item.reportLastTime);
+          this.$message.warning(
+            `投料时间不能早于上一工序报工时间(上一工序:${timeStr})`
+          );
+          this.$set(item, 'executorTime', '');
+        }
+      },
+
+      validateItemExecutorTime(item) {
+        if (!item || !item.executorTime) return;
+        const minMs = this.parseReportLastTimeMs(item.reportLastTime);
+        if (minMs == null) return;
+        const t = this.parseReportLastTimeMs(item.executorTime);
+        if (t != null && t < minMs) {
+          const timeStr = this.formatReportLastTimeDisplay(item.reportLastTime);
+          this.$message.warning(
+            `缓存的投料时间早于上一工序报工时间(上一工序:${timeStr}),已清空`
+          );
+          this.$set(item, 'executorTime', '');
+        }
+      },
+
       handleCreate(e) {
         if (e) {
+          const minMs = this.getListMaxReportLastTimeMs();
+          if (minMs != null) {
+            const t = this.parseReportLastTimeMs(e);
+            if (t != null && t < minMs) {
+              const timeStr = this.formatMsToExecutorTime(minMs);
+              this.$message.warning(
+                `批量投料时间不能早于各工单上一工序报工时间中最晚的一条(须≥ ${timeStr})`
+              );
+              this.executorTime = '';
+              return;
+            }
+          }
           const list = JSON.parse(JSON.stringify(this.List));
           console.log(list);
           list.map((item) => {
@@ -538,6 +625,15 @@
             });
             this.List = deepClone(arr);
             this.applyDefaultExecutorTime();
+            this.$nextTick(() => {
+              if (this.executorTime) {
+                const t = this.parseReportLastTimeMs(this.executorTime);
+                const minMs = this.getListMaxReportLastTimeMs();
+                if (minMs != null && t != null && t < minMs) {
+                  this.executorTime = '';
+                }
+              }
+            });
           })
           .finally(() => {
             this.isLoad = true;
@@ -565,8 +661,18 @@
         if (!this.useDefaultFeedDate || !this.List || this.List.length === 0) {
           return;
         }
-        const dateTime = this.getNowTime();
+        const nowMs = Date.now();
         this.List.forEach((item) => {
+          const minMs = this.parseReportLastTimeMs(item.reportLastTime);
+          if (minMs != null && nowMs < minMs) {
+            this.$set(item, 'executorTime', '');
+            return;
+          }
+          let dateTime = this.getNowTime();
+          const t = this.parseReportLastTimeMs(dateTime);
+          if (minMs != null && t != null && t < minMs) {
+            dateTime = this.formatMsToExecutorTime(minMs);
+          }
           this.$set(item, 'executorTime', dateTime);
         });
       },
@@ -773,6 +879,7 @@
                 f['revolvingDiskList'] = o.revolvingDiskList || [];
                 f['semiProductList'] = o.semiProductList || [];
                 this.$set(this.List[index], 'executorTime', o.executorTime);
+                this.validateItemExecutorTime(this.List[index]);
                 this.$forceUpdate();
               }
             });
@@ -786,6 +893,19 @@
           return this.$message.warning('请选择投料时间');
         }
 
+        for (const item of this.List) {
+          if (!item.executorTime) continue;
+          const minMs = this.parseReportLastTimeMs(item.reportLastTime);
+          if (minMs == null) continue;
+          const t = this.parseReportLastTimeMs(item.executorTime);
+          if (t != null && t < minMs) {
+            const timeStr = this.formatReportLastTimeDisplay(item.reportLastTime);
+            return this.$message.warning(
+              `工单${item.code}投料时间不能早于上一工序报工时间(上一工序:${timeStr})`
+            );
+          }
+        }
+
         if (this.executorIdList.length == 0) {
           return this.$message.warning('执行人不能为空!');
         }