PhoneBind.js 5.8 KB

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