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