|
@@ -85,32 +85,34 @@
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
watch: {
|
|
watch: {
|
|
|
- async visible(val) {
|
|
|
|
|
- if (!val || !this.taskId) return
|
|
|
|
|
- // set default completion date to today
|
|
|
|
|
- if (!this.form.completionDate) {
|
|
|
|
|
- const today = new Date()
|
|
|
|
|
- const y = today.getFullYear()
|
|
|
|
|
- const m = String(today.getMonth() + 1).padStart(2, '0')
|
|
|
|
|
- const d = String(today.getDate()).padStart(2, '0')
|
|
|
|
|
- this.form.completionDate = `${y}-${m}-${d}`
|
|
|
|
|
- }
|
|
|
|
|
- // pre-fill actualWorkHour from registered work hours
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await opsEventTaskApi.getWorkHourList(this.taskId)
|
|
|
|
|
- const workHourList = res.data?.list || res.data || []
|
|
|
|
|
- const totalRegisteredHours = workHourList.reduce((sum, row) => sum + (Number(row.actualHour) || 0), 0)
|
|
|
|
|
- if (totalRegisteredHours > 0) {
|
|
|
|
|
- this.form.actualWorkHour = Math.round(totalRegisteredHours * 10) / 10
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ visible: {
|
|
|
|
|
+ immediate: true,
|
|
|
|
|
+ async handler(val) {
|
|
|
|
|
+ if (!val || !this.taskId) return
|
|
|
|
|
+ // set default completion date to today
|
|
|
|
|
+ if (!this.form.completionDate) {
|
|
|
|
|
+ const today = new Date()
|
|
|
|
|
+ const y = today.getFullYear()
|
|
|
|
|
+ const m = String(today.getMonth() + 1).padStart(2, '0')
|
|
|
|
|
+ const d = String(today.getDate()).padStart(2, '0')
|
|
|
|
|
+ this.form.completionDate = `${y}-${m}-${d}`
|
|
|
|
|
+ }
|
|
|
|
|
+ // pre-fill actualWorkHour from taskData first (synchronous, guarantees the row value is used)
|
|
|
|
|
+ if (this.taskData && this.taskData.actualWorkHour != null) {
|
|
|
|
|
+ this.form.actualWorkHour = Number(this.taskData.actualWorkHour)
|
|
|
|
|
+ }
|
|
|
|
|
+ // then try to get more accurate registered work hours as enhancement
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await opsEventTaskApi.getWorkHourList(this.taskId)
|
|
|
|
|
+ const workHourList = res.data?.list || res.data || []
|
|
|
|
|
+ const totalRegisteredHours = workHourList.reduce((sum, row) => sum + (Number(row.actualHour) || 0), 0)
|
|
|
|
|
+ if (totalRegisteredHours > 0) {
|
|
|
|
|
+ this.form.actualWorkHour = Math.round(totalRegisteredHours * 10) / 10
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ // keep the taskData value
|
|
|
}
|
|
}
|
|
|
- } catch (e) {
|
|
|
|
|
- // fallback to taskData if query fails
|
|
|
|
|
- }
|
|
|
|
|
- // fallback: use taskData.actualWorkHour
|
|
|
|
|
- if (this.taskData && this.taskData.actualWorkHour != null) {
|
|
|
|
|
- this.form.actualWorkHour = this.taskData.actualWorkHour
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|