Files
fe_supplier_frontend/src/pages/supplierEvaluateManage/supplierEvaluateResult/supplierEvaluateResultByZb.tsx

149 lines
4.5 KiB
TypeScript
Raw Normal View History

2025-06-23 19:15:13 +08:00
// 评价结果详情
import React, { useState, useEffect } from 'react';
2025-06-24 14:00:51 +08:00
import { Card, Button, message, Typography } from 'antd';
2025-06-23 19:15:13 +08:00
import { ArrowLeftOutlined } from '@ant-design/icons';
import { history, useLocation } from 'umi';
2025-06-24 14:00:51 +08:00
import ScoreEvaluationTable from '@/components/ScoreEvaluationTable';
2025-06-23 19:15:13 +08:00
import styles from './supplierEvaluateResult.less';
2025-06-24 14:00:51 +08:00
import { getIndicator } from '@/servers/api/supplierEvaluate';
const { Title } = Typography;
// 评价打分详情数据接口
interface IndicatorDetailData {
category: string;
name: string;
taskIndicatorVo: {
baseIndicator: string;
indicatorDesc: string;
score: string;
subIndicator: {
id: string;
remark: string | null;
scoreNum: string | null;
starIndicator: string;
stId: string;
subIndicator: string;
subScore: string;
}[];
}[];
}
2025-06-23 19:15:13 +08:00
const SupplierEvaluateResultByZb: React.FC = () => {
2025-06-24 14:00:51 +08:00
const location = useLocation<{
record: API.EvaluateScoreIndicator;
parentRecord: API.EvaluateTaskRecord;
supplierRecord: API.EvaluateSupplierRecord;
scoreDetail: API.EvaluateScoreData;
}>();
2025-06-23 19:15:13 +08:00
const [loading, setLoading] = useState<boolean>(false);
2025-06-24 14:00:51 +08:00
const [scoreRecord, setScoreRecord] = useState<API.EvaluateScoreIndicator | null>(null);
const [parentRecord, setParentRecord] = useState<API.EvaluateTaskRecord | null>(null);
const [supplierRecord, setSupplierRecord] = useState<API.EvaluateSupplierRecord | null>(null);
const [indicatorDetail, setIndicatorDetail] = useState<IndicatorDetailData | null>(null);
2025-06-23 19:15:13 +08:00
2025-06-24 14:00:51 +08:00
// 获取上级页面传递的数据
useEffect(() => {
if (location.state?.record) {
setScoreRecord(location.state.record);
}
if (location.state?.parentRecord) {
setParentRecord(location.state.parentRecord);
}
if (location.state?.supplierRecord) {
setSupplierRecord(location.state.supplierRecord);
}
if (location.state?.scoreDetail) {
// 如果有上级页面传递的评分明细数据,暂存下来
// 稍后我们仍然会通过API获取最新数据
}
}, [location]);
2025-06-23 19:15:13 +08:00
2025-06-24 14:00:51 +08:00
// 获取评价打分详情数据
const fetchIndicatorDetail = async () => {
if (!scoreRecord?.id) {
message.error('缺少评价记录ID无法获取数据');
return;
}
2025-06-23 19:15:13 +08:00
2025-06-24 14:00:51 +08:00
setLoading(true);
try {
const response = await getIndicator(scoreRecord.id);
if (response.data && response.success) {
setIndicatorDetail(response.data);
} else {
message.error(response.message || '获取评价打分详情失败');
}
2025-06-23 19:15:13 +08:00
} catch (error) {
2025-06-24 14:00:51 +08:00
console.error('获取评价打分详情失败:', error);
message.error('获取评价打分详情失败');
} finally {
2025-06-23 19:15:13 +08:00
setLoading(false);
}
};
2025-06-24 14:00:51 +08:00
// 监听scoreRecord变化获取评价详情数据
2025-06-23 19:15:13 +08:00
useEffect(() => {
2025-06-24 14:00:51 +08:00
if (scoreRecord?.id) {
fetchIndicatorDetail();
2025-06-23 19:15:13 +08:00
}
2025-06-24 14:00:51 +08:00
}, [scoreRecord]);
2025-06-23 19:15:13 +08:00
// 返回上一页
const handleBack = () => {
history.goBack();
};
2025-06-24 14:00:51 +08:00
// 将API数据转换为ScoreEvaluationTable组件所需的格式
const formatDataForScoreTable = () => {
if (!indicatorDetail?.taskIndicatorVo) return [];
return indicatorDetail.taskIndicatorVo.map(indicator => {
return {
baseIndicator: indicator.baseIndicator,
descIndicator: indicator.indicatorDesc,
score: indicator.score,
indicatorNdList: indicator.subIndicator?.map(subItem => {
return {
subIndicator: subItem.subIndicator,
score: subItem.subScore,
isStar: subItem.starIndicator,
id: subItem.id,
actualScore: subItem.scoreNum || '',
remark: subItem.remark || ''
};
}) || []
};
2025-06-23 19:15:13 +08:00
});
};
2025-06-24 14:00:51 +08:00
if (loading && !indicatorDetail) {
2025-06-23 19:15:13 +08:00
return <div className="common-container">...</div>;
}
2025-06-24 14:00:51 +08:00
const supplierName = supplierRecord?.supplierName || indicatorDetail?.name || '供应商';
2025-06-23 19:15:13 +08:00
return (
<div className="common-container">
2025-06-24 14:00:51 +08:00
<div className="filter-action-row">
<Title level={4} className={styles.pageTitle}>
{supplierName} -
</Title>
2025-06-23 19:15:13 +08:00
<Button type="link" icon={<ArrowLeftOutlined />} onClick={handleBack}>
</Button>
</div>
2025-06-24 14:00:51 +08:00
<Card title="评价指标详情" bordered={false} className={styles.detailCard}>
<ScoreEvaluationTable
value={formatDataForScoreTable()}
isDetail={true}
loading={loading}
/>
2025-06-23 19:15:13 +08:00
</Card>
</div>
);
};
export default SupplierEvaluateResultByZb;