|
|
@@ -1,7 +1,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import { FiveIotProjectDailyReportApi } from '@/api/pms/fiveconstructiondailyreport'
|
|
|
import dayjs from 'dayjs'
|
|
|
-import type { FormInstance } from 'element-plus'
|
|
|
+import type { FormInstance, FormRules } from 'element-plus'
|
|
|
import ConstructionDailyReportFormSection from './ConstructionDailyReportFormSection.vue'
|
|
|
import {
|
|
|
createEmptyConstructionDailyReport,
|
|
|
@@ -23,6 +23,57 @@ const submitLoading = ref(false)
|
|
|
const drawerMode = ref<'edit' | 'readonly'>('edit')
|
|
|
const form = ref<ConstructionDailyReportRow>(createEmptyConstructionDailyReport())
|
|
|
const message = useMessage()
|
|
|
+const nonProductionFields: Array<keyof ConstructionDailyReportRow> = [
|
|
|
+ 'accidentTime',
|
|
|
+ 'repairTime',
|
|
|
+ 'selfStopTime',
|
|
|
+ 'complexityTime',
|
|
|
+ 'relocationTime',
|
|
|
+ 'rectificationTime',
|
|
|
+ 'waitingStopTime',
|
|
|
+ 'winterBreakTime',
|
|
|
+ 'partyaDesign',
|
|
|
+ 'partyaPrepare',
|
|
|
+ 'partyaResource',
|
|
|
+ 'otherNptTime'
|
|
|
+]
|
|
|
+
|
|
|
+function getNonProductionTimeTotal() {
|
|
|
+ return nonProductionFields.reduce((sum, field) => sum + Number(form.value[field] || 0), 0)
|
|
|
+}
|
|
|
+
|
|
|
+const rules = reactive<FormRules>({
|
|
|
+ ...Object.fromEntries(
|
|
|
+ nonProductionFields.map((field) => [
|
|
|
+ field,
|
|
|
+ [
|
|
|
+ {
|
|
|
+ validator: (_rule, _value, callback) => {
|
|
|
+ if (getNonProductionTimeTotal() > 24) {
|
|
|
+ callback(new Error('非生产时间总和不能超过24H'))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ callback()
|
|
|
+ },
|
|
|
+ trigger: ['blur', 'change']
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ ])
|
|
|
+ ),
|
|
|
+ malfunction: [
|
|
|
+ {
|
|
|
+ validator: (_rule, value, callback) => {
|
|
|
+ const accidentTime = Number(form.value.accidentTime || 0)
|
|
|
+ if (accidentTime > 0 && !String(value || '').trim()) {
|
|
|
+ callback(new Error('工程质量大于0时,故障情况必填'))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ callback()
|
|
|
+ },
|
|
|
+ trigger: ['blur', 'change']
|
|
|
+ }
|
|
|
+ ]
|
|
|
+})
|
|
|
|
|
|
const drawerTitle = computed(() =>
|
|
|
drawerMode.value === 'readonly' ? '查看施工日报' : '填报施工日报'
|
|
|
@@ -75,6 +126,7 @@ async function handleSubmit() {
|
|
|
|
|
|
submitLoading.value = true
|
|
|
try {
|
|
|
+ await formRef.value?.validate()
|
|
|
const payload = {
|
|
|
...form.value,
|
|
|
taskId: form.value.taskId ?? null
|
|
|
@@ -92,6 +144,29 @@ function handleModelChange(value: ConstructionDailyReportRow) {
|
|
|
form.value = value
|
|
|
}
|
|
|
|
|
|
+watch(
|
|
|
+ () => form.value.accidentTime,
|
|
|
+ () => {
|
|
|
+ if (!disabled.value) {
|
|
|
+ nextTick(() => {
|
|
|
+ formRef.value?.validateField('malfunction')
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => nonProductionFields.map((field) => form.value[field]),
|
|
|
+ () => {
|
|
|
+ if (!disabled.value) {
|
|
|
+ nextTick(() => {
|
|
|
+ formRef.value?.validateField(nonProductionFields as string[])
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ { deep: true }
|
|
|
+)
|
|
|
+
|
|
|
defineExpose({ handleOpenForm })
|
|
|
</script>
|
|
|
|
|
|
@@ -106,7 +181,7 @@ defineExpose({ handleOpenForm })
|
|
|
<span class="text-xl font-bold text-[var(--el-text-color-primary)]">{{ drawerTitle }}</span>
|
|
|
</template>
|
|
|
|
|
|
- <el-form ref="formRef" :model="form" label-position="top" v-loading="loading">
|
|
|
+ <el-form ref="formRef" :model="form" :rules="rules" label-position="top" v-loading="loading">
|
|
|
<div class="flex flex-col gap-6">
|
|
|
<ConstructionDailyReportFormSection
|
|
|
v-for="section in formSections"
|