import { Colors } from '@/constants/Colors'; import { WeightHistoryItem } from '@/store/userSlice'; import { Ionicons } from '@expo/vector-icons'; import dayjs from 'dayjs'; import React, { useRef } from 'react'; import { Alert, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { Swipeable } from 'react-native-gesture-handler'; interface WeightRecordCardProps { record: WeightHistoryItem; onPress?: (record: WeightHistoryItem) => void; onDelete?: (recordId: string) => void; weightChange?: number; } export const WeightRecordCard: React.FC = ({ record, onPress, onDelete, weightChange = 0 }) => { const swipeableRef = useRef(null); // 处理删除操作 const handleDelete = () => { Alert.alert( '确认删除', `确定要删除这条体重记录吗?此操作无法撤销。`, [ { text: '取消', style: 'cancel', }, { text: '删除', style: 'destructive', onPress: () => { const recordId = record.id || record.createdAt; onDelete?.(recordId); swipeableRef.current?.close(); }, }, ] ); }; // 渲染删除按钮 const renderRightActions = () => { return ( 删除 ); }; return ( onPress?.(record)} activeOpacity={0.7} > {dayjs(record.createdAt).format('MM月DD日 HH:mm')} onPress?.(record)} > 体重: {record.weight}kg {Math.abs(weightChange) > 0 && ( {Math.abs(weightChange).toFixed(1)} )} ); }; const styles = StyleSheet.create({ recordCard: { backgroundColor: '#FFFFFF', borderRadius: 16, padding: 20, marginBottom: 12, shadowColor: '#000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.06, shadowRadius: 8, elevation: 2, }, recordHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12, }, recordDateTime: { fontSize: 14, color: '#687076', fontWeight: '500', }, recordEditButton: { padding: 6, borderRadius: 8, backgroundColor: 'rgba(255, 149, 0, 0.1)', }, recordContent: { flexDirection: 'row', alignItems: 'center', }, recordWeightLabel: { fontSize: 16, color: '#687076', fontWeight: '500', }, recordWeightValue: { fontSize: 18, fontWeight: '700', color: '#192126', marginLeft: 4, flex: 1, }, weightChangeTag: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 8, paddingVertical: 4, borderRadius: 12, marginLeft: 12, }, weightChangeText: { fontSize: 12, fontWeight: '600', marginLeft: 2, }, deleteButton: { backgroundColor: '#EF4444', justifyContent: 'center', alignItems: 'center', width: 80, borderRadius: 16, marginBottom: 12, marginLeft: 8, }, deleteButtonText: { color: '#FFFFFF', fontSize: 12, fontWeight: '600', marginTop: 4, }, });