fix:施工立项项目内容的优化
This commit is contained in:
parent
a3aaf7da07
commit
2a461940d0
|
@ -15,6 +15,12 @@ export function getProject(id: string | number) {
|
|||
return http.get<T.ProjectResp>(`${BASE_URL}/${id}`)
|
||||
}
|
||||
|
||||
/** @desc 获取项目详情(标准详情接口) */
|
||||
export function getProjectDetail(id: string | number) {
|
||||
return http.get<T.ProjectResp>(`${BASE_URL}/detail/${id}`)
|
||||
}
|
||||
|
||||
|
||||
/** @desc 新增项目 */
|
||||
export function addProject(data: any) {
|
||||
return http.post(`${BASE_URL}`, data)
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
<template #icon><icon-arrow-left /></template>
|
||||
</a-button>
|
||||
<h2 class="ml-2">{{ projectTitle }}</h2>
|
||||
<a-tag class="ml-2" :color="getStatusColor(projectData.status)" v-if="projectData.status">{{
|
||||
projectData.status
|
||||
}}</a-tag>
|
||||
<a-tag class="ml-2" :color="getStatusColor(projectData.statusLabel ?? projectData.status)" v-if="projectData.status !== undefined && projectData.status !== null">
|
||||
{{ projectData.statusLabel ?? projectData.status }}
|
||||
</a-tag>
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<a-button v-permission="['project:update']" type="primary" class="mr-2" @click="editProject">
|
||||
|
@ -198,8 +198,8 @@
|
|||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { Message, Modal } from '@arco-design/web-vue'
|
||||
import { getProject, deleteProject } from '@/apis/project'
|
||||
import { addTask, addTaskGroup, listTask, updateTaskProgress } from '@/apis/project/task'
|
||||
import { getProjectDetail, deleteProject } from '@/apis/project'
|
||||
import { addTask, addTaskGroup, updateTaskProgress } from '@/apis/project/task'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
defineOptions({ name: 'ProjectDetail' })
|
||||
|
@ -257,10 +257,15 @@ const projectTitle = computed(() => {
|
|||
|
||||
const projectInfos = computed(() => [
|
||||
{ label: '项目编号', value: projectData.value?.projectCode },
|
||||
{ label: '项目负责人', value: projectData.value?.projectManager },
|
||||
{ label: '参与人', value: projectData.value?.projectStaff?.join(', ') },
|
||||
{ label: '项目周期', value: projectData.value?.projectPeriod ? `${projectData.value.projectPeriod[0]} 至 ${projectData.value.projectPeriod[1]}` : '' },
|
||||
{ label: '客户', value: projectData.value?.commissionUnit },
|
||||
{ label: '项目负责人', value: projectData.value?.projectManagerName || projectData.value?.projectManager },
|
||||
{ label: '项目来源', value: projectData.value?.projectOrigin },
|
||||
{ label: '风场名称', value: projectData.value?.farmName },
|
||||
{ label: '风场地址', value: projectData.value?.farmAddress },
|
||||
{ label: '开始时间', value: projectData.value?.startDate },
|
||||
{ label: '结束时间', value: projectData.value?.endDate },
|
||||
{ label: '项目规模', value: projectData.value?.scale },
|
||||
{ label: '状态', value: (statusMap as any)[Number(projectData.value?.status)]?.label || projectData.value?.statusLabel },
|
||||
{ label: '客户', value: projectData.value?.client },
|
||||
{ label: '备注', value: projectData.value?.projectIntro || '无' }
|
||||
])
|
||||
|
||||
|
@ -284,6 +289,15 @@ const taskDetailInfos = computed(() => {
|
|||
{ label: '状态', value: currentTask.value.status },
|
||||
{ label: '描述', value: currentTask.value.description || '无' }
|
||||
]
|
||||
|
||||
const statusMap: Record<number, { label: string; color: string }> = {
|
||||
0: { label: '待施工', color: 'gray' },
|
||||
1: { label: '施工中', color: 'blue' },
|
||||
2: { label: '已完工', color: 'green' },
|
||||
3: { label: '已审核', color: 'orange' },
|
||||
4: { label: '已验收', color: 'arcoblue' },
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
const getStatusColor = (status: string) => {
|
||||
|
@ -322,8 +336,14 @@ const formatDate = (date: string) => {
|
|||
const fetchProjectData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await getProject(projectId.value)
|
||||
projectData.value = res.data
|
||||
const res = await getProjectDetail(projectId.value)
|
||||
const detail = (res as any).data || res
|
||||
// 如果status是数字,补充statusLabel用于页面展示
|
||||
if (typeof detail.status === 'number' && !detail.statusLabel) {
|
||||
const mapper = (statusMap as any)[detail.status]
|
||||
if (mapper) detail.statusLabel = mapper.label
|
||||
}
|
||||
projectData.value = detail
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
Message.error('获取项目详情失败')
|
||||
|
@ -332,34 +352,39 @@ const fetchProjectData = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
const fetchTaskData = async () => {
|
||||
try {
|
||||
const res = await listTask({
|
||||
projectId: projectId.value,
|
||||
page: 1,
|
||||
size: 100
|
||||
})
|
||||
// 若任务未返回状态,依据计划时间简单推断状态
|
||||
const inferTaskStatus = (task: any): string => {
|
||||
if (task.status) return task.status
|
||||
const now = dayjs()
|
||||
const start = task.planStartDate ? dayjs(task.planStartDate) : null
|
||||
const end = task.planEndDate ? dayjs(task.planEndDate) : null
|
||||
if (end && end.isBefore(now)) return '已完成'
|
||||
if (start && start.isAfter(now)) return '计划中'
|
||||
if (start && (!end || end.isAfter(now))) return '正在做'
|
||||
return '其他'
|
||||
}
|
||||
|
||||
|
||||
const fetchTaskData = () => {
|
||||
// 使用详情接口返回的任务列表
|
||||
const detail = projectData.value || {}
|
||||
const tasks = (detail.tasks || []) as any[]
|
||||
|
||||
// 重置任务列表
|
||||
taskColumns.value.forEach(column => {
|
||||
column.tasks = []
|
||||
})
|
||||
|
||||
const tasks = res.data?.list || []
|
||||
|
||||
// 分配任务到对应的列
|
||||
// 分配任务到对应的列(按状态或推断状态)
|
||||
tasks.forEach((task: any) => {
|
||||
const column = taskColumns.value.find(col => col.status === task.status)
|
||||
const st = inferTaskStatus(task)
|
||||
const column = taskColumns.value.find(col => col.status === st)
|
||||
if (column) {
|
||||
column.tasks.push(task)
|
||||
} else {
|
||||
taskColumns.value.find(col => col.status === '其他')?.tasks.push(task)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
Message.error('获取任务数据失败')
|
||||
}
|
||||
}
|
||||
|
||||
const goBack = () => {
|
||||
|
@ -491,8 +516,7 @@ const submitProgressUpdate = async () => {
|
|||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchProjectData()
|
||||
fetchTaskData()
|
||||
fetchProjectData().then(() => fetchTaskData())
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
|
@ -356,7 +356,7 @@ import { useRouter } from 'vue-router'
|
|||
import { Message, Modal } from '@arco-design/web-vue'
|
||||
import type { TableColumnData } from '@arco-design/web-vue'
|
||||
import TurbineGrid from './TurbineGrid.vue'
|
||||
import { addProject, deleteProject, exportProject, importProject, listProject, updateProject } from '@/apis/project'
|
||||
import { addProject, deleteProject, exportProject, importProject, listProject, updateProject, getProjectDetail } from '@/apis/project'
|
||||
import { isMobile } from '@/utils'
|
||||
import http from '@/utils/http'
|
||||
import type { ColumnItem } from '@/components/GiForm'
|
||||
|
@ -781,6 +781,20 @@ const openEditModal = (record: T.ProjectResp) => {
|
|||
isEdit.value = true
|
||||
currentId.value = record.id || record.projectId || null
|
||||
|
||||
|
||||
// 若需要最新详情数据,调用标准详情接口回填
|
||||
// 可避免列表接口缺少的字段在编辑时丢失
|
||||
// 注意:后端若响应结构为 { code, data, msg },这里取 res.data
|
||||
// await 的使用需要在该函数标记为 async,这里暂保留同步,如需启用请将函数改为 async 并解开注释
|
||||
// try {
|
||||
// const res = await getProjectDetail(currentId.value as any)
|
||||
// const detail = (res as any).data || res
|
||||
// Object.assign(form, {
|
||||
// ...form,
|
||||
// ...detail,
|
||||
// })
|
||||
// } catch (e) { console.error('获取项目详情失败', e) }
|
||||
|
||||
// 重置表单为默认(确保 tasks、turbineList 等为数组初始值)
|
||||
resetForm()
|
||||
|
||||
|
@ -842,17 +856,55 @@ const handleSubmit = async () => {
|
|||
}))
|
||||
}))
|
||||
|
||||
const pickTaskFields = (t: any) => ({
|
||||
mainUserId: t.mainUserId ?? '',
|
||||
planEndDate: normalizeDate(t.planEndDate),
|
||||
planStartDate: normalizeDate(t.planStartDate),
|
||||
scales: t.scales ?? 0,
|
||||
taskCode: t.taskCode ?? '',
|
||||
taskGroupId: t.taskGroupId ?? '',
|
||||
taskName: t.taskName ?? '',
|
||||
})
|
||||
const flattenTasks = (tasks: any[]) => {
|
||||
const result: any[] = []
|
||||
;(tasks || []).forEach((t) => {
|
||||
result.push(pickTaskFields(t))
|
||||
;(t.children || []).forEach((c: any) => result.push(pickTaskFields(c)))
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
const submitData = {
|
||||
...form,
|
||||
// 确保projectId字段正确
|
||||
projectId: isEdit.value && currentId.value ? currentId.value : form.projectId,
|
||||
// 处理日期格式 - 确保是字符串格式 YYYY-MM-DD
|
||||
startDate: normalizeDate(form.startDate),
|
||||
auditorId: (form as any).auditorId || '',
|
||||
bonusProvision: (form as any).bonusProvision ?? 0,
|
||||
client: form.client || '',
|
||||
clientContact: form.clientContact || '',
|
||||
clientPhone: form.clientPhone || '',
|
||||
constructionTeamLeaderId: form.constructionTeamLeaderId || '',
|
||||
constructorIds: Array.isArray(form.constructorIds) ? form.constructorIds.join(',') : (form.constructorIds || ''),
|
||||
coverUrl: (form as any).coverUrl || '',
|
||||
duration: (form as any).duration ?? 0,
|
||||
endDate: normalizeDate(form.endDate),
|
||||
// 处理施工人员ID - 如果是数组,转换为逗号分隔的字符串
|
||||
constructorIds: Array.isArray(form.constructorIds) ? form.constructorIds.join(',') : form.constructorIds,
|
||||
// 新字段:任务
|
||||
tasks: mapTasks(form.tasks as any[]),
|
||||
equipmentAmortization: (form as any).equipmentAmortization ?? 0,
|
||||
farmAddress: form.farmAddress || '',
|
||||
farmName: form.farmName || '',
|
||||
inspectionContact: form.inspectionContact || '',
|
||||
inspectionPhone: form.inspectionPhone || '',
|
||||
inspectionUnit: form.inspectionUnit || '',
|
||||
laborCost: (form as any).laborCost ?? 0,
|
||||
othersCost: (form as any).othersCost ?? 0,
|
||||
projectBudget: (form as any).projectBudget ?? 0,
|
||||
projectId: isEdit.value && currentId.value ? currentId.value : form.projectId,
|
||||
projectManagerId: form.projectManagerId || '',
|
||||
projectName: form.projectName,
|
||||
projectOrigin: (form as any).projectOrigin || '',
|
||||
qualityOfficerId: form.qualityOfficerId || '',
|
||||
scale: form.scale || '',
|
||||
startDate: normalizeDate(form.startDate),
|
||||
status: (form as any).status ?? 0,
|
||||
tasks: flattenTasks(form.tasks as any[]),
|
||||
transAccomMeals: (form as any).transAccomMeals ?? 0,
|
||||
turbineModel: form.turbineModel || '',
|
||||
}
|
||||
|
||||
console.log('提交数据:', submitData)
|
||||
|
|
Loading…
Reference in New Issue