GoodsList.tsx 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { GoodsItem } from '@/services/mall';
  2. import React from 'react';
  3. import { StyleSheet, Text, View } from 'react-native';
  4. import { GoodsCard } from './GoodsCard';
  5. interface GoodsListProps {
  6. data: GoodsItem[];
  7. onItemPress?: (item: GoodsItem) => void;
  8. }
  9. export function GoodsList({ data, onItemPress }: GoodsListProps) {
  10. if (!data || data.length === 0) {
  11. return (
  12. <View style={styles.empty}>
  13. <Text style={styles.emptyText}>暂无商品</Text>
  14. </View>
  15. );
  16. }
  17. return (
  18. <View style={styles.container}>
  19. {data.map((item) => (
  20. <GoodsCard key={item.id} data={item} onPress={onItemPress} />
  21. ))}
  22. </View>
  23. );
  24. }
  25. const styles = StyleSheet.create({
  26. container: {
  27. flexDirection: 'row',
  28. flexWrap: 'wrap',
  29. justifyContent: 'space-between',
  30. marginHorizontal: 7,
  31. marginTop: 10,
  32. paddingBottom: 100,
  33. },
  34. empty: {
  35. paddingVertical: 50,
  36. alignItems: 'center',
  37. },
  38. emptyText: {
  39. color: '#666',
  40. fontSize: 14,
  41. },
  42. });