ShopBox.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @param:
  3. * data: 商品列表
  4. * discount: 优惠信息
  5. */
  6. import React, { Component } from 'react';
  7. import { StyleSheet, Text, View, Image, TouchableOpacity, ImageBackground } from 'react-native';
  8. import Dimensions from '../utils/dimensions';
  9. const styles = StyleSheet.create({
  10. bigWrapper: {
  11. flexDirection: 'column'
  12. },
  13. wrapper: {
  14. // width: Dimensions.width,
  15. // height: 45,
  16. justifyContent: 'center',
  17. flexDirection: 'row',
  18. justifyContent: 'space-around',
  19. paddingHorizontal: 7
  20. },
  21. item: {
  22. width: Dimensions.width * 168 / 375,
  23. height: Dimensions.width * 168 / 375 * 120 / 168,
  24. paddingLeft: 10
  25. },
  26. title: {
  27. fontSize: 20,
  28. color: '#fff',
  29. marginTop: 15
  30. },
  31. line2: {
  32. flexDirection: 'row',
  33. alignItems: 'center'
  34. // marginTop: 3
  35. },
  36. price: {
  37. fontSize: 24,
  38. color: '#fff',
  39. fontWeight: 'bold',
  40. marginRight: 5
  41. },
  42. originPrice: {
  43. fontSize: 11,
  44. color: '#fff',
  45. textDecorationLine: 'line-through'
  46. },
  47. line3: {
  48. alignItems: 'center',
  49. flexDirection: 'row',
  50. marginTop: 8
  51. },
  52. buy: {
  53. fontSize: 18,
  54. color: '#fff'
  55. },
  56. discount: {
  57. width: Dimensions.width,
  58. alignItems: 'center',
  59. justifyContent: 'center',
  60. height: 100
  61. },
  62. discountIcon: {
  63. width: Dimensions.width * 343 / 375,
  64. height: Dimensions.width * 343 / 375 * 80 / 343
  65. }
  66. });
  67. export default class ShopBox extends Component {
  68. renderGoods = (item, index) => {
  69. return (
  70. <ImageBackground source={item.background} style={styles.item} key={index}>
  71. <TouchableOpacity onPress={() => this.props.nav('Buy')}>
  72. <Text style={styles.title}>{item.title}</Text>
  73. <View style={styles.line2}>
  74. <Text style={styles.price}>¥{item.price}</Text>
  75. <Text style={styles.originPrice}>原价: {item.originPrice}</Text>
  76. </View>
  77. <View style={styles.line3}>
  78. <Text style={styles.buy}>立即购买</Text>
  79. <Image source={require('../images/shopBox/arrow.png')} style={styles.arrow} />
  80. </View>
  81. </TouchableOpacity>
  82. </ImageBackground>
  83. );
  84. };
  85. render() {
  86. return (
  87. <View style={styles.bigWrapper}>
  88. <View style={styles.wrapper}>
  89. {this.props.data.map((item, index) => this.renderGoods(item, index))}
  90. </View>
  91. <View style={styles.discount}>
  92. <Image
  93. source={this.props.discount.icon}
  94. style={{ height: '80%', width: '95%', borderRadius: 10 }}
  95. />
  96. </View>
  97. </View>
  98. );
  99. }
  100. }