ticket.js 5.7 KB

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