ticket.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. StatusBar,
  16. ScrollView,
  17. ImageBackground
  18. } from 'react-native';
  19. import BasePage from '../BasePage';
  20. import Dimensions from '../utils/dimensions';
  21. import CourseTitle from '../components/CourseTitle';
  22. export default class Ticket extends BasePage {
  23. state = {
  24. data: [
  25. {
  26. type: 1,
  27. price: 12,
  28. num: 6,
  29. time: '2019-12-12'
  30. },
  31. {
  32. type: 1,
  33. price: 33,
  34. num: 9,
  35. time: '2019-12-12'
  36. },
  37. {
  38. type: 1,
  39. price: 50,
  40. limit: '199',
  41. time: '2019-12-12'
  42. }
  43. ]
  44. };
  45. renderItem = (item, index) => {
  46. return (
  47. <View style={{ justifyContent: 'center', alignItems: 'center' }}>
  48. {item.type === 1 ? (
  49. // 抵用券
  50. <TouchableOpacity
  51. onPress={() => this.userdiscount(item)}
  52. activeOpacity={1}
  53. style={{ width: '100%', justifyContent: 'center', alignItems: 'center' }}
  54. >
  55. <ImageBackground
  56. source={require('../images/ticket/discount-bg.png')}
  57. style={styles.type1}
  58. imageStyle={{ resizeMode: 'contain' }}
  59. >
  60. <View style={{ flex: 0.3 }} />
  61. <View style={styles.topInfo}>
  62. <View style={{ flex: 1.3 }} />
  63. <View style={styles.left2}>
  64. <Text style={styles.price}>¥{item.price}</Text>
  65. <Text style={styles.type}>抵用券</Text>
  66. </View>
  67. <View style={{ flex: 0.05 }} />
  68. <View style={styles.right2}>
  69. <Text style={{ fontSize: 16, color: 'rgba(22, 22, 22, 1)' }}>
  70. 购买{item.num}个单课程的奖励
  71. </Text>
  72. <Text style={styles.greyText}>有效期:{item.time}</Text>
  73. </View>
  74. <View
  75. style={{
  76. flex: 0.4,
  77. marginRight: 50,
  78. marginTop: 20
  79. }}
  80. >
  81. <ImageBackground
  82. source={require('../images/ticket/button-bg.png')}
  83. style={{
  84. width: 85,
  85. height: 27,
  86. justifyContent: 'center'
  87. }}
  88. >
  89. <Text
  90. style={{
  91. fontSize: 16,
  92. color: 'white',
  93. textAlign: 'center',
  94. textAlignVertical: 'center'
  95. }}
  96. >
  97. 立即使用
  98. </Text>
  99. </ImageBackground>
  100. </View>
  101. <View style={{ flex: 1.5 }} />
  102. </View>
  103. <View style={{ flex: 0.2 }} />
  104. <View style={styles.bottomInfo}>
  105. <View style={{ flex: 1 }} />
  106. <Text style={styles.greyText}>注:开通会员时方可使用</Text>
  107. <View style={{ flex: 1 }} />
  108. <Text style={styles.blueText}>查看订单</Text>
  109. <View style={{ flex: 1 }} />
  110. </View>
  111. </ImageBackground>
  112. </TouchableOpacity>
  113. ) : (
  114. // 优惠券
  115. <ImageBackground
  116. source={require('../images/ticket/coupon-bg.png')}
  117. style={styles.type2}
  118. imageStyle={{ resizeMode: 'center' }}
  119. >
  120. <View style={styles.left2}>
  121. <Text style={styles.price}>¥{item.price}</Text>
  122. <Text style={styles.type}>优惠券</Text>
  123. </View>
  124. <View style={styles.right2}>
  125. <Text style={styles.greyText}>满{item.limit}可用</Text>
  126. <Text style={styles.greyText}>有效期:{item.time}</Text>
  127. </View>
  128. </ImageBackground>
  129. )}
  130. </View>
  131. );
  132. };
  133. render() {
  134. return (
  135. <View style={{ flex: 1 }}>
  136. <StatusBar barStyle={'dark-content'} backgroundColor={'white'} translucent={true} />
  137. <View
  138. style={{
  139. height: 50,
  140. backgroundColor: 'white',
  141. marginTop: 30
  142. }}
  143. >
  144. <CourseTitle
  145. width={this.getWindowWidth()}
  146. title="抵用券"
  147. lefttype={1}
  148. textcolor={'#231F20'}
  149. backPress={() => this.goBack()}
  150. // backPress={() => alert("左侧按钮")}
  151. />
  152. </View>
  153. <View style={{ flex: 0.1, backgroundColor: 'rgba(242, 242, 242, 1)' }} />
  154. <View style={{ flex: 5, backgroundColor: 'rgba(242, 242, 242, 1)' }}>
  155. <FlatList
  156. data={this.state.data}
  157. horizontal={false}
  158. renderItem={({ item, index }) => this.renderItem(item, index)}
  159. keyExtractor={(item, index) => index.toString()}
  160. />
  161. </View>
  162. </View>
  163. );
  164. }
  165. userdiscount = (item) => {
  166. if (this.props.navigation.state.params != undefined) {
  167. this.props.navigation.state.params.choseTicketCallBack(item);
  168. this.props.navigation.goBack();
  169. }
  170. };
  171. }
  172. const styles = StyleSheet.create({
  173. type1: {
  174. width: '100%',
  175. height: 154,
  176. flexDirection: 'column',
  177. justifyContent: 'center',
  178. // paddingHorizontal: 70,
  179. alignItems: 'center'
  180. },
  181. type2: {
  182. width: '100%',
  183. height: 100,
  184. flexDirection: 'row',
  185. justifyContent: 'center',
  186. alignItems: 'center'
  187. },
  188. left2: {
  189. flex: 1,
  190. flexDirection: 'column'
  191. },
  192. price: {
  193. color: '#ff6d2f',
  194. fontSize: 19,
  195. fontWeight: '500'
  196. },
  197. type: {
  198. color: '#ff6d2f',
  199. fontSize: 18,
  200. fontWeight: '500'
  201. },
  202. right2: {
  203. flex: 2.8,
  204. flexDirection: 'column',
  205. marginTop: 10
  206. },
  207. topInfo: {
  208. flex: 1,
  209. flexDirection: 'row',
  210. alignItems: 'center'
  211. },
  212. bottomInfo: {
  213. width: '100%',
  214. flex: 1,
  215. paddingHorizontal: 12,
  216. flexDirection: 'row',
  217. alignItems: 'center',
  218. justifyContent: 'space-between'
  219. },
  220. greyText: {
  221. fontSize: 14,
  222. color: '#888'
  223. },
  224. blueText: {
  225. color: '#4a90e2',
  226. fontSize: 14
  227. }
  228. });