PersonalInfo.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  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. 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. style={{ height: 10000 }}
  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/logoutbg.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.setView();
  668. BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
  669. }
  670. componentWillUnmount() {
  671. BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
  672. }
  673. async setView() {
  674. console.log('====================================');
  675. console.log('userInfo', global.userInfo);
  676. console.log('====================================');
  677. var time;
  678. if (
  679. global.userInfo.birthday == null ||
  680. global.userInfo.birthday == undefined ||
  681. global.userInfo.birthday === ''
  682. ) {
  683. time = this.formaterDate(Date.parse(new Date()));
  684. } else {
  685. time = this.formaterDate(global.userInfo.birthday);
  686. }
  687. this.setState({
  688. schoolName: global.userInfo.school === '' ? '未设置' : global.userInfo.school,
  689. provinceName: global.userInfo.province === '' ? '未设置' : global.userInfo.province,
  690. citys: global.userInfo.city === '' ? '未设置' : global.userInfo.city,
  691. phone: global.userInfo.mobile,
  692. wechat_nickName: global.userInfo.wechat_nickName,
  693. user_nickName: global.userInfo.nickName,
  694. birthday_time: time,
  695. photo_uri:
  696. global.userInfo.avatar.length > 0
  697. ? { uri: global.userInfo.avatar }
  698. : require('./images/userInfo/default_photo.png')
  699. });
  700. if (this.state.phone == null || this.state.phone === '') {
  701. this.setState({
  702. phone_bind_color: 'red',
  703. phone_bind_type: 1,
  704. phone: '未绑定'
  705. });
  706. } else {
  707. this.setState({
  708. phone_bind_color: 'rgba(113, 113, 113, 1)',
  709. phone_bind_type: 2
  710. });
  711. }
  712. if (this.state.wechat_nickName == null || this.state.wechat_nickName === '') {
  713. this.setState({
  714. wechat_bind_color: 'red',
  715. wechat_nickName: '未绑定'
  716. });
  717. } else {
  718. this.setState({
  719. wechat_bind_color: 'rgba(113, 113, 113, 1)'
  720. });
  721. }
  722. this.setState({
  723. ready: true
  724. });
  725. }
  726. onBackAndroid = () => {
  727. if (this.state.show_bind_phone) {
  728. this.setState({
  729. show_bind_phone: false
  730. });
  731. } else {
  732. DeviceEventEmitter.emit('infoback');
  733. this.goBack();
  734. }
  735. return true;
  736. };
  737. getArraowImg(type) {
  738. return (
  739. <View
  740. style={{
  741. width: '100%',
  742. height: '100%',
  743. alignItems: 'center',
  744. resizeMode: 'contain',
  745. justifyContent: 'center'
  746. }}
  747. //onPress={() => this.arrowpress(type)}
  748. >
  749. <Image
  750. source={require('./images/userInfo/arrow.png')}
  751. style={{
  752. width: '20%',
  753. height: '30%'
  754. }}
  755. />
  756. </View>
  757. );
  758. }
  759. choseheadericon(type) {
  760. let headerpath;
  761. switch (type) {
  762. case 0:
  763. headerpath = require('./images/userInfo/headportrait.png');
  764. break;
  765. case 1:
  766. headerpath = require('./images/userInfo/nickname.png');
  767. break;
  768. case 2:
  769. headerpath = require('./images/userInfo/birthday.png');
  770. break;
  771. case 3:
  772. headerpath = require('./images/userInfo/location.png');
  773. break;
  774. case 4:
  775. headerpath = require('./images/userInfo/school.png');
  776. break;
  777. case 5:
  778. headerpath = require('./images/userInfo/grade.png');
  779. break;
  780. case 6:
  781. headerpath = require('./images/userInfo/phone.png');
  782. break;
  783. case 7:
  784. headerpath = require('./images/userInfo/wechat.png');
  785. break;
  786. }
  787. // alert(headerpath);
  788. return (
  789. <Image
  790. source={headerpath}
  791. style={{
  792. width: '60%',
  793. height: '60%',
  794. resizeMode: 'contain'
  795. }}
  796. />
  797. );
  798. }
  799. arrowpress(type) {
  800. switch (type) {
  801. case 0:
  802. this.chosephoto.setModalVisible(true);
  803. break;
  804. case 1:
  805. this.dialog.setInfo('修改昵称', '昵称');
  806. this.dialog.setModalVisible(true, 1);
  807. break;
  808. case 2:
  809. // alert("生日");
  810. this.birthdaymodal.setModalVisible(true);
  811. break;
  812. case 3:
  813. this.regionmodal.setModalVisible(true);
  814. break;
  815. case 4:
  816. this.dialog.setInfo('我的学校', '学校名称');
  817. this.dialog.setModalVisible(true, 2);
  818. break;
  819. case 5:
  820. this.gradeselectionModal.setModalVisible(true);
  821. break;
  822. //手机号
  823. case 6:
  824. if (this.state.phone === '未绑定') {
  825. this.props.navigation.navigate('PhoneBind', {
  826. type: this.state.phone_bind_type,
  827. bind_phone_back: this.bind_phone_back.bind(this)
  828. });
  829. }
  830. break;
  831. //微信
  832. case 7:
  833. wechat.wechatLogin((result) => {
  834. let opts = {
  835. method: 'PUT',
  836. body: {
  837. openId: result['openid'],
  838. unionId: result['unionid'],
  839. avatar: '',
  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. this.Toast(res.message);
  852. }
  853. });
  854. });
  855. break;
  856. }
  857. }
  858. logout() {
  859. //清空存储的用户信息
  860. http_user.LoginOut().then((res) => {
  861. console.log('====================================');
  862. console.log('res', res);
  863. console.log('====================================');
  864. global.storage.remove({ key: 'userInfo' });
  865. this.clearPageToNext('Login');
  866. });
  867. }
  868. updateState(input_text, type) {
  869. if (type == 1) {
  870. this.setState({ user_nickName: input_text });
  871. this.updateUserInfo({ nickName: input_text }, 1);
  872. } else if (type == 2) {
  873. this.setState({ schoolName: input_text });
  874. this.updateUserInfo({ school: input_text }, 5);
  875. }
  876. }
  877. cityscommit(provinces_name, citys_name) {
  878. this.setState({
  879. provinceName: provinces_name,
  880. citys: citys_name
  881. });
  882. this.updateUserInfo({ province: provinces_name, city: citys_name }, 4);
  883. }
  884. commitGrade(text, index) {
  885. this.setState({
  886. grade_text: text,
  887. grade_index: index
  888. });
  889. this.updateUserInfo({ grade: index + 1 });
  890. }
  891. birthdaycommit(year, month, day) {
  892. this.setState({
  893. birthday_time: year + '年' + month + '月' + day + '日'
  894. });
  895. var date = new Date(year + '-' + month + '-' + day);
  896. this.updateUserInfo({ birthday: date }, 3);
  897. }
  898. photoback(photo_uri) {
  899. if (photo_uri == undefined || photo_uri === '' || photo_uri == null) {
  900. return;
  901. }
  902. this.upload_head(photo_uri);
  903. }
  904. updateUserInfo(object, type) {
  905. let opts = {
  906. method: 'PUT', //请求方法
  907. body: object //请求体
  908. };
  909. http_user.update_UserInfo(opts).then((res) => {
  910. switch (type) {
  911. case 0:
  912. //只改变头像
  913. global.userInfo.avatar = res.data.avatar;
  914. break;
  915. case 1:
  916. //修改昵称
  917. global.userInfo.nickName = res.data.nickName;
  918. break;
  919. case 2:
  920. global.userInfo.birthday = res.data.birthday;
  921. break;
  922. case 3:
  923. global.userInfo.birthday = res.data.birthday;
  924. break;
  925. case 4:
  926. global.userInfo.province = res.data.province;
  927. global.userInfo.city = res.data.city;
  928. break;
  929. case 5:
  930. global.userInfo.school = res.data.school;
  931. break;
  932. case 6:
  933. global.userInfo.mobile = res.data.mobile;
  934. break;
  935. }
  936. commonutil.saveUserInfo();
  937. });
  938. }
  939. bind_phone_back(phone_num, result) {
  940. if (result == true) {
  941. this.Toast('修改手机号成功');
  942. this.setState({
  943. phone: phone_num,
  944. phone_bind_result: result,
  945. show_bind_phone: true
  946. });
  947. this.updateUserInfo({ mobile: phone_num }, 6);
  948. } else {
  949. this.Toast('修改手机号失败');
  950. }
  951. }
  952. personinfoback() {
  953. // this.props.navigation.state.params.infoback();
  954. DeviceEventEmitter.emit('infoback');
  955. this.props.navigation.goBack();
  956. }
  957. formaterDate(date) {
  958. var date = new Date(date);
  959. var Y = date.getFullYear() + '';
  960. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '';
  961. var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
  962. this.setState({
  963. birthday_year: Y,
  964. birthday_month: M,
  965. birthday_day: D
  966. });
  967. return Y + '-' + M + '-' + D;
  968. }
  969. upload_head(file_path) {
  970. //上传成功但是没拿到数据
  971. http_user.uploadImage(file_path).then((res) => {
  972. //请求成功
  973. if (res.code == 200) {
  974. this.setState({
  975. photo_uri: { uri: res.data }
  976. });
  977. this.updateUserInfo({ avatar: res.data }, 0);
  978. this.Toast('上传成功');
  979. } else {
  980. this.Toast('上传失败:' + res.message);
  981. }
  982. });
  983. }
  984. }
  985. const styles = StyleSheet.create({
  986. item: {
  987. flex: 1,
  988. width: '100%',
  989. flexDirection: 'row',
  990. backgroundColor: 'white',
  991. marginTop: 1,
  992. backgroundColor: 'red'
  993. },
  994. item_text: {
  995. flex: 3,
  996. textAlignVertical: 'center',
  997. color: 'black',
  998. fontSize: 16
  999. }
  1000. });