对接评价结果接口
This commit is contained in:
@ -1,202 +1,145 @@
|
||||
// 评价结果详情
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Card, Form, Button, Descriptions, Divider, Row, Col, Tabs, message } from 'antd';
|
||||
import { Card, Button, message, Typography } from 'antd';
|
||||
import { ArrowLeftOutlined } from '@ant-design/icons';
|
||||
import { history, useLocation } from 'umi';
|
||||
import { EvaluateLevel, EvaluateLevelText } from '@/dicts/supplierTemplateDict';
|
||||
import GeneralEvaluation from './components/GeneralEvaluation';
|
||||
import TechnicalEvaluation from './components/TechnicalEvaluation';
|
||||
import ScoreEvaluationTable from '@/components/ScoreEvaluationTable';
|
||||
import styles from './supplierEvaluateResult.less';
|
||||
import { getIndicator } from '@/servers/api/supplierEvaluate';
|
||||
|
||||
const { TabPane } = Tabs;
|
||||
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;
|
||||
}[];
|
||||
}[];
|
||||
}
|
||||
|
||||
const SupplierEvaluateResultByZb: React.FC = () => {
|
||||
const location = useLocation<{ record: any }>();
|
||||
const location = useLocation<{
|
||||
record: API.EvaluateScoreIndicator;
|
||||
parentRecord: API.EvaluateTaskRecord;
|
||||
supplierRecord: API.EvaluateSupplierRecord;
|
||||
scoreDetail: API.EvaluateScoreData;
|
||||
}>();
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [scoreRecord, setScoreRecord] = useState<any>(null);
|
||||
const [evaluationData, setEvaluationData] = useState<{
|
||||
general: any[];
|
||||
technical: any[];
|
||||
}>({
|
||||
general: [],
|
||||
technical: [],
|
||||
});
|
||||
|
||||
// 模拟获取评价详情数据
|
||||
const fetchEvaluationData = (record: any) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// 模拟API请求
|
||||
setTimeout(() => {
|
||||
// 模拟通用评价数据
|
||||
const generalData = [
|
||||
{
|
||||
id: '1',
|
||||
firstIndex: '质量管理',
|
||||
firstDescription: '供应商质量管理体系评价',
|
||||
secondIndex: '质量管理体系认证',
|
||||
secondDescription: '是否通过ISO9001认证',
|
||||
score: 9,
|
||||
weight: 0.1,
|
||||
weightedScore: 0.9,
|
||||
comment: '已通过ISO9001认证,证书有效',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
firstIndex: '质量管理',
|
||||
firstDescription: '供应商质量管理体系评价',
|
||||
secondIndex: '质量控制流程',
|
||||
secondDescription: '是否建立完善的质量控制流程',
|
||||
score: 8,
|
||||
weight: 0.1,
|
||||
weightedScore: 0.8,
|
||||
comment: '质量控制流程完善,但执行记录不够完整',
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
firstIndex: '交付能力',
|
||||
firstDescription: '供应商交付能力评价',
|
||||
secondIndex: '准时交付率',
|
||||
secondDescription: '过去一年准时交付率评价',
|
||||
score: 9.5,
|
||||
weight: 0.15,
|
||||
weightedScore: 1.425,
|
||||
comment: '准时交付率98%,表现优秀',
|
||||
},
|
||||
];
|
||||
|
||||
// 模拟技术评价数据
|
||||
const technicalData = [
|
||||
{
|
||||
id: '1',
|
||||
firstIndex: '技术能力',
|
||||
firstDescription: '供应商技术研发能力评价',
|
||||
secondIndex: '研发投入',
|
||||
secondDescription: '研发投入占营业额比例',
|
||||
score: 8.5,
|
||||
weight: 0.1,
|
||||
weightedScore: 0.85,
|
||||
comment: '研发投入占营业额5%,符合行业平均水平',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
firstIndex: '技术能力',
|
||||
firstDescription: '供应商技术研发能力评价',
|
||||
secondIndex: '专利数量',
|
||||
secondDescription: '拥有专利数量评价',
|
||||
score: 9,
|
||||
weight: 0.05,
|
||||
weightedScore: 0.45,
|
||||
comment: '拥有15项有效专利,其中发明专利5项',
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
firstIndex: '设备设施',
|
||||
firstDescription: '供应商设备设施评价',
|
||||
secondIndex: '设备先进性',
|
||||
secondDescription: '生产设备先进程度评价',
|
||||
score: 8,
|
||||
weight: 0.1,
|
||||
weightedScore: 0.8,
|
||||
comment: '主要生产设备较为先进,但部分设备需要更新',
|
||||
},
|
||||
];
|
||||
|
||||
setEvaluationData({
|
||||
general: generalData,
|
||||
technical: technicalData,
|
||||
});
|
||||
setLoading(false);
|
||||
}, 500);
|
||||
} catch (error) {
|
||||
console.error('获取评价详情数据失败:', error);
|
||||
message.error('获取评价详情数据失败');
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
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);
|
||||
|
||||
// 获取上级页面传递的数据
|
||||
useEffect(() => {
|
||||
if (location.state?.record) {
|
||||
setScoreRecord(location.state.record);
|
||||
// 模拟获取评价详情数据
|
||||
fetchEvaluationData(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]);
|
||||
|
||||
// 获取评价打分详情数据
|
||||
const fetchIndicatorDetail = async () => {
|
||||
if (!scoreRecord?.id) {
|
||||
message.error('缺少评价记录ID,无法获取数据');
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await getIndicator(scoreRecord.id);
|
||||
if (response.data && response.success) {
|
||||
setIndicatorDetail(response.data);
|
||||
} else {
|
||||
message.error(response.message || '获取评价打分详情失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取评价打分详情失败:', error);
|
||||
message.error('获取评价打分详情失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 监听scoreRecord变化,获取评价详情数据
|
||||
useEffect(() => {
|
||||
if (scoreRecord?.id) {
|
||||
fetchIndicatorDetail();
|
||||
}
|
||||
}, [scoreRecord]);
|
||||
|
||||
// 返回上一页
|
||||
const handleBack = () => {
|
||||
history.goBack();
|
||||
};
|
||||
|
||||
// 计算总得分
|
||||
const calculateTotalScore = () => {
|
||||
let totalScore = 0;
|
||||
let totalWeight = 0;
|
||||
// 将API数据转换为ScoreEvaluationTable组件所需的格式
|
||||
const formatDataForScoreTable = () => {
|
||||
if (!indicatorDetail?.taskIndicatorVo) return [];
|
||||
|
||||
// 计算通用评价得分
|
||||
evaluationData.general.forEach((item: any) => {
|
||||
totalScore += item.weightedScore;
|
||||
totalWeight += item.weight;
|
||||
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 || ''
|
||||
};
|
||||
}) || []
|
||||
};
|
||||
});
|
||||
|
||||
// 计算技术评价得分
|
||||
evaluationData.technical.forEach((item: any) => {
|
||||
totalScore += item.weightedScore;
|
||||
totalWeight += item.weight;
|
||||
});
|
||||
|
||||
// 如果权重总和不为0,则计算加权平均分
|
||||
if (totalWeight > 0) {
|
||||
return (totalScore / totalWeight).toFixed(2);
|
||||
}
|
||||
|
||||
return '0.00';
|
||||
};
|
||||
|
||||
// 获取评价等级
|
||||
const getEvaluateLevel = (score: number) => {
|
||||
if (score >= 90) {
|
||||
return EvaluateLevelText[EvaluateLevel.EXCELLENT];
|
||||
} else if (score >= 80) {
|
||||
return EvaluateLevelText[EvaluateLevel.GOOD];
|
||||
} else if (score >= 70) {
|
||||
return EvaluateLevelText[EvaluateLevel.AVERAGE];
|
||||
} else {
|
||||
return EvaluateLevelText[EvaluateLevel.POOR];
|
||||
}
|
||||
};
|
||||
|
||||
if (!scoreRecord) {
|
||||
if (loading && !indicatorDetail) {
|
||||
return <div className="common-container">加载中...</div>;
|
||||
}
|
||||
|
||||
const supplierName = supplierRecord?.supplierName || indicatorDetail?.name || '供应商';
|
||||
|
||||
return (
|
||||
<div className="common-container">
|
||||
<div className="action-row">
|
||||
<div className="filter-action-row">
|
||||
<Title level={4} className={styles.pageTitle}>
|
||||
{supplierName} - 评价详情
|
||||
</Title>
|
||||
<Button type="link" icon={<ArrowLeftOutlined />} onClick={handleBack}>
|
||||
返回
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Card title="评价基本信息" bordered={false} className={styles.infoCard}>
|
||||
<Descriptions column={3}>
|
||||
<Descriptions.Item label="供应商名称">{scoreRecord.supplierName}</Descriptions.Item>
|
||||
<Descriptions.Item label="品类">{scoreRecord.category}</Descriptions.Item>
|
||||
<Descriptions.Item label="评价单位">{scoreRecord.evaluateUnit}</Descriptions.Item>
|
||||
<Descriptions.Item label="评价人员">{scoreRecord.evaluator}</Descriptions.Item>
|
||||
<Descriptions.Item label="评价时间">{scoreRecord.evaluateTime}</Descriptions.Item>
|
||||
<Descriptions.Item label="评价得分">{scoreRecord.score}</Descriptions.Item>
|
||||
<Descriptions.Item label="评价等级">
|
||||
{getEvaluateLevel(scoreRecord.score)}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</Card>
|
||||
|
||||
<Card title="评价详情" bordered={false} className={styles.detailCard}>
|
||||
<GeneralEvaluation supplierName={scoreRecord.supplierName} />
|
||||
<Card title="评价指标详情" bordered={false} className={styles.detailCard}>
|
||||
<ScoreEvaluationTable
|
||||
value={formatDataForScoreTable()}
|
||||
isDetail={true}
|
||||
loading={loading}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
|
Reference in New Issue
Block a user