ticket.js 5.7 KB

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