Jelajahi Sumber

1.修改抵用券—>支付->抵用券逻辑。(每次重新请求支付界面数据)

zhangmengjie 5 tahun lalu
induk
melakukan
a7899f1b30
2 mengubah file dengan 82 tambahan dan 80 penghapusan
  1. 7 8
      pages/buy/buy.js
  2. 75 72
      pages/buy/ticket.js

+ 7 - 8
pages/buy/buy.js

@@ -118,6 +118,12 @@ export default class Buy extends BasePage {
 	componentWillMount() {
 		//获取订购数据信息
 		this.getMember();
+		if (this.props.navigation.state.params != undefined) {
+			console.log('==========to_ticket==========================');
+			console.log('to_ticket', this.props.navigation.state.params.to_ticket);
+			console.log('===========to_ticket=========================');
+			this.choseTicketCallBack(this.props.navigation.state.params.to_ticket);
+		}
 		BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
 	}
 	componentWillUnmount() {
@@ -143,15 +149,8 @@ export default class Buy extends BasePage {
 		this.toNextPage('Ticket', { choseTicketCallBack: this.choseTicketCallBack.bind(this) });
 	};
 	choseTicketCallBack(item) {
-		/**item参数
-         * 	type: 1,
-			price: 12,
-			num: 6,
-			time: '2019-12-12'
-         * 
-         */
 		this.setState({
-			ticketPrice: item.price,
+			ticketPrice: item.amount,
 			useTicket: true
 		});
 	}

+ 75 - 72
pages/buy/ticket.js

@@ -26,10 +26,70 @@ export default class Ticket extends BasePage {
 		ticket_data: []
 	};
 	renderItem = (item, index) => {
+		return this.choseItem(item);
+	};
+	render() {
 		return (
-			<View style={{}}>
-				{item.type === 1 ? (
-					// 抵用券
+			<View style={{ flex: 1 }}>
+				<StatusBar barStyle={'dark-content'} backgroundColor={'white'} translucent={true} />
+				<View
+					style={{
+						height: 50,
+						backgroundColor: 'white',
+						marginTop: 30
+					}}
+				>
+					<CourseTitle
+						width={this.getWindowWidth()}
+						title="抵用券"
+						lefttype={1}
+						textcolor={'#231F20'}
+						backPress={() => this.goBack()}
+						// backPress={() => alert("左侧按钮")}
+					/>
+				</View>
+				<View style={{ flex: 0.1, backgroundColor: 'rgba(242, 242, 242, 1)' }} />
+				<View style={{ flex: 5, backgroundColor: 'rgba(242, 242, 242, 1)' }}>
+					{this.state.ticket_data.length > 0 ? (
+						<FlatList
+							data={this.state.ticket_data}
+							horizontal={false}
+							renderItem={({ item, index }) => this.renderItem(item, index)}
+							keyExtractor={(item, index) => index.toString()}
+						/>
+					) : (
+						<Text
+							style={{ height: '100%', width: '100%', textAlign: 'center', textAlignVertical: 'center' }}
+						>
+							还没有获取到抵用券
+						</Text>
+					)}
+				</View>
+			</View>
+		);
+	}
+	componentWillMount() {
+		//获取用户优惠券信息
+		this.getVoucher();
+	}
+
+	async getVoucher() {
+		await PayServer.getVoucher().then((result) => {
+			if (result.data.length == 0) {
+			} else {
+				this.setState({
+					ticket_data: result.data
+				});
+			}
+		});
+	}
+
+	choseItem(item) {
+		switch (item.type) {
+			case 1:
+			default:
+				// 抵用券
+				return (
 					<TouchableOpacity
 						onPress={() => this.userdiscount(item)}
 						activeOpacity={1}
@@ -44,7 +104,7 @@ export default class Ticket extends BasePage {
 							<View style={styles.topInfo}>
 								<View style={{ flex: 0.5 }} />
 								<View style={styles.left2}>
-									<Text style={styles.price}>¥{item.price}</Text>
+									<Text style={styles.price}>¥{item.amount}</Text>
 									<Text style={styles.type}>抵用券</Text>
 								</View>
 								<View style={{ flex: 0.2 }} />
@@ -76,6 +136,7 @@ export default class Ticket extends BasePage {
 												textAlign: 'center',
 												textAlignVertical: 'center'
 											}}
+											onPress={() => this.useTicket(item)}
 										>
 											立即使用
 										</Text>
@@ -86,12 +147,13 @@ export default class Ticket extends BasePage {
 							<View style={{ flex: 0.2 }} />
 							<View style={styles.bottomInfo}>
 								<Text style={styles.greyText}>注:开通会员时方可使用</Text>
-								<Text style={styles.blueText}>查看订单</Text>
+								{/* <Text style={styles.blueText}>查看订单</Text> */}
 							</View>
 						</ImageBackground>
 					</TouchableOpacity>
-				) : (
-					// 优惠券
+				);
+			case 2:
+				return (
 					<ImageBackground
 						source={require('../images/ticket/coupon-bg.png')}
 						style={styles.type2}
@@ -107,74 +169,15 @@ export default class Ticket extends BasePage {
 							<Text style={styles.greyText}>有效期:{item.time}</Text>
 						</View>
 					</ImageBackground>
-				)}
-			</View>
-		);
-	};
-	render() {
-		return (
-			<View style={{ flex: 1 }}>
-				<StatusBar barStyle={'dark-content'} backgroundColor={'white'} translucent={true} />
-				<View
-					style={{
-						height: 50,
-						backgroundColor: 'white',
-						marginTop: 30
-					}}
-				>
-					<CourseTitle
-						width={this.getWindowWidth()}
-						title="抵用券"
-						lefttype={1}
-						textcolor={'#231F20'}
-						backPress={() => this.goBack()}
-						// backPress={() => alert("左侧按钮")}
-					/>
-				</View>
-				<View style={{ flex: 0.1, backgroundColor: 'rgba(242, 242, 242, 1)' }} />
-				<View style={{ flex: 5, backgroundColor: 'rgba(242, 242, 242, 1)' }}>
-					{this.state.ticket_data.length > 0 ? (
-						<FlatList
-							data={this.state.ticket_data}
-							horizontal={false}
-							renderItem={({ item, index }) => this.renderItem(item, index)}
-							keyExtractor={(item, index) => index.toString()}
-						/>
-					) : (
-						<Text
-							style={{ height: '100%', width: '100%', textAlign: 'center', textAlignVertical: 'center' }}
-						>
-							还没有获取到抵用券
-						</Text>
-					)}
-				</View>
-			</View>
-		);
-	}
-	componentWillMount() {
-		//获取用户优惠券信息
-		this.getVoucher();
-	}
-
-	async getVoucher() {
-		await PayServer.getVoucher().then((result) => {
-			console.log('====================================');
-			console.log('getVoucher', result);
-			console.log('====================================');
-			if (result.data.length == 0) {
-			} else {
-				this.setState({
-					ticket_data: result.data
-				});
-			}
-		});
+				);
+		}
 	}
 
 	userdiscount = (item) => {
-		if (this.props.navigation.state.params != undefined) {
-			this.props.navigation.state.params.choseTicketCallBack(item);
-			this.props.navigation.goBack();
-		}
+		this.useTicket(item);
+	};
+	useTicket = (ticket_item) => {
+		this.toNextPage('Buy', { to_ticket: ticket_item });
 	};
 }