PurchaseBar.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import React from 'react';
  2. import {
  3. ImageBackground,
  4. StyleSheet,
  5. Text,
  6. TouchableOpacity,
  7. View,
  8. } from 'react-native';
  9. import { Images } from '@/constants/images';
  10. // Helper to determine background image based on type
  11. const getBtnBg = (type: 'one' | 'five' | 'many') => {
  12. switch (type) {
  13. case 'one': return Images.common.butBgV;
  14. case 'five': return Images.common.butBgL;
  15. case 'many': return Images.common.butBgH;
  16. default: return Images.common.butBgV;
  17. }
  18. };
  19. interface PurchaseBarProps {
  20. price: number;
  21. specialPrice?: number;
  22. specialPriceFive?: number;
  23. onBuy: (count: number) => void;
  24. onBuyMany: () => void;
  25. }
  26. export default function PurchaseBar({ price, specialPrice, specialPriceFive, onBuy, onBuyMany }: PurchaseBarProps) {
  27. return (
  28. <ImageBackground
  29. source={{ uri: Images.box.detail.boxDetailBott }}
  30. style={styles.container}
  31. resizeMode="stretch"
  32. >
  33. <View style={styles.btnRow}>
  34. {/* Buy One */}
  35. <TouchableOpacity onPress={() => onBuy(1)} style={styles.btnWrapper}>
  36. <ImageBackground source={{ uri: getBtnBg('one') }} style={styles.btnBg} resizeMode="stretch">
  37. <Text style={styles.btnTitle}>购买一盒</Text>
  38. <Text style={styles.btnPrice}>
  39. (¥{specialPrice ?? price})
  40. </Text>
  41. </ImageBackground>
  42. </TouchableOpacity>
  43. {/* Buy Five */}
  44. <TouchableOpacity onPress={() => onBuy(5)} style={styles.btnWrapper}>
  45. <ImageBackground source={{ uri: getBtnBg('five') }} style={styles.btnBg} resizeMode="stretch">
  46. <Text style={styles.btnTitle}>购买五盒</Text>
  47. <Text style={styles.btnPrice}>
  48. (¥{specialPriceFive ?? price * 5})
  49. </Text>
  50. </ImageBackground>
  51. </TouchableOpacity>
  52. {/* Buy Many */}
  53. <TouchableOpacity onPress={onBuyMany} style={styles.btnWrapper}>
  54. <ImageBackground source={{ uri: getBtnBg('many') }} style={styles.btnBg} resizeMode="stretch">
  55. <Text style={styles.btnTitle}>购买多盒</Text>
  56. </ImageBackground>
  57. </TouchableOpacity>
  58. </View>
  59. </ImageBackground>
  60. );
  61. }
  62. const styles = StyleSheet.create({
  63. container: {
  64. width: '100%',
  65. height: 100, // Adjust based on background aspect ratio
  66. justifyContent: 'center',
  67. paddingBottom: 20, // Safe area padding simulation
  68. },
  69. btnRow: {
  70. flexDirection: 'row',
  71. justifyContent: 'space-around',
  72. alignItems: 'center',
  73. paddingHorizontal: 10,
  74. },
  75. btnWrapper: {
  76. flex: 1,
  77. height: 50,
  78. marginHorizontal: 5,
  79. },
  80. btnBg: {
  81. width: '100%',
  82. height: '100%',
  83. justifyContent: 'center',
  84. alignItems: 'center',
  85. },
  86. btnTitle: {
  87. color: '#fff',
  88. fontSize: 14,
  89. fontWeight: 'bold',
  90. textShadowColor: '#000',
  91. textShadowOffset: { width: 1, height: 1 },
  92. textShadowRadius: 1,
  93. },
  94. btnPrice: {
  95. color: '#fff',
  96. fontSize: 10,
  97. fontWeight: 'bold',
  98. textShadowColor: '#000',
  99. textShadowOffset: { width: 1, height: 1 },
  100. textShadowRadius: 1,
  101. }
  102. });