前端优化:需求部门只看母任务卡片,接单部门只看子任务卡片
This commit is contained in:
parent
54438a9910
commit
beeedcc800
@ -2755,7 +2755,8 @@ const loadConfigs = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载任务列表(同时加载普通任务和子任务)
|
||||
// 加载任务大厅列表(可接单的任务)
|
||||
// 任务大厅只对接单部门开放,只显示子任务
|
||||
const loadTasks = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@ -2778,51 +2779,47 @@ const loadTasks = async () => {
|
||||
if (filters.timeRange) params.timeRange = filters.timeRange
|
||||
if (filters.sortBy) params.sortBy = filters.sortBy
|
||||
|
||||
// 同时获取普通任务和子任务
|
||||
const [taskResponse, itemResponse] = await Promise.all([
|
||||
taskApi.getTaskHall(params),
|
||||
taskApi.getAvailableTaskItems(params)
|
||||
])
|
||||
// 获取用户部门类型
|
||||
const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
|
||||
const userDeptType = userInfo.deptType
|
||||
const isAdmin = userInfo.isAdmin === 1 || userInfo.isAdmin === true
|
||||
|
||||
let allTasks: any[] = []
|
||||
let totalCount = 0
|
||||
|
||||
// 处理普通任务
|
||||
if (taskResponse.code === 200) {
|
||||
const tasks = (taskResponse.data.records || []).map((task: any) => ({
|
||||
...task,
|
||||
isSubTask: false // 标记为普通任务
|
||||
}))
|
||||
allTasks = [...allTasks, ...tasks]
|
||||
totalCount += taskResponse.data.total || 0
|
||||
// 需求部门用户不应看到任务大厅的任务
|
||||
if (userDeptType === 'demand' && !isAdmin) {
|
||||
taskList.value = []
|
||||
total.value = 0
|
||||
return
|
||||
}
|
||||
|
||||
// 处理子任务
|
||||
// 只加载子任务(可接单的任务都是子任务)
|
||||
const itemResponse = await taskApi.getAvailableTaskItems(params)
|
||||
|
||||
if (itemResponse.code === 200) {
|
||||
const items = (itemResponse.data.records || []).map((item: any) => ({
|
||||
// 将子任务字段映射到任务字段
|
||||
...item,
|
||||
id: item.id, // 保持子任务的ID
|
||||
itemId: item.id, // 额外保存子任务ID
|
||||
itemNo: item.itemNo, // 子任务编号(用于第三方API查询)
|
||||
title: item.mainTaskTitle || item.taskTitle || item.title, // 使用主任务标题
|
||||
subTaskNo: item.itemNo, // 子任务编号(兼容)
|
||||
isSubTask: true, // 标记为子任务
|
||||
taskId: item.taskId, // 保存主任务ID
|
||||
// 保留子任务的其他字段
|
||||
id: item.id,
|
||||
itemId: item.id,
|
||||
itemNo: item.itemNo,
|
||||
title: item.mainTaskTitle || item.taskTitle || item.title,
|
||||
subTaskNo: item.itemNo,
|
||||
isSubTask: true,
|
||||
taskId: item.taskId,
|
||||
groupNo: item.groupNo,
|
||||
taskTypeId: item.taskTypeId,
|
||||
taskTypeName: item.taskTypeName, // 任务类型名称
|
||||
taskSubType: item.taskSubType, // 任务子类型(新品、优化等)
|
||||
score: item.totalScore || item.score, // 预估积分
|
||||
taskTypeName: item.taskTypeName,
|
||||
taskSubType: item.taskSubType,
|
||||
score: item.totalScore || item.score,
|
||||
estimatedHours: item.estimatedHours,
|
||||
quantity: item.quantity || 1, // 数量
|
||||
previewImage: item.previewImage, // 预览图
|
||||
prevDownloadUrl: item.prevDownloadUrl, // 前置环节素材下载链接
|
||||
quantity: item.quantity || 1,
|
||||
previewImage: item.previewImage,
|
||||
prevDownloadUrl: item.prevDownloadUrl,
|
||||
description: item.description || item.taskDescription
|
||||
}))
|
||||
allTasks = [...allTasks, ...items]
|
||||
totalCount += itemResponse.data.total || 0
|
||||
allTasks = items
|
||||
totalCount = itemResponse.data.total || 0
|
||||
}
|
||||
|
||||
// 按创建时间排序
|
||||
@ -2873,6 +2870,9 @@ const handlePageChange = () => {
|
||||
}
|
||||
|
||||
// 加载已完成任务列表
|
||||
// - 需求部门用户:看到自己发起的已完成的母任务
|
||||
// - 接单部门用户:看到自己完成的子任务
|
||||
// - 管理员:看到所有已完成任务
|
||||
const loadCompletedTasks = async () => {
|
||||
completedLoading.value = true
|
||||
try {
|
||||
@ -2886,9 +2886,69 @@ const loadCompletedTasks = async () => {
|
||||
if (completedFilters.keyword) params.keyword = completedFilters.keyword
|
||||
if (completedFilters.sortBy) params.sortBy = completedFilters.sortBy
|
||||
|
||||
const response = await taskApi.getCompletedTasks(params)
|
||||
completedTaskList.value = response.data.records || []
|
||||
completedTotal.value = response.data.total || 0
|
||||
// 获取用户部门类型
|
||||
const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
|
||||
const userDeptType = userInfo.deptType
|
||||
const isAdmin = userInfo.isAdmin === 1 || userInfo.isAdmin === true
|
||||
|
||||
let allTasks: any[] = []
|
||||
let totalCount = 0
|
||||
|
||||
if (isAdmin) {
|
||||
// 管理员:看到所有已完成任务(母任务和子任务)
|
||||
const [taskResponse, itemResponse] = await Promise.all([
|
||||
taskApi.getCompletedTasks(params),
|
||||
taskApi.getCompletedTaskItems(params)
|
||||
])
|
||||
|
||||
if (taskResponse.data && taskResponse.data.records) {
|
||||
const tasks = taskResponse.data.records.map((task: any) => ({
|
||||
...task,
|
||||
isSubTask: false
|
||||
}))
|
||||
allTasks = [...allTasks, ...tasks]
|
||||
totalCount += taskResponse.data.total || 0
|
||||
}
|
||||
|
||||
if (itemResponse.data && itemResponse.data.records) {
|
||||
const items = itemResponse.data.records.map((item: any) => ({
|
||||
...mapTaskItemToTask(item),
|
||||
status: 'completed'
|
||||
}))
|
||||
allTasks = [...allTasks, ...items]
|
||||
totalCount += itemResponse.data.total || 0
|
||||
}
|
||||
} else if (userDeptType === 'demand') {
|
||||
// 需求部门用户:看到自己发起的已完成的母任务
|
||||
const response = await taskApi.getCompletedTasks(params)
|
||||
if (response.data && response.data.records) {
|
||||
allTasks = response.data.records.map((task: any) => ({
|
||||
...task,
|
||||
isSubTask: false
|
||||
}))
|
||||
totalCount = response.data.total || 0
|
||||
}
|
||||
} else {
|
||||
// 接单部门用户:看到自己完成的子任务
|
||||
const response = await taskApi.getCompletedTaskItems(params)
|
||||
if (response.data && response.data.records) {
|
||||
allTasks = response.data.records.map((item: any) => ({
|
||||
...mapTaskItemToTask(item),
|
||||
status: 'completed'
|
||||
}))
|
||||
totalCount = response.data.total || 0
|
||||
}
|
||||
}
|
||||
|
||||
// 按完成时间排序
|
||||
allTasks.sort((a, b) => {
|
||||
const timeA = new Date(a.completeTime || a.updateTime || 0).getTime()
|
||||
const timeB = new Date(b.completeTime || b.updateTime || 0).getTime()
|
||||
return timeB - timeA // 降序
|
||||
})
|
||||
|
||||
completedTaskList.value = allTasks
|
||||
completedTotal.value = totalCount
|
||||
} catch (error) {
|
||||
console.error('加载已完成任务失败:', error)
|
||||
message.error('加载已完成任务失败')
|
||||
@ -3562,7 +3622,10 @@ const handleCreateTask = () => {
|
||||
router.push('/tasks/create')
|
||||
}
|
||||
|
||||
// 加载进行中任务(同时加载普通任务和子任务)
|
||||
// 加载进行中任务
|
||||
// - 需求部门用户:只看母任务卡片(自己发起的任务)
|
||||
// - 接单部门用户:只看子任务卡片(自己接单的任务)
|
||||
// - 管理员:看到所有任务
|
||||
const loadInProgressTasks = async () => {
|
||||
inProgressLoading.value = true
|
||||
try {
|
||||
@ -3583,52 +3646,57 @@ const loadInProgressTasks = async () => {
|
||||
if (inProgressFilters.minProgress !== undefined) params.minProgress = inProgressFilters.minProgress
|
||||
if (inProgressFilters.maxProgress !== undefined) params.maxProgress = inProgressFilters.maxProgress
|
||||
|
||||
// 同时获取普通任务和子任务
|
||||
const [taskResponse, itemResponse] = await Promise.all([
|
||||
taskApi.getTasks(params),
|
||||
taskApi.getInProgressTaskItems(params)
|
||||
])
|
||||
// 获取用户部门类型
|
||||
const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
|
||||
const userDeptType = userInfo.deptType // 'demand' 或 'receiving'
|
||||
const isAdmin = userInfo.isAdmin === 1 || userInfo.isAdmin === true
|
||||
|
||||
let allTasks: any[] = []
|
||||
let totalCount = 0
|
||||
|
||||
// 处理普通任务
|
||||
if (taskResponse.data && taskResponse.data.records) {
|
||||
const tasks = taskResponse.data.records.map((task: any) => ({
|
||||
...task,
|
||||
isSubTask: false // 标记为普通任务
|
||||
}))
|
||||
allTasks = [...allTasks, ...tasks]
|
||||
totalCount += taskResponse.data.total || 0
|
||||
}
|
||||
// 根据部门类型决定加载哪些任务
|
||||
if (isAdmin) {
|
||||
// 管理员:看到所有任务(母任务和子任务)
|
||||
const [taskResponse, itemResponse] = await Promise.all([
|
||||
taskApi.getTasks(params),
|
||||
taskApi.getInProgressTaskItems(params)
|
||||
])
|
||||
|
||||
// 处理子任务
|
||||
if (itemResponse.data && itemResponse.data.records) {
|
||||
const items = itemResponse.data.records.map((item: any) => ({
|
||||
// 将子任务字段映射到任务字段
|
||||
...item,
|
||||
id: item.id, // 保持子任务的ID
|
||||
itemId: item.id, // 额外保存子任务ID
|
||||
itemNo: item.itemNo, // 子任务编号(用于第三方API查询)
|
||||
title: item.mainTaskTitle || item.taskTitle || item.title, // 使用主任务标题
|
||||
subTaskNo: item.itemNo, // 子任务编号(兼容)
|
||||
isSubTask: true, // 标记为子任务
|
||||
taskId: item.taskId, // 保存主任务ID
|
||||
// 保留子任务的其他字段
|
||||
groupNo: item.groupNo,
|
||||
taskTypeId: item.taskTypeId,
|
||||
taskTypeName: item.taskTypeName, // 任务类型名称
|
||||
score: item.totalScore || item.score,
|
||||
estimatedHours: item.estimatedHours,
|
||||
quantity: item.quantity || 1, // 数量
|
||||
previewImage: item.previewImage, // 预览图
|
||||
prevDownloadUrl: item.prevDownloadUrl, // 前置环节素材下载链接
|
||||
description: item.description || item.taskDescription,
|
||||
progress: item.progress,
|
||||
status: 'in_progress'
|
||||
}))
|
||||
allTasks = [...allTasks, ...items]
|
||||
totalCount += itemResponse.data.total || 0
|
||||
// 处理普通任务
|
||||
if (taskResponse.data && taskResponse.data.records) {
|
||||
const tasks = taskResponse.data.records.map((task: any) => ({
|
||||
...task,
|
||||
isSubTask: false
|
||||
}))
|
||||
allTasks = [...allTasks, ...tasks]
|
||||
totalCount += taskResponse.data.total || 0
|
||||
}
|
||||
|
||||
// 处理子任务
|
||||
if (itemResponse.data && itemResponse.data.records) {
|
||||
const items = itemResponse.data.records.map((item: any) => mapTaskItemToTask(item))
|
||||
allTasks = [...allTasks, ...items]
|
||||
totalCount += itemResponse.data.total || 0
|
||||
}
|
||||
} else if (userDeptType === 'demand') {
|
||||
// 需求部门用户:只看母任务卡片(自己发起的任务)
|
||||
const taskResponse = await taskApi.getTasks(params)
|
||||
if (taskResponse.data && taskResponse.data.records) {
|
||||
const tasks = taskResponse.data.records.map((task: any) => ({
|
||||
...task,
|
||||
isSubTask: false
|
||||
}))
|
||||
allTasks = tasks
|
||||
totalCount = taskResponse.data.total || 0
|
||||
}
|
||||
} else {
|
||||
// 接单部门用户(设计师):只看子任务卡片
|
||||
const itemResponse = await taskApi.getInProgressTaskItems(params)
|
||||
if (itemResponse.data && itemResponse.data.records) {
|
||||
const items = itemResponse.data.records.map((item: any) => mapTaskItemToTask(item))
|
||||
allTasks = items
|
||||
totalCount = itemResponse.data.total || 0
|
||||
}
|
||||
}
|
||||
|
||||
// 按更新时间排序
|
||||
@ -3649,6 +3717,30 @@ const loadInProgressTasks = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 将子任务映射为任务格式(供显示用)
|
||||
const mapTaskItemToTask = (item: any) => ({
|
||||
...item,
|
||||
id: item.id,
|
||||
itemId: item.id,
|
||||
itemNo: item.itemNo,
|
||||
title: item.mainTaskTitle || item.taskTitle || item.title,
|
||||
subTaskNo: item.itemNo,
|
||||
isSubTask: true,
|
||||
taskId: item.taskId,
|
||||
groupNo: item.groupNo,
|
||||
taskTypeId: item.taskTypeId,
|
||||
taskTypeName: item.taskTypeName,
|
||||
score: item.totalScore || item.score,
|
||||
estimatedHours: item.estimatedHours,
|
||||
quantity: item.quantity || 1,
|
||||
previewImage: item.previewImage,
|
||||
prevDownloadUrl: item.prevDownloadUrl,
|
||||
description: item.description || item.taskDescription,
|
||||
progress: item.progress,
|
||||
status: 'in_progress',
|
||||
receiverName: item.receiverName // 接单人姓名(部门负责人查看时显示)
|
||||
})
|
||||
|
||||
// 加载待审核任务(所有处于审批流程中的任务)
|
||||
const loadReviewTasks = async () => {
|
||||
reviewLoading.value = true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user