对接供应商评价任务新增
This commit is contained in:
@ -27,6 +27,9 @@ interface EvaluateTemplateTableProps {
|
||||
value?: any[];
|
||||
onChange?: (value: any[]) => void;
|
||||
isDetail?: boolean; // 是否详情展示用,如果为true则将input都改为text展示并且将操作列隐藏
|
||||
isCheck?: boolean; // 是否显示勾选操作,如果为true则在表格最后一列增加勾选操作项
|
||||
onSelect?: (selectedItems: any[]) => void; // 勾选回调函数
|
||||
defaultSelectedIds?: string[]; // 默认选中的二级指标ID数组
|
||||
}
|
||||
|
||||
// 内部使用的数据结构,扁平化后的行数据
|
||||
@ -44,12 +47,16 @@ interface TableRowItem {
|
||||
desc?: string;
|
||||
orderBy?: number;
|
||||
ndOrderBy?: number;
|
||||
selected?: boolean; // 是否选中
|
||||
}
|
||||
|
||||
const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
value = [],
|
||||
onChange,
|
||||
isDetail = false,
|
||||
isCheck = false,
|
||||
onSelect,
|
||||
defaultSelectedIds = [],
|
||||
}) => {
|
||||
const [dataSource, setDataSource] = useState<TableRowItem[]>([]);
|
||||
const [form] = Form.useForm();
|
||||
@ -86,7 +93,8 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
ndScore: item.score || '0',
|
||||
isStar: item.isStar || StarLevel.NO,
|
||||
orderBy: typeof item.stOrderBy === 'string' ? parseInt(item.stOrderBy) : item.stOrderBy,
|
||||
ndOrderBy: typeof item.orderBy === 'string' ? parseInt(item.orderBy) : item.orderBy
|
||||
ndOrderBy: typeof item.orderBy === 'string' ? parseInt(item.orderBy) : item.orderBy,
|
||||
selected: defaultSelectedIds.includes(item.id) // 根据defaultSelectedIds设置选中状态
|
||||
}));
|
||||
}
|
||||
|
||||
@ -109,7 +117,8 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
isStar: ndItem.isStar || StarLevel.NO,
|
||||
desc: ndItem.desc,
|
||||
orderBy: typeof stItem.orderBy === 'string' ? parseInt(stItem.orderBy) : stItem.orderBy,
|
||||
ndOrderBy: typeof ndItem.orderBy === 'string' ? parseInt(ndItem.orderBy) : ndItem.orderBy
|
||||
ndOrderBy: typeof ndItem.orderBy === 'string' ? parseInt(ndItem.orderBy) : ndItem.orderBy,
|
||||
selected: defaultSelectedIds.includes(ndItem.id) // 根据defaultSelectedIds设置选中状态
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -208,9 +217,13 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
(existing.baseIndicator === newItem.baseIndicator && existing.subIndicator === newItem.subIndicator)
|
||||
);
|
||||
|
||||
// 如果找到现有项,保留其key
|
||||
// 如果找到现有项,保留其key和selected状态
|
||||
if (existingItem) {
|
||||
return { ...newItem, key: existingItem.key };
|
||||
return {
|
||||
...newItem,
|
||||
key: existingItem.key,
|
||||
selected: defaultSelectedIds.includes(newItem.ndId || '') ? true : existingItem.selected
|
||||
};
|
||||
}
|
||||
|
||||
return newItem;
|
||||
@ -229,6 +242,27 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
// 处理defaultSelectedIds变化
|
||||
useEffect(() => {
|
||||
if (defaultSelectedIds.length > 0 && dataSource.length > 0) {
|
||||
const newData = dataSource.map(item => ({
|
||||
...item,
|
||||
selected: defaultSelectedIds.includes(item.ndId || '')
|
||||
}));
|
||||
console.log("newData",newData)
|
||||
|
||||
setDataSource(newData);
|
||||
|
||||
// 如果有onSelect回调,传递所有选中的项
|
||||
if (onSelect) {
|
||||
const selectedItems = newData.filter(item => item.selected);
|
||||
// 转换为API格式再传递给父组件
|
||||
const selectedApiData = convertTableDataToApiData(selectedItems);
|
||||
onSelect(selectedApiData);
|
||||
}
|
||||
}
|
||||
}, [defaultSelectedIds]);
|
||||
|
||||
// 更新数据源
|
||||
const updateDataSource = (newData: TableRowItem[]) => {
|
||||
// 确保每行都有唯一稳定的key
|
||||
@ -242,6 +276,25 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
// 处理勾选状态变化
|
||||
const handleCheckChange = (record: TableRowItem, checked: boolean) => {
|
||||
console.log("handleCheckChange")
|
||||
const newData = [...dataSource];
|
||||
const index = newData.findIndex((item) => item.key === record.key);
|
||||
if (index > -1) {
|
||||
newData[index] = { ...newData[index], selected: checked };
|
||||
setDataSource(newData);
|
||||
|
||||
// 如果有onSelect回调,传递所有选中的项
|
||||
if (onSelect) {
|
||||
const selectedItems = newData.filter(item => item.selected);
|
||||
// 转换为API格式再传递给父组件
|
||||
const selectedApiData = convertTableDataToApiData(selectedItems);
|
||||
onSelect(selectedApiData);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 处理输入变化
|
||||
const handleInputChange = (val: any, record: TableRowItem, field: string) => {
|
||||
const newData = [...dataSource];
|
||||
@ -311,7 +364,8 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
isStar: StarLevel.NO,
|
||||
desc: '',
|
||||
orderBy: dataSource.length + 1, // 确保正确的排序
|
||||
ndOrderBy: 1 // 设置二级指标初始排序
|
||||
ndOrderBy: 1, // 设置二级指标初始排序
|
||||
selected: false, // 默认未选中
|
||||
};
|
||||
|
||||
// 制作数据源的副本,避免直接修改状态
|
||||
@ -375,7 +429,8 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
ndScore: '0',
|
||||
isStar: StarLevel.NO,
|
||||
desc: '',
|
||||
ndOrderBy: dataSource.filter(item => item.baseIndicator === parent.baseIndicator).length + 1
|
||||
ndOrderBy: dataSource.filter(item => item.baseIndicator === parent.baseIndicator).length + 1,
|
||||
selected: false, // 默认未选中
|
||||
};
|
||||
|
||||
// 找到当前记录所在的位置
|
||||
@ -698,6 +753,20 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
);
|
||||
},
|
||||
},
|
||||
// 添加勾选列,只在isCheck为true时显示
|
||||
...(isCheck ? [{
|
||||
title: '勾选',
|
||||
key: 'check',
|
||||
align: 'center',
|
||||
width: 80,
|
||||
render: (_: any, record: TableRowItem) => (
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={record.selected}
|
||||
onChange={(e) => handleCheckChange(record, e.target.checked)}
|
||||
/>
|
||||
),
|
||||
}] : []),
|
||||
].filter((col) => !(isDetail && col.key === 'level2Action')),
|
||||
},
|
||||
];
|
||||
|
@ -7,6 +7,8 @@ EvaluateTemplateTable 是一个用于管理供应商评价模板指标的表格
|
||||
- 添加/删除二级指标
|
||||
- 设置指标类型、分值、星号项等
|
||||
- 支持详情模式查看
|
||||
- 支持勾选模式选择指标
|
||||
- 支持默认选中指定的指标
|
||||
|
||||
## 使用方式
|
||||
|
||||
@ -35,6 +37,119 @@ const YourComponent = () => {
|
||||
<EvaluateTemplateTable value={detailData} isDetail={true} />
|
||||
```
|
||||
|
||||
### 勾选模式
|
||||
|
||||
```jsx
|
||||
const [selectedIndicators, setSelectedIndicators] = useState([]);
|
||||
|
||||
const handleIndicatorSelect = (selectedItems) => {
|
||||
console.log('选中的指标:', selectedItems);
|
||||
setSelectedIndicators(selectedItems);
|
||||
};
|
||||
|
||||
return (
|
||||
<EvaluateTemplateTable
|
||||
value={templateData}
|
||||
isDetail={true}
|
||||
isCheck={true}
|
||||
onSelect={handleIndicatorSelect}
|
||||
/>
|
||||
);
|
||||
```
|
||||
|
||||
### 默认选中指定指标
|
||||
|
||||
```jsx
|
||||
// 指定要默认选中的二级指标ID数组
|
||||
const defaultSelectedIds = ['1001', '1002', '1003'];
|
||||
|
||||
return (
|
||||
<EvaluateTemplateTable
|
||||
value={templateData}
|
||||
isDetail={true}
|
||||
isCheck={true}
|
||||
onSelect={handleIndicatorSelect}
|
||||
defaultSelectedIds={defaultSelectedIds}
|
||||
/>
|
||||
);
|
||||
```
|
||||
|
||||
## 属性说明
|
||||
|
||||
| 属性名 | 类型 | 默认值 | 说明 |
|
||||
| --- | --- | --- | --- |
|
||||
| value | any[] | [] | 表格数据源,通常是指标列表 |
|
||||
| onChange | (value: any[]) => void | - | 数据变更回调函数 |
|
||||
| isDetail | boolean | false | 是否为详情模式,为true时隐藏编辑功能 |
|
||||
| isCheck | boolean | false | 是否显示勾选功能,为true时在表格最后一列增加勾选框 |
|
||||
| onSelect | (selectedItems: any[]) => void | - | 勾选变更回调函数,返回所有选中的项 |
|
||||
| defaultSelectedIds | string[] | [] | 默认选中的二级指标ID数组 |
|
||||
|
||||
## 勾选功能使用场景
|
||||
|
||||
勾选功能主要用于以下场景:
|
||||
|
||||
1. **指标分配**:在评价任务中,为评价人员分配特定的评价指标
|
||||
2. **指标筛选**:从模板中选择部分指标用于特定评价场景
|
||||
3. **批量操作**:选择多个指标进行批量设置或操作
|
||||
|
||||
### 勾选功能实现细节
|
||||
|
||||
- 勾选状态存储在组件内部状态中
|
||||
- 勾选变更时,通过`onSelect`回调将所有选中的项(已转换为API格式)传递给父组件
|
||||
- 选中的项会保留完整的一级指标和二级指标层级结构
|
||||
|
||||
### 勾选功能最佳实践
|
||||
|
||||
```jsx
|
||||
// 在评价分工设置中使用勾选功能
|
||||
const DivisionStep = () => {
|
||||
const [selectedIndicators, setSelectedIndicators] = useState([]);
|
||||
const [evaluator, setEvaluator] = useState(null);
|
||||
|
||||
// 处理指标选择
|
||||
const handleIndicatorSelect = (selectedItems) => {
|
||||
setSelectedIndicators(selectedItems);
|
||||
};
|
||||
|
||||
// 保存分配
|
||||
const handleSaveAssignment = () => {
|
||||
if (!evaluator) {
|
||||
message.warning('请先选择评价人员');
|
||||
return;
|
||||
}
|
||||
|
||||
// 将选中的指标分配给评价人员
|
||||
const assignment = {
|
||||
userId: evaluator.id,
|
||||
userName: evaluator.name,
|
||||
indicatorIds: selectedIndicators.flatMap(item =>
|
||||
item.indicatorNdList.map(nd => nd.id)
|
||||
),
|
||||
type: selectedIndicators.length > 0 ? 'INDICATOR' : 'ALL'
|
||||
};
|
||||
|
||||
// 保存分配结果
|
||||
saveAssignment(assignment);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<UserSelector onSelect={setEvaluator} />
|
||||
|
||||
<Modal title="选择评价指标" visible={modalVisible} onOk={handleSaveAssignment}>
|
||||
<EvaluateTemplateTable
|
||||
value={templateData}
|
||||
isDetail={true}
|
||||
isCheck={true}
|
||||
onSelect={handleIndicatorSelect}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
## 接口对接指南
|
||||
|
||||
EvaluateTemplateTable 组件使用了全局命名空间 SupplierEvaluate 中的类型定义,可以用于新增和修改操作。
|
||||
@ -142,4 +257,6 @@ const fetchTemplateDetail = async (id) => {
|
||||
1. 表格组件内部将值输出为标准的API格式,无需额外转换
|
||||
2. 创建新模板时,需要设置Edit相关字段,这些在表格组件中没有UI界面
|
||||
3. 修改操作需要保持ID字段以便后端识别哪些指标需要更新
|
||||
4. 表格组件对空baseIndicator的行会特殊处理,确保添加一级指标功能正常工作
|
||||
4. 表格组件对空baseIndicator的行会特殊处理,确保添加一级指标功能正常工作
|
||||
5. 使用勾选功能时,建议在详情模式下使用,以避免编辑和勾选操作冲突
|
||||
6. 勾选状态在组件内部维护,不会随着`value`属性的变化而重置,除非组件重新挂载
|
||||
|
@ -1,7 +1,6 @@
|
||||
.supplier-selector {
|
||||
.supplier-lists {
|
||||
margin-top: 16px;
|
||||
min-height: 450px;
|
||||
|
||||
.list-title {
|
||||
font-weight: 500;
|
||||
|
@ -1,9 +1,10 @@
|
||||
import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
|
||||
import { Card, Table, Tag, Switch, Space, Button, message, Modal, Radio, Checkbox, Row, Col } from 'antd';
|
||||
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 type { PersonnelItem } from '@/servers/types/evaluator';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import type { CheckboxValueType } from 'antd/es/checkbox/Group';
|
||||
import styles from '../supplierTaskManageAdd.less';
|
||||
import EvaluateTemplateTable from '@/components/EvaluateTemplateTable';
|
||||
import { getTemplateDetail } from '@/servers/api/supplierEvaluate';
|
||||
|
||||
// 评价指标类型定义
|
||||
interface IndicatorItem {
|
||||
@ -19,12 +20,14 @@ interface DivisionStepProps {
|
||||
}
|
||||
|
||||
// 评价方式枚举
|
||||
// 注意:type值是根据用户是否关联了指标自动计算的,不是由用户直接选择的
|
||||
// 默认为0(按评价单),当用户关联了指标则为1(按指标)
|
||||
enum EvaluateType {
|
||||
ALL = 'ALL', // 按评价单评价(全部指标)
|
||||
INDICATOR = 'INDICATOR', // 按指标评价(部分指标)
|
||||
ALL = 0, // 按评价单评价(全部指标)
|
||||
INDICATOR = 1, // 按指标评价(部分指标)
|
||||
}
|
||||
|
||||
// 模拟的评价指标数据
|
||||
// 模拟的评价指标数据 - 仅作为备用
|
||||
const mockIndicators: IndicatorItem[] = [
|
||||
{ id: 'I001', name: '产品质量', description: '评估供应商产品质量' },
|
||||
{ id: 'I002', name: '交货及时性', description: '评估供应商交货的及时性' },
|
||||
@ -48,18 +51,71 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
// 选中的行keys
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||
|
||||
// 指标列表
|
||||
const [indicators] = useState<IndicatorItem[]>(mockIndicators);
|
||||
// 指标列表 - 不再直接使用mockIndicators,而是从templateData派生
|
||||
const [indicators, setIndicators] = useState<IndicatorItem[]>([]);
|
||||
|
||||
// 指标分工弹窗可见性
|
||||
const [divisionModalVisible, setDivisionModalVisible] = useState(false);
|
||||
// 评价指标模板查看弹窗可见性
|
||||
const [templateViewModalVisible, setTemplateViewModalVisible] = useState(false);
|
||||
|
||||
// 评价方式类型
|
||||
const [batchEvaluateType, setBatchEvaluateType] = useState<EvaluateType>(EvaluateType.ALL);
|
||||
// 批量指标设置弹窗可见性
|
||||
const [batchTemplateModalVisible, setBatchTemplateModalVisible] = useState(false);
|
||||
|
||||
// 批量选择的指标
|
||||
const [batchSelectedIndicators, setBatchSelectedIndicators] = useState<string[]>([]);
|
||||
|
||||
// 批量选择的模板项
|
||||
const [batchSelectedTemplateItems, setBatchSelectedTemplateItems] = useState<any[]>([]);
|
||||
|
||||
// 当前查看的用户ID
|
||||
const [currentUserId, setCurrentUserId] = useState<string>('');
|
||||
|
||||
// 模板数据
|
||||
const [templateData, setTemplateData] = useState<any[]>([]);
|
||||
|
||||
// 加载状态
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
// 选中的指标项
|
||||
const [selectedTemplateItems, setSelectedTemplateItems] = useState<any[]>([]);
|
||||
|
||||
// 获取模板详情 先写死 "1937123786334322688" 省的一步一步操作
|
||||
const fetchTemplateDetail = async (templateId: string = "1937123786334322688") => {
|
||||
if (!templateId) return;
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const res = await getTemplateDetail(templateId);
|
||||
if (res.success && res.data) {
|
||||
// 直接设置指标数据,无需转换
|
||||
if (res.data.indicatorStList && res.data.indicatorStList.length > 0) {
|
||||
setTemplateData(res.data.indicatorStList);
|
||||
|
||||
// 更新指标列表
|
||||
const newIndicators = res.data.indicatorStList.map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.baseIndicator,
|
||||
description: item.descIndicator || '',
|
||||
}));
|
||||
|
||||
// 更新indicators状态
|
||||
setIndicators(newIndicators);
|
||||
}
|
||||
} else {
|
||||
message.error(res.message || '获取模板详情失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取模板详情失败:', error);
|
||||
message.error('获取模板详情失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 监听templateId变化,获取模板详情
|
||||
useEffect(() => {
|
||||
fetchTemplateDetail(formData.templateId);
|
||||
}, []);
|
||||
|
||||
// 处理行选择变化
|
||||
const handleSelectChange = (newSelectedRowKeys: React.Key[]) => {
|
||||
setSelectedRowKeys(newSelectedRowKeys);
|
||||
@ -71,17 +127,21 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
message.warning('请先选择评价人员');
|
||||
return;
|
||||
}
|
||||
setDivisionModalVisible(true);
|
||||
// 直接显示批量模板选择弹窗
|
||||
setBatchTemplateModalVisible(true);
|
||||
|
||||
// 重置已选中的模板项
|
||||
setBatchSelectedTemplateItems([]);
|
||||
};
|
||||
|
||||
// 处理评价方式变更
|
||||
const handleEvaluateTypeChange = (e: any) => {
|
||||
setBatchEvaluateType(e.target.value);
|
||||
// 处理批量模板指标选择
|
||||
const handleBatchTemplateItemsSelect = (selectedItems: any[]) => {
|
||||
setBatchSelectedTemplateItems(selectedItems);
|
||||
};
|
||||
|
||||
// 处理指标选择变更
|
||||
const handleIndicatorChange = (checkedValues: CheckboxValueType[]) => {
|
||||
setBatchSelectedIndicators(checkedValues.map(v => v.toString()));
|
||||
// 关闭批量模板选择弹窗
|
||||
const handleCloseBatchTemplateModal = () => {
|
||||
setBatchTemplateModalVisible(false);
|
||||
};
|
||||
|
||||
// 批量设置指标分工
|
||||
@ -91,28 +151,100 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
evaluator => selectedRowKeys.includes(evaluator.id)
|
||||
);
|
||||
|
||||
// 提取所有选中指标的ID
|
||||
const selectedIndicatorIds: string[] = [];
|
||||
|
||||
// 从选中的模板项中提取所有指标ID
|
||||
batchSelectedTemplateItems.forEach(stItem => {
|
||||
// 添加二级指标ID
|
||||
if (stItem.indicatorNdList && stItem.indicatorNdList.length > 0) {
|
||||
stItem.indicatorNdList.forEach((ndItem: any) => {
|
||||
selectedIndicatorIds.push(ndItem.id);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 更新指标分配数据
|
||||
const newAssignments = { ...indicatorAssignments };
|
||||
|
||||
selectedEvaluators.forEach(evaluator => {
|
||||
newAssignments[evaluator.id] = {
|
||||
type: batchEvaluateType,
|
||||
indicatorIds: batchEvaluateType === EvaluateType.INDICATOR ? batchSelectedIndicators : [],
|
||||
// 评价类型:如果用户关联了指标则为1(按指标),否则为0(按评价单)
|
||||
type: selectedIndicatorIds.length > 0 ? EvaluateType.INDICATOR : EvaluateType.ALL,
|
||||
indicatorIds: selectedIndicatorIds,
|
||||
};
|
||||
});
|
||||
|
||||
setIndicatorAssignments(newAssignments);
|
||||
setDivisionModalVisible(false);
|
||||
setBatchTemplateModalVisible(false);
|
||||
message.success(`已为${selectedRowKeys.length}名评价人员设置分工`);
|
||||
};
|
||||
|
||||
// 处理单个评价人员的指标分工
|
||||
const handleAssignIndicators = (userId: string) => {
|
||||
Modal.info({
|
||||
title: '评价指标分工',
|
||||
content: '此功能将在后续完善',
|
||||
okText: '确定',
|
||||
setCurrentUserId(userId);
|
||||
|
||||
// 重置已选中的指标项
|
||||
setSelectedTemplateItems([]);
|
||||
// 打开模态框
|
||||
setTemplateViewModalVisible(true);
|
||||
};
|
||||
|
||||
// 关闭模板查看模态框
|
||||
const handleCloseTemplateViewModal = () => {
|
||||
setTemplateViewModalVisible(false);
|
||||
};
|
||||
|
||||
// 处理模板指标选择
|
||||
const handleTemplateItemsSelect = (selectedItems: any[]) => {
|
||||
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) {
|
||||
message.warning('未选择评价人员');
|
||||
return;
|
||||
}
|
||||
|
||||
// 提取所有选中指标的ID
|
||||
const selectedIndicatorIds: string[] = [];
|
||||
|
||||
// 从选中的模板项中提取所有指标ID
|
||||
selectedTemplateItems.forEach(stItem => {
|
||||
// 添加二级指标ID
|
||||
if (stItem.indicatorNdList && stItem.indicatorNdList.length > 0) {
|
||||
stItem.indicatorNdList.forEach((ndItem: any) => {
|
||||
selectedIndicatorIds.push(ndItem.id);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 更新指标分配
|
||||
const newAssignments = { ...indicatorAssignments };
|
||||
newAssignments[currentUserId] = {
|
||||
// 评价类型:如果用户关联了指标则为1(按指标),否则为0(按评价单)
|
||||
type: selectedIndicatorIds.length > 0 ? EvaluateType.INDICATOR : EvaluateType.ALL,
|
||||
indicatorIds: selectedIndicatorIds,
|
||||
};
|
||||
|
||||
setIndicatorAssignments(newAssignments);
|
||||
setTemplateViewModalVisible(false);
|
||||
message.success('已设置评价人员指标分工');
|
||||
};
|
||||
|
||||
// 查看评价人员的指标分工
|
||||
@ -332,36 +464,67 @@ const DivisionStep = forwardRef<any, DivisionStepProps>(({ formData, onFormDataC
|
||||
pagination={false}
|
||||
/>
|
||||
|
||||
{/* 批量设置指标分工弹窗 */}
|
||||
{/* 批量选择指标模板弹窗 */}
|
||||
<Modal
|
||||
title="批量设置评价指标分工"
|
||||
visible={divisionModalVisible}
|
||||
onOk={handleBatchSetDivision}
|
||||
onCancel={() => setDivisionModalVisible(false)}
|
||||
okText="确定"
|
||||
cancelText="取消"
|
||||
width={700}
|
||||
title={`批量设置评价指标分工 (已选择 ${selectedRowKeys.length} 名评价人员)`}
|
||||
visible={batchTemplateModalVisible}
|
||||
onCancel={handleCloseBatchTemplateModal}
|
||||
width={800}
|
||||
footer={[
|
||||
<Button key="cancel" onClick={handleCloseBatchTemplateModal}>
|
||||
取消
|
||||
</Button>,
|
||||
<Button key="save" type="primary" onClick={handleBatchSetDivision}>
|
||||
确定并保存
|
||||
</Button>
|
||||
]}
|
||||
>
|
||||
<div>
|
||||
<p>您已选择 {selectedRowKeys.length} 名评价人员进行指标分工设置</p>
|
||||
<Radio.Group defaultValue={EvaluateType.ALL} onChange={handleEvaluateTypeChange}>
|
||||
<Radio value={EvaluateType.ALL}>按评价单评价</Radio>
|
||||
<Radio value={EvaluateType.INDICATOR}>按指标评价</Radio>
|
||||
</Radio.Group>
|
||||
<Spin spinning={loading}>
|
||||
{templateData.length > 0 ? (
|
||||
<EvaluateTemplateTable
|
||||
value={templateData}
|
||||
isDetail={true}
|
||||
isCheck={true}
|
||||
onSelect={handleBatchTemplateItemsSelect}
|
||||
/>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '20px 0' }}>
|
||||
{loading ? '加载中...' : '暂无模板数据'}
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
</Modal>
|
||||
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<p>指标列表:</p>
|
||||
<Checkbox.Group style={{ width: '100%' }} onChange={handleIndicatorChange}>
|
||||
<Row>
|
||||
{indicators.map(indicator => (
|
||||
<Col span={8} key={indicator.id}>
|
||||
<Checkbox value={indicator.id}>{indicator.name}</Checkbox>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</Checkbox.Group>
|
||||
</div>
|
||||
</div>
|
||||
{/* 评价指标模板查看弹窗 */}
|
||||
<Modal
|
||||
title="设置评价指标分工"
|
||||
visible={templateViewModalVisible}
|
||||
onCancel={handleCloseTemplateViewModal}
|
||||
footer={[
|
||||
<Button key="cancel" onClick={handleCloseTemplateViewModal}>
|
||||
取消
|
||||
</Button>,
|
||||
<Button key="save" type="primary" onClick={handleSaveIndicatorAssignment}>
|
||||
保存
|
||||
</Button>
|
||||
]}
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
{templateData.length > 0 ? (
|
||||
<EvaluateTemplateTable
|
||||
value={templateData}
|
||||
isDetail={true}
|
||||
isCheck={true}
|
||||
key={currentUserId}
|
||||
onSelect={handleTemplateItemsSelect}
|
||||
defaultSelectedIds={getCurrentUserSelectedIds()}
|
||||
/>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '20px 0' }}>
|
||||
{loading ? '加载中...' : '暂无模板数据'}
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
|
@ -43,8 +43,8 @@ const SupplierTable: React.FC<SupplierTableProps> = ({
|
||||
const columns = [
|
||||
{
|
||||
title: '供应商名称', // 列标题
|
||||
dataIndex: 'supplierName', // 数据字段名
|
||||
key: 'supplierName', // 列的唯一标识
|
||||
dataIndex: 'name', // 数据字段名
|
||||
key: 'name', // 列的唯一标识
|
||||
},
|
||||
{
|
||||
title: '统一社会信用代码',
|
||||
|
@ -218,7 +218,10 @@ const EvaluatorSelectStep = forwardRef<any, EvaluatorSelectStepProps>(
|
||||
}));
|
||||
|
||||
setWeightUnits(updatedWeightUnits);
|
||||
|
||||
// 将更新后的权重数据传递给父组件
|
||||
updateFormData({ weightUnits: updatedWeightUnits });
|
||||
|
||||
setWeightSettingModalVisible(false);
|
||||
});
|
||||
};
|
||||
|
@ -53,7 +53,21 @@ const SupplierTaskManageAdd: React.FC = () => {
|
||||
|
||||
// 更新权重单位
|
||||
if (data.weightUnits) {
|
||||
// 将 weightUnits 存储在 formData.WeightUnit 中
|
||||
setFormData((prev) => ({ ...prev, WeightUnit: data.weightUnits }));
|
||||
|
||||
// 同时将 weightUnits 转换为 taskDeptWeightList 格式
|
||||
const taskDeptWeightList = data.weightUnits.map((unit: any) => ({
|
||||
weightDept: unit.name,
|
||||
weightValue: unit.weight.toString(),
|
||||
}));
|
||||
|
||||
// 更新 taskDeptWeightList 和 weightStatus
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
taskDeptWeightList,
|
||||
weightStatus: taskDeptWeightList.length > 0 ? 1 : 0, // 如果有权重设置则为1,否则为0
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
@ -158,10 +172,28 @@ const SupplierTaskManageAdd: React.FC = () => {
|
||||
templateId: formData.templateId || '', // 模板ID
|
||||
categoryLimitation: formData.categoryLimitation || '0', // 品类限制
|
||||
evaluateYear: formData.evaluateYear || '', // 评价年份
|
||||
supplierIds: formData.selectedSuppliers?.map((supplier: any) => supplier.id) || [], // 供应商ID列表
|
||||
indicatorList: formData.indicatorList || [], // 指标分配列表
|
||||
taskDeptWeightList: formData.taskDeptWeightList || [], // 部门权重列表
|
||||
weightStatus: formData.weightStatus || 0 // 权重状态
|
||||
|
||||
// 修复供应商ID列表格式,确保包含 userIds 字段
|
||||
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 || [],
|
||||
})) || [],
|
||||
|
||||
taskDeptWeightList: formData.taskDeptWeightList?.filter((item: any) => {
|
||||
return item.weightValue !== '0'
|
||||
}) || [], // 部门权重列表 过滤掉权重为0的
|
||||
};
|
||||
|
||||
// 调用API提交数据
|
||||
|
Reference in New Issue
Block a user