任务修改回显
This commit is contained in:
@ -30,3 +30,9 @@ export const TaskTypeText = {
|
||||
[TaskType.REGULAR]: '常规评价',
|
||||
[TaskType.SPECIAL]: '专项评价',
|
||||
};
|
||||
|
||||
// 任务是否通知下级单位完善评价人及评价分工
|
||||
export enum TaskNotifyLowerUnits {
|
||||
NO = 0,
|
||||
YES = 1,
|
||||
}
|
@ -5,12 +5,13 @@ import { getAllTemplates } from '@/servers/api/supplierEvaluate';
|
||||
import CategorySelector from '@/components/CategorySelector';
|
||||
import styles from '../supplierTaskManageAdd.less';
|
||||
import { CategoryLimitationType } from '@/dicts/supplierTemplateDict';
|
||||
import type { TaskAddRequest } from '@/servers/types/supplierEvaluateTask';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
interface BasicInfoStepProps {
|
||||
formData: Partial<SupplierEvaluate.TaskAddRequest>;
|
||||
onFormDataChange: (data: Partial<SupplierEvaluate.TaskAddRequest>) => void;
|
||||
formData: Partial<TaskAddRequest>;
|
||||
onFormDataChange: (data: TaskAddRequest) => void;
|
||||
}
|
||||
|
||||
interface TemplateItem {
|
||||
|
@ -1,10 +1,32 @@
|
||||
import React, { useState, useEffect, forwardRef, useImperativeHandle, useMemo, useCallback } from 'react';
|
||||
import { Card, Table, Tag, Switch, Space, Button, message, Modal, Radio, Checkbox, Row, Col, Spin } from 'antd';
|
||||
import React, {
|
||||
useState,
|
||||
useEffect,
|
||||
forwardRef,
|
||||
useImperativeHandle,
|
||||
useMemo,
|
||||
useCallback,
|
||||
useRef,
|
||||
} from 'react';
|
||||
import {
|
||||
Card,
|
||||
Table,
|
||||
Tag,
|
||||
Switch,
|
||||
Space,
|
||||
Button,
|
||||
message,
|
||||
Modal,
|
||||
Radio,
|
||||
Checkbox,
|
||||
Row,
|
||||
Col,
|
||||
Spin,
|
||||
} from 'antd';
|
||||
import type { PersonnelItem } from '@/servers/types/evaluator';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import type { CheckboxValueType } from 'antd/es/checkbox/Group';
|
||||
import EvaluateTemplateTable from '@/components/EvaluateTemplateTable';
|
||||
import { getTemplateDetail } from '@/servers/api/supplierEvaluate';
|
||||
import type { TaskAddRequest } from '@/servers/types/supplierEvaluateTask';
|
||||
|
||||
// 评价指标类型定义
|
||||
interface IndicatorItem {
|
||||
@ -15,8 +37,8 @@ interface IndicatorItem {
|
||||
|
||||
// 组件接收的Props定义
|
||||
interface DivisionStepProps {
|
||||
formData: any;
|
||||
onFormDataChange?: (values: any) => void;
|
||||
formData: Partial<TaskAddRequest>;
|
||||
onFormDataChange?: (values: Partial<TaskAddRequest>) => void;
|
||||
}
|
||||
|
||||
// 评价方式枚举
|
||||
@ -27,26 +49,23 @@ enum EvaluateType {
|
||||
INDICATOR = 1, // 按指标评价(部分指标)
|
||||
}
|
||||
|
||||
// 模拟的评价指标数据 - 仅作为备用
|
||||
const mockIndicators: IndicatorItem[] = [
|
||||
{ id: 'I001', name: '产品质量', description: '评估供应商产品质量' },
|
||||
{ id: 'I002', name: '交货及时性', description: '评估供应商交货的及时性' },
|
||||
{ id: 'I003', name: '服务水平', description: '评估供应商提供的服务水平' },
|
||||
{ id: 'I004', name: '价格竞争力', description: '评估供应商产品价格的竞争力' },
|
||||
{ id: 'I005', name: '技术能力', description: '评估供应商的技术创新能力' },
|
||||
];
|
||||
|
||||
const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataChange }, ref) => {
|
||||
// 从上一步获取的评价人员列表
|
||||
const [evaluators, setEvaluators] = useState<PersonnelItem[]>([]);
|
||||
|
||||
// 评价人员指标分配数据
|
||||
const [indicatorAssignments, setIndicatorAssignments] = useState<{
|
||||
const indicatorAssignments = useRef<{
|
||||
[userId: string]: {
|
||||
type: EvaluateType;
|
||||
indicatorIds: string[];
|
||||
};
|
||||
}>({});
|
||||
// const [indicatorAssignments, setIndicatorAssignments] = useState<{
|
||||
// [userId: string]: {
|
||||
// type: EvaluateType;
|
||||
// indicatorIds: string[];
|
||||
// };
|
||||
// }>({});
|
||||
|
||||
// 选中的行keys
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||
@ -78,8 +97,66 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
// 选中的指标项
|
||||
const [selectedTemplateItems, setSelectedTemplateItems] = useState<any[]>([]);
|
||||
|
||||
// 查看指标分工弹窗可见性
|
||||
const [viewModalVisible, setViewModalVisible] = useState(false);
|
||||
|
||||
// 查看模式下的过滤后指标数据
|
||||
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]);
|
||||
|
||||
// 根据指标ID过滤模板数据
|
||||
const filterTemplateDataByIds = useCallback((data: any[], indicatorIds: string[]) => {
|
||||
// 如果indicatorIds为空,表示显示所有模板数据(按评价单评价)
|
||||
if (!indicatorIds || indicatorIds.length === 0) {
|
||||
return data;
|
||||
}
|
||||
|
||||
// 按指标ID过滤
|
||||
const filtered = [];
|
||||
for (const stItem of data) {
|
||||
const ndItems = [];
|
||||
if (stItem.indicatorNdList) {
|
||||
for (const ndItem of stItem.indicatorNdList) {
|
||||
const matched = indicatorIds.some((id) => String(id) === String(ndItem.id));
|
||||
if (matched) {
|
||||
ndItems.push(ndItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ndItems.length > 0) {
|
||||
filtered.push({
|
||||
...stItem,
|
||||
indicatorNdList: ndItems,
|
||||
});
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}, []);
|
||||
|
||||
// 获取模板详情 先写死 "1937123786334322688" 省的一步一步操作
|
||||
const fetchTemplateDetail = async (templateId: string = "1937123786334322688") => {
|
||||
const fetchTemplateDetail = async (templateId: string) => {
|
||||
if (!templateId) return;
|
||||
|
||||
try {
|
||||
@ -113,7 +190,7 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
|
||||
// 监听templateId变化,获取模板详情
|
||||
useEffect(() => {
|
||||
fetchTemplateDetail(formData.templateId);
|
||||
fetchTemplateDetail(formData.templateId as string);
|
||||
}, []);
|
||||
|
||||
// 处理行选择变化
|
||||
@ -147,15 +224,15 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
// 批量设置指标分工
|
||||
const handleBatchSetDivision = () => {
|
||||
// 获取选中的评价人员
|
||||
const selectedEvaluators = evaluators.filter(
|
||||
evaluator => selectedRowKeys.includes(evaluator.id)
|
||||
const selectedEvaluators = evaluators.filter((evaluator) =>
|
||||
selectedRowKeys.includes(evaluator.id),
|
||||
);
|
||||
|
||||
// 提取所有选中指标的ID
|
||||
const selectedIndicatorIds: string[] = [];
|
||||
|
||||
// 从选中的模板项中提取所有指标ID
|
||||
batchSelectedTemplateItems.forEach(stItem => {
|
||||
batchSelectedTemplateItems.forEach((stItem) => {
|
||||
// 添加二级指标ID
|
||||
if (stItem.indicatorNdList && stItem.indicatorNdList.length > 0) {
|
||||
stItem.indicatorNdList.forEach((ndItem: any) => {
|
||||
@ -165,9 +242,9 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
});
|
||||
|
||||
// 更新指标分配数据
|
||||
const newAssignments = { ...indicatorAssignments };
|
||||
const newAssignments = { ...indicatorAssignments.current };
|
||||
|
||||
selectedEvaluators.forEach(evaluator => {
|
||||
selectedEvaluators.forEach((evaluator) => {
|
||||
newAssignments[evaluator.id] = {
|
||||
// 评价类型:如果用户关联了指标则为1(按指标),否则为0(按评价单)
|
||||
type: selectedIndicatorIds.length > 0 ? EvaluateType.INDICATOR : EvaluateType.ALL,
|
||||
@ -175,7 +252,7 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
};
|
||||
});
|
||||
|
||||
setIndicatorAssignments(newAssignments);
|
||||
indicatorAssignments.current = newAssignments;
|
||||
setBatchTemplateModalVisible(false);
|
||||
message.success(`已为${selectedRowKeys.length}名评价人员设置分工`);
|
||||
};
|
||||
@ -197,23 +274,10 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
|
||||
// 处理模板指标选择
|
||||
const handleTemplateItemsSelect = (selectedItems: any[]) => {
|
||||
console.log(selectedItems)
|
||||
console.log(selectedItems);
|
||||
setSelectedTemplateItems(selectedItems);
|
||||
};
|
||||
|
||||
// 获取当前用户的已分配指标ID
|
||||
const getCurrentUserSelectedIds = useCallback(() => {
|
||||
if (!currentUserId) return [];
|
||||
|
||||
const userAssignment = indicatorAssignments[currentUserId];
|
||||
if (userAssignment && userAssignment.type === EvaluateType.INDICATOR) {
|
||||
const selectedIds = userAssignment.indicatorIds || [];
|
||||
return selectedIds;
|
||||
}
|
||||
|
||||
return [];
|
||||
}, [currentUserId, indicatorAssignments]);
|
||||
|
||||
// 保存指标分配
|
||||
const handleSaveIndicatorAssignment = () => {
|
||||
if (!currentUserId) {
|
||||
@ -225,7 +289,7 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
const selectedIndicatorIds: string[] = [];
|
||||
|
||||
// 从选中的模板项中提取所有指标ID
|
||||
selectedTemplateItems.forEach(stItem => {
|
||||
selectedTemplateItems.forEach((stItem) => {
|
||||
// 添加二级指标ID
|
||||
if (stItem.indicatorNdList && stItem.indicatorNdList.length > 0) {
|
||||
stItem.indicatorNdList.forEach((ndItem: any) => {
|
||||
@ -235,46 +299,43 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
});
|
||||
|
||||
// 更新指标分配
|
||||
const newAssignments = { ...indicatorAssignments };
|
||||
const newAssignments = { ...indicatorAssignments.current };
|
||||
newAssignments[currentUserId] = {
|
||||
// 评价类型:如果用户关联了指标则为1(按指标),否则为0(按评价单)
|
||||
type: selectedIndicatorIds.length > 0 ? EvaluateType.INDICATOR : EvaluateType.ALL,
|
||||
indicatorIds: selectedIndicatorIds,
|
||||
};
|
||||
|
||||
setIndicatorAssignments(newAssignments);
|
||||
indicatorAssignments.current = newAssignments;
|
||||
setTemplateViewModalVisible(false);
|
||||
message.success('已设置评价人员指标分工');
|
||||
};
|
||||
|
||||
// 查看评价人员的指标分工
|
||||
const handleViewAssignment = (userId: string) => {
|
||||
const assignment = indicatorAssignments[userId];
|
||||
const assignment = indicatorAssignments.current[userId];
|
||||
if (!assignment) {
|
||||
message.info('该评价人员尚未设置分工');
|
||||
return;
|
||||
}
|
||||
|
||||
const assignedIndicators = indicators.filter(ind =>
|
||||
assignment.type === EvaluateType.ALL ||
|
||||
assignment.indicatorIds.includes(ind.id)
|
||||
);
|
||||
setCurrentUserId(userId);
|
||||
setLoading(true);
|
||||
|
||||
Modal.info({
|
||||
title: '查看评价指标分工',
|
||||
content: (
|
||||
<div>
|
||||
<p>评价方式: {assignment.type === EvaluateType.ALL ? '按评价单评价' : '按指标评价'}</p>
|
||||
<p>评价指标: </p>
|
||||
<ul>
|
||||
{assignedIndicators.map(ind => (
|
||||
<li key={ind.id}>{ind.name}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
),
|
||||
okText: '确定',
|
||||
});
|
||||
// 获取该评价人员的指标ID
|
||||
const indicatorIds = getUserIndicatorIds(userId);
|
||||
|
||||
// 过滤模板数据
|
||||
const filtered = filterTemplateDataByIds(templateData, indicatorIds);
|
||||
setFilteredIndicators(filtered);
|
||||
|
||||
setLoading(false);
|
||||
setViewModalVisible(true);
|
||||
};
|
||||
|
||||
// 关闭查看模态框
|
||||
const handleCloseViewModal = () => {
|
||||
setViewModalVisible(false);
|
||||
};
|
||||
|
||||
// 删除评价人员
|
||||
@ -286,12 +347,12 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
cancelText: '取消',
|
||||
onOk: () => {
|
||||
// 更新评价人员列表
|
||||
setEvaluators(prev => prev.filter(e => e.id !== userId));
|
||||
setEvaluators((prev) => prev.filter((e) => e.id !== userId));
|
||||
|
||||
// 更新指标分配数据
|
||||
const newAssignments = { ...indicatorAssignments };
|
||||
const newAssignments = { ...indicatorAssignments.current };
|
||||
delete newAssignments[userId];
|
||||
setIndicatorAssignments(newAssignments);
|
||||
indicatorAssignments.current = newAssignments;
|
||||
|
||||
message.success('已删除评价人员');
|
||||
},
|
||||
@ -300,7 +361,7 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
|
||||
// 初始化:从formData中提取指标分配数据
|
||||
useEffect(() => {
|
||||
if (formData.indicatorList) {
|
||||
if (formData.indicatorList && formData.indicatorList.length > 0) {
|
||||
// 如果已有指标分配数据,直接使用
|
||||
const assignments: any = {};
|
||||
formData.indicatorList.forEach((item: any) => {
|
||||
@ -309,7 +370,7 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
indicatorIds: item.indicatorIds || [],
|
||||
};
|
||||
});
|
||||
setIndicatorAssignments(assignments);
|
||||
indicatorAssignments.current = assignments;
|
||||
}
|
||||
}, [formData.indicatorList]);
|
||||
|
||||
@ -324,7 +385,7 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
if (supplier.evaluators && supplier.evaluators.length > 0) {
|
||||
supplier.evaluators.forEach((evaluator: PersonnelItem) => {
|
||||
// 检查是否已存在(避免重复)
|
||||
if (!allEvaluators.some(e => e.id === evaluator.id)) {
|
||||
if (!allEvaluators.some((e) => e.id === evaluator.id)) {
|
||||
allEvaluators.push({
|
||||
...evaluator,
|
||||
// 添加单位和员工编号,假设这些字段可能不存在
|
||||
@ -343,11 +404,11 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
// 为评价人员初始化指标分配数据 - 作为单独的效果处理
|
||||
useEffect(() => {
|
||||
// 检查是否有新的评价人员需要初始化
|
||||
const newAssignments = { ...indicatorAssignments };
|
||||
const newAssignments = { ...indicatorAssignments.current };
|
||||
let hasNewAssignments = false;
|
||||
|
||||
evaluators.forEach(evaluator => {
|
||||
if (!indicatorAssignments[evaluator.id]) {
|
||||
evaluators.forEach((evaluator) => {
|
||||
if (!indicatorAssignments.current[evaluator.id]) {
|
||||
newAssignments[evaluator.id] = {
|
||||
type: EvaluateType.ALL,
|
||||
indicatorIds: [],
|
||||
@ -355,22 +416,26 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
hasNewAssignments = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (hasNewAssignments) {
|
||||
setIndicatorAssignments(newAssignments);
|
||||
indicatorAssignments.current = newAssignments;
|
||||
}
|
||||
}, [evaluators, indicatorAssignments]);
|
||||
|
||||
// 同步数据回表单 - 使用防抖确保不会频繁触发
|
||||
const previousValueRef = React.useRef<string>("");
|
||||
const previousValueRef = React.useRef<string>('');
|
||||
|
||||
useEffect(() => {
|
||||
// 若当前还未初始化完成(没有任何指标数据),不应向父组件同步
|
||||
if (evaluators.length === 0 || Object.keys(indicatorAssignments.current).length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 将评价人员列表和指标分配数据同步回表单
|
||||
const indicatorList = evaluators.map(evaluator => ({
|
||||
const indicatorList = evaluators.map((evaluator) => ({
|
||||
userId: evaluator.id,
|
||||
userName: evaluator.name,
|
||||
type: indicatorAssignments[evaluator.id]?.type || EvaluateType.ALL,
|
||||
indicatorIds: indicatorAssignments[evaluator.id]?.indicatorIds || [],
|
||||
type: indicatorAssignments.current[evaluator.id]?.type ?? EvaluateType.ALL,
|
||||
indicatorIds: indicatorAssignments.current[evaluator.id]?.indicatorIds ?? [],
|
||||
}));
|
||||
|
||||
// 使用JSON字符串比较确保只有在真正变化时才更新
|
||||
@ -382,7 +447,7 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
indicatorList,
|
||||
});
|
||||
}
|
||||
}, [evaluators, indicatorAssignments, formData, onFormDataChange]);
|
||||
}, [evaluators, formData, onFormDataChange]);
|
||||
|
||||
// 暴露给父组件的方法
|
||||
useImperativeHandle(ref, () => ({
|
||||
@ -397,6 +462,12 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
},
|
||||
}));
|
||||
|
||||
// 获取当前评价人员名称
|
||||
const getCurrentEvaluatorName = () => {
|
||||
const evaluator = evaluators.find((e) => e.id === currentUserId);
|
||||
return evaluator ? evaluator.name : currentUserId;
|
||||
};
|
||||
|
||||
// 表格列定义
|
||||
const columns: ColumnsType<PersonnelItem> = [
|
||||
{
|
||||
@ -404,27 +475,23 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
},
|
||||
{
|
||||
title: '所属单位',
|
||||
dataIndex: 'company',
|
||||
key: 'company',
|
||||
},
|
||||
{
|
||||
title: '所属部门',
|
||||
dataIndex: 'department',
|
||||
key: 'department',
|
||||
dataIndex: 'userDept',
|
||||
key: 'userDept',
|
||||
},
|
||||
{
|
||||
title: '员工编号',
|
||||
dataIndex: 'employeeNumber',
|
||||
key: 'employeeNumber',
|
||||
dataIndex: 'id',
|
||||
key: 'id',
|
||||
},
|
||||
{
|
||||
title: '是否设置分工',
|
||||
key: 'hasDivision',
|
||||
render: (_: any, record: PersonnelItem) => {
|
||||
const assignment = indicatorAssignments[record.id];
|
||||
if (!assignment) return <Tag color="red">未设置</Tag>;
|
||||
const assignment = indicatorAssignments.current[record.id];
|
||||
if (!assignment || assignment.indicatorIds.length === 0)
|
||||
return <Tag color="red">未设置</Tag>;
|
||||
return <Tag color="green">已设置</Tag>;
|
||||
},
|
||||
},
|
||||
@ -433,9 +500,15 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
key: 'action',
|
||||
render: (_: any, record: PersonnelItem) => (
|
||||
<Space size="middle">
|
||||
<Button type="link" onClick={() => handleAssignIndicators(record.id)}>评价指标分工</Button>
|
||||
<Button type="link" onClick={() => handleViewAssignment(record.id)}>查看</Button>
|
||||
<Button type="link" onClick={() => handleRemoveEvaluator(record.id)}>删除</Button>
|
||||
<Button type="link" onClick={() => handleAssignIndicators(record.id)}>
|
||||
评价指标分工
|
||||
</Button>
|
||||
<Button type="link" onClick={() => handleViewAssignment(record.id)}>
|
||||
查看
|
||||
</Button>
|
||||
<Button type="link" onClick={() => handleRemoveEvaluator(record.id)}>
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
@ -469,14 +542,14 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
title={`批量设置评价指标分工 (已选择 ${selectedRowKeys.length} 名评价人员)`}
|
||||
visible={batchTemplateModalVisible}
|
||||
onCancel={handleCloseBatchTemplateModal}
|
||||
width={800}
|
||||
width={1200}
|
||||
footer={[
|
||||
<Button key="cancel" onClick={handleCloseBatchTemplateModal}>
|
||||
取消
|
||||
</Button>,
|
||||
<Button key="save" type="primary" onClick={handleBatchSetDivision}>
|
||||
确定并保存
|
||||
</Button>
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
@ -507,7 +580,7 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
</Button>,
|
||||
<Button key="save" type="primary" onClick={handleSaveIndicatorAssignment}>
|
||||
保存
|
||||
</Button>
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
@ -527,6 +600,29 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
)}
|
||||
</Spin>
|
||||
</Modal>
|
||||
|
||||
{/* 查看评价人员指标分工弹窗 */}
|
||||
<Modal
|
||||
title={`评价人员 ${getCurrentEvaluatorName()} 的指标分工`}
|
||||
visible={viewModalVisible}
|
||||
onCancel={handleCloseViewModal}
|
||||
width={1200}
|
||||
footer={[
|
||||
<Button key="close" onClick={handleCloseViewModal}>
|
||||
关闭
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
{filteredIndicators.length > 0 ? (
|
||||
<EvaluateTemplateTable value={filteredIndicators} isDetail={true} />
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '20px 0' }}>
|
||||
{loading ? '加载中...' : '暂无指标分工数据'}
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
@ -64,7 +64,7 @@ const SupplierEvaluatorModal: React.FC<SupplierEvaluatorModalProps> = ({
|
||||
<List.Item>
|
||||
<List.Item.Meta
|
||||
title={item.name}
|
||||
description={`${item.department || '未知部门'}`}
|
||||
description={`${item.userDept || '未知部门'}`}
|
||||
/>
|
||||
</List.Item>
|
||||
)}
|
||||
|
@ -43,8 +43,8 @@ const SupplierTable: React.FC<SupplierTableProps> = ({
|
||||
const columns = [
|
||||
{
|
||||
title: '供应商名称', // 列标题
|
||||
dataIndex: 'name', // 数据字段名
|
||||
key: 'name', // 列的唯一标识
|
||||
dataIndex: 'supplierName', // 数据字段名
|
||||
key: 'supplierName', // 列的唯一标识
|
||||
},
|
||||
{
|
||||
title: '统一社会信用代码',
|
||||
@ -63,8 +63,8 @@ const SupplierTable: React.FC<SupplierTableProps> = ({
|
||||
},
|
||||
{
|
||||
title: '准入部门',
|
||||
dataIndex: 'department',
|
||||
key: 'department',
|
||||
dataIndex: 'deptName',
|
||||
key: 'deptName',
|
||||
},
|
||||
{
|
||||
title: '评价人员数',
|
||||
|
@ -1,12 +1,12 @@
|
||||
import React from 'react';
|
||||
import { Modal, Form, Row, Col, InputNumber } from 'antd';
|
||||
import type { WeightUnit } from '@/servers/types/evaluator';
|
||||
import type { DeptWeightItem } from '@/servers/types/supplierEvaluateTask';
|
||||
|
||||
interface WeightSettingModalProps {
|
||||
visible: boolean;
|
||||
onCancel: () => void;
|
||||
onOk: () => void;
|
||||
weightUnits: WeightUnit[];
|
||||
taskDeptWeightList: DeptWeightItem[];
|
||||
form: any;
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ const WeightSettingModal: React.FC<WeightSettingModalProps> = ({
|
||||
visible,
|
||||
onCancel,
|
||||
onOk,
|
||||
weightUnits,
|
||||
taskDeptWeightList,
|
||||
form,
|
||||
}) => {
|
||||
return (
|
||||
@ -26,12 +26,12 @@ const WeightSettingModal: React.FC<WeightSettingModalProps> = ({
|
||||
>
|
||||
<Form form={form} layout="horizontal">
|
||||
<Row gutter={16}>
|
||||
{weightUnits.map((unit) => (
|
||||
<Col span={12} key={unit.id}>
|
||||
{taskDeptWeightList.map((item) => (
|
||||
<Col span={12} key={item.weightDept}>
|
||||
<Form.Item
|
||||
key={unit.id}
|
||||
label={unit.name}
|
||||
name={['weightUnits', unit.id]}
|
||||
key={item.weightDept}
|
||||
label={item.weightDeptName}
|
||||
name={['taskDeptWeightList', item.weightDept]}
|
||||
rules={[
|
||||
{ required: true, message: '请输入权重值' },
|
||||
{ type: 'number', min: 0, message: '请输入大于等于0的数值' },
|
||||
|
@ -8,11 +8,12 @@ import {
|
||||
WeightSettingModal,
|
||||
} from './EvaluatorComponents';
|
||||
import { ModalMode } from '@/servers/types/evaluator';
|
||||
import type { PersonnelItem, SupplierItem, WeightUnit } from '@/servers/types/evaluator';
|
||||
import type { PersonnelItem, SupplierItem } from '@/servers/types/evaluator';
|
||||
import type { DeptWeightItem,TaskAddRequest } from '@/servers/types/supplierEvaluateTask';
|
||||
|
||||
interface EvaluatorSelectStepProps {
|
||||
formData: any; // 从上层组件传递过来的表单数据
|
||||
onFormDataChange: (data: any) => void; // 表单数据变更回调函数
|
||||
formData: Partial<TaskAddRequest>; // 从上层组件传递过来的表单数据
|
||||
onFormDataChange: (data: Partial<TaskAddRequest>) => void; // 表单数据变更回调函数
|
||||
}
|
||||
|
||||
const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
@ -39,7 +40,7 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
const [modalMode, setModalMode] = useState<ModalMode>(ModalMode.SELECT);
|
||||
|
||||
// 权重单位列表,根据评价人员部门动态生成
|
||||
const [weightUnits, setWeightUnits] = useState<WeightUnit[]>([]);
|
||||
const [taskDeptWeightList, setTaskDeptWeightList] = useState<DeptWeightItem[]>([]);
|
||||
|
||||
// 表单实例,用于权重设置
|
||||
const [form] = Form.useForm();
|
||||
@ -84,24 +85,25 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
indicatorList,
|
||||
supplierIds,
|
||||
suppliersWithEvaluators: suppliers,
|
||||
weightUnits,
|
||||
taskDeptWeightList,
|
||||
};
|
||||
},
|
||||
setFieldsValue: (values: any) => {
|
||||
if (values.suppliersWithEvaluators) {
|
||||
setSuppliers(values.suppliersWithEvaluators);
|
||||
}
|
||||
if (values.weightUnits) {
|
||||
setWeightUnits(values.weightUnits);
|
||||
if (values.taskDeptWeightList) {
|
||||
setTaskDeptWeightList(values.taskDeptWeightList);
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
// 从上一步获取供应商数据
|
||||
useEffect(() => {
|
||||
console.log(formData.selectedSuppliers)
|
||||
if (formData.selectedSuppliers && formData.selectedSuppliers.length > 0) {
|
||||
// 转换上一步的供应商数据,添加评价人员数量字段
|
||||
const suppliersWithEvaluators = formData.selectedSuppliers.map((supplier: any) => {
|
||||
const suppliersWithEvaluators = formData.selectedSuppliers.map((supplier: SupplierItem) => {
|
||||
// 确保evaluators字段存在且为数组
|
||||
const evaluators = supplier.evaluators || [];
|
||||
return {
|
||||
@ -118,11 +120,11 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
}
|
||||
|
||||
// 初始化权重数据(如果有)
|
||||
if (formData.WeightUnit && formData.WeightUnit.length > 0) {
|
||||
setWeightUnits(formData.WeightUnit);
|
||||
if (formData.taskDeptWeightList && formData.taskDeptWeightList.length > 0) {
|
||||
setTaskDeptWeightList(formData.taskDeptWeightList);
|
||||
} else {
|
||||
// 没有权重数据,将在下面的useEffect中根据人员部门计算
|
||||
setWeightUnits([]);
|
||||
setTaskDeptWeightList([]);
|
||||
}
|
||||
}, [formData]);
|
||||
|
||||
@ -152,19 +154,19 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
|
||||
// 如果有部门数据,生成权重单位列表
|
||||
if (uniqueDepartments.length > 0) {
|
||||
const newWeightUnits: WeightUnit[] = uniqueDepartments.map((dept, index) => ({
|
||||
id: dept.userDeptId,
|
||||
name: dept.userDept,
|
||||
weight: 0, // 默认权重为0
|
||||
const newTaskDeptWeightList: DeptWeightItem[] = uniqueDepartments.map((dept) => ({
|
||||
weightDept: dept.userDeptId || '',
|
||||
weightValue: '0', // 默认权重为0
|
||||
weightDeptName: dept.userDept || '',
|
||||
}));
|
||||
|
||||
// 更新权重单位列表,保留原有权重值
|
||||
setWeightUnits((prevUnits) => {
|
||||
const prevUnitsMap = new Map(prevUnits.map((unit) => [unit.id, unit.weight]));
|
||||
setTaskDeptWeightList((prevList) => {
|
||||
const prevValuesMap = new Map(prevList.map((item) => [item.weightDept, item.weightValue]));
|
||||
|
||||
return newWeightUnits.map((unit) => ({
|
||||
...unit,
|
||||
weight: prevUnitsMap.get(unit.id) || 0, // 如果有原来的权重值则保留
|
||||
return newTaskDeptWeightList.map((item) => ({
|
||||
...item,
|
||||
weightValue: prevValuesMap.get(item.weightDept) || '0', // 如果有原来的权重值则保留
|
||||
}));
|
||||
});
|
||||
}
|
||||
@ -187,12 +189,23 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
id: supplier.id,
|
||||
userIds: supplier.evaluators?.map((e: PersonnelItem) => e.id) || [],
|
||||
}));
|
||||
onFormDataChange({
|
||||
...updatedData,
|
||||
indicatorList,
|
||||
supplierIds,
|
||||
weightUnits,
|
||||
});
|
||||
|
||||
// 如果有taskDeptWeightList数据,直接使用
|
||||
if (updatedData.taskDeptWeightList) {
|
||||
onFormDataChange({
|
||||
...updatedData,
|
||||
indicatorList,
|
||||
supplierIds,
|
||||
});
|
||||
} else {
|
||||
// 否则包含当前的taskDeptWeightList
|
||||
onFormDataChange({
|
||||
...updatedData,
|
||||
indicatorList,
|
||||
supplierIds,
|
||||
taskDeptWeightList,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 处理批量选择
|
||||
@ -205,8 +218,8 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
const handleWeightSetting = () => {
|
||||
// 设置初始表单值
|
||||
form.setFieldsValue({
|
||||
weightUnits: weightUnits.reduce((acc, unit) => {
|
||||
acc[unit.id] = unit.weight;
|
||||
taskDeptWeightList: taskDeptWeightList.reduce((acc, item) => {
|
||||
acc[item.weightDept] = parseInt(item.weightValue, 10) || 0;
|
||||
return acc;
|
||||
}, {} as Record<string, number>),
|
||||
});
|
||||
@ -217,23 +230,16 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
// 保存权重设置
|
||||
const handleSaveWeights = () => {
|
||||
form.validateFields().then((values) => {
|
||||
const updatedWeightUnits = weightUnits.map((unit) => ({
|
||||
...unit,
|
||||
weight: values.weightUnits[unit.id],
|
||||
const updatedTaskDeptWeightList = taskDeptWeightList.map((item) => ({
|
||||
...item,
|
||||
weightValue: values.taskDeptWeightList[item.weightDept].toString(),
|
||||
}));
|
||||
|
||||
setWeightUnits(updatedWeightUnits);
|
||||
|
||||
// 将更新后的权重数据传递给父组件
|
||||
// 同时转换为taskDeptWeightList格式
|
||||
const taskDeptWeightList = updatedWeightUnits.map(unit => ({
|
||||
weightDept: unit.name, // 使用部门名称
|
||||
weightValue: unit.weight.toString(), // 转换为字符串格式
|
||||
}));
|
||||
setTaskDeptWeightList(updatedTaskDeptWeightList);
|
||||
|
||||
updateFormData({
|
||||
weightUnits: updatedWeightUnits,
|
||||
taskDeptWeightList: taskDeptWeightList,
|
||||
suppliersWithEvaluators: suppliers,
|
||||
taskDeptWeightList: updatedTaskDeptWeightList,
|
||||
});
|
||||
|
||||
setWeightSettingModalVisible(false);
|
||||
@ -321,7 +327,7 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
>
|
||||
批量选择评价人员
|
||||
</Button>
|
||||
<Button onClick={handleWeightSetting} disabled={weightUnits.length === 0}>
|
||||
<Button onClick={handleWeightSetting} disabled={taskDeptWeightList.length === 0}>
|
||||
设置评分单位权重
|
||||
</Button>
|
||||
</Space>
|
||||
@ -363,7 +369,7 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
visible={weightSettingModalVisible}
|
||||
onCancel={() => setWeightSettingModalVisible(false)}
|
||||
onOk={handleSaveWeights}
|
||||
weightUnits={weightUnits}
|
||||
taskDeptWeightList={taskDeptWeightList}
|
||||
form={form}
|
||||
/>
|
||||
</Card>
|
||||
|
@ -1,21 +1,25 @@
|
||||
import React, { forwardRef, useImperativeHandle } from 'react';
|
||||
import React, { forwardRef, useImperativeHandle, useEffect, useState } from 'react';
|
||||
import { Card, Form } from 'antd';
|
||||
import styles from '../supplierTaskManageAdd.less';
|
||||
import SupplierSelector from '@/components/SupplierSelector';
|
||||
import type { TaskAddRequest,SupplierItem } from '@/servers/types/supplierEvaluateTask';
|
||||
|
||||
interface SupplierSelectStepProps {
|
||||
formData: any; // 从父组件传递的表单数据
|
||||
onFormDataChange: (data: any) => void; // 表单数据变更的回调函数
|
||||
}
|
||||
|
||||
interface SupplierItem {
|
||||
id: string; // 供应商ID
|
||||
name: string; // 供应商名称
|
||||
supplierType: string; // 供应商类型
|
||||
[key: string]: any; // 其他可能的字段
|
||||
formData: Partial<TaskAddRequest>; // 从父组件传递的表单数据
|
||||
onFormDataChange: (data: Partial<TaskAddRequest>) => void; // 表单数据变更的回调函数
|
||||
}
|
||||
|
||||
const SupplierSelectStep = forwardRef<any, SupplierSelectStepProps>(({ formData, onFormDataChange }, ref) => {
|
||||
// 内部状态,避免直接操作formData导致循环更新
|
||||
const [selectedSuppliers, setSelectedSuppliers] = useState<SupplierItem[]>([]);
|
||||
|
||||
// 当formData.selectedSuppliers更新时,同步到本地状态
|
||||
useEffect(() => {
|
||||
if (formData.selectedSuppliers && formData.selectedSuppliers.length > 0) {
|
||||
setSelectedSuppliers(formData.selectedSuppliers);
|
||||
}
|
||||
}, [formData.selectedSuppliers]); // 只在表单ID变化时更新(编辑模式加载时)
|
||||
|
||||
// 暴露表单方法给父组件
|
||||
useImperativeHandle(ref, () => ({
|
||||
validateFields: () => {
|
||||
@ -24,23 +28,19 @@ const SupplierSelectStep = forwardRef<any, SupplierSelectStepProps>(({ formData,
|
||||
},
|
||||
getFieldsValue: () => {
|
||||
return {
|
||||
selectedSuppliers: formData.selectedSuppliers || [],
|
||||
supplierIds: (formData.selectedSuppliers || []).map((supplier: SupplierItem) => ({ id: supplier.id }))
|
||||
selectedSuppliers,
|
||||
supplierIds: selectedSuppliers.map((supplier: SupplierItem) => ({ id: supplier.id }))
|
||||
};
|
||||
},
|
||||
setFieldsValue: (values: any) => {
|
||||
if (values.selectedSuppliers) {
|
||||
onFormDataChange({
|
||||
...formData,
|
||||
selectedSuppliers: values.selectedSuppliers
|
||||
});
|
||||
setSelectedSuppliers(values.selectedSuppliers);
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
// 处理供应商选择
|
||||
const handleSupplierSelect = (suppliers: SupplierItem[]) => {
|
||||
|
||||
// 确保每个供应商都有evaluators字段
|
||||
const suppliersWithEvaluators = suppliers.map(supplier => ({
|
||||
...supplier,
|
||||
@ -48,9 +48,11 @@ const SupplierSelectStep = forwardRef<any, SupplierSelectStepProps>(({ formData,
|
||||
evaluatorCount: supplier.evaluators?.length || 0 // 计算评价人员数量
|
||||
}));
|
||||
|
||||
// 更新本地状态
|
||||
setSelectedSuppliers(suppliersWithEvaluators);
|
||||
|
||||
// 通知父组件
|
||||
onFormDataChange({
|
||||
...formData,
|
||||
selectedSuppliers: suppliersWithEvaluators,
|
||||
supplierIds: suppliersWithEvaluators.map(supplier => ({ id: supplier.id }))
|
||||
});
|
||||
@ -61,7 +63,7 @@ const SupplierSelectStep = forwardRef<any, SupplierSelectStepProps>(({ formData,
|
||||
<Card title="供应商选择" bordered={false} className="inner-card">
|
||||
<SupplierSelector
|
||||
onSelect={handleSupplierSelect}
|
||||
selectedSuppliers={formData.selectedSuppliers || []}
|
||||
selectedSuppliers={selectedSuppliers}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
|
@ -1,16 +1,32 @@
|
||||
import React, { useState, useRef } from 'react';
|
||||
import { Card, Steps, Button, message, Space, Row, Col, Form } from 'antd';
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import { Card, Steps, Button, message, Space, Row, Col, Form, Modal } from 'antd';
|
||||
import { history } from 'umi';
|
||||
import { ArrowLeftOutlined, SaveOutlined } from '@ant-design/icons';
|
||||
import { addTask } from '@/servers/api/supplierEvaluate';
|
||||
import { addTask, getTaskDetail, updateTask } from '@/servers/api/supplierEvaluate';
|
||||
import BasicInfoStep from './components/BasicInfoStep';
|
||||
import SupplierSelectStep from './components/SupplierSelectStep';
|
||||
import EvaluatorSelectStep from './components/EvaluatorSelectStep';
|
||||
import DivisionStep from './components/DivisionStep';
|
||||
import styles from './supplierTaskManageAdd.less';
|
||||
import type {
|
||||
DeptWeightItem,
|
||||
TaskAddRequest,
|
||||
TaskDetailData,
|
||||
} from '@/servers/types/supplierEvaluateTask';
|
||||
import { TaskNotifyLowerUnits } from '@/dicts/supplierTaskDict';
|
||||
|
||||
const { Step } = Steps;
|
||||
|
||||
// 获取URL参数
|
||||
const getUrlParams = () => {
|
||||
const location = window.location.href;
|
||||
const url = new URL(location);
|
||||
return {
|
||||
id: url.searchParams.get('id'),
|
||||
mode: url.searchParams.get('mode'),
|
||||
};
|
||||
};
|
||||
|
||||
const SupplierTaskManageAdd: React.FC = () => {
|
||||
// 当前步骤索引,从0开始
|
||||
const [currentStep, setCurrentStep] = useState<number>(0);
|
||||
@ -18,11 +34,91 @@ const SupplierTaskManageAdd: React.FC = () => {
|
||||
// 提交加载状态
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
// 判断是否为编辑模式
|
||||
const urlParams = getUrlParams();
|
||||
const isEditMode = urlParams.mode === 'edit' && urlParams.id;
|
||||
const taskId = urlParams.id || '';
|
||||
|
||||
// 整个表单的数据,包含所有步骤的数据
|
||||
const [formData, setFormData] = useState<Partial<SupplierEvaluate.TaskAddRequest>>({});
|
||||
const [formData, setFormData] = useState<Partial<TaskAddRequest>>({});
|
||||
|
||||
// 加载状态
|
||||
const [detailLoading, setDetailLoading] = useState<boolean>(false);
|
||||
|
||||
// 创建表单引用,用于访问子组件的表单方法(仅用于验证)
|
||||
const basicFormRef = useRef<any>(null); // 基本信息表单引用
|
||||
const supplierFormRef = useRef<any>(null); // 供应商选择表单引用
|
||||
const evaluatorFormRef = useRef<any>(null); // 评价人员表单引用
|
||||
const divisionFormRef = useRef<any>(null); // 评价分工表单引用
|
||||
|
||||
// 确认对话框可见性状态
|
||||
const [confirmModalVisible, setConfirmModalVisible] = useState(false);
|
||||
|
||||
// 获取任务详情
|
||||
const fetchTaskDetail = async (id: string) => {
|
||||
setDetailLoading(true);
|
||||
try {
|
||||
const response = await getTaskDetail(id);
|
||||
if (response.success) {
|
||||
const detail: TaskDetailData = response.data;
|
||||
|
||||
// 转换任务详情数据为表单数据结构
|
||||
const taskFormData: Partial<TaskAddRequest> = {
|
||||
id: detail.id || '',
|
||||
evaluateTheme: detail.evaluateTheme || '',
|
||||
startTime: detail.startTime || '',
|
||||
endTime: detail.endTime || '',
|
||||
templateId: detail.templateId || '',
|
||||
categoryLimitation: detail.categoryLimitation || '0',
|
||||
evaluateYear: detail.evaluateYear || '',
|
||||
categoryId: detail.categoryId || undefined,
|
||||
|
||||
// 供应商数据回显转换
|
||||
selectedSuppliers: detail.blackSupplierVos.map((item) => ({
|
||||
...item,
|
||||
id: item.supplierId,
|
||||
name: item.supplierName,
|
||||
evaluators: item.userList,
|
||||
})),
|
||||
|
||||
// 接口返回的人员分配的指标,以人员userId 为维度 indicatorIds[string] 指标id
|
||||
indicatorList: detail.indicatorList || [],
|
||||
// 后台用供应商集合,包含供应商id 并且关联 userIds
|
||||
supplierIds: detail.supplierIds || [],
|
||||
|
||||
// 部门权重设置
|
||||
taskDeptWeightList: detail.taskDeptWeightList || [],
|
||||
// 分配指标分工回显
|
||||
suppliersWithEvaluators: detail.blackSupplierVos.map((item) => ({
|
||||
...item,
|
||||
id: item.supplierId,
|
||||
name: item.supplierName,
|
||||
evaluators: item.userList,
|
||||
})),
|
||||
};
|
||||
|
||||
// 更新表单数据 - 子组件通过props获取
|
||||
setFormData(taskFormData);
|
||||
} else {
|
||||
message.error(response.message || '获取任务详情失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取任务详情失败:', error);
|
||||
message.error('获取任务详情失败');
|
||||
} finally {
|
||||
setDetailLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 编辑模式下获取任务详情
|
||||
useEffect(() => {
|
||||
if (isEditMode) {
|
||||
fetchTaskDetail(taskId);
|
||||
}
|
||||
}, [isEditMode, taskId]);
|
||||
|
||||
// 处理表单数据变更
|
||||
const handleFormDataChange = (data: any) => {
|
||||
const handleFormDataChange = (data: Partial<TaskAddRequest>) => {
|
||||
// 第一步:基本信息
|
||||
if (data) {
|
||||
setFormData((prev) => ({ ...prev, ...data }));
|
||||
@ -46,53 +142,64 @@ const SupplierTaskManageAdd: React.FC = () => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
suppliersWithEvaluators: evaluatedSuppliers,
|
||||
selectedSuppliers: evaluatedSuppliers // 同步更新selectedSuppliers
|
||||
selectedSuppliers: evaluatedSuppliers, // 同步更新selectedSuppliers
|
||||
}));
|
||||
}
|
||||
|
||||
// 更新权重单位
|
||||
if (data.weightUnits) {
|
||||
// 将 weightUnits 存储在 formData.WeightUnit 中
|
||||
setFormData((prev) => ({ ...prev, WeightUnit: data.weightUnits }));
|
||||
}
|
||||
|
||||
// 处理部门权重列表
|
||||
// 处理部门权重列表 taskDeptWeightList
|
||||
if (data.taskDeptWeightList) {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
taskDeptWeightList: data.taskDeptWeightList,
|
||||
// weightStatus: data.weightStatus || 0
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
// 创建表单引用,用于访问子组件的表单方法
|
||||
const basicFormRef = useRef<any>(null); // 基本信息表单引用
|
||||
const supplierFormRef = useRef<any>(null); // 供应商选择表单引用
|
||||
const evaluatorFormRef = useRef<any>(null); // 评价人员表单引用
|
||||
const divisionFormRef = useRef<any>(null); // 评价分工表单引用
|
||||
|
||||
// 步骤配置
|
||||
const steps = [
|
||||
{
|
||||
title: '基本信息', // 步骤标题
|
||||
description: '请填写基本信息', // 步骤描述
|
||||
content: <BasicInfoStep formData={formData} onFormDataChange={handleFormDataChange} ref={basicFormRef} />, // 步骤内容组件
|
||||
title: '基本信息', // 步骤标题
|
||||
description: '请填写基本信息', // 步骤描述
|
||||
content: (
|
||||
<BasicInfoStep
|
||||
formData={formData}
|
||||
onFormDataChange={handleFormDataChange}
|
||||
ref={basicFormRef}
|
||||
/>
|
||||
), // 步骤内容组件
|
||||
},
|
||||
{
|
||||
title: '选择供应商',
|
||||
description: '请选择参加评价的供应商',
|
||||
content: <SupplierSelectStep formData={formData} onFormDataChange={handleFormDataChange} ref={supplierFormRef} />,
|
||||
content: (
|
||||
<SupplierSelectStep
|
||||
formData={formData}
|
||||
onFormDataChange={handleFormDataChange}
|
||||
ref={supplierFormRef}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '选择评价人员',
|
||||
description: '请选择供应商评价人员',
|
||||
content: <EvaluatorSelectStep formData={formData} onFormDataChange={handleFormDataChange} ref={evaluatorFormRef} />,
|
||||
content: (
|
||||
<EvaluatorSelectStep
|
||||
formData={formData}
|
||||
onFormDataChange={handleFormDataChange}
|
||||
ref={evaluatorFormRef}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '设置评价分工',
|
||||
description: '不设置按默认全部指标评价',
|
||||
content: <DivisionStep formData={formData} onFormDataChange={handleFormDataChange} ref={divisionFormRef} />,
|
||||
content: (
|
||||
<DivisionStep
|
||||
formData={formData}
|
||||
onFormDataChange={handleFormDataChange}
|
||||
ref={divisionFormRef}
|
||||
/>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
@ -141,60 +248,65 @@ const SupplierTaskManageAdd: React.FC = () => {
|
||||
setCurrentStep(currentStep - 1);
|
||||
};
|
||||
|
||||
// 提交表单
|
||||
const handleSubmit = async () => {
|
||||
// 实际提交数据的函数
|
||||
const submitTaskData = async (taskStatus: TaskNotifyLowerUnits) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// 验证评价分工
|
||||
if (divisionFormRef.current) {
|
||||
const result = divisionFormRef.current.validate();
|
||||
if (!result.valid) {
|
||||
message.error(result.message);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 构建提交数据
|
||||
const submitData: SupplierEvaluate.TaskAddRequest = {
|
||||
evaluateTheme: formData.evaluateTheme || '', // 评价主题
|
||||
startTime: formData.startTime || '', // 开始时间
|
||||
endTime: formData.endTime || '', // 结束时间
|
||||
templateId: formData.templateId || '', // 模板ID
|
||||
// 构建提交数据,确保必填字段有值
|
||||
const submitData = {
|
||||
evaluateTheme: formData.evaluateTheme || '', // 评价主题
|
||||
startTime: formData.startTime || '', // 开始时间
|
||||
endTime: formData.endTime || '', // 结束时间
|
||||
templateId: formData.templateId || '', // 模板ID
|
||||
categoryLimitation: formData.categoryLimitation || '0', // 品类限制
|
||||
evaluateYear: formData.evaluateYear || '', // 评价年份
|
||||
// weightStatus: formData.weightStatus || 0, // 权重状态
|
||||
evaluateYear: formData.evaluateYear || '', // 评价年份
|
||||
categoryId: formData.categoryId || '', // 品类ID
|
||||
taskStatus: taskStatus, // 任务状态,根据用户的选择决定
|
||||
|
||||
// 修复供应商ID列表格式,确保包含 userIds 字段
|
||||
supplierIds: formData.selectedSuppliers?.map((supplier: any) => {
|
||||
// 从供应商的evaluators中提取用户ID
|
||||
const userIds = supplier.evaluators?.map((evaluator: any) => evaluator.id) || [];
|
||||
return {
|
||||
id: supplier.id,
|
||||
userIds
|
||||
};
|
||||
}) || [],
|
||||
// 供应商ID列表,包含评价人员ID
|
||||
supplierIds:
|
||||
formData.selectedSuppliers?.map((supplier: any) => {
|
||||
// 从供应商的evaluators中提取用户ID
|
||||
const userIds = supplier.evaluators?.map((evaluator: any) => evaluator.id) || [];
|
||||
return {
|
||||
id: supplier.id,
|
||||
userIds,
|
||||
};
|
||||
}) || [],
|
||||
|
||||
// 确保指标列表中的每个项目都有正确的type值
|
||||
indicatorList: formData.indicatorList?.map((item: any) => ({
|
||||
userId: item.userId,
|
||||
// 评价类型:如果用户关联了指标则为1(按指标),否则为0(按评价单)
|
||||
type: item.indicatorIds && item.indicatorIds.length > 0 ? 1 : 0,
|
||||
indicatorIds: item.indicatorIds || [],
|
||||
})) || [],
|
||||
// 评价指标列表
|
||||
indicatorList:
|
||||
formData.indicatorList?.map((item: any) => ({
|
||||
userId: item.userId,
|
||||
// 评价类型:如果用户关联了指标则为1(按指标),否则为0(按评价单)
|
||||
type: item.indicatorIds && item.indicatorIds.length > 0 ? 1 : 0,
|
||||
indicatorIds: item.indicatorIds || [],
|
||||
})) || [],
|
||||
|
||||
// 部门权重列表,过滤掉权重为0的
|
||||
taskDeptWeightList: formData.taskDeptWeightList?.filter((item: any) => {
|
||||
return item.weightValue && item.weightValue !== '0';
|
||||
}) || [],
|
||||
taskDeptWeightList:
|
||||
formData.taskDeptWeightList?.filter((item: any) => {
|
||||
return item.weightValue && item.weightValue !== '0';
|
||||
}) || [],
|
||||
};
|
||||
|
||||
// 调用API提交数据
|
||||
const response = await addTask(submitData);
|
||||
let response;
|
||||
|
||||
if (isEditMode) {
|
||||
// 编辑模式,添加ID字段
|
||||
const updateData = {
|
||||
...submitData,
|
||||
id: taskId,
|
||||
};
|
||||
response = await updateTask(updateData);
|
||||
} else {
|
||||
// 新增模式
|
||||
response = await addTask(submitData);
|
||||
}
|
||||
|
||||
if (response.success) {
|
||||
message.success('任务创建成功');
|
||||
// 创建成功后直接返回列表页面
|
||||
message.success(isEditMode ? '任务更新成功' : '任务创建成功');
|
||||
// 成功后直接返回列表页面
|
||||
history.push('/supplier/supplierTaskManage');
|
||||
} else {
|
||||
message.error(response.message || '提交失败');
|
||||
@ -207,11 +319,43 @@ const SupplierTaskManageAdd: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 提交表单
|
||||
const handleSubmit = async () => {
|
||||
// 验证评价分工
|
||||
if (divisionFormRef.current) {
|
||||
const result = divisionFormRef.current.validate();
|
||||
if (!result.valid) {
|
||||
message.error(result.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 显示确认对话框
|
||||
setConfirmModalVisible(true);
|
||||
};
|
||||
|
||||
// 处理确认对话框的取消
|
||||
const handleConfirmCancel = () => {
|
||||
setConfirmModalVisible(false);
|
||||
};
|
||||
|
||||
// 处理确认对话框的"是"选项
|
||||
const handleConfirmYes = () => {
|
||||
submitTaskData(TaskNotifyLowerUnits.YES); // 未开始状态,需要下级单位完善
|
||||
setConfirmModalVisible(false);
|
||||
};
|
||||
|
||||
// 处理确认对话框的"否"选项
|
||||
const handleConfirmNo = () => {
|
||||
submitTaskData(TaskNotifyLowerUnits.NO); // 进行中状态,不需要下级单位完善
|
||||
setConfirmModalVisible(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="common-container">
|
||||
<Card bordered={false}>
|
||||
<Card bordered={false} loading={detailLoading}>
|
||||
<div className="page-header">
|
||||
<h2>新增评价任务</h2>
|
||||
<h2>{isEditMode ? '修改评价任务' : '新增评价任务'}</h2>
|
||||
<Button type="link" icon={<ArrowLeftOutlined />} onClick={handleBack}>
|
||||
返回
|
||||
</Button>
|
||||
@ -220,21 +364,17 @@ const SupplierTaskManageAdd: React.FC = () => {
|
||||
<Row gutter={24} className={styles.stepsLayout}>
|
||||
<Col span={6} className={styles.stepsLeft}>
|
||||
<Steps direction="vertical" current={currentStep} className={styles.verticalSteps}>
|
||||
{steps.map(item => (
|
||||
{steps.map((item) => (
|
||||
<Step key={item.title} title={item.title} description={item.description} />
|
||||
))}
|
||||
</Steps>
|
||||
</Col>
|
||||
<Col span={18} className={styles.stepsRight}>
|
||||
<div className={styles.stepsContent}>
|
||||
{steps[currentStep].content}
|
||||
</div>
|
||||
<div className={styles.stepsContent}>{steps[currentStep].content}</div>
|
||||
|
||||
<div className={styles.stepsAction}>
|
||||
<Space>
|
||||
{currentStep > 0 && (
|
||||
<Button onClick={handlePrev}>上一步</Button>
|
||||
)}
|
||||
{currentStep > 0 && <Button onClick={handlePrev}>上一步</Button>}
|
||||
{currentStep < steps.length - 1 && (
|
||||
<Button type="primary" onClick={handleNext}>
|
||||
下一步
|
||||
@ -247,7 +387,7 @@ const SupplierTaskManageAdd: React.FC = () => {
|
||||
icon={<SaveOutlined />}
|
||||
onClick={handleSubmit}
|
||||
>
|
||||
提交
|
||||
{isEditMode ? '保存' : '提交'}
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
@ -255,6 +395,25 @@ const SupplierTaskManageAdd: React.FC = () => {
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
{/* 确认对话框 */}
|
||||
<Modal
|
||||
title="提交确认"
|
||||
visible={confirmModalVisible}
|
||||
onCancel={handleConfirmCancel}
|
||||
footer={null}
|
||||
>
|
||||
<p>是否提示给下级单位继续完善评价人及评价分工?</p>
|
||||
<div style={{ textAlign: 'right', marginTop: 24 }}>
|
||||
<Space>
|
||||
<Button type="primary" onClick={handleConfirmYes}>
|
||||
是
|
||||
</Button>
|
||||
<Button onClick={handleConfirmNo}>否</Button>
|
||||
<Button onClick={handleConfirmCancel}>取消</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -165,7 +165,7 @@ export async function addTask(params: SupplierEvaluate.TaskAddRequest) {
|
||||
* @param params 任务数据
|
||||
* @returns Promise
|
||||
*/
|
||||
export async function updateTask(params: SupplierEvaluate.TaskUpdateRequest) {
|
||||
export async function updateTask(params: SupplierEvaluate.TaskAddRequest) {
|
||||
return request<API.APIResponse<any>>('/coscoEvaluate/task', {
|
||||
method: 'PUT',
|
||||
data: params,
|
||||
|
@ -60,13 +60,24 @@ export interface TaskDetailData {
|
||||
weightDept: string | null;
|
||||
weightStatus: number | null;
|
||||
weightValue: string | null;
|
||||
taskDeptWeightList: {
|
||||
weightDept: string;
|
||||
weightValue: string;
|
||||
}[] | null;
|
||||
taskDeptWeightList: DeptWeightItem[] | null;
|
||||
blackSupplierVos: {
|
||||
deptName: string;
|
||||
supplierId: string;
|
||||
supplierName: string;
|
||||
userList: User[];
|
||||
}[],
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
// 部门配置权重
|
||||
export interface DeptWeightItem {
|
||||
//部门id
|
||||
weightDept: string;
|
||||
// 部门权重值
|
||||
weightValue: string;
|
||||
// 部门名称
|
||||
weightDeptName: string;
|
||||
}
|
||||
/**
|
||||
* 任务详情响应
|
||||
*/
|
||||
@ -77,3 +88,61 @@ export interface TaskDetailResponse {
|
||||
success: boolean;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
// 新增评价任务和修改 请求参数定义
|
||||
export type TaskAddRequest = {
|
||||
/**
|
||||
* 品类限制类型(0.通用不限品类、1.限制品类)
|
||||
*/
|
||||
categoryLimitation?: string;
|
||||
/**
|
||||
* 评价结束时间
|
||||
*/
|
||||
endTime: string;
|
||||
/**
|
||||
* 评价主题
|
||||
*/
|
||||
evaluateTheme: string;
|
||||
/**
|
||||
* 评价年度
|
||||
*/
|
||||
evaluateYear: string;
|
||||
indicatorList: IndicatorList[];
|
||||
/**
|
||||
* 评价开始时间
|
||||
*/
|
||||
startTime: string;
|
||||
supplierIds: SupplierId[];
|
||||
taskDeptWeightList: DeptWeightItem[];
|
||||
/**
|
||||
* 评价表模板id(cosco_evaluate_template表主键)
|
||||
*/
|
||||
templateId: string;
|
||||
// 品类id
|
||||
categoryId?: string;
|
||||
[property: string]: any;
|
||||
}
|
||||
/**
|
||||
* 供应商项
|
||||
*/
|
||||
export interface SupplierItem {
|
||||
id: string; // 供应商ID
|
||||
supplierName: string; // 供应商名称
|
||||
socialCreditCode?: string; // 统一社会信用代码
|
||||
category?: string; // 品类
|
||||
department?: string; // 准入部门
|
||||
evaluatorCount: number; // 评价人员数量
|
||||
evaluators: User[]; // 评价人员列表
|
||||
// 其他可能的字段
|
||||
[key: string]: any;
|
||||
}
|
||||
export type SupplierId = {
|
||||
/**
|
||||
* 供应商id
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* 用户集合
|
||||
*/
|
||||
userIds?: string[];
|
||||
}
|
4
src/typings.d.ts
vendored
4
src/typings.d.ts
vendored
@ -497,6 +497,10 @@ declare namespace SupplierEvaluate {
|
||||
* 权重启用状态(0.不启用、1.启用)
|
||||
*/
|
||||
// weightStatus: number;
|
||||
/**
|
||||
* 是否通知下级单位完善评价人及评价分工 0否1是
|
||||
*/
|
||||
taskStatus: number;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user