PersonalInfo.js 25 KB

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