任务管理新增修改添加分工功能
This commit is contained in:
@ -14,13 +14,7 @@ import { getTemplateDetail } from '@/servers/api/supplierEvaluate';
|
||||
import type { Dispatch } from 'umi';
|
||||
import { connect } from 'umi';
|
||||
import type { SupplierTaskModelState } from '@/models/supplierTaskManage';
|
||||
|
||||
// 评价指标类型定义
|
||||
interface IndicatorItem {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
import type { IndicatorItem } from '@/servers/dao/supplierEvaluateTask';
|
||||
|
||||
// 组件接收的Props定义
|
||||
interface DivisionStepProps {
|
||||
@ -42,19 +36,11 @@ const DivisionStepComponent = (props: DivisionStepProps) => {
|
||||
const { supplierTaskManage, dispatch, innerRef } = props;
|
||||
|
||||
// 从 model 获取表单数据,避免通过 props 层层传递
|
||||
const { taskFormData } = supplierTaskManage;
|
||||
const { taskFormData, mode } = supplierTaskManage;
|
||||
|
||||
// 从上一步获取的评价人员列表
|
||||
const [evaluators, setEvaluators] = useState<PersonnelItem[]>([]);
|
||||
|
||||
// 评价人员指标分配数据
|
||||
const indicatorAssignments = useRef<{
|
||||
[userId: string]: {
|
||||
type: EvaluateType;
|
||||
indicatorIds: string[];
|
||||
};
|
||||
}>({});
|
||||
|
||||
// 选中的行keys
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||
|
||||
@ -88,27 +74,14 @@ const DivisionStepComponent = (props: DivisionStepProps) => {
|
||||
// 查看模式下的过滤后指标数据
|
||||
const [filteredIndicators, setFilteredIndicators] = useState<any[]>([]);
|
||||
|
||||
// 统一获取用户指标ID的函数
|
||||
const getUserIndicatorIds = useCallback((userId: string) => {
|
||||
if (!userId) return [];
|
||||
|
||||
const assignment = indicatorAssignments.current[userId];
|
||||
if (!assignment) return [];
|
||||
|
||||
// 如果是按评价单评价(全部指标),返回空数组
|
||||
if (assignment.type == EvaluateType.ALL) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 如果是按指标评价,返回指标ID列表
|
||||
return assignment.indicatorIds || [];
|
||||
}, []);
|
||||
|
||||
// 获取当前用户的已分配指标ID
|
||||
const getCurrentUserSelectedIds = useCallback(() => {
|
||||
// 使用统一的getUserIndicatorIds函数获取当前用户的指标ID
|
||||
return getUserIndicatorIds(currentUserId);
|
||||
}, [currentUserId, getUserIndicatorIds]);
|
||||
if (!currentUserId) return [];
|
||||
|
||||
// 直接从 taskFormData.userList 中获取当前用户的指标ID
|
||||
const currentUser = taskFormData.userList?.find((user: any) => user.id === currentUserId);
|
||||
return currentUser?.indicatorIds || [];
|
||||
}, [currentUserId, taskFormData.userList]);
|
||||
|
||||
// 根据指标ID过滤模板数据
|
||||
const filterTemplateDataByIds = useCallback((data: any[], indicatorIds: string[]) => {
|
||||
@ -226,34 +199,55 @@ const DivisionStepComponent = (props: DivisionStepProps) => {
|
||||
);
|
||||
return indicatorNdListIds;
|
||||
};
|
||||
// 处理指标,将处理后的指标放到dva中,同步处理userList,展示table
|
||||
const handleIndicatorAssignment = (indicatorNdListIds: string[]) => {
|
||||
// 读取dva中的indicatorList
|
||||
const indicatorList = JSON.parse(JSON.stringify(taskFormData?.indicatorList));
|
||||
// 将指标id塞到当前激活的评价人员中
|
||||
indicatorList?.map((item: any) => {
|
||||
// 判断当前激活的评价人员和选择评价人构建的userId一直
|
||||
if (item.userId === currentUserId) {
|
||||
item.indicatorIds = [...new Set([...item.indicatorIds, ...indicatorNdListIds])];
|
||||
}
|
||||
});
|
||||
// 构建userList带指标id 为了表单回显
|
||||
const userList = JSON.parse(JSON.stringify(taskFormData?.userList));
|
||||
userList?.map((item: any) => {
|
||||
if (item.id === currentUserId) {
|
||||
item.indicatorIds = indicatorNdListIds;
|
||||
}
|
||||
// 处理指标,将处理后的指标放到dva中,同步处理userList,展示table 第二个参数是判断是否是批量设置,
|
||||
// 如果批量则取 selectedRowKeys(table选中所有user)
|
||||
const handleIndicatorAssignment = (indicatorNdListIds: string[], userIds: string[]) => {
|
||||
// 读取dva中的数据,只克隆一次
|
||||
const indicatorList = JSON.parse(JSON.stringify(taskFormData?.indicatorList || []));
|
||||
const userList = JSON.parse(JSON.stringify(taskFormData?.userList || []));
|
||||
|
||||
// 批量更新indicatorList和userList
|
||||
userIds.forEach((userId) => {
|
||||
// 更新indicatorList
|
||||
indicatorList.forEach((item: IndicatorItem) => {
|
||||
if (item.userId === userId) {
|
||||
item.indicatorIds = [...new Set([...(item.indicatorIds || []), ...indicatorNdListIds])];
|
||||
}
|
||||
});
|
||||
|
||||
// 更新userList
|
||||
userList.forEach((item: PersonnelItem) => {
|
||||
if (item.id === userId) {
|
||||
item.indicatorIds = indicatorNdListIds;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 只调用一次updateFormData
|
||||
updateFormData({
|
||||
indicatorList,
|
||||
userList,
|
||||
});
|
||||
};
|
||||
// 保存指标分配
|
||||
const handleSaveIndicatorAssignment = () => {
|
||||
if (!currentUserId) {
|
||||
message.warning('未选择评价人员');
|
||||
return;
|
||||
}
|
||||
// 将选择回来的指标提取二级指标id
|
||||
const indicatorNdListIds = getIndicatorNdListIds(selectedTemplateItems);
|
||||
handleIndicatorAssignment(indicatorNdListIds, [currentUserId]);
|
||||
setTemplateViewModalVisible(false);
|
||||
message.success('已设置评价人员指标分工');
|
||||
};
|
||||
|
||||
// 批量设置指标分工
|
||||
const handleBatchSetDivision = () => {
|
||||
// 将选择回来的指标提取二级指标id
|
||||
const indicatorNdListIds = getIndicatorNdListIds(batchSelectedTemplateItems);
|
||||
handleIndicatorAssignment(indicatorNdListIds);
|
||||
const userIds = selectedRowKeys.map((key) => key.toString());
|
||||
handleIndicatorAssignment(indicatorNdListIds, userIds);
|
||||
setBatchTemplateModalVisible(false);
|
||||
message.success(`已为${selectedRowKeys.length}名评价人员设置分工`);
|
||||
};
|
||||
@ -278,19 +272,6 @@ const DivisionStepComponent = (props: DivisionStepProps) => {
|
||||
setSelectedTemplateItems(selectedItems);
|
||||
};
|
||||
|
||||
// 保存指标分配
|
||||
const handleSaveIndicatorAssignment = () => {
|
||||
if (!currentUserId) {
|
||||
message.warning('未选择评价人员');
|
||||
return;
|
||||
}
|
||||
// 将选择回来的指标提取二级指标id
|
||||
const indicatorNdListIds = getIndicatorNdListIds(selectedTemplateItems);
|
||||
handleIndicatorAssignment(indicatorNdListIds);
|
||||
setTemplateViewModalVisible(false);
|
||||
message.success('已设置评价人员指标分工');
|
||||
};
|
||||
|
||||
// 查看评价人员的指标分工
|
||||
const handleViewAssignment = (person: PersonnelItem) => {
|
||||
const assignment = person.indicatorIds;
|
||||
@ -329,35 +310,23 @@ const DivisionStepComponent = (props: DivisionStepProps) => {
|
||||
// 更新评价人员列表
|
||||
setEvaluators((prev) => prev.filter((e) => e.id !== userId));
|
||||
|
||||
// 更新指标分配数据
|
||||
const newAssignments = { ...indicatorAssignments.current };
|
||||
delete newAssignments[userId];
|
||||
indicatorAssignments.current = newAssignments;
|
||||
//更新dva中的userList
|
||||
dispatch({
|
||||
type: 'supplierTaskManage/deleteUser',
|
||||
payload: {
|
||||
userIds: [userId],
|
||||
},
|
||||
});
|
||||
|
||||
message.success('已删除评价人员');
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 初始化:从formData中提取指标分配数据
|
||||
useEffect(() => {
|
||||
if (taskFormData.indicatorList && taskFormData.indicatorList.length > 0) {
|
||||
// 如果已有指标分配数据,直接使用
|
||||
const assignments: any = {};
|
||||
taskFormData.indicatorList.forEach((item: any) => {
|
||||
assignments[item.userId] = {
|
||||
type: item.type,
|
||||
indicatorIds: item.indicatorIds || [],
|
||||
};
|
||||
});
|
||||
indicatorAssignments.current = assignments;
|
||||
}
|
||||
}, [taskFormData.indicatorList]);
|
||||
|
||||
// 从上一步获取评价人员列表 - 避免频繁更新
|
||||
useEffect(() => {
|
||||
if (!taskFormData.userList) return;
|
||||
setEvaluators(taskFormData.userList);
|
||||
setEvaluators(taskFormData.userList as PersonnelItem[]);
|
||||
}, [taskFormData.userList]);
|
||||
|
||||
// 暴露给父组件的方法
|
||||
@ -401,8 +370,7 @@ const DivisionStepComponent = (props: DivisionStepProps) => {
|
||||
title: '是否设置分工',
|
||||
key: 'hasDivision',
|
||||
render: (_: any, record: PersonnelItem) => {
|
||||
const assignment = indicatorAssignments.current[record.id];
|
||||
if (!assignment || assignment.indicatorIds.length === 0)
|
||||
if (!record.indicatorIds || record.indicatorIds.length === 0)
|
||||
return <Tag color="red">未设置</Tag>;
|
||||
return <Tag color="green">已设置</Tag>;
|
||||
},
|
||||
@ -412,38 +380,45 @@ const DivisionStepComponent = (props: DivisionStepProps) => {
|
||||
key: 'action',
|
||||
render: (_: any, record: PersonnelItem) => (
|
||||
<Space size="middle">
|
||||
<Button type="link" onClick={() => handleAssignIndicators(record.id)}>
|
||||
评价指标分工
|
||||
</Button>
|
||||
{!record.isSelected && (
|
||||
<>
|
||||
<Button type="link" onClick={() => handleAssignIndicators(record.id)}>
|
||||
评价指标分工
|
||||
</Button>
|
||||
<Button type="link" onClick={() => handleRemoveEvaluator(record.id)}>
|
||||
删除
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
<Button type="link" onClick={() => handleViewAssignment(record)}>
|
||||
查看
|
||||
</Button>
|
||||
<Button type="link" onClick={() => handleRemoveEvaluator(record.id)}>
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
const rowSelection = {
|
||||
selectedRowKeys,
|
||||
onChange: handleSelectChange,
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={handleOpenDivisionModal}
|
||||
disabled={selectedRowKeys.length === 0}
|
||||
>
|
||||
设置评价指标分工
|
||||
</Button>
|
||||
</div>
|
||||
{mode !== 'division' && (
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={handleOpenDivisionModal}
|
||||
disabled={selectedRowKeys.length === 0}
|
||||
>
|
||||
设置评价指标分工
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Table
|
||||
rowKey="id"
|
||||
rowSelection={{
|
||||
selectedRowKeys,
|
||||
onChange: handleSelectChange,
|
||||
}}
|
||||
rowSelection={mode === 'division' ? undefined : rowSelection}
|
||||
columns={columns}
|
||||
dataSource={evaluators}
|
||||
pagination={false}
|
||||
|
Reference in New Issue
Block a user