PhoneBind.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * 登录
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. Platform,
  7. StyleSheet,
  8. Text,
  9. View,
  10. Image,
  11. TouchableOpacity,
  12. ImageBackground,
  13. Button,
  14. StatusBar,
  15. Modal,
  16. TouchableHighlight,
  17. ToastAndroid,
  18. DeviceEventEmitter,
  19. TextInput,
  20. ScrollView
  21. } from 'react-native';
  22. import BasePage from './BasePage';
  23. import Dimensions from './utils/dimensions';
  24. import ShopBox from './components/ShopBox';
  25. import TopicTitle from './components/TopicTitle';
  26. import ScrollRow from './components/ScrollRow';
  27. import http_user from './services/user';
  28. export default class PhoneBind extends BasePage {
  29. state = {
  30. type: '',
  31. phone_num: '',
  32. verification_text: '获取验证码',
  33. verification_code: '',
  34. http_verification_code: '',
  35. page_title_text: '绑定手机号',
  36. click_ok_text: '绑 定'
  37. };
  38. render() {
  39. return (
  40. <View style={styles.wrapper}>
  41. <View style={styles.jump}>
  42. <TouchableOpacity style={styles.jumpBtn}>
  43. <Text style={styles.jumpText}>{this.state.page_title_text}</Text>
  44. </TouchableOpacity>
  45. </View>
  46. <View style={styles.phoneNumberBox}>
  47. <Text style={styles.phoneNumber}>手机号</Text>
  48. <TextInput
  49. style={styles.phoneText}
  50. maxLength={11}
  51. onChangeText={(text) => this.setState({ phone_num: text })}
  52. value={this.state.phone_num}
  53. placeholder={'请输入手机号'}
  54. />
  55. </View>
  56. <View style={styles.signNumberBox}>
  57. <Text style={styles.phoneNumber}>验证码</Text>
  58. <View style={styles.signNumberLine2}>
  59. <TextInput
  60. style={styles.signText}
  61. maxLength={4}
  62. onChangeText={(text) => this.setState({ verification_code: text })}
  63. value={this.state.verification_code}
  64. placeholder={'请输入验证码'}
  65. />
  66. <TouchableOpacity>
  67. <Text style={styles.getSign} onPress={this.getVerification.bind(this)}>
  68. {this.state.verification_text}
  69. </Text>
  70. </TouchableOpacity>
  71. </View>
  72. </View>
  73. <View style={styles.loginIn}>
  74. <Text style={styles.loginText} onPress={this.clickOK.bind(this)}>
  75. {this.state.click_ok_text}
  76. </Text>
  77. </View>
  78. <View style={styles.wechatLogin}>
  79. {/* <Image source={require('./images/common/wechat.png')} /> */}
  80. <Text style={styles.wechatLoginText} />
  81. {/* <Image source={require('./images/common/arrowRight.png')} /> */}
  82. </View>
  83. </View>
  84. );
  85. }
  86. componentWillMount() {
  87. switch (this.props.navigation.state.params.type) {
  88. case 1:
  89. this.setState({
  90. type: this.props.navigation.state.params.type,
  91. page_title_text: '绑定手机号',
  92. click_ok_text: '绑 定'
  93. });
  94. break;
  95. case 2:
  96. this.setState({
  97. type: this.props.navigation.state.params.type,
  98. page_title_text: '修改手机号',
  99. click_ok_text: '修 改'
  100. });
  101. break;
  102. }
  103. }
  104. getVerification() {
  105. if (this.state.verification_text === '获取验证码') {
  106. if (this.isPoneAvailable(this.state.phone_num)) {
  107. http_user.getVerificationCode(this.state.phone_num).then((result) => {
  108. if (result.code != 200) {
  109. ToastAndroid.show(result.message, ToastAndroid.SHORT);
  110. } else {
  111. console.log('====================================');
  112. console.log(result.data);
  113. console.log('====================================');
  114. this.setState({
  115. http_verification_code: result.data
  116. });
  117. }
  118. this.setState({
  119. verification_text: '60'
  120. });
  121. this.CountDown();
  122. });
  123. } else {
  124. ToastAndroid.show('请输入正确的手机号', ToastAndroid.SHORT);
  125. }
  126. } else {
  127. }
  128. }
  129. CountDown() {
  130. if (parseInt(this.state.verification_text) == 0) {
  131. this.setState({
  132. verification_text: '获取验证码'
  133. });
  134. } else {
  135. setTimeout(() => {
  136. this.setState({
  137. verification_text: parseInt(this.state.verification_text) - 1 + ''
  138. });
  139. this.CountDown();
  140. }, 1000);
  141. }
  142. }
  143. //验证手机号
  144. isPoneAvailable(str) {
  145. let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
  146. if (str.length == 0 || str == null) {
  147. return false;
  148. } else if (!myreg.test(str)) {
  149. return false;
  150. } else {
  151. return true;
  152. }
  153. }
  154. //绑定手机号
  155. clickOK() {
  156. if (this.state.http_verification_code == this.state.verification_code) {
  157. let option = {
  158. method: 'PUT', //请求方法
  159. //请求体
  160. body: {
  161. mobile: this.state.phone_num,
  162. sign: this.state.verification_code
  163. }
  164. };
  165. http_user.bind_phone(option).then((result) => {});
  166. } else {
  167. ToastAndroid.show('验证码不正确', ToastAndroid.SHORT);
  168. }
  169. }
  170. }
  171. const styles = StyleSheet.create({
  172. wrapper: {
  173. flex: 1
  174. },
  175. jumpText: {
  176. color: '#3e3e3e',
  177. fontSize: 16,
  178. marginRight: 4
  179. },
  180. jump: {
  181. // width: Dimensions.width,
  182. flex: 2,
  183. alignItems: 'center',
  184. justifyContent: 'center',
  185. paddingHorizontal: '8%'
  186. },
  187. jumpBtn: {
  188. flexDirection: 'row',
  189. alignItems: 'center',
  190. justifyContent: 'center'
  191. },
  192. phoneNumberBox: {
  193. flex: 2,
  194. paddingHorizontal: '8%'
  195. },
  196. phoneNumber: {
  197. color: '#3e3e3e',
  198. fontSize: 18,
  199. marginBottom: 10
  200. },
  201. phoneText: {
  202. width: '100%',
  203. height: Dimensions.getHeight(50),
  204. borderRadius: 25,
  205. backgroundColor: '#f3f3f3'
  206. },
  207. signNumberBox: {
  208. flex: 2,
  209. paddingHorizontal: '8%'
  210. },
  211. signNumberLine2: {
  212. flexDirection: 'row',
  213. width: Dimensions.width
  214. },
  215. signText: {
  216. width: '54%',
  217. height: Dimensions.getHeight(50),
  218. borderRadius: 25,
  219. backgroundColor: '#f3f3f3',
  220. marginRight: 9
  221. },
  222. getSign: {
  223. width: 105,
  224. height: Dimensions.getHeight(50),
  225. borderRadius: 25,
  226. backgroundColor: '#38da84',
  227. lineHeight: Dimensions.getHeight(50),
  228. color: '#fff',
  229. fontSize: 16,
  230. textAlign: 'center'
  231. },
  232. loginIn: {
  233. flex: 3,
  234. paddingHorizontal: '8%'
  235. },
  236. loginText: {
  237. width: '100%',
  238. height: Dimensions.getHeight(50),
  239. backgroundColor: '#63aeff',
  240. textAlign: 'center',
  241. lineHeight: Dimensions.getHeight(50),
  242. color: '#fff',
  243. fontSize: 20,
  244. borderRadius: 25
  245. },
  246. wechatLogin: {
  247. flex: 3,
  248. flexDirection: 'row',
  249. paddingHorizontal: '33.6%',
  250. alignItems: 'center',
  251. justifyContent: 'center'
  252. },
  253. wechatLoginText: {
  254. fontSize: 16,
  255. color: '#3e3e3e',
  256. marginHorizontal: 6
  257. }
  258. });