|
@@ -148,8 +148,36 @@
|
|
:title="`${currentRow?.contractName} - ${currentRow?.wellName} - 任务计划`"
|
|
:title="`${currentRow?.contractName} - ${currentRow?.wellName} - 任务计划`"
|
|
width="80%"
|
|
width="80%"
|
|
>
|
|
>
|
|
|
|
+ <div class="mb-15px">
|
|
|
|
+ <el-button type="primary" @click="addNewRow">
|
|
|
|
+ <Icon icon="ep:plus" class="mr-5px" /> 新增行
|
|
|
|
+ </el-button>
|
|
|
|
+ </div>
|
|
|
|
+
|
|
<el-table :data="planList" border stripe>
|
|
<el-table :data="planList" border stripe>
|
|
- <el-table-column label="施工状态" prop="name" min-width="200" />
|
|
|
|
|
|
+ <el-table-column label="序号" width="60" align="center">
|
|
|
|
+ <template #default="scope">
|
|
|
|
+ {{ scope.$index + 1 }}
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
|
|
+ <el-table-column label="施工状态" min-width="200">
|
|
|
|
+ <template #default="scope">
|
|
|
|
+ <el-select
|
|
|
|
+ v-model="scope.row.status"
|
|
|
|
+ placeholder="请选择施工状态"
|
|
|
|
+ clearable
|
|
|
|
+ class="w-full"
|
|
|
|
+ @change="onStatusChange(scope.row)"
|
|
|
|
+ >
|
|
|
|
+ <el-option
|
|
|
|
+ v-for="dict in workProgressDictOptions"
|
|
|
|
+ :key="dict.value"
|
|
|
|
+ :label="dict.label"
|
|
|
|
+ :value="dict.value"
|
|
|
|
+ />
|
|
|
|
+ </el-select>
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
<el-table-column label="开始时间" min-width="200">
|
|
<el-table-column label="开始时间" min-width="200">
|
|
<template #default="scope">
|
|
<template #default="scope">
|
|
<el-date-picker
|
|
<el-date-picker
|
|
@@ -157,6 +185,7 @@
|
|
type="datetime"
|
|
type="datetime"
|
|
placeholder="选择开始时间"
|
|
placeholder="选择开始时间"
|
|
value-format="YYYY-MM-DD HH:mm:ss"
|
|
value-format="YYYY-MM-DD HH:mm:ss"
|
|
|
|
+ class="w-full"
|
|
/>
|
|
/>
|
|
</template>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table-column>
|
|
@@ -167,9 +196,18 @@
|
|
type="datetime"
|
|
type="datetime"
|
|
placeholder="选择结束时间"
|
|
placeholder="选择结束时间"
|
|
value-format="YYYY-MM-DD HH:mm:ss"
|
|
value-format="YYYY-MM-DD HH:mm:ss"
|
|
|
|
+ class="w-full"
|
|
|
|
+ v-if="rowShowEndTime(scope.row)"
|
|
/>
|
|
/>
|
|
</template>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
|
+ <el-table-column label="操作" width="100" align="center">
|
|
|
|
+ <template #default="scope">
|
|
|
|
+ <el-button link type="danger" @click="removeRow(scope.$index)">
|
|
|
|
+ 删除
|
|
|
|
+ </el-button>
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
</el-table>
|
|
</el-table>
|
|
|
|
|
|
<template #footer>
|
|
<template #footer>
|
|
@@ -193,6 +231,9 @@ import IotProjectTaskForm from './IotProjectTaskForm.vue'
|
|
import * as DictDataApi from '@/api/system/dict/dict.data'
|
|
import * as DictDataApi from '@/api/system/dict/dict.data'
|
|
import { DictDataVO } from '@/api/system/dict/dict.data'
|
|
import { DictDataVO } from '@/api/system/dict/dict.data'
|
|
import dayjs from 'dayjs'
|
|
import dayjs from 'dayjs'
|
|
|
|
+import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
|
|
|
+import { ref, reactive, onMounted, computed } from 'vue'
|
|
|
|
+import { useRouter } from 'vue-router'
|
|
|
|
|
|
/** 项目信息任务拆分 列表 */
|
|
/** 项目信息任务拆分 列表 */
|
|
defineOptions({ name: 'IotProjectTask' })
|
|
defineOptions({ name: 'IotProjectTask' })
|
|
@@ -230,11 +271,15 @@ const queryFormRef = ref() // 搜索的表单
|
|
const exportLoading = ref(false) // 导出的加载中
|
|
const exportLoading = ref(false) // 导出的加载中
|
|
const { push } = useRouter() // 路由跳转
|
|
const { push } = useRouter() // 路由跳转
|
|
|
|
|
|
|
|
+const COMPLETED_STATUS = 5;
|
|
|
|
+
|
|
// 计划相关状态
|
|
// 计划相关状态
|
|
const planDialogVisible = ref(false)
|
|
const planDialogVisible = ref(false)
|
|
-const planList = ref<Array<{name: string, value: string, startTime: string, endTime: string}>>([])
|
|
|
|
|
|
+// const planList = ref<Array<{name: string, value: string, startTime: string, endTime: string}>>([])
|
|
|
|
+const planList = ref<Array<{id?: number, status: number, startTime: string, endTime: string, showEndTime: boolean}>>([])
|
|
const saveLoading = ref(false)
|
|
const saveLoading = ref(false)
|
|
const currentRow = ref<IotProjectTaskVO | null>(null)
|
|
const currentRow = ref<IotProjectTaskVO | null>(null)
|
|
|
|
+const workProgressDictOptions = ref<any[]>([]) // 施工进度字典选项
|
|
|
|
|
|
/** 时间戳转换为日期时间字符串(使用dayjs处理) */
|
|
/** 时间戳转换为日期时间字符串(使用dayjs处理) */
|
|
const timestampToDateTime = (timestamp: number | null): string => {
|
|
const timestampToDateTime = (timestamp: number | null): string => {
|
|
@@ -242,6 +287,16 @@ const timestampToDateTime = (timestamp: number | null): string => {
|
|
return dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')
|
|
return dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/** 获取施工进度字典数据 */
|
|
|
|
+const getWorkProgressDictOptions = async () => {
|
|
|
|
+ try {
|
|
|
|
+ workProgressDictOptions.value = getIntDictOptions(DICT_TYPE.PMS_PROJECT_TASK_SCHEDULE)
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('获取施工进度字典失败:', error)
|
|
|
|
+ workProgressDictOptions.value = []
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
/** 时间戳转换为日期时间字符串(修正时区问题)
|
|
/** 时间戳转换为日期时间字符串(修正时区问题)
|
|
const timestampToDateTime = (timestamp: number | null): string => {
|
|
const timestampToDateTime = (timestamp: number | null): string => {
|
|
if (!timestamp) return ''
|
|
if (!timestamp) return ''
|
|
@@ -263,42 +318,28 @@ const timestampToDateTime = (timestamp: number | null): string => {
|
|
/** 打开计划对话框 */
|
|
/** 打开计划对话框 */
|
|
const openPlanDialog = async (row: IotProjectTaskVO) => {
|
|
const openPlanDialog = async (row: IotProjectTaskVO) => {
|
|
currentRow.value = row
|
|
currentRow.value = row
|
|
|
|
+ planList.value = [] // 清空计划列表
|
|
try {
|
|
try {
|
|
- // 并行获取数据字典和已有计划数据
|
|
|
|
- const [dictData, taskSchedules] = await Promise.all([
|
|
|
|
- DictDataApi.getDictDataPage(dictQueryParams),
|
|
|
|
- IotProjectTaskScheduleApi.getIotProjectTaskSchedules({ taskId: row.id })
|
|
|
|
- ])
|
|
|
|
-
|
|
|
|
- // 获取数据字典 - 这里假设有一个获取计划项目字典的接口
|
|
|
|
- // const dictData = await DictDataApi.getDictDataPage(dictQueryParams)
|
|
|
|
|
|
+ // 获取施工进度字典选项
|
|
|
|
+ await getWorkProgressDictOptions()
|
|
|
|
|
|
- // 对字典数据按照 sort 升序排序
|
|
|
|
- const sortedDictData = dictData.list.sort((a: DictDataVO, b: DictDataVO) => a.sort - b.sort)
|
|
|
|
|
|
+ // 获取已有计划数据
|
|
|
|
+ const taskSchedules = await IotProjectTaskScheduleApi.getIotProjectTaskSchedules({ taskId: row.id })
|
|
|
|
|
|
- // 将已有计划数据转换为以status为键的映射
|
|
|
|
- const existingPlansMap = new Map()
|
|
|
|
if (taskSchedules && taskSchedules.length > 0) {
|
|
if (taskSchedules && taskSchedules.length > 0) {
|
|
- console.log('任务计划已经存在数据了')
|
|
|
|
- taskSchedules.forEach((plan: any) => {
|
|
|
|
- existingPlansMap.set(plan.status, {
|
|
|
|
|
|
+ // 如果有数据,则使用接口返回的数据初始化表格
|
|
|
|
+ planList.value = taskSchedules.map((plan: any) => {
|
|
|
|
+ const statusNum = Number(plan.status);
|
|
|
|
+ return {
|
|
|
|
+ id: plan.id,
|
|
|
|
+ status: statusNum,
|
|
startTime: timestampToDateTime(plan.startTime),
|
|
startTime: timestampToDateTime(plan.startTime),
|
|
- endTime: timestampToDateTime(plan.endTime)
|
|
|
|
- })
|
|
|
|
|
|
+ endTime: timestampToDateTime(plan.endTime),
|
|
|
|
+ showEndTime: statusNum !== COMPLETED_STATUS // 如果已是完工状态,则不显示结束时间列
|
|
|
|
+ }
|
|
})
|
|
})
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 初始化计划列表,合并字典数据和已有计划数据
|
|
|
|
- planList.value = sortedDictData.map((item: DictDataVO) => {
|
|
|
|
- const existingPlan = existingPlansMap.get(Number(item.value))
|
|
|
|
-
|
|
|
|
- return {
|
|
|
|
- name: item.label,
|
|
|
|
- value: item.value,
|
|
|
|
- startTime: existingPlan ? existingPlan.startTime : '',
|
|
|
|
- endTime: existingPlan ? existingPlan.endTime : ''
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ // 如果没有数据,planList.value保持为空数组
|
|
|
|
|
|
planDialogVisible.value = true
|
|
planDialogVisible.value = true
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -307,18 +348,58 @@ const openPlanDialog = async (row: IotProjectTaskVO) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/** 判断某一行是否应该显示结束时间列 */
|
|
|
|
+const rowShowEndTime = (row) => {
|
|
|
|
+ return row.showEndTime;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/** 处理施工状态变化 */
|
|
|
|
+const onStatusChange = (row) => {
|
|
|
|
+ // 当状态变为“完工”时,隐藏结束时间列并清空结束时间;否则显示
|
|
|
|
+ if (row.status === COMPLETED_STATUS) {
|
|
|
|
+ row.showEndTime = false;
|
|
|
|
+ row.endTime = ''; // 清空结束时间
|
|
|
|
+ } else {
|
|
|
|
+ row.showEndTime = true;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/** 新增行 */
|
|
|
|
+const addNewRow = () => {
|
|
|
|
+ planList.value.push({
|
|
|
|
+ status: undefined, // 默认值或空值
|
|
|
|
+ startTime: '',
|
|
|
|
+ endTime: '',
|
|
|
|
+ showEndTime: true
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/** 删除行 */
|
|
|
|
+const removeRow = (index: number) => {
|
|
|
|
+ planList.value.splice(index, 1)
|
|
|
|
+}
|
|
|
|
+
|
|
/** 保存计划 */
|
|
/** 保存计划 */
|
|
const savePlan = async () => {
|
|
const savePlan = async () => {
|
|
try {
|
|
try {
|
|
saveLoading.value = true
|
|
saveLoading.value = true
|
|
|
|
|
|
- // 准备提交数据,符合新接口格式
|
|
|
|
|
|
+ // 验证数据
|
|
|
|
+ for (let i = 0; i < planList.value.length; i++) {
|
|
|
|
+ const item = planList.value[i]
|
|
|
|
+ if (!item.status) {
|
|
|
|
+ message.error(`第${i + 1}行请选择施工状态`)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 准备提交数据
|
|
const submitData = planList.value.map(item => ({
|
|
const submitData = planList.value.map(item => ({
|
|
- taskId: currentRow.value?.id, // 取自当前行的id
|
|
|
|
- status: Number(item.value), // 取自planList中的value值,转换为数字
|
|
|
|
- description: item.name, // 取自planList中的name值
|
|
|
|
- startTime: item.startTime ? new Date(item.startTime).getTime().toString() : null, // 转换为时间戳字符串
|
|
|
|
- endTime: item.endTime ? new Date(item.endTime).getTime().toString() : null // 转换为时间戳字符串
|
|
|
|
|
|
+ id: item.id, // 更新时使用
|
|
|
|
+ taskId: currentRow.value?.id,
|
|
|
|
+ status: Number(item.status),
|
|
|
|
+ startTime: item.startTime ? new Date(item.startTime).getTime() : null,
|
|
|
|
+ endTime: (item.status !== COMPLETED_STATUS && item.endTime) ? new Date(item.endTime).getTime() : null
|
|
}))
|
|
}))
|
|
|
|
|
|
// 调用保存接口
|
|
// 调用保存接口
|
|
@@ -399,5 +480,7 @@ const handleExport = async () => {
|
|
/** 初始化 **/
|
|
/** 初始化 **/
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
getList()
|
|
getList()
|
|
|
|
+ // 预加载字典数据
|
|
|
|
+ getWorkProgressDictOptions()
|
|
})
|
|
})
|
|
</script>
|
|
</script>
|