修复被驳回任务重新编辑时任务类型信息显示不正确的问题
- 从子任务的typeDetails中解析完整的任务类型信息 - 添加findTaskTypePath函数用于查找任务类型的级联路径 - 加载任务后自动设置taskTypePath以正确显示级联选择器 - 不预设selectedDeptId,让用户重新选择或自动匹配
This commit is contained in:
parent
9b5407060a
commit
06194088ac
@ -861,6 +861,21 @@ const findTaskTypeById = (id: number, items: any[] = hierarchicalTaskTypes.value
|
||||
return null
|
||||
}
|
||||
|
||||
// 根据任务类型ID查找完整的级联路径
|
||||
const findTaskTypePath = (targetId: number, items: any[] = hierarchicalTaskTypes.value, currentPath: number[] = []): number[] | null => {
|
||||
for (const item of items) {
|
||||
const newPath = [...currentPath, item.id]
|
||||
if (item.id === targetId) {
|
||||
return newPath
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
const found = findTaskTypePath(targetId, item.children, newPath)
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// 加载设计师列表(根据任务类型ID)
|
||||
const loadDesignersForItem = async (item: TaskTypeItem) => {
|
||||
if (!item.taskTypeId) return
|
||||
@ -1684,16 +1699,51 @@ const loadTaskForEdit = async (taskId: number) => {
|
||||
}]
|
||||
}
|
||||
|
||||
// 处理任务类型和数量 - 优先从子任务中获取
|
||||
// 处理任务类型和数量 - 优先从子任务的typeDetails中获取
|
||||
if (task.isPipeline === 1 && task.subTasks && task.subTasks.length > 0) {
|
||||
// 流水线任务:从子任务中提取任务类型信息
|
||||
// 流水线任务:从子任务的typeDetails中提取任务类型信息
|
||||
console.log('流水线任务子任务:', task.subTasks)
|
||||
formData.taskTypes = task.subTasks.map((subTask: any) => ({
|
||||
taskTypeId: subTask.taskTypeId,
|
||||
quantity: subTask.quantity || 1,
|
||||
receiverId: subTask.receiverId,
|
||||
selectedDeptId: subTask.receiverDeptId
|
||||
}))
|
||||
const taskTypeItems: TaskTypeItem[] = []
|
||||
|
||||
for (const subTask of task.subTasks) {
|
||||
// 优先从typeDetails解析(包含完整的任务类型明细)
|
||||
if (subTask.typeDetails) {
|
||||
try {
|
||||
const details = typeof subTask.typeDetails === 'string'
|
||||
? JSON.parse(subTask.typeDetails)
|
||||
: subTask.typeDetails
|
||||
|
||||
for (const detail of details) {
|
||||
taskTypeItems.push({
|
||||
taskTypeId: detail.typeId,
|
||||
quantity: detail.quantity || 1,
|
||||
receiverId: detail.receiverId || subTask.receiverId,
|
||||
selectedDeptId: undefined // 不预设部门,让用户重新选择或自动匹配
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('解析typeDetails失败:', e)
|
||||
// 解析失败时使用子任务的基本信息
|
||||
taskTypeItems.push({
|
||||
taskTypeId: subTask.taskTypeId,
|
||||
quantity: subTask.quantity || 1,
|
||||
receiverId: subTask.receiverId,
|
||||
selectedDeptId: undefined
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 没有typeDetails时使用子任务的基本信息
|
||||
taskTypeItems.push({
|
||||
taskTypeId: subTask.taskTypeId,
|
||||
quantity: subTask.quantity || 1,
|
||||
receiverId: subTask.receiverId,
|
||||
selectedDeptId: undefined
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
formData.taskTypes = taskTypeItems
|
||||
console.log('解析后的任务类型:', formData.taskTypes)
|
||||
} else if (task.taskTypeIds) {
|
||||
// 非流水线任务:从taskTypeIds字符串解析
|
||||
const typeIds = task.taskTypeIds.split(',').map((id: string) => parseInt(id.trim()))
|
||||
@ -1711,6 +1761,20 @@ const loadTaskForEdit = async (taskId: number) => {
|
||||
}]
|
||||
}
|
||||
|
||||
// 为每个任务类型设置级联路径(需要在层级数据加载后执行)
|
||||
// 使用 nextTick 确保层级数据已加载
|
||||
nextTick(() => {
|
||||
for (const item of formData.taskTypes) {
|
||||
if (item.taskTypeId) {
|
||||
const path = findTaskTypePath(item.taskTypeId)
|
||||
if (path) {
|
||||
item.taskTypePath = path
|
||||
console.log(`任务类型 ${item.taskTypeId} 的路径:`, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 处理附件 - 完整加载原有附件
|
||||
if (task.attachmentUrl) {
|
||||
formData.attachmentUrl = task.attachmentUrl
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user