任务管理新增修改添加分工功能
This commit is contained in:
@ -6,7 +6,7 @@ import type {
|
||||
TaskDetailResponse
|
||||
} from '@/servers/dao/supplierEvaluateTask';
|
||||
import type { TaskNotifyLowerUnits } from '@/dicts/supplierTaskDict';
|
||||
import type { PersonnelItem } from '@/servers/dao/supplierEvaluateTask';
|
||||
import type { PersonnelItem, IndicatorItem, SupplierItem } from '@/servers/dao/supplierEvaluateTask';
|
||||
|
||||
// Define the types for dva effects and reducers
|
||||
type Effect = (action: { payload: any }, effects: { call: any; put: any; select: any }) => Generator<any, void, unknown>;
|
||||
@ -22,7 +22,7 @@ export interface SupplierTaskModelState {
|
||||
detailLoading: boolean; // 详情数据加载状态
|
||||
taskFormData: Partial<TaskAddRequest>; // 任务表单数据
|
||||
taskDetail: TaskDetailData | null; // 任务详情数据
|
||||
userList: PersonnelItem[]; // 用户列表
|
||||
mode: 'add' | 'edit' | 'division'; // 模式
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,6 +39,9 @@ export interface SupplierTaskModelType {
|
||||
nextStep: Effect; // 下一步
|
||||
prevStep: Effect; // 上一步
|
||||
resetState: Effect; // 重置状态
|
||||
setCurrentStep: Effect; // 设置当前步骤
|
||||
setMode: Effect; // 设置模式
|
||||
deleteUser: Effect; // 删除用户
|
||||
};
|
||||
reducers: {
|
||||
saveCurrentStep: Reducer<SupplierTaskModelState>; // 保存当前步骤
|
||||
@ -46,6 +49,7 @@ export interface SupplierTaskModelType {
|
||||
saveDetailLoading: Reducer<SupplierTaskModelState>; // 保存详情加载状态
|
||||
saveTaskFormData: Reducer<SupplierTaskModelState>; // 保存任务表单数据
|
||||
saveTaskDetail: Reducer<SupplierTaskModelState>; // 保存任务详情数据
|
||||
saveMode: Reducer<SupplierTaskModelState>; // 保存模式
|
||||
};
|
||||
}
|
||||
|
||||
@ -63,7 +67,7 @@ const SupplierTaskModel: SupplierTaskModelType = {
|
||||
detailLoading: false, // 详情数据加载状态
|
||||
taskFormData: {}, // 任务表单数据
|
||||
taskDetail: null, // 任务详情数据
|
||||
userList: [], // 用户列表
|
||||
mode: 'add', // 模式
|
||||
},
|
||||
|
||||
// 副作用处理函数
|
||||
@ -94,6 +98,7 @@ const SupplierTaskModel: SupplierTaskModelType = {
|
||||
evaluateYear: detail.evaluateYear || '',
|
||||
categoryId: detail.categoryId || undefined,
|
||||
|
||||
|
||||
// 供应商数据转换,添加id和name字段用于UI展示
|
||||
selectedSuppliers: detail.blackSupplierVos.map((item) => ({
|
||||
...item,
|
||||
@ -110,9 +115,8 @@ const SupplierTaskModel: SupplierTaskModelType = {
|
||||
|
||||
// 部门权重
|
||||
taskDeptWeightList: detail.taskDeptWeightList || [],
|
||||
|
||||
//设置评价分工table回显 需处理
|
||||
userList: detail.userList.map((user) => {
|
||||
userList: detail.userList.map((user) => {
|
||||
const matchedIndicator = detail.indicatorList?.find(
|
||||
(indicator) => indicator.userId === user.userId
|
||||
);
|
||||
@ -124,21 +128,7 @@ const SupplierTaskModel: SupplierTaskModelType = {
|
||||
};
|
||||
}),
|
||||
|
||||
// 供应商与评价人员关联,用于分工步骤 需要以userList[]人员为维度,
|
||||
// 关联出 indicatorList[]指标中的 userId,
|
||||
// 关联出来的对象中的indicatorIds[]为指标id,
|
||||
// 对象中的type不需要关注,只在保存时动态修改即可
|
||||
suppliersWithEvaluators: 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 || [],
|
||||
};
|
||||
}),
|
||||
|
||||
};
|
||||
|
||||
// 保存数据到状态
|
||||
@ -255,14 +245,29 @@ const SupplierTaskModel: SupplierTaskModelType = {
|
||||
}));
|
||||
updatedFormData.selectedSuppliers = suppliersWithEvaluators;
|
||||
}
|
||||
// 处理评价人员更新 - 更新后要保留原有对象中的indicatorIds
|
||||
if (payload.userList) {
|
||||
const existingUserMap = new Map(
|
||||
(taskFormData.userList || []).map((user: PersonnelItem) => [user.id || user.userId, user])
|
||||
);
|
||||
|
||||
// 处理评价人员更新 - 保持suppliersWithEvaluators和selectedSuppliers同步
|
||||
if (payload.suppliersWithEvaluators) {
|
||||
const evaluatedSuppliers = payload.suppliersWithEvaluators;
|
||||
updatedFormData.suppliersWithEvaluators = evaluatedSuppliers;
|
||||
updatedFormData.selectedSuppliers = evaluatedSuppliers; // 同步更新selectedSuppliers
|
||||
updatedFormData.userList = payload.userList.map((newUser: PersonnelItem) => {
|
||||
const userId = newUser.id || newUser.userId;
|
||||
const existing = existingUserMap.get(userId);
|
||||
|
||||
const indicatorIds =
|
||||
newUser.indicatorIds && newUser.indicatorIds.length > 0
|
||||
? newUser.indicatorIds
|
||||
: existing?.indicatorIds || [];
|
||||
|
||||
return {
|
||||
...newUser,
|
||||
indicatorIds,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 处理部门权重
|
||||
if (payload.taskDeptWeightList) {
|
||||
updatedFormData.taskDeptWeightList = payload.taskDeptWeightList;
|
||||
@ -272,6 +277,49 @@ const SupplierTaskModel: SupplierTaskModelType = {
|
||||
// 保存更新后的表单数据
|
||||
yield put({ type: 'saveTaskFormData', payload: updatedFormData });
|
||||
},
|
||||
/**
|
||||
* 删除用户
|
||||
* @param payload.userId 用户ID
|
||||
*/
|
||||
*deleteUser({ payload }: { payload: { userIds: string[] } }, { put, select }: { put: any; select: any }) {
|
||||
const { userIds } = payload;
|
||||
if (!userIds || userIds.length === 0) return;
|
||||
|
||||
const userIdSet = new Set(userIds.filter(Boolean).map(String));
|
||||
|
||||
const { taskFormData } = (yield select((state: any) => state.supplierTaskManage)) as {
|
||||
taskFormData: TaskAddRequest;
|
||||
};
|
||||
|
||||
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))
|
||||
);
|
||||
|
||||
// 3. 删除 selectedSuppliers(供应商对象) 中 evaluator(评价人员对象) 对象
|
||||
updatedFormData.selectedSuppliers = (updatedFormData.selectedSuppliers || [])
|
||||
.map((supplier: SupplierItem) => {
|
||||
const newEvaluators = (supplier.evaluators || []).filter(
|
||||
(evaluator: PersonnelItem) => !userIdSet.has(String(evaluator.id))
|
||||
);
|
||||
return {
|
||||
...supplier,
|
||||
evaluators: newEvaluators,
|
||||
};
|
||||
})
|
||||
.filter((supplier) => (supplier.evaluators || []).length > 0);
|
||||
|
||||
// 保存更新
|
||||
yield put({ type: 'saveTaskFormData', payload: updatedFormData });
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 下一步
|
||||
@ -290,6 +338,12 @@ const SupplierTaskModel: SupplierTaskModelType = {
|
||||
const { currentStep } = (yield select((state: any) => state.supplierTaskManage)) as { currentStep: number };
|
||||
yield put({ type: 'saveCurrentStep', payload: currentStep - 1 });
|
||||
},
|
||||
/*
|
||||
设置当前步骤
|
||||
*/
|
||||
*setCurrentStep({ payload }: { payload: number }, { put }: { put: any }) {
|
||||
yield put({ type: 'saveCurrentStep', payload });
|
||||
},
|
||||
|
||||
/**
|
||||
* 重置状态
|
||||
@ -307,6 +361,12 @@ const SupplierTaskModel: SupplierTaskModelType = {
|
||||
payload: 0
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 设置模式
|
||||
*/
|
||||
*setMode({ payload }: { payload: 'add' | 'edit' | 'division' }, { put }: { put: any }) {
|
||||
yield put({ type: 'saveMode', payload });
|
||||
},
|
||||
},
|
||||
|
||||
// reducers用于更新状态
|
||||
@ -317,6 +377,12 @@ const SupplierTaskModel: SupplierTaskModelType = {
|
||||
saveCurrentStep(state, { payload }) {
|
||||
return { ...state, currentStep: payload };
|
||||
},
|
||||
/**
|
||||
* 保存模式
|
||||
*/
|
||||
saveMode(state, { payload }) {
|
||||
return { ...state, mode: payload };
|
||||
},
|
||||
/**
|
||||
* 保存加载状态
|
||||
*/
|
||||
|
Reference in New Issue
Block a user