Quellcode durchsuchen

1.增加绑定手机和个人信息界面的物理返回键监听
2.根据绑定手机界面返回信息提示是否绑定成功

zhangmengjie vor 5 Jahren
Ursprung
Commit
bd7bc6e7bc
2 geänderte Dateien mit 110 neuen und 26 gelöschten Zeilen
  1. 45 6
      pages/PersonalInfo.js
  2. 65 20
      pages/PhoneBind.js

+ 45 - 6
pages/PersonalInfo.js

@@ -16,7 +16,7 @@ import {
 	TouchableOpacity,
 	TouchableOpacity,
 	ImageBackground,
 	ImageBackground,
 	ToastAndroid,
 	ToastAndroid,
-	Button,
+	BackHandler,
 	StatusBar,
 	StatusBar,
 	Modal
 	Modal
 } from 'react-native';
 } from 'react-native';
@@ -51,7 +51,8 @@ export default class PersonalInfo extends BasePage {
 		phone_bind_type: 1, //1是绑定,2是修改
 		phone_bind_type: 1, //1是绑定,2是修改
 		phone_bind_color: '',
 		phone_bind_color: '',
 		wechat_nickName: '',
 		wechat_nickName: '',
-		wechat_bind_color: ''
+		wechat_bind_color: '',
+		show_bind_phone: false
 	};
 	};
 
 
 	render() {
 	render() {
@@ -665,6 +666,7 @@ export default class PersonalInfo extends BasePage {
 						</View>
 						</View>
 					</View>
 					</View>
 				</View>
 				</View>
+				{/* <BindPhoneSuccess show={this.state.show_bind_phone} /> */}
 			</View>
 			</View>
 		);
 		);
 	}
 	}
@@ -702,8 +704,23 @@ export default class PersonalInfo extends BasePage {
 				wechat_bind_color: 'rgba(113, 113, 113, 1)'
 				wechat_bind_color: 'rgba(113, 113, 113, 1)'
 			});
 			});
 		}
 		}
+		BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
+	}
+	componentWillUnmount() {
+		BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
 	}
 	}
 
 
+	onBackAndroid = () => {
+		if (this.state.show_bind_phone) {
+			this.setState({
+				show_bind_phone: false
+			});
+		} else {
+			this.goBack();
+		}
+		return true;
+	};
+
 	getArraowImg(type) {
 	getArraowImg(type) {
 		return (
 		return (
 			<TouchableOpacity
 			<TouchableOpacity
@@ -798,7 +815,7 @@ export default class PersonalInfo extends BasePage {
 			case 6:
 			case 6:
 				this.props.navigation.navigate('PhoneBind', {
 				this.props.navigation.navigate('PhoneBind', {
 					type: this.state.phone_bind_type,
 					type: this.state.phone_bind_type,
-					BindData: this.bind_phone.bind(this)
+					bind_phone_back: this.bind_phone_back.bind(this)
 				});
 				});
 				break;
 				break;
 			//微信
 			//微信
@@ -895,12 +912,34 @@ export default class PersonalInfo extends BasePage {
 		});
 		});
 	}
 	}
 
 
-	bind_phone(phone_num, result) {
-		alert('绑定手机号回传');
-		this.setState({ phone: phone_num, phone_bind_result: result });
+	bind_phone_back(phone_num, result) {
+		if (result == true) {
+			ToastAndroid.show('修改成功', ToastAndroid.SHORT);
+			this.setState({ phone: phone_num, phone_bind_result: result, show_bind_phone: true });
+		} else {
+			ToastAndroid.show('修改失败', ToastAndroid.SHORT);
+		}
 	}
 	}
 }
 }
 
 
+class BindPhoneSuccess extends BasePage {
+	render() {
+		if (this.props.show) {
+			return (
+				<View
+					style={{
+						position: 'absolute',
+						width: '100%',
+						height: '100%',
+						backgroundColor: 'rgba(0, 0, 0, 0.5)'
+					}}
+				/>
+			);
+		} else {
+			return null;
+		}
+	}
+}
 const styles = StyleSheet.create({
 const styles = StyleSheet.create({
 	item: {
 	item: {
 		flex: 1,
 		flex: 1,

+ 65 - 20
pages/PhoneBind.js

@@ -3,27 +3,18 @@
 */
 */
 import React, { Component } from 'react';
 import React, { Component } from 'react';
 import {
 import {
-	Platform,
 	StyleSheet,
 	StyleSheet,
 	Text,
 	Text,
 	View,
 	View,
 	Image,
 	Image,
 	TouchableOpacity,
 	TouchableOpacity,
-	ImageBackground,
-	Button,
-	StatusBar,
-	Modal,
-	TouchableHighlight,
 	ToastAndroid,
 	ToastAndroid,
-	DeviceEventEmitter,
+	StatusBar,
 	TextInput,
 	TextInput,
-	ScrollView
+	BackHandler
 } from 'react-native';
 } from 'react-native';
 import BasePage from './BasePage';
 import BasePage from './BasePage';
 import Dimensions from './utils/dimensions';
 import Dimensions from './utils/dimensions';
-import ShopBox from './components/ShopBox';
-import TopicTitle from './components/TopicTitle';
-import ScrollRow from './components/ScrollRow';
 import http_user from './services/user';
 import http_user from './services/user';
 import commonutil from './utils/commonutil';
 import commonutil from './utils/commonutil';
 
 
@@ -35,15 +26,29 @@ export default class PhoneBind extends BasePage {
 		verification_code: '',
 		verification_code: '',
 		http_verification_code: '',
 		http_verification_code: '',
 		page_title_text: '绑定手机号',
 		page_title_text: '绑定手机号',
-		click_ok_text: '绑 定'
+		click_ok_text: '绑 定',
+		phone_bind_result: false
 	};
 	};
 	render() {
 	render() {
 		return (
 		return (
 			<View style={styles.wrapper}>
 			<View style={styles.wrapper}>
-				<View style={styles.jump}>
-					<TouchableOpacity style={styles.jumpBtn}>
-						<Text style={styles.jumpText}>{this.state.page_title_text}</Text>
-					</TouchableOpacity>
+				<StatusBar backgroundColor={'white'} translucent={true} barStyle={'dark-content'} />
+
+				<View style={{ flex: 2 }}>
+					<View style={{ marginTop: '6%', flex: 2, flexDirection: 'row' }}>
+						<TouchableOpacity
+							style={{ marginLeft: '5%' }}
+							activeOpacity={1}
+							onPress={this.backresult.bind(this)}
+						>
+							<Image source={require('./images/schedulePage/back_black.png')} />
+						</TouchableOpacity>
+					</View>
+					<View style={styles.jump}>
+						<TouchableOpacity style={styles.jumpBtn}>
+							<Text style={styles.jumpText}>{this.state.page_title_text}</Text>
+						</TouchableOpacity>
+					</View>
 				</View>
 				</View>
 				<View style={styles.phoneNumberBox}>
 				<View style={styles.phoneNumberBox}>
 					<Text style={styles.phoneNumber}>手机号</Text>
 					<Text style={styles.phoneNumber}>手机号</Text>
@@ -86,24 +91,39 @@ export default class PhoneBind extends BasePage {
 		);
 		);
 	}
 	}
 	componentWillMount() {
 	componentWillMount() {
-		switch (this.props.navigation.state.params.type) {
+		BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
+		var type;
+		if (this.props.navigation.state.params == undefined) {
+			type = 1;
+		} else {
+			type = this.props.navigation.state.params.type;
+		}
+		switch (type) {
 			case 1:
 			case 1:
 				this.setState({
 				this.setState({
-					type: this.props.navigation.state.params.type,
+					type: type,
 					page_title_text: '绑定手机号',
 					page_title_text: '绑定手机号',
 					click_ok_text: '绑 定'
 					click_ok_text: '绑 定'
 				});
 				});
 				break;
 				break;
 			case 2:
 			case 2:
 				this.setState({
 				this.setState({
-					type: this.props.navigation.state.params.type,
+					type: type,
 					page_title_text: '修改手机号',
 					page_title_text: '修改手机号',
 					click_ok_text: '修 改'
 					click_ok_text: '修 改'
 				});
 				});
 				break;
 				break;
 		}
 		}
 	}
 	}
+	componentWillUnmount() {
+		BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
+	}
 
 
+	onBackAndroid = () => {
+		this.props.navigation.state.params.bind_phone_back(this.state.phone_num, this.state.phone_bind_result);
+		this.props.navigation.goBack();
+		return true;
+	};
 	getVerification() {
 	getVerification() {
 		if (this.state.verification_text === '获取验证码') {
 		if (this.state.verification_text === '获取验证码') {
 			if (commonutil.isPoneAvailable(this.state.phone_num)) {
 			if (commonutil.isPoneAvailable(this.state.phone_num)) {
@@ -148,6 +168,14 @@ export default class PhoneBind extends BasePage {
 
 
 	//绑定手机号
 	//绑定手机号
 	clickOK() {
 	clickOK() {
+		if (!commonutil.isPoneAvailable(this.state.phone_num)) {
+			ToastAndroid.show('请输入正确的手机号', ToastAndroid.SHORT);
+			return;
+		}
+		if (this.state.verification_code == '') {
+			ToastAndroid.show('请输入验证码', ToastAndroid.SHORT);
+			return;
+		}
 		if (this.state.http_verification_code == this.state.verification_code) {
 		if (this.state.http_verification_code == this.state.verification_code) {
 			let option = {
 			let option = {
 				method: 'PUT', //请求方法
 				method: 'PUT', //请求方法
@@ -157,11 +185,28 @@ export default class PhoneBind extends BasePage {
 					sign: this.state.verification_code
 					sign: this.state.verification_code
 				}
 				}
 			};
 			};
-			http_user.bind_phone(option).then((result) => {});
+			http_user.bind_phone(option).then((result) => {
+				if (result.code == 200) {
+					this.setState({
+						phone_bind_result: true
+					});
+					ToastAndroid.show(result.message, ToastAndroid.SHORT);
+				} else {
+					this.setState({
+						phone_bind_result: false
+					});
+					ToastAndroid.show(result.message, ToastAndroid.SHORT);
+				}
+			});
 		} else {
 		} else {
 			ToastAndroid.show('验证码不正确', ToastAndroid.SHORT);
 			ToastAndroid.show('验证码不正确', ToastAndroid.SHORT);
 		}
 		}
 	}
 	}
+
+	backresult() {
+		this.props.navigation.state.params.bind_phone_back(this.state.phone_num, this.state.phone_bind_result);
+		this.props.navigation.goBack();
+	}
 }
 }
 
 
 const styles = StyleSheet.create({
 const styles = StyleSheet.create({