Przeglądaj źródła

1.增加绑定手机号功能

zhangmengjie 5 lat temu
rodzic
commit
18d625690c
2 zmienionych plików z 52 dodań i 19 usunięć
  1. 38 9
      pages/PhoneBind.js
  2. 14 10
      pages/services/user.js

+ 38 - 9
pages/PhoneBind.js

@@ -31,6 +31,8 @@ export default class PhoneBind extends BasePage {
 		type: '',
 		phone_num: '',
 		verification_text: '获取验证码',
+		verification_code: '',
+		http_verification_code: '',
 		page_title_text: '绑定手机号',
 		click_ok_text: '绑 定'
 	};
@@ -70,7 +72,9 @@ export default class PhoneBind extends BasePage {
 					</View>
 				</View>
 				<View style={styles.loginIn}>
-					<Text style={styles.loginText}>{this.state.click_ok_text}</Text>
+					<Text style={styles.loginText} onPress={this.clickOK.bind(this)}>
+						{this.state.click_ok_text}
+					</Text>
 				</View>
 				<View style={styles.wechatLogin}>
 					{/* <Image source={require('./images/common/wechat.png')} /> */}
@@ -102,11 +106,22 @@ export default class PhoneBind extends BasePage {
 	getVerification() {
 		if (this.state.verification_text === '获取验证码') {
 			if (this.isPoneAvailable(this.state.phone_num)) {
-				// http_user.getVerificationCode(this.state.phone_num);
-				this.setState({
-					verification_text: '60'
+				http_user.getVerificationCode(this.state.phone_num).then((result) => {
+					if (result.code != 200) {
+						ToastAndroid.show(result.message, ToastAndroid.SHORT);
+					} else {
+						console.log('====================================');
+						console.log(result.data);
+						console.log('====================================');
+						this.setState({
+							http_verification_code: result.data
+						});
+					}
+					this.setState({
+						verification_text: '60'
+					});
+					this.CountDown();
 				});
-				this.CountDown();
 			} else {
 				ToastAndroid.show('请输入正确的手机号', ToastAndroid.SHORT);
 			}
@@ -120,14 +135,11 @@ export default class PhoneBind extends BasePage {
 				verification_text: '获取验证码'
 			});
 		} else {
-			console.log('====================================');
-			console.log(parseInt(this.state.verification_text) - 1 + '');
-			console.log('====================================');
 			setTimeout(() => {
 				this.setState({
 					verification_text: parseInt(this.state.verification_text) - 1 + ''
 				});
-				CountDown();
+				this.CountDown();
 			}, 1000);
 		}
 	}
@@ -143,6 +155,23 @@ export default class PhoneBind extends BasePage {
 			return true;
 		}
 	}
+
+	//绑定手机号
+	clickOK() {
+		if (this.state.http_verification_code == this.state.verification_code) {
+			let option = {
+				method: 'PUT', //请求方法
+				//请求体
+				body: {
+					mobile: this.state.phone_num,
+					sign: this.state.verification_code
+				}
+			};
+			http_user.bind_phone(option).then((result) => {});
+		} else {
+			ToastAndroid.show('验证码不正确', ToastAndroid.SHORT);
+		}
+	}
 }
 
 const styles = StyleSheet.create({

+ 14 - 10
pages/services/user.js

@@ -3,16 +3,16 @@ import efunRequest from '../utils/efunRequest';
 import request from '../utils/request';
 
 export default class user {
-  static update_UserInfo(opts) {
-    console.log('opts',opts);
-    return request(APIConfig.getUserUrl(``), opts);
-  }
-  // 个人中心
-  static userMember() {
-    return request(`http://ott80test-base.yifangjiaoyu.cn/mobile/user/member`, {
-      method: 'get'
-    });
-  }
+	static update_UserInfo(opts) {
+		console.log('opts', opts);
+		return request(APIConfig.getUserUrl(``), opts);
+	}
+	// 个人中心
+	static userMember() {
+		return request(`http://ott80test-base.yifangjiaoyu.cn/mobile/user/member`, {
+			method: 'get'
+		});
+	}
 	static update_UserInfo(opts) {
 		return request(APIConfig.getUserUrl(``), opts);
 	}
@@ -24,4 +24,8 @@ export default class user {
 	static getVerificationCode(phone) {
 		return request(APIConfig.getUserUrl(`/sendCode?mobile=` + phone));
 	}
+
+	static bind_phone(opts) {
+		return request(APIConfig.getUserUrl(`/mobileBind`));
+	}
 }