695593266@qq.com před 3 měsíci
rodič
revize
7ee1f5c8b3

+ 1 - 0
src/views/pick/pickApply/components/produceOrder.vue

@@ -18,6 +18,7 @@
       :datasource="datasource"
       :selection.sync="selection"
       cache-key="produceOrderZ"
+      :pageSize="50"
       highlight-current-row
     >
       <template v-slot:code="{ row }">

+ 249 - 37
src/views/produce/components/jobBooking/index.vue

@@ -7,20 +7,33 @@
       >
         <div class="rx-bc" v-if="isReportTime">
           <div class="name">批量报工时间:</div>
-          <el-date-picker
-            v-model="reportTime"
-            type="datetimerange"
-            range-separator="至"
-            start-placeholder="开始时间"
-            end-placeholder="结束时间"
-            format="yyyy-MM-dd HH:mm:ss"
-            value-format="yyyy-MM-dd HH:mm:ss"
-            align="right"
-            @change="changeBatchReportTime"
-            :picker-options="pickerOptionsTwo"
-            @calendar-change="handleCalendarChange"
-          >
-          </el-date-picker>
+          <div>
+            <el-date-picker
+              v-model="reportTime[0]"
+              type="datetime"
+              format="yyyy-MM-dd HH:mm:ss"
+              value-format="yyyy-MM-dd HH:mm:ss"
+              placeholder="开始时间"
+              style="margin-right: 5px; width: 190px"
+              @change="onBatchReportStartTimeChange"
+              :picker-options="pickerOptionsTwo"
+              @calendar-change="handleCalendarChange"
+            >
+            </el-date-picker
+            >至
+            <el-date-picker
+              v-model="reportTime[1]"
+              type="datetime"
+              format="yyyy-MM-dd HH:mm:ss"
+              value-format="yyyy-MM-dd HH:mm:ss"
+              placeholder="结束时间"
+              style="margin-left: 5px; width: 190px"
+              @change="onBatchReportEndTimeChange"
+              :picker-options="pickerOptionsTwo"
+              @calendar-change="handleCalendarChange"
+            >
+            </el-date-picker>
+          </div>
         </div>
 
         <div class="rx-bc" v-if="!isReportTime">
@@ -107,6 +120,33 @@
           <div v-if="isReportTime">
             报工时间
             <el-date-picker
+              v-model="item.workReportInfo.executorStartTime"
+              type="datetime"
+              format="yyyy-MM-dd HH:mm:ss"
+              value-format="yyyy-MM-dd HH:mm:ss"
+              placeholder="开始时间"
+              style="margin-right: 5px; width: 190px"
+              @change="onExecutorStartTimeChange(index)"
+              @calendar-change="handleCalendarChange"
+              :picker-options="pickerOptionsTwo"
+            >
+            </el-date-picker
+            >至
+            <!-- @calendar-change="handleCalendarChange" -->
+            <!-- :picker-options="pickerOptionsTwo" -->
+            <el-date-picker
+              v-model="item.workReportInfo.executorTime"
+              type="datetime"
+              format="yyyy-MM-dd HH:mm:ss"
+              value-format="yyyy-MM-dd HH:mm:ss"
+              placeholder="结束时间"
+              style="margin-left: 5px; width: 190px"
+              @change="onExecutorEndTimeChange(index)"
+              @calendar-change="handleCalendarChange"
+              :picker-options="pickerOptionsTwo"
+            >
+            </el-date-picker>
+            <!-- <el-date-picker
               v-model="item.workReportInfo.reportTime"
               type="datetimerange"
               range-separator="至"
@@ -120,7 +160,7 @@
               :picker-options="pickerOptionsTwo"
               @calendar-change="handleCalendarChange"
             >
-            </el-date-picker>
+            </el-date-picker> -->
 
             工时
             <el-input
@@ -673,7 +713,7 @@
         teamName: '',
         checked: false,
         isReportTime: false,
-        reportTime: '',
+        reportTime: [null, null],
         workHour: '',
         pickerOptions: {
           disabledDate(time) {
@@ -691,8 +731,15 @@
           disabledDate: (time) => {
             // 禁止选择当前时间之后的所有日期时间
             return time.getTime() > Date.now();
-          },
-          selectableRange: '00:00:00 - 23:59:59' // 默认全天可选,后面会动态修改
+          }
+          // shortcuts: [
+          //   {
+          //     text: '此刻',
+          //     onClick(picker) {
+          //       picker.$emit('pick', new Date());
+          //     }
+          //   }
+          // ]
         }
       };
     },
@@ -757,6 +804,9 @@
           const list = JSON.parse(JSON.stringify(this.List));
           list.map((item) => {
             item.workReportInfo.reportTime = e;
+            // isReportTime=true 时界面/提交使用 executorStartTime/executorTime,这里保持批量逻辑不变的同时同步字段
+            item.workReportInfo.executorStartTime = e[0];
+            item.workReportInfo.executorTime = e[1];
             const startTime = new Date(item.workReportInfo.reportTime[0]);
             const endTime = new Date(item.workReportInfo.reportTime[1]);
 
@@ -764,14 +814,64 @@
             const diffHours = diffMs / (1000 * 60 * 60);
 
             if (this.executorIdList.length != 0) {
-              item.workReportInfo.workTime =
-                Number(diffHours) * Number(this.executorIdList.length);
+              item.workReportInfo.workTime = Number(
+                (
+                  Number(diffHours) * Number(this.executorIdList.length)
+                ).toFixed(2)
+              );
+            } else {
+              item.workReportInfo.workTime = Number(
+                Number(diffHours).toFixed(2)
+              );
             }
           });
           this.$set(this, 'List', list);
         }
       },
 
+      onBatchReportStartTimeChange() {
+        if (!Array.isArray(this.reportTime)) {
+          this.$set(this, 'reportTime', [this.reportTime, null]);
+        }
+        this.tryApplyBatchReportTime();
+      },
+
+      onBatchReportEndTimeChange() {
+        if (!Array.isArray(this.reportTime)) {
+          this.$set(this, 'reportTime', [null, this.reportTime]);
+        }
+        this.tryApplyBatchReportTime();
+      },
+
+      tryApplyBatchReportTime() {
+        const [start, end] = Array.isArray(this.reportTime)
+          ? this.reportTime
+          : [null, null];
+        if (!start || !end) return;
+
+        const startDate = this.parseDateTime(start);
+        const endDate = this.parseDateTime(end);
+
+        if (startDate && startDate.getTime() > Date.now()) {
+          this.$set(this.reportTime, 0, null);
+          this.$message?.warning?.('开始时间不能超过当前时间');
+          return;
+        }
+        if (endDate && endDate.getTime() > Date.now()) {
+          this.$set(this.reportTime, 1, null);
+          this.$message?.warning?.('结束时间不能超过当前时间');
+          return;
+        }
+        if (startDate && endDate && startDate > endDate) {
+          this.$set(this.reportTime, 1, null);
+          this.$message?.warning?.('结束时间不能小于开始时间');
+          return;
+        }
+
+        // 保持原有批量逻辑不变:仍然走 changeBatchReportTime(array)
+        this.changeBatchReportTime([start, end]);
+      },
+
       async getTeamList(id) {
         if (!id) return;
         const ids = id.split(',');
@@ -824,7 +924,9 @@
               if (!item.workReportInfo) {
                 this.$set(item, 'workReportInfo', {});
               }
-              this.$set(item.workReportInfo, 'executorTime', dateTime);
+              if (!this.isReportTime) {
+                this.$set(item.workReportInfo, 'executorTime', dateTime);
+              }
             });
           });
         }
@@ -894,7 +996,11 @@
 
       changeId(index) {
         if (this.isReportTime) {
-          this.calculateWorkingHours(index);
+          if (this.List?.[index]?.workReportInfo?.reportTime) {
+            this.calculateWorkingHours(index);
+          } else {
+            this.calculateWorkTimeByStartEnd(index);
+          }
         }
 
         if (this.executorIdList.length == this.teamUserList.length) {
@@ -922,9 +1028,99 @@
         const diffHours = diffMs / (1000 * 60 * 60);
 
         if (this.executorIdList.length != 0) {
-          this.List[index].workReportInfo.workTime =
-            Number(diffHours) * Number(this.executorIdList.length);
+          this.List[index].workReportInfo.workTime = Number(
+            (Number(diffHours) * Number(this.executorIdList.length)).toFixed(2)
+          );
+        } else {
+          this.List[index].workReportInfo.workTime = Number(
+            Number(diffHours).toFixed(2)
+          );
+        }
+      },
+
+      parseDateTime(val) {
+        if (!val) return null;
+        if (val instanceof Date) return val;
+        if (typeof val === 'string') {
+          // `yyyy-MM-dd HH:mm:ss` -> safer parsing across browsers
+          return new Date(val.replace(/-/g, '/'));
+        }
+        return new Date(val);
+      },
+
+      onExecutorStartTimeChange(index) {
+        const info = this.List?.[index]?.workReportInfo;
+        if (!info) return;
+
+        const start = this.parseDateTime(info.executorStartTime);
+        const end = this.parseDateTime(info.executorTime);
+
+        if (start && start.getTime() > Date.now()) {
+          info.executorStartTime = null;
+          info.workTime = '';
+          this.$message?.warning?.('开始时间不能超过当前时间');
+          return;
+        }
+
+        if (start && end && start > end) {
+          info.executorStartTime = null;
+          info.workTime = '';
+          this.$message?.warning?.('开始时间不能大于结束时间');
+          return;
         }
+
+        this.calculateWorkTimeByStartEnd(index);
+      },
+
+      onExecutorEndTimeChange(index) {
+        const info = this.List?.[index]?.workReportInfo;
+        if (!info) return;
+
+        const start = this.parseDateTime(info.executorStartTime);
+        const end = this.parseDateTime(info.executorTime);
+
+        if (end && end.getTime() > Date.now()) {
+          info.executorTime = null;
+          info.workTime = '';
+          this.$message?.warning?.('结束时间不能超过当前时间');
+          return;
+        }
+
+        if (start && end && end < start) {
+          info.executorTime = null;
+          info.workTime = '';
+          this.$message?.warning?.('结束时间不能小于开始时间');
+          return;
+        }
+
+        this.calculateWorkTimeByStartEnd(index);
+      },
+
+      calculateWorkTimeByStartEnd(index) {
+        const info = this.List?.[index]?.workReportInfo;
+        if (!info) return;
+
+        const start = this.parseDateTime(info.executorStartTime);
+        const end = this.parseDateTime(info.executorTime);
+
+        if (!start || !end) {
+          info.workTime = '';
+          return;
+        }
+
+        const diffMs = end - start;
+        if (!(diffMs >= 0)) {
+          info.workTime = '';
+          return;
+        }
+
+        const diffHours = diffMs / (1000 * 60 * 60);
+        const baseHours = Number.isFinite(diffHours) ? Number(diffHours) : 0;
+        const totalHours =
+          this.executorIdList.length != 0
+            ? baseHours * Number(this.executorIdList.length)
+            : baseHours;
+        info.workTime = Number(totalHours.toFixed(2));
       },
 
       checkChange(index) {
@@ -937,7 +1133,11 @@
         }
 
         if (this.isReportTime) {
-          this.calculateWorkingHours(index);
+          if (this.List?.[index]?.workReportInfo?.reportTime) {
+            this.calculateWorkingHours(index);
+          } else {
+            this.calculateWorkTimeByStartEnd(index);
+          }
         }
       },
 
@@ -1402,8 +1602,9 @@
       },
 
       handleCalendarChange(val) {
-        if (!val || val.length === 0) return;
-        const selected = val[val.length - 1]; // 当前选中的日期
+        if (!val) return;
+        const selected = Array.isArray(val) ? val[val.length - 1] : val; // 当前选中的日期
+        if (!selected) return;
         const now = new Date();
         const todayStr = now.toDateString();
         const selectedStr = new Date(selected).toDateString();
@@ -1490,19 +1691,30 @@
         });
 
         if (this.isReportTime) {
-          let arr = this.List.filter((L) => L.workReportInfo.reportTime);
-          if (!arr.length) {
-            this.loading.close();
-            return this.$message.warning('请选择执行时间');
+          // let arr = this.List.filter((L) => L.workReportInfo.reportTime);
+          // if (!arr.length) {
+          //   this.loading.close();
+          //   return this.$message.warning('请选择执行时间');
+          // }
+
+          for (let item of this.List) {
+            if (!item.workReportInfo.executorStartTime) {
+              this.loading.close();
+              return this.$message.warning('请选择开始时间');
+            }
+            if (!item.workReportInfo.executorTime) {
+              this.loading.close();
+              return this.$message.warning('请选择结束时间');
+            }
           }
 
-          this.List.forEach((item) => {
-            item.workReportInfo.executorStartTime =
-              item.workReportInfo.reportTime[0];
+          // this.List.forEach((item) => {
+          //   item.workReportInfo.executorStartTime =
+          //     item.workReportInfo.reportTime[0];
 
-            item.workReportInfo.executorTime =
-              item.workReportInfo.reportTime[1];
-          });
+          //   item.workReportInfo.executorTime =
+          //     item.workReportInfo.reportTime[1];
+          // });
         } else {
           let arr = this.List.filter((L) => L.workReportInfo.executorTime);
           if (!arr.length) {