年审模块
This commit is contained in:
@ -1,12 +1,8 @@
|
||||
import { message } from 'antd';
|
||||
import { addTask, getTaskDetail } from '@/servers/api/supplierEvaluate';
|
||||
import type {
|
||||
TaskDetailData,
|
||||
TaskAddRequest,
|
||||
TaskDetailResponse
|
||||
} from '@/servers/dao/supplierAnnualTaskManag';
|
||||
import { addAnnualTask, getAnnualTaskDetail,updateAnnualTask } from '@/servers/api/supplierAnnual';
|
||||
import type { SupplierItem } from '@/servers/dao/supplierEvaluateTask';
|
||||
|
||||
import type { TaskNotifyLowerUnits } from '@/dicts/supplierTaskDict';
|
||||
import type { PersonnelItem, IndicatorItem, SupplierItem } from '@/servers/dao/supplierAnnualTaskManag';
|
||||
|
||||
// Define the types for dva effects and reducers
|
||||
type Effect = (action: { payload: any }, effects: { call: any; put: any; select: any }) => Generator<any, void, unknown>;
|
||||
@ -20,8 +16,8 @@ export interface SupplierTaskModelState {
|
||||
currentStep: number; // 当前步骤索引,从0开始
|
||||
loading: boolean; // 提交加载状态
|
||||
detailLoading: boolean; // 详情数据加载状态
|
||||
taskFormData: Partial<TaskAddRequest>; // 任务表单数据
|
||||
taskDetail: TaskDetailData | null; // 任务详情数据
|
||||
taskFormData: Partial<supplierAnnualTaskManage.AddTaskRequest>; // 任务表单数据
|
||||
taskDetail: supplierAnnualTaskManage.TaskDetailData | null; // 任务详情数据
|
||||
mode: 'add' | 'edit' | 'division'; // 模式
|
||||
}
|
||||
|
||||
@ -82,20 +78,20 @@ const supplierAnnualTaskManage: SupplierTaskModelType = {
|
||||
|
||||
try {
|
||||
// 调用API获取任务详情
|
||||
const response = (yield call(getTaskDetail, taskId)) as TaskDetailResponse;
|
||||
const response = (yield call(getAnnualTaskDetail, taskId)) as supplierAnnualTaskManage.TaskDetailResponse;
|
||||
|
||||
if (response.success) {
|
||||
const detail: TaskDetailData = response.data;
|
||||
const detail: supplierAnnualTaskManage.TaskDetailData = response.data;
|
||||
|
||||
// 转换任务详情数据为表单数据结构
|
||||
const taskFormData: Partial<TaskAddRequest> = {
|
||||
const taskFormData: Partial<supplierAnnualTaskManage.AddTaskRequest> = {
|
||||
id: detail.id || '',
|
||||
evaluateTheme: detail.evaluateTheme || '',
|
||||
annualreviewTheme: detail.annualreviewTheme || '',
|
||||
startTime: detail.startTime || '',
|
||||
endTime: detail.endTime || '',
|
||||
templateId: detail.templateId || '',
|
||||
categoryLimitation: detail.categoryLimitation || '0',
|
||||
evaluateYear: detail.evaluateYear || '',
|
||||
annualreviewYear: detail.annualreviewYear || '',
|
||||
categoryId: detail.categoryId || undefined,
|
||||
|
||||
|
||||
@ -107,25 +103,8 @@ const supplierAnnualTaskManage: SupplierTaskModelType = {
|
||||
evaluators: item.userList,
|
||||
})),
|
||||
|
||||
// 指标列表
|
||||
indicatorList: detail.indicatorList || [],
|
||||
|
||||
// 供应商IDs与用户IDs
|
||||
supplierIds: detail.supplierIds || [],
|
||||
|
||||
//设置评价分工table回显 需处理
|
||||
userList: detail.userList.map((user) => {
|
||||
const matchedIndicator = detail.indicatorList?.find(
|
||||
(indicator) => indicator.userId === user.userId
|
||||
);
|
||||
return {
|
||||
...user,
|
||||
name: user.userName,
|
||||
id: user.userId,
|
||||
indicatorIds: matchedIndicator?.indicatorIds || [],
|
||||
};
|
||||
}),
|
||||
|
||||
supplierPeopleVo: detail.supplierPeopleVo || [],
|
||||
|
||||
};
|
||||
|
||||
@ -145,53 +124,41 @@ const supplierAnnualTaskManage: SupplierTaskModelType = {
|
||||
|
||||
/**
|
||||
* 提交任务数据
|
||||
* @param payload.taskStatus 任务状态
|
||||
* @param payload.isEditMode 是否为编辑模式
|
||||
* @param payload.taskId 任务ID(编辑模式必须)
|
||||
* @param payload.onSuccess 成功回调函数
|
||||
*/
|
||||
*submitTaskData(
|
||||
{ payload }: { payload: { taskStatus: TaskNotifyLowerUnits | null; isEditMode: boolean; taskId: string; onSuccess?: () => void } },
|
||||
{ payload }: { payload: {isEditMode: boolean; taskId: string; onSuccess?: () => void } },
|
||||
{ call, put, select }: { call: any; put: any; select: any }
|
||||
) {
|
||||
const { taskStatus, isEditMode, taskId, onSuccess } = payload;
|
||||
const { isEditMode, taskId, onSuccess } = payload;
|
||||
yield put({ type: 'saveLoading', payload: true });
|
||||
|
||||
try {
|
||||
// 获取表单数据
|
||||
const { taskFormData } = (yield select((state: any) => state.supplierAnnualTaskManage)) as { taskFormData: TaskAddRequest };
|
||||
const { taskFormData } = (yield select((state: any) => state.supplierAnnualTaskManage)) as { taskFormData: supplierAnnualTaskManage.AddTaskRequest };
|
||||
|
||||
// 构建提交数据
|
||||
let submitData: TaskAddRequest = {
|
||||
evaluateTheme: taskFormData.evaluateTheme || '',
|
||||
let submitData: supplierAnnualTaskManage.AddTaskRequest = {
|
||||
annualreviewTheme: taskFormData.annualreviewTheme || '',
|
||||
startTime: taskFormData.startTime || '',
|
||||
endTime: taskFormData.endTime || '',
|
||||
templateId: taskFormData.templateId || '',
|
||||
categoryLimitation: taskFormData.categoryLimitation || '0',
|
||||
evaluateYear: taskFormData.evaluateYear || '',
|
||||
annualreviewYear: taskFormData.annualreviewYear || '',
|
||||
categoryId: taskFormData.categoryId || '',
|
||||
taskStatus: taskStatus || null,
|
||||
|
||||
// 供应商IDs与评价人员IDs
|
||||
supplierIds:
|
||||
taskFormData.selectedSuppliers?.map((supplier: any) => {
|
||||
supplierPeopleVo:
|
||||
taskFormData.selectedSuppliers?.map((supplier: SupplierItem) => {
|
||||
// 从供应商的evaluators中提取用户ID
|
||||
const userIds = supplier.evaluators?.map((evaluator: any) => evaluator.id) || [];
|
||||
const userIds = supplier.evaluators?.map((evaluator: supplierAnnualTaskManage.PersonnelItem) => evaluator.id) || [];
|
||||
return {
|
||||
id: supplier.id,
|
||||
suppliedId: supplier.id,
|
||||
userIds,
|
||||
};
|
||||
}) || [],
|
||||
|
||||
// 指标列表
|
||||
indicatorList:
|
||||
taskFormData.indicatorList?.map((item: any) => ({
|
||||
userId: item.userId,
|
||||
// 评价类型:如果用户关联了指标则为1(按指标),否则为0(按评价单)
|
||||
type: item.indicatorIds && item.indicatorIds.length > 0 ? 1 : 0,
|
||||
indicatorIds: item.indicatorIds || [],
|
||||
})) || [],
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -202,7 +169,7 @@ const supplierAnnualTaskManage: SupplierTaskModelType = {
|
||||
id: taskId,
|
||||
};
|
||||
}
|
||||
const response = (yield call(addTask, submitData)) as API.Response;
|
||||
const response = (yield call(isEditMode? updateAnnualTask : addAnnualTask, submitData)) as supplierAnnualTaskManage.ApiResponse;
|
||||
if (response.success) {
|
||||
message.success(isEditMode ? '任务更新成功' : '任务创建成功');
|
||||
if (onSuccess) {
|
||||
@ -226,7 +193,7 @@ const supplierAnnualTaskManage: SupplierTaskModelType = {
|
||||
*/
|
||||
*updateFormData({ payload }: { payload: any }, { put, select }: { put: any; select: any }) {
|
||||
// 获取当前表单数据
|
||||
const { taskFormData } = (yield select((state: any) => state.supplierAnnualTaskManage)) as { taskFormData: TaskAddRequest };
|
||||
const { taskFormData } = (yield select((state: any) => state.supplierAnnualTaskManage)) as { taskFormData: supplierAnnualTaskManage.AddTaskRequest };
|
||||
// 合并新的表单数据
|
||||
const updatedFormData = { ...taskFormData, ...payload };
|
||||
// 处理供应商选择更新
|
||||
@ -256,33 +223,28 @@ const supplierAnnualTaskManage: SupplierTaskModelType = {
|
||||
const userIdSet = new Set(userIds.filter(Boolean).map(String));
|
||||
|
||||
const { taskFormData } = (yield select((state: any) => state.supplierAnnualTaskManage)) as {
|
||||
taskFormData: TaskAddRequest;
|
||||
taskFormData: supplierAnnualTaskManage.AddTaskRequest;
|
||||
};
|
||||
|
||||
const updatedFormData = { ...taskFormData };
|
||||
|
||||
// 1. 删除 userList 中的用户
|
||||
updatedFormData.userList = (updatedFormData.userList || []).filter(
|
||||
(user: PersonnelItem) => !userIdSet.has(String(user.id || user.userId))
|
||||
);
|
||||
|
||||
// 2. 删除 indicatorList(指标对象) 中该用户的指标
|
||||
updatedFormData.indicatorList = (updatedFormData.indicatorList || []).filter(
|
||||
(item: IndicatorItem) => !userIdSet.has(String(item.userId))
|
||||
(user: supplierAnnualTaskManage.TaskUserList) => !userIdSet.has(String(user.id || user.userId))
|
||||
);
|
||||
|
||||
// 3. 删除 selectedSuppliers(供应商对象) 中 evaluator(评价人员对象) 对象
|
||||
updatedFormData.selectedSuppliers = (updatedFormData.selectedSuppliers || [])
|
||||
.map((supplier: SupplierItem) => {
|
||||
const newEvaluators = (supplier.evaluators || []).filter(
|
||||
(evaluator: PersonnelItem) => !userIdSet.has(String(evaluator.id))
|
||||
(evaluator: supplierAnnualTaskManage.PersonnelItem) => !userIdSet.has(String(evaluator.id))
|
||||
);
|
||||
return {
|
||||
...supplier,
|
||||
evaluators: newEvaluators,
|
||||
};
|
||||
})
|
||||
.filter((supplier) => (supplier.evaluators || []).length > 0);
|
||||
.filter((supplier: SupplierItem) => (supplier.evaluators || []).length > 0);
|
||||
|
||||
// 保存更新
|
||||
yield put({ type: 'saveTaskFormData', payload: updatedFormData });
|
||||
|
Reference in New Issue
Block a user