/* * */ import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View, Image, TouchableOpacity, FlatList, TouchableHighlight, BackHandler, DeviceEventEmitter, StatusBar, ScrollView, ImageBackground } from 'react-native'; import BasePage from '../BasePage'; import Dimensions from '../utils/dimensions'; import CourseTitle from '../components/CourseTitle'; import PayServer from '../services/Pay'; import NoDataView from '../components/NoDataView'; export default class Ticket extends BasePage { state = { ticket_data: [] }; renderItem = (item, index) => { return this.choseItem(item); }; render() { return ( this.goBack()} // backPress={() => alert("左侧按钮")} /> {this.state.ticket_data.length > 0 ? ( this.renderItem(item, index)} keyExtractor={(item, index) => index.toString()} /> ) : ( )} ); } choseItem(item) { switch (item.type) { case 1: default: // 抵用券 return ( this.userdiscount(item)} activeOpacity={1} style={{ width: '100%', justifyContent: 'center', alignItems: 'center' }} > ¥{item.amount} 抵用券 购买{item.num}个单课程的奖励 有效期:{item.time} this.useTicket(item)} > 立即使用 注:开通会员时方可使用 {/* 查看订单 */} ); case 2: return ( ¥{item.price} 优惠券 满{item.limit}可用 有效期:{item.time} ); } } componentWillMount() { //获取用户优惠券信息 this.getVoucher(); BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid); } componentWillUnmount() { BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid); } onBackAndroid = () => { this.goBack(); return true; }; async getVoucher() { await PayServer.getVoucher().then((result) => { if (result.data.length == 0) { } else { this.setState({ ticket_data: result.data }); } }); } userdiscount = (item) => { this.useTicket(item); }; useTicket = (ticket_item) => { this.toNextPage('Buy', { to_ticket: ticket_item }); }; } const styles = StyleSheet.create({ type1: { width: '100%', height: 154, flexDirection: 'column', justifyContent: 'center', // paddingHorizontal: 70, alignItems: 'center' }, type2: { width: '100%', height: 100, flexDirection: 'row', justifyContent: 'center', alignItems: 'center' }, left2: { flex: 1.2, flexDirection: 'column' }, price: { color: '#ff6d2f', fontSize: 19, fontWeight: '500' }, type: { color: '#ff6d2f', fontSize: 18, fontWeight: '500' }, right2: { flex: 3.5, flexDirection: 'column', marginTop: 10 }, topInfo: { flex: 1, flexDirection: 'row', alignItems: 'center' }, bottomInfo: { width: '90%', flex: 1, // paddingHorizontal: 12, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }, greyText: { fontSize: 14, color: '#888' }, blueText: { color: '#4a90e2', fontSize: 14 } });