import { Ionicons } from '@expo/vector-icons';
import { useRouter } from 'expo-router';
import { useState } from 'react';
import {
ActivityIndicator,
Pressable,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import Svg, { Line, Path, Polygon, Text as SvgText } from 'react-native-svg';
import { useJobEvaluationEmptyState, useJobEvaluations } from '../src/hooks';
import { colors } from '../src/theme';
import type {
JobEvaluationDimension,
JobEvaluationEmptyState,
JobEvaluationEmptyTab,
JobEvaluationSummary,
JobReview,
} from '../src/types';
/* ===================== 子组件:顶部导航 ===================== */
function Header({ onBack }: { onBack: () => void }) {
return (
岗位评价管理
);
}
/* ===================== 子组件:综合评分卡 ===================== */
function OverallScoreCard({
score,
change,
reviewCount,
positiveRate,
replyRate,
complaintRate,
}: {
score: number;
change: number;
reviewCount: number;
positiveRate: number;
replyRate: number;
complaintRate: number;
}) {
const up = change >= 0;
return (
{score.toFixed(1)}
企业综合评分
较上期 {up ? '+' : ''}{change.toFixed(1)}
{reviewCount} 条评价
{positiveRate}%
好评率
{replyRate}%
回复率
{complaintRate}%
投诉率
);
}
/* ===================== 子组件:趋势折线图 ===================== */
function TrendChart({ trend }: { trend: { month: string; score: number }[] }) {
const width = 320;
const height = 120;
const padding = { top: 16, right: 24, bottom: 24, left: 32 };
const chartW = width - padding.left - padding.right;
const chartH = height - padding.top - padding.bottom;
const minScore = 4.0;
const maxScore = 5.0;
const points = trend.map((t, i) => {
const x = padding.left + (i / (trend.length - 1)) * chartW;
const y = padding.top + chartH - ((t.score - minScore) / (maxScore - minScore)) * chartH;
return { x, y, score: t.score, month: t.month };
});
const pathD = points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ');
return (
评分趋势
);
}
/* ===================== 子组件:雷达图 ===================== */
function RadarChart({ dimensions }: { dimensions: JobEvaluationDimension[] }) {
const size = 200;
const center = size / 2;
const radius = 70;
const angleStep = (Math.PI * 2) / dimensions.length;
const points = dimensions.map((d, i) => {
const angle = i * angleStep - Math.PI / 2;
const r = (d.score / d.maxScore) * radius;
const x = center + r * Math.cos(angle);
const y = center + r * Math.sin(angle);
return { x, y, label: d.name };
});
const axisPoints = dimensions.map((_, i) => {
const angle = i * angleStep - Math.PI / 2;
return {
x: center + radius * Math.cos(angle),
y: center + radius * Math.sin(angle),
label: dimensions[i].name,
};
});
const polygonPoints = points.map((p) => `${p.x},${p.y}`).join(' ');
return (
六维评分
);
}
/* ===================== 子组件:岗位评分列表 ===================== */
function JobScoreList({ jobs }: { jobs: JobEvaluationSummary[] }) {
return (
各岗位评分
{jobs.map((job) => {
const up = job.change >= 0;
return (
{job.positionName}
{job.department} · {job.reviewCount} 条评价
{job.score.toFixed(1)}
{up ? '↑' : '↓'} {Math.abs(job.change).toFixed(1)}
);
})}
);
}
/* ===================== 子组件:空状态 Tab 栏 ===================== */
function EmptyTabBar({
tabs,
active,
onChange,
}: {
tabs: JobEvaluationEmptyTab[];
active: string;
onChange: (key: string) => void;
}) {
return (
{tabs.map((tab) => {
const isActive = tab.key === active;
return (
onChange(tab.key)}
>
{tab.label}
({tab.count})
);
})}
);
}
/* ===================== 子组件:空状态 ===================== */
function EmptyState({ state }: { state: JobEvaluationEmptyState }) {
const [activeTab, setActiveTab] = useState('all');
return (
暂无评分数据
{state.emptyTitle}
{state.emptySubtitle}
如何获得更多好评?
{state.tips.map((tip, index) => (
{tip}
))}
);
}
/* ===================== 子组件:评价列表 ===================== */
function ReviewList({ reviews }: { reviews: JobReview[] }) {
return (
最新评价
{reviews.map((review) => (
{review.userName}
{review.userRole}
{review.rating}.0
{review.content}
{review.tags.map((tag) => (
{tag}
))}
{review.date}
{review.replied ? '已回复' : '回复'}
))}
);
}
/* ===================== 页面主组件 ===================== */
export default function JobEvaluationsScreen() {
const router = useRouter();
const { management, loading: dataLoading, error: dataError } = useJobEvaluations();
const { state: emptyState, loading: emptyLoading, error: emptyError } = useJobEvaluationEmptyState();
const loading = dataLoading || emptyLoading;
const error = dataError || emptyError;
if (loading) {
return (
);
}
if (error) {
return (
加载失败,请稍后重试
);
}
const showEmpty = emptyState?.hasData === false;
return (
{showEmpty && emptyState ? (
) : management ? (
<>
>
) : null}
);
}
/* ===================== 样式 ===================== */
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: colors.pageBg,
},
loadingContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: colors.pageBg,
},
errorText: {
color: colors.textSecondary,
fontSize: 14,
},
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: 16,
paddingVertical: 12,
backgroundColor: colors.white,
borderBottomWidth: 1,
borderBottomColor: colors.borderLight,
},
headerBtn: {
width: 36,
height: 36,
justifyContent: 'center',
alignItems: 'center',
},
headerTitle: {
fontSize: 17,
fontWeight: '600',
color: colors.textPrimary,
},
scroll: {
flex: 1,
},
scrollContent: {
padding: 16,
paddingBottom: 32,
},
scoreCard: {
backgroundColor: colors.primary,
borderRadius: 16,
padding: 20,
marginBottom: 16,
},
scoreMain: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 20,
},
scoreValue: {
fontSize: 42,
fontWeight: '700',
color: colors.white,
},
scoreLabel: {
fontSize: 14,
color: colors.white,
opacity: 0.9,
},
scoreMeta: {
alignItems: 'flex-end',
},
scoreChange: {
fontSize: 14,
fontWeight: '600',
marginBottom: 4,
},
scoreCount: {
fontSize: 13,
color: colors.white,
opacity: 0.9,
},
rateRow: {
flexDirection: 'row',
borderTopWidth: 1,
borderTopColor: 'rgba(255,255,255,0.2)',
paddingTop: 16,
},
rateItem: {
flex: 1,
alignItems: 'center',
},
rateValue: {
fontSize: 18,
fontWeight: '700',
color: colors.white,
marginBottom: 2,
},
rateLabel: {
fontSize: 12,
color: colors.white,
opacity: 0.9,
},
card: {
backgroundColor: colors.white,
borderRadius: 16,
padding: 16,
marginBottom: 16,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.04,
shadowRadius: 6,
elevation: 2,
},
cardTitle: {
fontSize: 16,
fontWeight: '700',
color: colors.textPrimary,
marginBottom: 12,
},
chartCard: {
backgroundColor: colors.white,
borderRadius: 16,
padding: 16,
marginBottom: 16,
alignItems: 'center',
},
radarCard: {
backgroundColor: colors.white,
borderRadius: 16,
padding: 16,
marginBottom: 16,
alignItems: 'center',
},
jobRow: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingVertical: 12,
borderBottomWidth: 1,
borderBottomColor: colors.borderLight,
},
jobInfo: {
flex: 1,
},
jobName: {
fontSize: 15,
fontWeight: '600',
color: colors.textPrimary,
marginBottom: 2,
},
jobDepartment: {
fontSize: 12,
color: colors.textSecondary,
},
jobScoreBox: {
alignItems: 'flex-end',
},
jobScore: {
fontSize: 18,
fontWeight: '700',
color: colors.primary,
},
jobChange: {
fontSize: 11,
fontWeight: '500',
marginTop: 2,
},
reviewItem: {
paddingVertical: 14,
borderBottomWidth: 1,
borderBottomColor: colors.borderLight,
},
reviewHeader: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 8,
},
reviewUser: {
flexDirection: 'row',
alignItems: 'center',
},
reviewName: {
fontSize: 14,
fontWeight: '600',
color: colors.textPrimary,
marginRight: 8,
},
reviewRole: {
fontSize: 12,
color: colors.textSecondary,
},
reviewRating: {
flexDirection: 'row',
alignItems: 'center',
},
reviewScore: {
fontSize: 14,
fontWeight: '700',
color: colors.compareOrange,
marginRight: 4,
},
reviewContent: {
fontSize: 14,
color: colors.textPrimary,
lineHeight: 20,
marginBottom: 10,
},
tagRow: {
flexDirection: 'row',
flexWrap: 'wrap',
marginBottom: 10,
},
reviewTag: {
paddingHorizontal: 8,
paddingVertical: 4,
borderRadius: 12,
backgroundColor: colors.primaryLight,
marginRight: 8,
marginBottom: 6,
},
reviewTagText: {
fontSize: 11,
color: colors.primaryText,
},
reviewFooter: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
reviewDate: {
fontSize: 12,
color: colors.textHint,
},
replyBtn: {
paddingHorizontal: 12,
paddingVertical: 5,
borderRadius: 12,
backgroundColor: colors.primaryLight,
},
replyText: {
fontSize: 12,
color: colors.primary,
fontWeight: '500',
},
/* ---- 空状态 ---- */
emptyWrapper: {
marginBottom: 16,
},
emptyTabContent: {
paddingHorizontal: 8,
paddingVertical: 12,
gap: 8,
},
emptyTabItem: {
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 12,
paddingVertical: 6,
borderRadius: 16,
backgroundColor: colors.pageBg,
borderWidth: 1,
borderColor: colors.border,
},
emptyTabItemActive: {
backgroundColor: colors.primaryLight,
borderColor: colors.primary,
},
emptyTabLabel: {
fontSize: 13,
color: colors.textSecondary,
},
emptyTabLabelActive: {
color: colors.primary,
fontWeight: '600',
},
emptyTabCount: {
fontSize: 12,
color: colors.textHint,
marginLeft: 2,
},
emptyTabCountActive: {
color: colors.primary,
},
emptyCard: {
backgroundColor: colors.white,
borderRadius: 16,
padding: 28,
alignItems: 'center',
marginTop: 8,
},
emptyIconWrap: {
width: 88,
height: 88,
borderRadius: 44,
backgroundColor: colors.primaryLight,
alignItems: 'center',
justifyContent: 'center',
marginBottom: 16,
},
emptyMainTitle: {
fontSize: 18,
fontWeight: '700',
color: colors.textPrimary,
marginBottom: 8,
},
emptyTitle: {
fontSize: 16,
fontWeight: '600',
color: colors.textPrimary,
marginBottom: 6,
},
emptySubtitle: {
fontSize: 13,
color: colors.textSecondary,
textAlign: 'center',
lineHeight: 20,
marginBottom: 20,
},
tipCard: {
width: '100%',
backgroundColor: colors.actionLight,
borderRadius: 12,
padding: 16,
alignItems: 'flex-start',
},
tipHeader: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 12,
},
tipHeaderTitle: {
fontSize: 14,
fontWeight: '700',
color: colors.actionText,
marginLeft: 8,
},
tipRow: {
flexDirection: 'row',
alignItems: 'flex-start',
marginBottom: 10,
},
tipDot: {
width: 6,
height: 6,
borderRadius: 3,
backgroundColor: colors.action,
marginTop: 6,
marginRight: 10,
},
tipText: {
flex: 1,
fontSize: 13,
color: colors.textPrimary,
lineHeight: 18,
},
});