PersonalInfo.js 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, { Component } from 'react';
  9. import {
  10. Platform,
  11. StyleSheet,
  12. Text,
  13. View,
  14. Image,
  15. TouchableOpacity,
  16. ImageBackground,
  17. ToastAndroid,
  18. BackHandler,
  19. StatusBar,
  20. Modal
  21. } from 'react-native';
  22. import BasePage from './BasePage';
  23. import CourseTitle from '../pages/components/CourseTitle';
  24. import ChosePhoto from '../pages/components/ChosePhoto';
  25. import RegionModal from '../pages/components/RegionModal';
  26. import BirthdayModal from '../pages/components/BirthdayModal';
  27. import GradeSelectionModal from '../pages/components/GradeSelectionModal';
  28. import PersonalInfoDialog from '../pages/components/PersonalInfoDialog';
  29. import { NavigationActions, StackActions } from 'react-navigation';
  30. import asyncStorage from './utils/asyncStorage';
  31. import http_user from './services/user';
  32. import wechat from './utils/wechat';
  33. type Props = {};
  34. export default class PersonalInfo extends BasePage {
  35. state = {
  36. user_nickName: '未设置',
  37. schoolName: '未设置',
  38. provinceName: '未设置',
  39. citys: '',
  40. grade_text: '七年级',
  41. grade_index: 6,
  42. birthday_year: 0,
  43. birthday_month: 0,
  44. birthday_day: 0,
  45. birthday_time: 0,
  46. photo_uri: require('./images/userInfo/default_photo.png'),
  47. phone: '',
  48. phone_bind_result: false,
  49. phone_bind_type: 1, //1是绑定,2是修改
  50. phone_bind_color: 'red',
  51. wechat_nickName: '',
  52. wechat_bind_color: 'red',
  53. show_bind_phone: false
  54. };
  55. render() {
  56. return (
  57. <View style={{ backgroundColor: '#F0F1F5', flex: 1 }}>
  58. <View style={{ width: '100%', height: this.getWindowHeight() }}>
  59. <PersonalInfoDialog
  60. ref={(view) => (this.dialog = view)}
  61. updateParentState={this.updateState.bind(this)}
  62. />
  63. <ChosePhoto ref={(view) => (this.chosephoto = view)} photoback={this.photoback.bind(this)} />
  64. <RegionModal
  65. ref={(view) => (this.regionmodal = view)}
  66. cityscommit={this.cityscommit.bind(this)}
  67. provinceName={this.state.provinceName}
  68. citys={this.state.citys}
  69. />
  70. <GradeSelectionModal
  71. ref={(view) => (this.gradeselectionModal = view)}
  72. commitGrade={this.commitGrade.bind(this)}
  73. grade_index={this.state.grade_index}
  74. />
  75. <BirthdayModal
  76. ref={(view) => (this.birthdaymodal = view)}
  77. birthdaycommit={this.birthdaycommit.bind(this)}
  78. year={this.state.birthday_year}
  79. month={this.state.birthday_month}
  80. day={this.state.birthday_day}
  81. />
  82. <StatusBar backgroundColor={'transparent'} translucent={true} />
  83. <View
  84. style={{
  85. flex: 1,
  86. flexDirection: 'column'
  87. }}
  88. >
  89. <ImageBackground
  90. source={require('./images/userInfo/top.png')}
  91. style={{
  92. flex: 3,
  93. width: '100%',
  94. backgroundColor: '#F0F1F5',
  95. height: '75%'
  96. }}
  97. imageStyle={{ resizeMode: 'cover' }}
  98. >
  99. <View
  100. style={{
  101. flex: 1,
  102. alignItems: 'center',
  103. justifyContent: 'center',
  104. flexDirection: 'column'
  105. }}
  106. >
  107. <CourseTitle
  108. style={{ flex: 5 }}
  109. width={this.getWindowWidth()}
  110. title="个人信息"
  111. lefttype={2}
  112. righttype={0}
  113. textcolor={'white'}
  114. backPress={() => this.goBack()}
  115. />
  116. <TouchableOpacity
  117. style={{
  118. flex: 1.3,
  119. backgroundColor: 'white',
  120. width: '90%',
  121. bottom: 0,
  122. alignItems: 'center',
  123. justifyContent: 'flex-end',
  124. bottom: -30,
  125. borderRadius: 10,
  126. overflow: 'hidden'
  127. }}
  128. activeOpacity={1}
  129. onPress={() => this.arrowpress(0)}
  130. >
  131. <View
  132. style={{
  133. flex: 1,
  134. borderRadius: 20,
  135. overflow: 'hidden',
  136. alignItems: 'center',
  137. justifyContent: 'center',
  138. flexDirection: 'row'
  139. }}
  140. >
  141. <View style={{ flex: 0.5 }} />
  142. <View
  143. style={{
  144. flex: 3,
  145. height: '100%',
  146. alignItems: 'center',
  147. justifyContent: 'center'
  148. }}
  149. >
  150. <Image
  151. style={{
  152. borderRadius: 50,
  153. width: '80%',
  154. height: '70%'
  155. // borderWidth: 3
  156. // borderColor: "red"
  157. }}
  158. source={this.state.photo_uri}
  159. />
  160. </View>
  161. <View
  162. style={{
  163. flex: 9,
  164. backgroundColor: 'white',
  165. height: '100%',
  166. justifyContent: 'center'
  167. }}
  168. >
  169. <Text style={{ left: 10, color: 'black', fontSize: 16 }}>修改头像</Text>
  170. </View>
  171. <View
  172. style={{
  173. flex: 1.5,
  174. height: '65%',
  175. alignItems: 'center',
  176. justifyContent: 'center'
  177. }}
  178. >
  179. {this.getArraowImg(0)}
  180. </View>
  181. </View>
  182. </TouchableOpacity>
  183. <View style={{ flex: 0.5 }} />
  184. </View>
  185. </ImageBackground>
  186. <View style={{ flex: 0.2 }} />
  187. <View
  188. style={{
  189. width: '100%',
  190. flex: 4,
  191. alignItems: 'center',
  192. backgroundColor: '#F0F1F5'
  193. }}
  194. >
  195. <View
  196. style={{
  197. backgroundColor: 'rgb(242, 242, 242)',
  198. width: '90%',
  199. alignItems: 'center',
  200. justifyContent: 'center',
  201. height: '100%',
  202. overflow: 'hidden',
  203. borderRadius: 10
  204. }}
  205. >
  206. <View
  207. style={{
  208. width: '100%',
  209. alignItems: 'center',
  210. justifyContent: 'center',
  211. height: '100%'
  212. }}
  213. >
  214. <TouchableOpacity
  215. style={{
  216. flex: 1,
  217. marginVertical: 1,
  218. width: '100%',
  219. flexDirection: 'row',
  220. backgroundColor: 'white'
  221. }}
  222. activeOpacity={1}
  223. onPress={() => this.arrowpress(1)}
  224. >
  225. <View
  226. style={{
  227. flex: 2,
  228. alignItems: 'center',
  229. justifyContent: 'center'
  230. }}
  231. >
  232. {this.choseheadericon(1)}
  233. </View>
  234. <Text style={styles.item_text}>昵称</Text>
  235. <View
  236. style={{
  237. flex: 5,
  238. alignItems: 'flex-end'
  239. }}
  240. >
  241. <Text
  242. style={{
  243. flex: 1,
  244. fontSize: 15,
  245. textAlignVertical: 'center'
  246. }}
  247. numberOfLines={1}
  248. ellipsizeMode={'tail'}
  249. >
  250. {this.state.user_nickName}
  251. </Text>
  252. </View>
  253. <View
  254. style={{
  255. flex: 1.1,
  256. alignItems: 'center',
  257. justifyContent: 'center'
  258. }}
  259. >
  260. {this.getArraowImg(1)}
  261. </View>
  262. </TouchableOpacity>
  263. <TouchableOpacity
  264. style={{
  265. flex: 1,
  266. width: '100%',
  267. flexDirection: 'row',
  268. backgroundColor: 'white',
  269. marginVertical: 1
  270. }}
  271. activeOpacity={1}
  272. onPress={() => this.arrowpress(2)}
  273. >
  274. <View
  275. style={{
  276. flex: 2,
  277. alignItems: 'center',
  278. justifyContent: 'center'
  279. }}
  280. >
  281. {this.choseheadericon(2)}
  282. </View>
  283. <Text style={styles.item_text}>生日</Text>
  284. <View
  285. style={{
  286. flex: 5,
  287. alignItems: 'flex-end'
  288. }}
  289. >
  290. <Text
  291. style={{
  292. flex: 1,
  293. fontSize: 15,
  294. textAlignVertical: 'center'
  295. }}
  296. numberOfLines={1}
  297. ellipsizeMode={'tail'}
  298. >
  299. {this.state.birthday_time}
  300. </Text>
  301. </View>
  302. <View
  303. style={{
  304. flex: 1.1,
  305. alignItems: 'center',
  306. justifyContent: 'center'
  307. }}
  308. >
  309. {this.getArraowImg(2)}
  310. </View>
  311. </TouchableOpacity>
  312. <TouchableOpacity
  313. style={{
  314. flex: 1,
  315. width: '100%',
  316. flexDirection: 'row',
  317. backgroundColor: 'white',
  318. marginVertical: 1
  319. }}
  320. activeOpacity={1}
  321. onPress={() => this.arrowpress(3)}
  322. >
  323. <View
  324. style={{
  325. flex: 2,
  326. alignItems: 'center',
  327. justifyContent: 'center'
  328. }}
  329. >
  330. {this.choseheadericon(3)}
  331. </View>
  332. <Text style={styles.item_text}>所在地区</Text>
  333. <View
  334. style={{
  335. flex: 5,
  336. alignItems: 'flex-end'
  337. }}
  338. >
  339. <Text
  340. style={{
  341. flex: 1,
  342. fontSize: 15,
  343. textAlignVertical: 'center'
  344. }}
  345. numberOfLines={1}
  346. ellipsizeMode={'tail'}
  347. >
  348. {this.state.provinceName}-{this.state.citys}
  349. </Text>
  350. </View>
  351. <View
  352. style={{
  353. flex: 1.1,
  354. alignItems: 'center',
  355. justifyContent: 'center'
  356. }}
  357. >
  358. {this.getArraowImg(3)}
  359. </View>
  360. </TouchableOpacity>
  361. <TouchableOpacity
  362. style={{
  363. flex: 1,
  364. width: '100%',
  365. flexDirection: 'row',
  366. backgroundColor: 'white',
  367. marginVertical: 1
  368. }}
  369. activeOpacity={1}
  370. onPress={() => this.arrowpress(4)}
  371. >
  372. <View
  373. style={{
  374. flex: 2,
  375. alignItems: 'center',
  376. justifyContent: 'center'
  377. }}
  378. >
  379. {this.choseheadericon(4)}
  380. </View>
  381. <Text style={styles.item_text}>我的学校</Text>
  382. <View
  383. style={{
  384. flex: 5,
  385. alignItems: 'flex-end'
  386. }}
  387. >
  388. <Text
  389. style={{
  390. flex: 1,
  391. fontSize: 15,
  392. textAlignVertical: 'center'
  393. }}
  394. numberOfLines={1}
  395. ellipsizeMode={'tail'}
  396. >
  397. {this.state.schoolName}
  398. </Text>
  399. </View>
  400. <View
  401. style={{
  402. flex: 1.1,
  403. alignItems: 'center',
  404. justifyContent: 'center'
  405. }}
  406. >
  407. {this.getArraowImg(4)}
  408. </View>
  409. </TouchableOpacity>
  410. <TouchableOpacity
  411. style={{
  412. flex: 1,
  413. marginTop: 1,
  414. width: '100%',
  415. flexDirection: 'row',
  416. backgroundColor: 'white',
  417. marginVertical: 1
  418. }}
  419. activeOpacity={1}
  420. onPress={() => this.arrowpress(5)}
  421. >
  422. <View
  423. style={{
  424. flex: 2,
  425. alignItems: 'center',
  426. justifyContent: 'center'
  427. }}
  428. >
  429. {this.choseheadericon(5)}
  430. </View>
  431. <Text style={styles.item_text}>我的年级</Text>
  432. <View
  433. style={{
  434. flex: 5,
  435. alignItems: 'flex-end'
  436. }}
  437. >
  438. <Text
  439. style={{
  440. flex: 1.1,
  441. fontSize: 15,
  442. textAlignVertical: 'center'
  443. }}
  444. numberOfLines={1}
  445. ellipsizeMode={'tail'}
  446. >
  447. {this.state.grade_text}
  448. </Text>
  449. </View>
  450. <View
  451. style={{
  452. flex: 1.1,
  453. alignItems: 'center',
  454. justifyContent: 'center'
  455. }}
  456. >
  457. {this.getArraowImg(5)}
  458. </View>
  459. </TouchableOpacity>
  460. </View>
  461. </View>
  462. </View>
  463. <View style={{ flex: 0.3, backgroundColor: '#F0F1F5' }} />
  464. <View
  465. style={{
  466. flex: 1.5,
  467. backgroundColor: '#F0F1F5',
  468. alignItems: 'center',
  469. justifyContent: 'center'
  470. }}
  471. >
  472. <View
  473. style={{
  474. width: '90%',
  475. alignItems: 'center',
  476. justifyContent: 'center',
  477. height: '100%',
  478. overflow: 'hidden',
  479. borderRadius: 10
  480. }}
  481. >
  482. <TouchableOpacity
  483. style={{
  484. flex: 1,
  485. width: '100%',
  486. flexDirection: 'row',
  487. backgroundColor: 'white',
  488. marginVertical: 1
  489. }}
  490. activeOpacity={1}
  491. onPress={() => this.arrowpress(6)}
  492. >
  493. <View
  494. style={{
  495. flex: 2,
  496. alignItems: 'center',
  497. justifyContent: 'center'
  498. }}
  499. >
  500. {this.choseheadericon(6)}
  501. </View>
  502. <Text style={styles.item_text}>我的手机号</Text>
  503. <View
  504. style={{
  505. flex: 5,
  506. alignItems: 'flex-end'
  507. }}
  508. >
  509. <Text
  510. style={{
  511. flex: 1,
  512. fontSize: 15,
  513. textAlignVertical: 'center',
  514. color: this.state.phone_bind_color
  515. }}
  516. numberOfLines={1}
  517. ellipsizeMode={'tail'}
  518. >
  519. {this.state.phone}
  520. </Text>
  521. </View>
  522. <View
  523. style={{
  524. flex: 1.1,
  525. alignItems: 'center',
  526. justifyContent: 'center'
  527. }}
  528. >
  529. {this.getArraowImg(6)}
  530. </View>
  531. </TouchableOpacity>
  532. <TouchableOpacity
  533. style={{
  534. flex: 1,
  535. width: '100%',
  536. flexDirection: 'row',
  537. backgroundColor: 'white',
  538. marginVertical: 1
  539. }}
  540. activeOpacity={1}
  541. onPress={() => this.arrowpress(7)}
  542. >
  543. <View
  544. style={{
  545. flex: 2,
  546. alignItems: 'center',
  547. justifyContent: 'center'
  548. }}
  549. >
  550. {this.choseheadericon(7)}
  551. </View>
  552. <Text style={styles.item_text}>我的微信</Text>
  553. <View
  554. style={{
  555. flex: 5,
  556. alignItems: 'flex-end'
  557. }}
  558. >
  559. <Text
  560. style={{
  561. flex: 1,
  562. fontSize: 15,
  563. textAlignVertical: 'center',
  564. color: this.state.wechat_bind_color
  565. }}
  566. numberOfLines={1}
  567. ellipsizeMode={'tail'}
  568. >
  569. {this.state.wechat_nickName}
  570. </Text>
  571. </View>
  572. <View
  573. style={{
  574. flex: 1.1,
  575. alignItems: 'center',
  576. justifyContent: 'center'
  577. }}
  578. >
  579. {this.getArraowImg(4)}
  580. </View>
  581. </TouchableOpacity>
  582. </View>
  583. </View>
  584. <View
  585. style={{
  586. width: '100%',
  587. flex: 2,
  588. backgroundColor: '#F0F1F5',
  589. flexDirection: 'column'
  590. }}
  591. >
  592. <View
  593. style={{
  594. flex: 1,
  595. flexDirection: 'row',
  596. alignItems: 'center',
  597. justifyContent: 'center'
  598. }}
  599. >
  600. <View
  601. style={{
  602. alignItems: 'center',
  603. width: '100%',
  604. height: '100%',
  605. backgroundColor: '#F0F1F5',
  606. justifyContent: 'center'
  607. }}
  608. >
  609. <View
  610. style={{
  611. flex: 1.5
  612. }}
  613. />
  614. <TouchableOpacity
  615. activeOpacity={1}
  616. style={{
  617. flex: 2,
  618. width: '100%',
  619. alignItems: 'center',
  620. justifyContent: 'center',
  621. height: '100%'
  622. }}
  623. onPress={() => this.logout()}
  624. >
  625. <ImageBackground
  626. source={require('./images/userInfo/logoutbg1.png')}
  627. style={{
  628. flex: 1,
  629. width: '100%',
  630. alignItems: 'center',
  631. justifyContent: 'center',
  632. height: '100%'
  633. }}
  634. imageStyle={{ resizeMode: 'contain' }}
  635. >
  636. <Text
  637. style={{
  638. fontSize: 22,
  639. color: 'white',
  640. width: '100%',
  641. textAlign: 'center'
  642. }}
  643. >
  644. 退出登录
  645. </Text>
  646. </ImageBackground>
  647. </TouchableOpacity>
  648. <View
  649. style={{
  650. flex: 1.5
  651. }}
  652. />
  653. </View>
  654. </View>
  655. </View>
  656. </View>
  657. </View>
  658. {/* <BindPhoneSuccess show={this.state.show_bind_phone} /> */}
  659. </View>
  660. );
  661. }
  662. componentWillMount() {
  663. //获取用户信息
  664. this.getUserInfo();
  665. BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
  666. }
  667. componentWillUnmount() {
  668. BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
  669. }
  670. async getUserInfo() {
  671. let userinfo = await global.storage
  672. .load({
  673. key: 'userInfo'
  674. })
  675. .then((result) => {
  676. console.log('============PersonalInfo========================');
  677. console.log(result.user.birthday);
  678. console.log('============PersonalInfo========================');
  679. var time = this.formaterDate(result.user.birthday);
  680. this.setState({
  681. schoolName:
  682. result.user.school === '' ? '未设置' :
  683. result.user.school,
  684. provinceName:
  685. result.user.province === '' ? '未设置' :
  686. result.user.province,
  687. citys:
  688. result.user.city === '' ? '未设置' :
  689. result.user.city,
  690. phone: result.user.mobile,
  691. wechat_nickName: result.user.wechat_nickName,
  692. user_nickName: result.user.nickName,
  693. birthday_time: time
  694. });
  695. if (this.state.phone == null || this.state.phone === '') {
  696. this.setState({
  697. phone_bind_color: 'red',
  698. phone_bind_type: 1,
  699. phone: '未绑定'
  700. });
  701. } else {
  702. this.setState({
  703. phone_bind_color: 'rgba(113, 113, 113, 1)',
  704. phone_bind_type: 2
  705. });
  706. }
  707. if (this.state.wechat_nickName == null || this.state.wechat_nickName === '') {
  708. this.setState({
  709. wechat_bind_color: 'red',
  710. wechat_nickName: '未绑定'
  711. });
  712. } else {
  713. this.setState({
  714. wechat_bind_color: 'rgba(113, 113, 113, 1)'
  715. });
  716. }
  717. return result;
  718. })
  719. .catch((err) => {
  720. console.log('PersonalInfo:ERROR' + err.message);
  721. return null;
  722. });
  723. }
  724. onBackAndroid = () => {
  725. if (this.state.show_bind_phone) {
  726. this.setState({
  727. show_bind_phone: false
  728. });
  729. } else {
  730. this.goBack();
  731. }
  732. return true;
  733. };
  734. getArraowImg(type) {
  735. return (
  736. <View
  737. style={{
  738. width: '100%',
  739. height: '100%',
  740. alignItems: 'center',
  741. resizeMode: 'contain',
  742. justifyContent: 'center'
  743. }}
  744. //onPress={() => this.arrowpress(type)}
  745. >
  746. <Image
  747. source={require('./images/userInfo/arrow.png')}
  748. style={{
  749. width: '20%',
  750. height: '30%'
  751. }}
  752. />
  753. </View>
  754. );
  755. }
  756. choseheadericon(type) {
  757. let headerpath;
  758. switch (type) {
  759. case 0:
  760. headerpath = require('./images/userInfo/headportrait.png');
  761. break;
  762. case 1:
  763. headerpath = require('./images/userInfo/nickname.png');
  764. break;
  765. case 2:
  766. headerpath = require('./images/userInfo/birthday.png');
  767. break;
  768. case 3:
  769. headerpath = require('./images/userInfo/location.png');
  770. break;
  771. case 4:
  772. headerpath = require('./images/userInfo/school.png');
  773. break;
  774. case 5:
  775. headerpath = require('./images/userInfo/grade.png');
  776. break;
  777. case 6:
  778. headerpath = require('./images/userInfo/phone.png');
  779. break;
  780. case 7:
  781. headerpath = require('./images/userInfo/wechat.png');
  782. break;
  783. }
  784. // alert(headerpath);
  785. return (
  786. <Image
  787. source={headerpath}
  788. style={{
  789. width: '60%',
  790. height: '60%',
  791. resizeMode: 'contain'
  792. }}
  793. />
  794. );
  795. }
  796. arrowpress(type) {
  797. switch (type) {
  798. case 0:
  799. this.chosephoto.setModalVisible(true);
  800. break;
  801. case 1:
  802. this.dialog.setInfo('修改昵称', '昵称');
  803. this.dialog.setModalVisible(true, 1);
  804. break;
  805. case 2:
  806. // alert("生日");
  807. this.birthdaymodal.setModalVisible(true);
  808. break;
  809. case 3:
  810. this.regionmodal.setModalVisible(true);
  811. break;
  812. case 4:
  813. this.dialog.setInfo('我的学校', '学校名称');
  814. this.dialog.setModalVisible(true, 2);
  815. break;
  816. case 5:
  817. this.gradeselectionModal.setModalVisible(true);
  818. break;
  819. //手机号
  820. case 6:
  821. this.props.navigation.navigate('PhoneBind', {
  822. type: this.state.phone_bind_type,
  823. bind_phone_back: this.bind_phone_back.bind(this)
  824. });
  825. break;
  826. //微信
  827. case 7:
  828. wechat.wechatLogin((result) => {
  829. console.log('openid:' + result['openid']);
  830. console.log('unionid:' + result['unionid']);
  831. console.log('nickname:' + result['nickname']);
  832. console.log('sex:' + result['sex']);
  833. console.log('avatar:' + result['province'] + result['city']);
  834. let opts = {
  835. method: 'PUT',
  836. body: {
  837. openId: result['openid'],
  838. unionId: result['unionid'],
  839. avatar: result['province'] + result['city'],
  840. sex: result['sex'],
  841. nickName: result['nickname']
  842. }
  843. };
  844. http_user.bind_wechat(opts).then((res) => {
  845. if (res.code == 200) {
  846. this.setState({
  847. wechat_nickName: res['nickname'],
  848. wechat_bind_color: 'rgba(113, 113, 113, 1)'
  849. });
  850. } else {
  851. ToastAndroid.show(res.message, ToastAndroid.SHORT);
  852. }
  853. });
  854. });
  855. break;
  856. }
  857. }
  858. logout() {
  859. //清空存储的用户信息
  860. global.storage.remove({ key: 'userInfo' });
  861. this.clearPageToNext('Login');
  862. }
  863. updateState(input_text, type) {
  864. if (type == 1) {
  865. this.setState({ nickName: input_text });
  866. this.updateUserInfo({ nickName: input_text });
  867. } else if (type == 2) {
  868. this.setState({ schoolName: input_text });
  869. this.updateUserInfo({ school: input_text });
  870. }
  871. }
  872. cityscommit(provinces_name, citys_name) {
  873. this.setState({
  874. provinceName: provinces_name,
  875. citys: citys_name
  876. });
  877. this.updateUserInfo({ province: provinces_name, city: citys_name });
  878. }
  879. commitGrade(text, index) {
  880. this.setState({
  881. grade_text: text,
  882. grade_index: index
  883. });
  884. this.updateUserInfo({ grade: index + 1 });
  885. }
  886. birthdaycommit(year, month, day) {
  887. this.setState({
  888. birthday_time: year + '年' + month + '月' + day + '日'
  889. });
  890. var date = new Date(year + '-' + month + '-' + day);
  891. this.updateUserInfo({ birthday: date });
  892. }
  893. photoback(photo_uri) {
  894. if (photo_uri == undefined || photo_uri === '' || photo_uri == null) {
  895. return;
  896. }
  897. this.setState({
  898. photo_uri: { uri: photo_uri }
  899. });
  900. }
  901. updateUserInfo(object) {
  902. let opts = {
  903. method: 'PUT', //请求方法
  904. body: object //请求体
  905. };
  906. http_user.update_UserInfo(opts).then((res) => {
  907. console.log(res);
  908. });
  909. }
  910. bind_phone_back(phone_num, result) {
  911. if (result == true) {
  912. ToastAndroid.show('修改成功', ToastAndroid.SHORT);
  913. this.setState({ phone: phone_num, phone_bind_result: result, show_bind_phone: true });
  914. } else {
  915. // ToastAndroid.show('修改失败', ToastAndroid.SHORT);
  916. }
  917. }
  918. formaterDate(date) {
  919. var date = new Date(date);
  920. var Y = date.getFullYear() + '';
  921. var M =
  922. (
  923. date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) :
  924. date.getMonth() + 1) + '';
  925. var D =
  926. (
  927. date.getDate() < 10 ? '0' + date.getDate() :
  928. date.getDate()) + ' ';
  929. //影响选择出生年月日了。
  930. this.setState({
  931. birthday_year: Y,
  932. birthday_month: M,
  933. birthday_day: D
  934. });
  935. return Y + '-' + M + '-' + D;
  936. }
  937. }
  938. class BindPhoneSuccess extends BasePage {
  939. render() {
  940. if (this.props.show) {
  941. return (
  942. <View
  943. style={{
  944. position: 'absolute',
  945. width: '100%',
  946. height: '100%',
  947. backgroundColor: 'rgba(0, 0, 0, 0.5)'
  948. }}
  949. />
  950. );
  951. } else {
  952. return null;
  953. }
  954. }
  955. }
  956. const styles = StyleSheet.create({
  957. item: {
  958. flex: 1,
  959. width: '100%',
  960. flexDirection: 'row',
  961. backgroundColor: 'white',
  962. marginTop: 1,
  963. backgroundColor: 'red'
  964. },
  965. item_text: {
  966. flex: 3,
  967. textAlignVertical: 'center',
  968. color: 'black',
  969. fontSize: 16
  970. }
  971. });