PhoneBind.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. } else {
  112. console.log('====================================');
  113. console.log(result.data);
  114. console.log('====================================');
  115. this.setState({
  116. http_verification_code: result.data
  117. });
  118. }
  119. this.setState({
  120. verification_text: '60'
  121. });
  122. this.CountDown();
  123. });
  124. } else {
  125. ToastAndroid.show('请输入正确的手机号', ToastAndroid.SHORT);
  126. }
  127. } else {
  128. }
  129. }
  130. CountDown() {
  131. if (parseInt(this.state.verification_text) == 0) {
  132. this.setState({
  133. verification_text: '获取验证码'
  134. });
  135. } else {
  136. setTimeout(() => {
  137. this.setState({
  138. verification_text: parseInt(this.state.verification_text) - 1 + ''
  139. });
  140. this.CountDown();
  141. }, 1000);
  142. }
  143. }
  144. //绑定手机号
  145. clickOK() {
  146. if (this.state.http_verification_code == this.state.verification_code) {
  147. let option = {
  148. method: 'PUT', //请求方法
  149. //请求体
  150. body: {
  151. mobile: this.state.phone_num,
  152. sign: this.state.verification_code
  153. }
  154. };
  155. http_user.bind_phone(option).then((result) => {});
  156. } else {
  157. ToastAndroid.show('验证码不正确', ToastAndroid.SHORT);
  158. }
  159. }
  160. }
  161. const styles = StyleSheet.create({
  162. wrapper: {
  163. flex: 1
  164. },
  165. jumpText: {
  166. color: '#3e3e3e',
  167. fontSize: 16,
  168. marginRight: 4
  169. },
  170. jump: {
  171. // width: Dimensions.width,
  172. flex: 2,
  173. alignItems: 'center',
  174. justifyContent: 'center',
  175. paddingHorizontal: '8%'
  176. },
  177. jumpBtn: {
  178. flexDirection: 'row',
  179. alignItems: 'center',
  180. justifyContent: 'center'
  181. },
  182. phoneNumberBox: {
  183. flex: 2,
  184. paddingHorizontal: '8%'
  185. },
  186. phoneNumber: {
  187. color: '#3e3e3e',
  188. fontSize: 18,
  189. marginBottom: 10
  190. },
  191. phoneText: {
  192. width: '100%',
  193. height: Dimensions.getHeight(50),
  194. borderRadius: 25,
  195. backgroundColor: '#f3f3f3'
  196. },
  197. signNumberBox: {
  198. flex: 2,
  199. paddingHorizontal: '8%'
  200. },
  201. signNumberLine2: {
  202. flexDirection: 'row',
  203. width: Dimensions.width
  204. },
  205. signText: {
  206. width: '54%',
  207. height: Dimensions.getHeight(50),
  208. borderRadius: 25,
  209. backgroundColor: '#f3f3f3',
  210. marginRight: 9
  211. },
  212. getSign: {
  213. width: 105,
  214. height: Dimensions.getHeight(50),
  215. borderRadius: 25,
  216. backgroundColor: '#38da84',
  217. lineHeight: Dimensions.getHeight(50),
  218. color: '#fff',
  219. fontSize: 16,
  220. textAlign: 'center'
  221. },
  222. loginIn: {
  223. flex: 3,
  224. paddingHorizontal: '8%'
  225. },
  226. loginText: {
  227. width: '100%',
  228. height: Dimensions.getHeight(50),
  229. backgroundColor: '#63aeff',
  230. textAlign: 'center',
  231. lineHeight: Dimensions.getHeight(50),
  232. color: '#fff',
  233. fontSize: 20,
  234. borderRadius: 25
  235. },
  236. wechatLogin: {
  237. flex: 3,
  238. flexDirection: 'row',
  239. paddingHorizontal: '33.6%',
  240. alignItems: 'center',
  241. justifyContent: 'center'
  242. },
  243. wechatLoginText: {
  244. fontSize: 16,
  245. color: '#3e3e3e',
  246. marginHorizontal: 6
  247. }
  248. });