PersonalInfo.js 25 KB

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