Răsfoiți Sursa

日报计划

yanghao 1 săptămână în urmă
părinte
comite
461bc60d80
1 a modificat fișierele cu 71 adăugiri și 60 ștergeri
  1. 71 60
      src/views/pms/iotprojecttask/index.vue

+ 71 - 60
src/views/pms/iotprojecttask/index.vue

@@ -44,10 +44,17 @@ interface PlanRow {
   startTime: string
   endTime: string
   showEndTime: boolean
-  planWellTrips?: string
-  planLayers?: string
-  planGasInjection?: string
-  planFootage?: string
+  [key: string]: any
+}
+
+interface PlanExtColumn {
+  name: string
+  identifier: string
+  dataType?: string
+  required?: number
+  unit?: string
+  defaultValue?: string | number | null
+  sort?: number
 }
 
 const message = useMessage()
@@ -111,14 +118,50 @@ const timestampToDateTime = (timestamp: number | string | null | undefined): str
   return dayjs(value).format('YYYY-MM-DD HH:mm')
 }
 
-let currentTableCol = ref<any[]>([])
+const currentTableColumns = ref<PlanExtColumn[]>([])
+
+const normalizeWorkloadColumns = (res: any): PlanExtColumn[] => {
+  const columns = Array.isArray(res?.data) ? res.data : Array.isArray(res) ? res : []
+  return columns
+    .filter((item: PlanExtColumn) => item?.identifier)
+    .sort((a: PlanExtColumn, b: PlanExtColumn) => (a?.sort ?? 0) - (b?.sort ?? 0))
+}
+
+const isRequiredColumn = (column: PlanExtColumn) => Number(column.required) === 1
+
+const isEmptyValue = (value: unknown) =>
+  value === undefined || value === null || (typeof value === 'string' && value.trim() === '')
+
+const getPlanDynamicValues = (row: PlanRow) =>
+  currentTableColumns.value.reduce<Record<string, any>>((values, column) => {
+    values[column.identifier] = row[column.identifier] ?? ''
+    return values
+  }, {})
+
+const createPlanRow = (plan?: any): PlanRow => {
+  const row: PlanRow = {
+    id: plan?.id,
+    status: plan?.status || '',
+    startTime: timestampToDateTime(plan?.startTime),
+    endTime: timestampToDateTime(plan?.endTime),
+    showEndTime: plan?.status !== COMPLETED_STATUS
+  }
+
+  currentTableColumns.value.forEach((column) => {
+    row[column.identifier] = plan?.[column.identifier] ?? column.defaultValue ?? ''
+  })
+
+  return row
+}
+
 const openPlanDialog = async (row: ProjectTaskRow) => {
   currentRow.value = row
   planList.value = []
+  currentTableColumns.value = []
 
   try {
     const res = await IotProjectTaskScheduleApi.getWorkload(row.id)
-    currentTableCol.value = res
+    currentTableColumns.value = normalizeWorkloadColumns(res)
   } catch {
     message.error('获取部门数据失败')
   }
@@ -130,21 +173,7 @@ const openPlanDialog = async (row: ProjectTaskRow) => {
     })
 
     if (taskSchedules?.length) {
-      planList.value = taskSchedules.map((plan: any) => {
-        const status = plan.status
-
-        return {
-          id: plan.id,
-          status,
-          startTime: timestampToDateTime(plan.startTime),
-          endTime: timestampToDateTime(plan.endTime),
-          showEndTime: status !== COMPLETED_STATUS,
-          planWellTrips: plan.planWellTrips,
-          planLayers: plan.planLayers,
-          planGasInjection: plan.planGasInjection,
-          planFootage: plan.planFootage
-        }
-      })
+      planList.value = taskSchedules.map((plan: any) => createPlanRow(plan))
     }
 
     planDialogVisible.value = true
@@ -166,12 +195,7 @@ const onStatusChange = (row: PlanRow) => {
 }
 
 const addNewRow = () => {
-  planList.value.push({
-    status: '',
-    startTime: '',
-    endTime: '',
-    showEndTime: true
-  })
+  planList.value.push(createPlanRow())
 }
 
 const removeRow = (index: number) => {
@@ -179,42 +203,22 @@ const removeRow = (index: number) => {
 }
 
 const savePlan = async () => {
-  console.log('ssssssssssssssss', currentTableCol.value[0])
   try {
     saveLoading.value = true
 
     for (let index = 0; index < planList.value.length; index++) {
-      // if (!planList.value[index].status) {
-      //   message.error(`第${index + 1}行请选择施工状态`)
-      //   return
-      // }
+      const row = planList.value[index]
 
-      if (!planList.value[index].startTime) {
+      if (!row.startTime) {
         message.error(`第${index + 1}行请选择开始时间`)
         return
       }
 
-      if (
-        currentTableCol.value[0].identifier === 'planLayers' &&
-        !planList.value[index].planLayers
-      ) {
-        message.error(`第${index + 1}行请选择计划层数`)
-        return
-      }
-
-      if (
-        currentTableCol.value[0].identifier === 'planWellTrips' &&
-        !planList.value[index].planWellTrips
-      ) {
-        message.error(`第${index + 1}行请选择计划井次`)
-        return
-      }
-
-      if (
-        currentTableCol.value[0].identifier === 'planGasInjection' &&
-        !planList.value[index].planGasInjection
-      ) {
-        message.error(`第${index + 1}行请选择计划注气量`)
+      const emptyRequiredColumn = currentTableColumns.value.find(
+        (column) => isRequiredColumn(column) && isEmptyValue(row[column.identifier])
+      )
+      if (emptyRequiredColumn) {
+        message.error(`第${index + 1}行请填写${emptyRequiredColumn.name}`)
         return
       }
     }
@@ -226,10 +230,7 @@ const savePlan = async () => {
       startTime: item.startTime ? new Date(item.startTime).getTime() : null,
       endTime:
         item.status !== COMPLETED_STATUS && item.endTime ? new Date(item.endTime).getTime() : null,
-      planWellTrips: item.planWellTrips,
-      planLayers: item.planLayers,
-      planGasInjection: item.planGasInjection,
-      planFootage: item.planFootage
+      ...getPlanDynamicValues(item)
     }))
 
     await IotProjectTaskScheduleApi.saveTaskSchedule(submitData)
@@ -581,10 +582,15 @@ onMounted(async () => {
 
       <el-table-column
         min-width="120"
-        v-for="item in currentTableCol"
+        v-for="item in currentTableColumns"
         :key="item.identifier"
-        :label="item.name"
         :prop="item.identifier">
+        <template #header>
+          <span>
+            <span v-if="isRequiredColumn(item)" class="required-mark">*</span>
+            {{ item.unit ? `${item.name}(${item.unit})` : item.name }}
+          </span>
+        </template>
         <template #default="scope">
           <el-input type="number" v-model="scope.row[item.identifier]" placeholder="请输入" />
         </template>
@@ -693,6 +699,11 @@ onMounted(async () => {
   margin-bottom: 0;
 }
 
+.required-mark {
+  margin-right: 2px;
+  color: var(--el-color-danger);
+}
+
 @media (width >= 2200px) {
   .query-actions {
     grid-column: 4;