ticket.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. *
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. Platform,
  7. StyleSheet,
  8. Text,
  9. View,
  10. Image,
  11. TouchableOpacity,
  12. FlatList,
  13. TouchableHighlight,
  14. DeviceEventEmitter,
  15. ScrollView,
  16. ImageBackground
  17. } from 'react-native';
  18. import BasePage from '../BasePage';
  19. import Dimensions from '../utils/dimensions';
  20. export default class Ticket extends BasePage {
  21. state = {
  22. data: [
  23. {
  24. type: 1,
  25. price: 12,
  26. num: 6,
  27. time: '2019-12-12'
  28. },
  29. {
  30. type: 1,
  31. price: 33,
  32. num: 9,
  33. time: '2019-12-12'
  34. },
  35. {
  36. type: 2,
  37. price: 50,
  38. limit: '199',
  39. time: '2019-12-12'
  40. }
  41. ]
  42. };
  43. renderItem = (item, index) => {
  44. return (
  45. <View>
  46. {item.type === 1 ? (
  47. // 抵用券
  48. <TouchableOpacity onPress={() => this.userdiscount(item)} activeOpacity={1}>
  49. <ImageBackground source={require('../images/ticket/discount-bg.png')} style={styles.type1}>
  50. <View style={styles.topInfo}>
  51. <View style={styles.left2}>
  52. <Text style={styles.price}>¥{item.price}</Text>
  53. <Text style={styles.type}>抵用券</Text>
  54. </View>
  55. <View style={styles.right2}>
  56. <Text style={styles.greyText}>购买{item.num}个单课程的奖励</Text>
  57. <Text style={styles.greyText}>有效期:{item.time}</Text>
  58. </View>
  59. </View>
  60. <View style={styles.bottomInfo}>
  61. <Text style={styles.greyText}>注:开通会员时方可使用</Text>
  62. <Text style={styles.blueText}>查看订单</Text>
  63. </View>
  64. </ImageBackground>
  65. </TouchableOpacity>
  66. ) : (
  67. // 优惠券
  68. <ImageBackground source={require('../images/ticket/coupon-bg.png')} style={styles.type2}>
  69. <View style={styles.left2}>
  70. <Text style={styles.price}>¥{item.price}</Text>
  71. <Text style={styles.type}>优惠券</Text>
  72. </View>
  73. <View style={styles.right2}>
  74. <Text style={styles.greyText}>满{item.limit}可用</Text>
  75. <Text style={styles.greyText}>有效期:{item.time}</Text>
  76. </View>
  77. </ImageBackground>
  78. )}
  79. </View>
  80. );
  81. };
  82. render() {
  83. return (
  84. <FlatList
  85. data={this.state.data}
  86. horizontal={false}
  87. renderItem={({ item, index }) => this.renderItem(item, index)}
  88. keyExtractor={(item, index) => index.toString()}
  89. />
  90. );
  91. }
  92. userdiscount = (item) => {
  93. if (this.props.navigation.state.params != undefined) {
  94. this.props.navigation.state.params.choseTicketCallBack(item);
  95. this.props.navigation.goBack();
  96. }
  97. };
  98. }
  99. const styles = StyleSheet.create({
  100. type1: {
  101. width: 343,
  102. height: 144,
  103. flexDirection: 'column',
  104. justifyContent: 'space-between',
  105. alignItems: 'center',
  106. paddingTop: 12,
  107. paddingBottom: 14
  108. },
  109. type2: {
  110. width: 343,
  111. height: 100,
  112. flexDirection: 'row',
  113. justifyContent: 'flex-start',
  114. alignItems: 'center',
  115. paddingLeft: 27
  116. },
  117. left2: {
  118. flexDirection: 'column'
  119. },
  120. price: {
  121. color: '#ff6d2f',
  122. fontSize: 19,
  123. fontWeight: '500'
  124. },
  125. type: {
  126. color: '#ff6d2f',
  127. fontSize: 18,
  128. fontWeight: '500'
  129. },
  130. right2: {
  131. flexDirection: 'column'
  132. },
  133. topInfo: {
  134. flexDirection: 'row',
  135. alignItems: 'center'
  136. },
  137. bottomInfo: {
  138. width: '100%',
  139. paddingHorizontal: 12,
  140. flexDirection: 'row',
  141. alignItems: 'center',
  142. justifyContent: 'space-between'
  143. },
  144. greyText: {
  145. fontSize: 14,
  146. color: '#888'
  147. },
  148. blueText: {
  149. color: '#4a90e2',
  150. fontSize: 14
  151. }
  152. });