|
|
@@ -92,13 +92,29 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
<!-- {{ clientEnvironmentId }} {{ pType }} -->
|
|
|
- <view class="title_box mt20 rx-bc" v-if="pType == 'feed' || pType == 'job'">
|
|
|
- <view class="name"
|
|
|
- >{{ pType == "feed" ? "实际投料时间" : "实际报工时间" }}
|
|
|
+ <view class="title_box mt20 rx-bc" v-if="pType == 'feed'">
|
|
|
+ <view class="name"> 实际投料时间 </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="material" v-if="pType == 'feed'">
|
|
|
+ <view class="content_table">
|
|
|
+ <view class="item">
|
|
|
+ <view class="content">
|
|
|
+ <uni-datetime-picker
|
|
|
+ type="datetime"
|
|
|
+ :value="currentExecutorTime"
|
|
|
+ @change="changeTime($event, item)"
|
|
|
+ />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
- <view class="material" v-if="pType == 'feed' || pType == 'job'">
|
|
|
+ <view class="title_box mt20 rx-bc" v-if="pType == 'job' && !isReportTime">
|
|
|
+ <view class="name"> 实际报工时间 </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="material" v-if="pType == 'job' && !isReportTime">
|
|
|
<view class="content_table">
|
|
|
<view class="item">
|
|
|
<view class="content">
|
|
|
@@ -111,6 +127,32 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
+
|
|
|
+ <view class="title_box mt20 rx-bc" v-if="pType == 'job' && isReportTime">
|
|
|
+ <view class="name"> 实际报工时间 </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="material" v-if="pType == 'job' && isReportTime">
|
|
|
+ <view class="content_table">
|
|
|
+ <view class="item">
|
|
|
+ <view class="content">
|
|
|
+ <uni-datetime-picker
|
|
|
+ v-model="datetimerange"
|
|
|
+ type="datetimerange"
|
|
|
+ rangeSeparator="至"
|
|
|
+ />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="item" v-if="isReportWork && pType == 'job'">
|
|
|
+ <view class="lable rx-cc">工时</view>
|
|
|
+
|
|
|
+ <view class="content content_num">
|
|
|
+ <input style="width: 40%" v-model="item.workTime" />小时
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
@@ -148,8 +190,47 @@ export default {
|
|
|
uni.getStorageSync("userInfo") &&
|
|
|
uni.getStorageSync("userInfo").clientEnvironmentId,
|
|
|
currentExecutorTime: "",
|
|
|
+ isReportTime: false,
|
|
|
+ datetimerange: [],
|
|
|
};
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ datetimerange: {
|
|
|
+ deep: true,
|
|
|
+ handler(val) {
|
|
|
+ if (!(this.pType == "job" && this.isReportTime)) return;
|
|
|
+ this.applyDateTimeRange(val);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ item: {
|
|
|
+ immediate: true,
|
|
|
+ deep: true,
|
|
|
+ handler() {
|
|
|
+ // 初始化/回显:当外部把 start/end 带进来时,同步到 range 组件
|
|
|
+ if (!(this.pType == "job" && this.isReportTime)) return;
|
|
|
+ const start =
|
|
|
+ this.item?.workReportInfo?.executorStartTime ||
|
|
|
+ this.item?.executorStartTime ||
|
|
|
+ "";
|
|
|
+ const end =
|
|
|
+ this.item?.workReportInfo?.executorTime ||
|
|
|
+ this.item?.executorTime ||
|
|
|
+ "";
|
|
|
+ if (start && end) {
|
|
|
+ const range = [this.normalizeDateTime(start), this.normalizeDateTime(end)];
|
|
|
+ // 避免反复触发 watch 造成抖动
|
|
|
+ if (
|
|
|
+ !Array.isArray(this.datetimerange) ||
|
|
|
+ this.datetimerange.length !== 2 ||
|
|
|
+ this.datetimerange[0] !== range[0] ||
|
|
|
+ this.datetimerange[1] !== range[1]
|
|
|
+ ) {
|
|
|
+ this.datetimerange = range;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
// watch: {
|
|
|
// item: {
|
|
|
// immediate: true,
|
|
|
@@ -169,8 +250,8 @@ export default {
|
|
|
// },
|
|
|
|
|
|
created() {
|
|
|
- console.log("item", this.item);
|
|
|
this.getByCode();
|
|
|
+ this.getChooseEngrave();
|
|
|
},
|
|
|
methods: {
|
|
|
changeTime(e, val) {
|
|
|
@@ -183,8 +264,127 @@ export default {
|
|
|
}
|
|
|
this.item.executorTime = this.currentExecutorTime;
|
|
|
},
|
|
|
+
|
|
|
+ normalizeDateTime(value) {
|
|
|
+ if (!value) return "";
|
|
|
+ const v = String(value).trim();
|
|
|
+ // yyyy-MM-dd => yyyy-MM-dd 00:00:00
|
|
|
+ const dateOnly = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
+ if (dateOnly.test(v)) return `${v} 00:00:00`;
|
|
|
+ return v;
|
|
|
+ },
|
|
|
+
|
|
|
+ parseDateTime(value) {
|
|
|
+ const v = this.normalizeDateTime(value);
|
|
|
+ if (!v) return null;
|
|
|
+ // 兼容部分环境 Date("yyyy-MM-dd HH:mm:ss") 的解析问题
|
|
|
+ const safe = v.replace(/-/g, "/");
|
|
|
+ const d = new Date(safe);
|
|
|
+ return Number.isNaN(d.getTime()) ? null : d;
|
|
|
+ },
|
|
|
+
|
|
|
+ hoursDiff(start, end) {
|
|
|
+ const s = this.parseDateTime(start);
|
|
|
+ const e = this.parseDateTime(end);
|
|
|
+ if (!s || !e) return "";
|
|
|
+ const ms = e.getTime() - s.getTime();
|
|
|
+ if (ms < 0) return "";
|
|
|
+ // 保留 2 位小数(小时)
|
|
|
+ return (ms / 36e5).toFixed(2);
|
|
|
+ },
|
|
|
+
|
|
|
+ applyDateTimeRange(range) {
|
|
|
+ // 清空时间范围时,同步清空开始/结束/工时,避免残留
|
|
|
+ if (
|
|
|
+ !Array.isArray(range) ||
|
|
|
+ range.length !== 2 ||
|
|
|
+ !range[0] ||
|
|
|
+ !range[1]
|
|
|
+ ) {
|
|
|
+ this.clearReportTimesAndWorkTime();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const start = this.normalizeDateTime(range[0]);
|
|
|
+ const end = this.normalizeDateTime(range[1]);
|
|
|
+ if (!start || !end) {
|
|
|
+ this.clearReportTimesAndWorkTime();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const s = this.parseDateTime(start);
|
|
|
+ const e = this.parseDateTime(end);
|
|
|
+ if (!s || !e) return;
|
|
|
+
|
|
|
+ // 结束时间不能大于当前时间:超出则回填为当前时间
|
|
|
+ const now = new Date();
|
|
|
+ if (e.getTime() > now.getTime()) {
|
|
|
+ const pad2 = (n) => String(n).padStart(2, "0");
|
|
|
+ const nowStr = `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())} ${pad2(now.getHours())}:${pad2(now.getMinutes())}:${pad2(now.getSeconds())}`;
|
|
|
+ this.datetimerange = [start, nowStr];
|
|
|
+ uni.showToast({
|
|
|
+ title: "结束时间不能大于当前时间",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ this.setReportTimes(start, nowStr);
|
|
|
+ this.setWorkTime(this.hoursDiff(start, nowStr));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (e.getTime() < s.getTime()) {
|
|
|
+ // 结束不能小于开始:直接把结束回填为开始,并提示
|
|
|
+ this.datetimerange = [start, start];
|
|
|
+ uni.showToast({
|
|
|
+ title: "结束时间不能小于开始时间",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ this.setReportTimes(start, start);
|
|
|
+ this.setWorkTime(this.hoursDiff(start, start));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setReportTimes(start, end);
|
|
|
+ this.setWorkTime(this.hoursDiff(start, end));
|
|
|
+ },
|
|
|
+
|
|
|
+ clearReportTimesAndWorkTime() {
|
|
|
+ if (!this.item) return;
|
|
|
+ if (!this.item.workReportInfo) {
|
|
|
+ this.$set(this.item, "workReportInfo", {});
|
|
|
+ }
|
|
|
+ this.$set(this.item.workReportInfo, "executorStartTime", "");
|
|
|
+ this.$set(this.item.workReportInfo, "executorTime", "");
|
|
|
+ this.$set(this.item.workReportInfo, "workTime", "");
|
|
|
+
|
|
|
+ this.$set(this.item, "executorStartTime", "");
|
|
|
+ this.$set(this.item, "executorTime", "");
|
|
|
+ this.$set(this.item, "workTime", "");
|
|
|
+ this.$forceUpdate();
|
|
|
+ },
|
|
|
+
|
|
|
+ setReportTimes(start, end) {
|
|
|
+ if (!this.item) return;
|
|
|
+ if (!this.item.workReportInfo) {
|
|
|
+ this.$set(this.item, "workReportInfo", {});
|
|
|
+ }
|
|
|
+ this.$set(this.item.workReportInfo, "executorStartTime", start);
|
|
|
+ this.$set(this.item.workReportInfo, "executorTime", end);
|
|
|
+
|
|
|
+ // 兼容页面上其他逻辑可能直接读 item 上的字段
|
|
|
+ this.$set(this.item, "executorStartTime", start);
|
|
|
+ this.$set(this.item, "executorTime", end);
|
|
|
+ },
|
|
|
+
|
|
|
+ setWorkTime(hours) {
|
|
|
+ if (hours === "") return;
|
|
|
+ if (!this.item) return;
|
|
|
+ if (!this.item.workReportInfo) {
|
|
|
+ this.$set(this.item, "workReportInfo", {});
|
|
|
+ }
|
|
|
+ this.$set(this.item.workReportInfo, "workTime", hours);
|
|
|
+ this.$set(this.item, "workTime", hours);
|
|
|
+ this.$forceUpdate();
|
|
|
+ },
|
|
|
async getByCode() {
|
|
|
- console.log("11111");
|
|
|
await parameterGetByCode({ code: "mes_order_feed_by_default_date" }).then(
|
|
|
(res) => {
|
|
|
console.log("res", res);
|
|
|
@@ -204,16 +404,22 @@ export default {
|
|
|
this.$set(
|
|
|
this.item.workReportInfo,
|
|
|
"executorTime",
|
|
|
- this.currentExecutorTime
|
|
|
+ this.currentExecutorTime,
|
|
|
);
|
|
|
- console.log("executorTime", this.item.executorTime);
|
|
|
- console.log("item", this.item);
|
|
|
this.$forceUpdate();
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
);
|
|
|
},
|
|
|
+
|
|
|
+ async getChooseEngrave() {
|
|
|
+ await parameterGetByCode({
|
|
|
+ code: "work_hour",
|
|
|
+ }).then((res) => {
|
|
|
+ this.isReportTime = res.value == "1" ? true : false;
|
|
|
+ });
|
|
|
+ },
|
|
|
handleScan(id) {
|
|
|
this.$emit("handleScan", id, "wordOrder");
|
|
|
},
|