fix: 发布任务指定设计师模式下,自动加载任务类型对应的接单部门设计师列表及工作量
This commit is contained in:
parent
190ee52b4f
commit
8c4f37d309
@ -621,8 +621,8 @@ interface CascaderOption {
|
||||
estimatedHours?: number
|
||||
}
|
||||
|
||||
// 设计师列表缓存 { deptId: designers[] }
|
||||
const designersCache = reactive<Record<number, any[]>>({})
|
||||
// 设计师列表缓存 { cacheKey: designers[] }
|
||||
const designersCache = reactive<Record<string, any[]>>({})
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
@ -853,27 +853,22 @@ const findTaskTypeById = (id: number, items: any[] = hierarchicalTaskTypes.value
|
||||
return null
|
||||
}
|
||||
|
||||
// 加载设计师列表
|
||||
// 加载设计师列表(根据任务类型配置的接单部门获取设计师及工作量)
|
||||
const loadDesignersForItem = async (item: TaskTypeItem) => {
|
||||
if (!item.taskTypeId) return
|
||||
|
||||
const typeInfo = getTaskTypeInfo(item.taskTypeId)
|
||||
if (!typeInfo || !typeInfo.allowedDeptIds) return
|
||||
// 使用 taskTypeId 作为缓存key
|
||||
const cacheKey = `type_${item.taskTypeId}`
|
||||
|
||||
// 简化处理:取第一个允许的部门ID
|
||||
const deptIds = typeInfo.allowedDeptIds.split(',')
|
||||
if (deptIds.length === 0) return
|
||||
|
||||
const deptId = Number(deptIds[0])
|
||||
|
||||
if (!designersCache[deptId]) {
|
||||
if (!designersCache[cacheKey]) {
|
||||
try {
|
||||
const res = await userApi.getDesignersWithWorkload(deptId)
|
||||
if (res.code === 200) {
|
||||
designersCache[deptId] = res.data
|
||||
}
|
||||
// 传入 taskTypeId,后端会根据任务类型配置的接单部门获取设计师
|
||||
const designers = await userApi.getDesignersWithWorkload(undefined, item.taskTypeId)
|
||||
designersCache[cacheKey] = designers || []
|
||||
console.log(`加载任务类型 ${item.taskTypeId} 的设计师列表:`, designers?.length || 0, '人')
|
||||
} catch (error) {
|
||||
console.error('加载设计师失败:', error)
|
||||
designersCache[cacheKey] = []
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -882,14 +877,8 @@ const loadDesignersForItem = async (item: TaskTypeItem) => {
|
||||
const getDesignersForItem = (item: TaskTypeItem) => {
|
||||
if (!item.taskTypeId) return []
|
||||
|
||||
const typeInfo = getTaskTypeInfo(item.taskTypeId)
|
||||
if (!typeInfo || !typeInfo.allowedDeptIds) return []
|
||||
|
||||
const deptIds = typeInfo.allowedDeptIds.split(',')
|
||||
if (deptIds.length === 0) return []
|
||||
|
||||
const deptId = Number(deptIds[0])
|
||||
return designersCache[deptId] || []
|
||||
const cacheKey = `type_${item.taskTypeId}`
|
||||
return designersCache[cacheKey] || []
|
||||
}
|
||||
|
||||
// 添加任务类型
|
||||
@ -962,6 +951,39 @@ watch(
|
||||
}
|
||||
)
|
||||
|
||||
// 监听发布类型变化,当切换到"指定任务"模式时,自动加载设计师列表
|
||||
watch(
|
||||
() => formData.releaseType,
|
||||
async (newValue) => {
|
||||
if (newValue === 'assigned') {
|
||||
// 为所有已选择任务类型的项加载设计师列表
|
||||
for (const item of formData.taskTypes) {
|
||||
if (item.taskTypeId) {
|
||||
await loadDesignersForItem(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// 监听任务类型选择变化,当在"指定任务"模式下选择新任务类型时,自动加载设计师
|
||||
watch(
|
||||
() => formData.taskTypes.map(item => item.taskTypeId),
|
||||
async (newIds, oldIds) => {
|
||||
if (formData.releaseType === 'assigned') {
|
||||
// 找出新增或变化的任务类型
|
||||
for (let i = 0; i < newIds.length; i++) {
|
||||
const newId = newIds[i]
|
||||
const oldId = oldIds?.[i]
|
||||
if (newId && newId !== oldId) {
|
||||
await loadDesignersForItem(formData.taskTypes[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
// 计算预估积分(累加所有任务类型)
|
||||
const estimatedScore = computed(() => {
|
||||
let totalScore = 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user