PhoneBind.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. page_title_text: '绑定手机号',
  34. click_ok_text: '绑 定'
  35. };
  36. render() {
  37. return (
  38. <View style={styles.wrapper}>
  39. <View style={styles.jump}>
  40. <TouchableOpacity style={styles.jumpBtn}>
  41. <Text style={styles.jumpText}>{this.state.page_title_text}</Text>
  42. </TouchableOpacity>
  43. </View>
  44. <View style={styles.phoneNumberBox}>
  45. <Text style={styles.phoneNumber}>手机号</Text>
  46. <TextInput
  47. style={styles.phoneText}
  48. maxLength={11}
  49. onChangeText={(text) => this.setState({ phone_num: text })}
  50. value={this.state.phone_num}
  51. placeholder={'请输入手机号'}
  52. />
  53. </View>
  54. <View style={styles.signNumberBox}>
  55. <Text style={styles.phoneNumber}>验证码</Text>
  56. <View style={styles.signNumberLine2}>
  57. <TextInput
  58. style={styles.signText}
  59. maxLength={4}
  60. onChangeText={(text) => this.setState({ verification_code: text })}
  61. value={this.state.verification_code}
  62. placeholder={'请输入验证码'}
  63. />
  64. <TouchableOpacity>
  65. <Text style={styles.getSign} onPress={this.getVerification.bind(this)}>
  66. {this.state.verification_text}
  67. </Text>
  68. </TouchableOpacity>
  69. </View>
  70. </View>
  71. <View style={styles.loginIn}>
  72. <Text style={styles.loginText}>{this.state.click_ok_text}</Text>
  73. </View>
  74. <View style={styles.wechatLogin}>
  75. {/* <Image source={require('./images/common/wechat.png')} /> */}
  76. <Text style={styles.wechatLoginText} />
  77. {/* <Image source={require('./images/common/arrowRight.png')} /> */}
  78. </View>
  79. </View>
  80. );
  81. }
  82. componentWillMount() {
  83. switch (this.props.navigation.state.params.type) {
  84. case 1:
  85. this.setState({
  86. type: this.props.navigation.state.params.type,
  87. page_title_text: '绑定手机号',
  88. click_ok_text: '绑 定'
  89. });
  90. break;
  91. case 2:
  92. this.setState({
  93. type: this.props.navigation.state.params.type,
  94. page_title_text: '修改手机号',
  95. click_ok_text: '修 改'
  96. });
  97. break;
  98. }
  99. }
  100. getVerification() {
  101. if (this.state.verification_text === '获取验证码') {
  102. if (this.isPoneAvailable(this.state.phone_num)) {
  103. // http_user.getVerificationCode(this.state.phone_num);
  104. this.setState({
  105. verification_text: '60'
  106. });
  107. this.CountDown();
  108. } else {
  109. ToastAndroid.show('请输入正确的手机号', ToastAndroid.SHORT);
  110. }
  111. } else {
  112. }
  113. }
  114. CountDown() {
  115. if (parseInt(this.state.verification_text) == 0) {
  116. this.setState({
  117. verification_text: '获取验证码'
  118. });
  119. } else {
  120. console.log('====================================');
  121. console.log(parseInt(this.state.verification_text) - 1 + '');
  122. console.log('====================================');
  123. setTimeout(() => {
  124. this.setState({
  125. verification_text: parseInt(this.state.verification_text) - 1 + ''
  126. });
  127. CountDown();
  128. }, 1000);
  129. }
  130. }
  131. //验证手机号
  132. isPoneAvailable(str) {
  133. let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
  134. if (str.length == 0 || str == null) {
  135. return false;
  136. } else if (!myreg.test(str)) {
  137. return false;
  138. } else {
  139. return true;
  140. }
  141. }
  142. }
  143. const styles = StyleSheet.create({
  144. wrapper: {
  145. flex: 1
  146. },
  147. jumpText: {
  148. color: '#3e3e3e',
  149. fontSize: 16,
  150. marginRight: 4
  151. },
  152. jump: {
  153. // width: Dimensions.width,
  154. flex: 2,
  155. alignItems: 'center',
  156. justifyContent: 'center',
  157. paddingHorizontal: '8%'
  158. },
  159. jumpBtn: {
  160. flexDirection: 'row',
  161. alignItems: 'center',
  162. justifyContent: 'center'
  163. },
  164. phoneNumberBox: {
  165. flex: 2,
  166. paddingHorizontal: '8%'
  167. },
  168. phoneNumber: {
  169. color: '#3e3e3e',
  170. fontSize: 18,
  171. marginBottom: 10
  172. },
  173. phoneText: {
  174. width: '100%',
  175. height: Dimensions.getHeight(50),
  176. borderRadius: 25,
  177. backgroundColor: '#f3f3f3'
  178. },
  179. signNumberBox: {
  180. flex: 2,
  181. paddingHorizontal: '8%'
  182. },
  183. signNumberLine2: {
  184. flexDirection: 'row',
  185. width: Dimensions.width
  186. },
  187. signText: {
  188. width: '54%',
  189. height: Dimensions.getHeight(50),
  190. borderRadius: 25,
  191. backgroundColor: '#f3f3f3',
  192. marginRight: 9
  193. },
  194. getSign: {
  195. width: 105,
  196. height: Dimensions.getHeight(50),
  197. borderRadius: 25,
  198. backgroundColor: '#38da84',
  199. lineHeight: Dimensions.getHeight(50),
  200. color: '#fff',
  201. fontSize: 16,
  202. textAlign: 'center'
  203. },
  204. loginIn: {
  205. flex: 3,
  206. paddingHorizontal: '8%'
  207. },
  208. loginText: {
  209. width: '100%',
  210. height: Dimensions.getHeight(50),
  211. backgroundColor: '#63aeff',
  212. textAlign: 'center',
  213. lineHeight: Dimensions.getHeight(50),
  214. color: '#fff',
  215. fontSize: 20,
  216. borderRadius: 25
  217. },
  218. wechatLogin: {
  219. flex: 3,
  220. flexDirection: 'row',
  221. paddingHorizontal: '33.6%',
  222. alignItems: 'center',
  223. justifyContent: 'center'
  224. },
  225. wechatLoginText: {
  226. fontSize: 16,
  227. color: '#3e3e3e',
  228. marginHorizontal: 6
  229. }
  230. });