| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import React from 'react';
- import {
- ImageBackground,
- StyleSheet,
- Text,
- TouchableOpacity,
- View,
- } from 'react-native';
- import { Images } from '@/constants/images';
- // Helper to determine background image based on type
- const getBtnBg = (type: 'one' | 'five' | 'many') => {
- switch (type) {
- case 'one': return Images.common.butBgV;
- case 'five': return Images.common.butBgL;
- case 'many': return Images.common.butBgH;
- default: return Images.common.butBgV;
- }
- };
- interface PurchaseBarProps {
- price: number;
- specialPrice?: number;
- specialPriceFive?: number;
- onBuy: (count: number) => void;
- onBuyMany: () => void;
- }
- export default function PurchaseBar({ price, specialPrice, specialPriceFive, onBuy, onBuyMany }: PurchaseBarProps) {
- return (
- <ImageBackground
- source={{ uri: Images.box.detail.boxDetailBott }}
- style={styles.container}
- resizeMode="stretch"
- >
- <View style={styles.btnRow}>
- {/* Buy One */}
- <TouchableOpacity onPress={() => onBuy(1)} style={styles.btnWrapper}>
- <ImageBackground source={{ uri: getBtnBg('one') }} style={styles.btnBg} resizeMode="stretch">
- <Text style={styles.btnTitle}>购买一盒</Text>
- <Text style={styles.btnPrice}>
- (¥{specialPrice ?? price})
- </Text>
- </ImageBackground>
- </TouchableOpacity>
- {/* Buy Five */}
- <TouchableOpacity onPress={() => onBuy(5)} style={styles.btnWrapper}>
- <ImageBackground source={{ uri: getBtnBg('five') }} style={styles.btnBg} resizeMode="stretch">
- <Text style={styles.btnTitle}>购买五盒</Text>
- <Text style={styles.btnPrice}>
- (¥{specialPriceFive ?? price * 5})
- </Text>
- </ImageBackground>
- </TouchableOpacity>
- {/* Buy Many */}
- <TouchableOpacity onPress={onBuyMany} style={styles.btnWrapper}>
- <ImageBackground source={{ uri: getBtnBg('many') }} style={styles.btnBg} resizeMode="stretch">
- <Text style={styles.btnTitle}>购买多盒</Text>
- </ImageBackground>
- </TouchableOpacity>
- </View>
- </ImageBackground>
- );
- }
- const styles = StyleSheet.create({
- container: {
- width: '100%',
- height: 100, // Adjust based on background aspect ratio
- justifyContent: 'center',
- paddingBottom: 20, // Safe area padding simulation
- },
- btnRow: {
- flexDirection: 'row',
- justifyContent: 'space-around',
- alignItems: 'center',
- paddingHorizontal: 10,
- },
- btnWrapper: {
- flex: 1,
- height: 50,
- marginHorizontal: 5,
- },
- btnBg: {
- width: '100%',
- height: '100%',
- justifyContent: 'center',
- alignItems: 'center',
- },
- btnTitle: {
- color: '#fff',
- fontSize: 14,
- fontWeight: 'bold',
- textShadowColor: '#000',
- textShadowOffset: { width: 1, height: 1 },
- textShadowRadius: 1,
- },
- btnPrice: {
- color: '#fff',
- fontSize: 10,
- fontWeight: 'bold',
- textShadowColor: '#000',
- textShadowOffset: { width: 1, height: 1 },
- textShadowRadius: 1,
- }
- });
|