ticket.js 5.5 KB

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