Переглянути джерело

feat(TaskConfigPanel): 添加标准工时列及相关逻辑,自动计算结束时间

xieyong 1 тиждень тому
батько
коміт
ca0d2215ae

+ 108 - 2
src/views/productionPlan/components/newFactoryProductionScheduling/TaskConfigPanel.vue

@@ -316,6 +316,30 @@
                 </el-tooltip>
               </template>
             </el-table-column>
+            <el-table-column
+              v-if="isDispatchColumnVisible('standardHours')"
+              label="标准工时(小时)"
+              align="center"
+              width="140"
+            >
+              <template slot-scope="{ row }">
+                <el-tooltip
+                  :disabled="!isDispatchRowDeviceTypeLimited(row)"
+                  content="该工序已制定设备类型"
+                  placement="top"
+                >
+                  <span class="dispatch-disabled-tooltip-wrap">
+                    <el-input
+                      :value="row.standardHours"
+                      placeholder="请输入标准工时"
+                      class="config-table-control"
+                      :disabled="isDispatchRowControlDisabled(row)"
+                      @input="handleDispatchRowStandardHoursChange(row, $event)"
+                    />
+                  </span>
+                </el-tooltip>
+              </template>
+            </el-table-column>
             <el-table-column
               v-if="isDispatchColumnVisible('startTime')"
               label="计划开始时间"
@@ -795,6 +819,7 @@
           { key: 'userNames', label: '人员' },
           { key: 'status', label: '状态' },
           { key: 'quantity', label: '数量' },
+          { key: 'standardHours', label: '标准工时(小时)' },
           { key: 'startTime', label: '计划开始时间' },
           { key: 'endTime', label: '计划完成时间' },
           { key: 'action', label: '操作' }
@@ -809,6 +834,7 @@
           userNames: true,
           status: true,
           quantity: true,
+          standardHours: true,
           startTime: true,
           endTime: true,
           action: true
@@ -950,6 +976,8 @@
                   : task?.executionEndTime ||
                     assignment?.executionEndTime ||
                     defaultEndTime,
+              standardHours:
+                draft.standardHours !== undefined ? draft.standardHours : '',
               status: assignment?.status || '',
               changeId: assignment?.changeId || '',
               teamTimeIds: task?.teamTimeIds || assignment?.teamTimeIds,
@@ -1913,11 +1941,13 @@
           row.quantity = '';
           row.executionStartTime = '';
           row.executionEndTime = '';
+          row.standardHours = '';
           return;
         }
         row.quantity = '';
         row.executionStartTime = '';
         row.executionEndTime = '';
+        row.standardHours = '';
         if (task._dispatchDraft) {
           this.emitDispatchTaskListChange('remove-task-row', task);
           return;
@@ -2139,6 +2169,79 @@
         }
         this.$emit('time-change', row, 'executionEndTime');
       },
+      parseDispatchStandardHours(value) {
+        if (value === null || value === undefined || value === '') {
+          return null;
+        }
+        const text = String(value).trim();
+        if (!text) {
+          return null;
+        }
+        const num = Number(text);
+        if (!Number.isFinite(num) || num < 0) {
+          return null;
+        }
+        return num;
+      },
+      calculateDispatchEndTimeByStandardHours(startTime, hours) {
+        if (!startTime) {
+          return '';
+        }
+        const num = this.parseDispatchStandardHours(hours);
+        if (num === null) {
+          return '';
+        }
+        const startMs = this.parseDispatchTime(startTime);
+        if (startMs === null) {
+          return '';
+        }
+        const endMs = startMs + num * 3600 * 1000;
+        const date = new Date(endMs);
+        const pad = (n) => String(n).padStart(2, '0');
+        return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(
+          date.getDate()
+        )} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(
+          date.getSeconds()
+        )}`;
+      },
+      recalculateDispatchRowEndTime(row) {
+        if (!row) {
+          return;
+        }
+        const standardHours = this.parseDispatchStandardHours(
+          row.standardHours
+        );
+        if (standardHours === null || !row.executionStartTime) {
+          return;
+        }
+        const calculated = this.calculateDispatchEndTimeByStandardHours(
+          row.executionStartTime,
+          standardHours
+        );
+        if (!calculated) {
+          return;
+        }
+        this.$set(row, 'executionEndTime', calculated);
+        this.updateDispatchRowDraft(row, { executionEndTime: calculated });
+        const task = this.getDispatchRowTask(row);
+        if (task) {
+          this.$set(task, 'executionEndTime', calculated);
+        }
+      },
+      handleDispatchRowStandardHoursChange(row, value) {
+        if (this.isDispatchRowControlDisabled(row)) {
+          return;
+        }
+        this.$set(row, 'standardHours', value);
+        this.updateDispatchRowDraft(row, { standardHours: value });
+        // 标准工时变化时,结合已有开始时间自动计算结束时间
+        this.recalculateDispatchRowEndTime(row);
+        if (row.executionEndTime) {
+          this.updateDispatchRowDraft(row, {
+            executionEndTime: row.executionEndTime
+          });
+        }
+      },
       handleDispatchRowStartTimeChange(row) {
         if (this.isDispatchRowControlDisabled(row)) {
           return;
@@ -2150,8 +2253,11 @@
         this.$set(task, 'executionStartTime', row.executionStartTime || '');
         this.handleDispatchStartTimeChange(task);
         row.executionStartTime = task.executionStartTime || '';
-        row.executionEndTime =
-          task.executionEndTime || row.executionEndTime || '';
+        // 标准工时与开始时间同时存在时,自动计算执行结束时间
+        this.recalculateDispatchRowEndTime(row);
+        if (!row.executionEndTime) {
+          row.executionEndTime = task.executionEndTime || '';
+        }
         this.updateDispatchRowDraft(row, {
           executionStartTime: row.executionStartTime,
           executionEndTime: row.executionEndTime