对接评价结果接口
This commit is contained in:
@ -8,33 +8,27 @@ import {
|
||||
Button,
|
||||
Table,
|
||||
Space,
|
||||
Tag,
|
||||
TablePaginationConfig,
|
||||
Modal,
|
||||
Row,
|
||||
Col,
|
||||
Tooltip,
|
||||
message,
|
||||
} from 'antd';
|
||||
import type { TablePaginationConfig } from 'antd';
|
||||
import {
|
||||
SearchOutlined,
|
||||
DeleteOutlined,
|
||||
ArrowLeftOutlined,
|
||||
FileTextOutlined,
|
||||
BarChartOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { history, useLocation } from 'umi';
|
||||
import moment from 'moment';
|
||||
import { EvaluateLevel, EvaluateLevelText, EvaluateLevelColor } from '@/dicts/supplierTemplateDict';
|
||||
import styles from './supplierEvaluateResult.less';
|
||||
import { getEvaluateSupplierList, getAllEvaluateRules } from '@/servers/api/supplierEvaluate';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
const SupplierEvaluateResultInfo: React.FC = () => {
|
||||
const location = useLocation<{ record: SupplierEvaluate.EvaluateResultRecord }>();
|
||||
const location = useLocation<{ record: API.EvaluateTaskRecord }>();
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [form] = Form.useForm();
|
||||
const [resultData, setResultData] = useState<SupplierEvaluate.EvaluateResultDetailRecord[]>([]);
|
||||
const [resultData, setResultData] = useState<API.EvaluateSupplierRecord[]>([]);
|
||||
const [pagination, setPagination] = useState<TablePaginationConfig>({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
@ -44,10 +38,11 @@ const SupplierEvaluateResultInfo: React.FC = () => {
|
||||
showTotal: (total) => `共 ${total} 条记录`,
|
||||
});
|
||||
const [searchParams, setSearchParams] =
|
||||
useState<SupplierEvaluate.EvaluateResultDetailSearchParams>({});
|
||||
const [parentRecord, setParentRecord] = useState<SupplierEvaluate.EvaluateResultRecord | null>(
|
||||
useState<API.EvaluateSupplierSearchParams>({});
|
||||
const [parentRecord, setParentRecord] = useState<API.EvaluateTaskRecord | null>(
|
||||
null,
|
||||
);
|
||||
const [evaluateRules, setEvaluateRules] = useState<API.EvaluateRuleItem[]>([]);
|
||||
|
||||
// 品类数据
|
||||
const categoryOptions = [
|
||||
@ -58,12 +53,6 @@ const SupplierEvaluateResultInfo: React.FC = () => {
|
||||
{ label: '医药', value: '医药' },
|
||||
];
|
||||
|
||||
// 评价等级选项
|
||||
const levelOptions = Object.entries(EvaluateLevelText).map(([value, label]) => ({
|
||||
label,
|
||||
value,
|
||||
}));
|
||||
|
||||
// 获取上级页面传递的数据
|
||||
useEffect(() => {
|
||||
if (location.state?.record) {
|
||||
@ -71,12 +60,38 @@ const SupplierEvaluateResultInfo: React.FC = () => {
|
||||
}
|
||||
}, [location]);
|
||||
|
||||
// 模拟获取评价结果详情列表
|
||||
// 获取评价规则列表
|
||||
const fetchEvaluateRules = async () => {
|
||||
try {
|
||||
const response = await getAllEvaluateRules();
|
||||
if (response.success && response.data) {
|
||||
setEvaluateRules(response.data);
|
||||
} else {
|
||||
message.error(response.message || '获取评价规则列表失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取评价规则列表失败:', error);
|
||||
message.error('获取评价规则列表失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 首次加载获取评价规则列表
|
||||
useEffect(() => {
|
||||
fetchEvaluateRules();
|
||||
}, []);
|
||||
|
||||
// 获取评价结果详情列表
|
||||
const fetchResultDetailList = async (
|
||||
current = 1,
|
||||
pageSize = 10,
|
||||
params: SupplierEvaluate.EvaluateResultDetailSearchParams = searchParams,
|
||||
params: API.EvaluateSupplierSearchParams = searchParams,
|
||||
) => {
|
||||
// 确保有评价任务ID
|
||||
if (!parentRecord?.id) {
|
||||
message.error('缺少评价任务ID,无法获取数据');
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新搜索参数状态
|
||||
if (params !== searchParams) {
|
||||
setSearchParams(params);
|
||||
@ -84,77 +99,58 @@ const SupplierEvaluateResultInfo: React.FC = () => {
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
// 模拟API请求
|
||||
setTimeout(() => {
|
||||
// 模拟数据
|
||||
const mockData: SupplierEvaluate.EvaluateResultDetailRecord[] = Array.from({
|
||||
length: 35,
|
||||
}).map((_, index) => {
|
||||
const id = `${index + 1}`;
|
||||
// 构建请求参数
|
||||
const requestParams: API.EvaluateSupplierRequest = {
|
||||
basePageRequest: {
|
||||
pageNo: current,
|
||||
pageSize: pageSize,
|
||||
},
|
||||
evaluateTaskId: parentRecord.id,
|
||||
};
|
||||
|
||||
// 随机选择品类
|
||||
const categoryIndex = Math.floor(Math.random() * categoryOptions.length);
|
||||
// 添加搜索条件
|
||||
if (params.supplierName) {
|
||||
requestParams.supplierName = params.supplierName;
|
||||
}
|
||||
if (params.level) {
|
||||
requestParams.level = params.level;
|
||||
}
|
||||
|
||||
// 随机生成得分和等级
|
||||
const score = Math.floor(Math.random() * 40) + 60; // 60-100分
|
||||
let level;
|
||||
if (score >= 90) {
|
||||
level = EvaluateLevel.EXCELLENT;
|
||||
} else if (score >= 80) {
|
||||
level = EvaluateLevel.GOOD;
|
||||
} else if (score >= 70) {
|
||||
level = EvaluateLevel.AVERAGE;
|
||||
} else {
|
||||
level = EvaluateLevel.POOR;
|
||||
}
|
||||
// 调用接口获取数据
|
||||
const response = await getEvaluateSupplierList(requestParams);
|
||||
if (response.data && response.success) {
|
||||
const { records, total, current: currentPage, size } = response.data;
|
||||
|
||||
return {
|
||||
id,
|
||||
key: id,
|
||||
supplierName: `供应商${index + 1}`,
|
||||
category: categoryOptions[categoryIndex].value,
|
||||
score,
|
||||
level,
|
||||
};
|
||||
});
|
||||
// 处理数据,增加表格需要的key属性
|
||||
const formattedData = records.map(record => ({
|
||||
...record,
|
||||
key: record.id,
|
||||
}));
|
||||
|
||||
// 根据搜索条件过滤
|
||||
let filteredData = [...mockData];
|
||||
if (params.supplierName) {
|
||||
filteredData = filteredData.filter((item) =>
|
||||
item.supplierName.includes(params.supplierName || ''),
|
||||
);
|
||||
}
|
||||
if (params.level) {
|
||||
filteredData = filteredData.filter((item) => item.level === params.level);
|
||||
}
|
||||
|
||||
// 分页
|
||||
const startIndex = (current - 1) * pageSize;
|
||||
const endIndex = startIndex + pageSize;
|
||||
const paginatedData = filteredData.slice(startIndex, endIndex);
|
||||
|
||||
setResultData(paginatedData);
|
||||
setResultData(formattedData);
|
||||
setPagination({
|
||||
...pagination,
|
||||
current,
|
||||
pageSize,
|
||||
total: filteredData.length,
|
||||
current: currentPage,
|
||||
pageSize: size,
|
||||
total,
|
||||
});
|
||||
|
||||
setLoading(false);
|
||||
}, 500);
|
||||
} else {
|
||||
message.error(response.message || '获取评价结果详情列表失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取评价结果详情列表失败:', error);
|
||||
message.error('获取评价结果详情列表失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 首次加载获取数据
|
||||
useEffect(() => {
|
||||
fetchResultDetailList(pagination.current, pagination.pageSize, {});
|
||||
}, []);
|
||||
if (parentRecord?.id) {
|
||||
fetchResultDetailList(pagination.current, pagination.pageSize, {});
|
||||
}
|
||||
}, [parentRecord]);
|
||||
|
||||
// 处理表格分页变化
|
||||
const handleTableChange = (newPagination: TablePaginationConfig) => {
|
||||
@ -178,31 +174,25 @@ const SupplierEvaluateResultInfo: React.FC = () => {
|
||||
};
|
||||
|
||||
// 查看得分明细
|
||||
const handleViewScoreDetail = (record: SupplierEvaluate.EvaluateResultDetailRecord) => {
|
||||
const handleViewScoreDetail = (record: API.EvaluateSupplierRecord) => {
|
||||
history.push({
|
||||
pathname: 'supplierEvaluateResultScoreDetail',
|
||||
state: { record }
|
||||
state: { record, parentRecord }
|
||||
});
|
||||
};
|
||||
|
||||
// 查看打分情况
|
||||
const handleViewScoring = (record: SupplierEvaluate.EvaluateResultDetailRecord) => {
|
||||
const handleViewScoring = (record: API.EvaluateSupplierRecord) => {
|
||||
history.push({
|
||||
pathname: 'supplierEvaluateResultScoreByList',
|
||||
state: { record }
|
||||
state: { record, parentRecord }
|
||||
});
|
||||
};
|
||||
|
||||
// 获取等级标签
|
||||
const getLevelTag = (level: string) => {
|
||||
const text = EvaluateLevelText[level as keyof typeof EvaluateLevelText] || '未知等级';
|
||||
return text;
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '序号',
|
||||
render: (_: any, __: SupplierEvaluate.EvaluateResultDetailRecord, index: number) =>
|
||||
render: (_: any, __: API.EvaluateSupplierRecord, index: number) =>
|
||||
(pagination.current! - 1) * pagination.pageSize! + index + 1,
|
||||
width: 80,
|
||||
},
|
||||
@ -228,24 +218,23 @@ const SupplierEvaluateResultInfo: React.FC = () => {
|
||||
},
|
||||
{
|
||||
title: '评价得分',
|
||||
dataIndex: 'score',
|
||||
key: 'score',
|
||||
dataIndex: 'reviewScore',
|
||||
key: 'reviewScore',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '评价等级',
|
||||
dataIndex: 'level',
|
||||
key: 'level',
|
||||
dataIndex: 'levelName',
|
||||
key: 'levelName',
|
||||
width: 100,
|
||||
align: 'center' as const,
|
||||
render: (level: string) => getLevelTag(level),
|
||||
align: 'center' as const
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 180,
|
||||
align: 'center' as const,
|
||||
render: (_: unknown, record: SupplierEvaluate.EvaluateResultDetailRecord) => (
|
||||
render: (_: unknown, record: API.EvaluateSupplierRecord) => (
|
||||
<Space size="middle">
|
||||
<Button
|
||||
type="link"
|
||||
@ -270,9 +259,9 @@ const SupplierEvaluateResultInfo: React.FC = () => {
|
||||
</Form.Item>
|
||||
<Form.Item name="level" label="评价等级">
|
||||
<Select placeholder="请选择评价等级" allowClear style={{ width: 150 }}>
|
||||
{levelOptions.map((option) => (
|
||||
<Option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
{evaluateRules.map((rule) => (
|
||||
<Option key={rule.id} value={rule.levelName}>
|
||||
{rule.levelName}
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
|
Reference in New Issue
Block a user