PersonalInfo.js 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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. this.goBack();
  741. }
  742. return true;
  743. };
  744. getArraowImg(type) {
  745. return (
  746. <View
  747. style={{
  748. width: '100%',
  749. height: '100%',
  750. alignItems: 'center',
  751. resizeMode: 'contain',
  752. justifyContent: 'center'
  753. }}
  754. //onPress={() => this.arrowpress(type)}
  755. >
  756. <Image
  757. source={require('./images/userInfo/arrow.png')}
  758. style={{
  759. width: '20%',
  760. height: '30%'
  761. }}
  762. />
  763. </View>
  764. );
  765. }
  766. choseheadericon(type) {
  767. let headerpath;
  768. switch (type) {
  769. case 0:
  770. headerpath = require('./images/userInfo/headportrait.png');
  771. break;
  772. case 1:
  773. headerpath = require('./images/userInfo/nickname.png');
  774. break;
  775. case 2:
  776. headerpath = require('./images/userInfo/birthday.png');
  777. break;
  778. case 3:
  779. headerpath = require('./images/userInfo/location.png');
  780. break;
  781. case 4:
  782. headerpath = require('./images/userInfo/school.png');
  783. break;
  784. case 5:
  785. headerpath = require('./images/userInfo/grade.png');
  786. break;
  787. case 6:
  788. headerpath = require('./images/userInfo/phone.png');
  789. break;
  790. case 7:
  791. headerpath = require('./images/userInfo/wechat.png');
  792. break;
  793. }
  794. // alert(headerpath);
  795. return (
  796. <Image
  797. source={headerpath}
  798. style={{
  799. width: '60%',
  800. height: '60%',
  801. resizeMode: 'contain'
  802. }}
  803. />
  804. );
  805. }
  806. arrowpress(type) {
  807. switch (type) {
  808. case 0:
  809. this.chosephoto.setModalVisible(true);
  810. break;
  811. case 1:
  812. this.dialog.setInfo('修改昵称', '昵称');
  813. this.dialog.setModalVisible(true, 1);
  814. break;
  815. case 2:
  816. // alert("生日");
  817. this.birthdaymodal.setModalVisible(true);
  818. break;
  819. case 3:
  820. this.regionmodal.setModalVisible(true);
  821. break;
  822. case 4:
  823. this.dialog.setInfo('我的学校', '学校名称');
  824. this.dialog.setModalVisible(true, 2);
  825. break;
  826. case 5:
  827. this.gradeselectionModal.setModalVisible(true);
  828. break;
  829. //手机号
  830. case 6:
  831. if (this.state.phone === '未绑定') {
  832. this.props.navigation.navigate('PhoneBind', {
  833. type: this.state.phone_bind_type,
  834. bind_phone_back: this.bind_phone_back.bind(this)
  835. });
  836. }
  837. break;
  838. //微信
  839. case 7:
  840. wechat.wechatLogin((result) => {
  841. let opts = {
  842. method: 'PUT',
  843. body: {
  844. openId: result['openid'],
  845. unionId: result['unionid'],
  846. avatar: '',
  847. sex: result['sex'],
  848. nickName: result['nickname']
  849. }
  850. };
  851. http_user.bind_wechat(opts).then((res) => {
  852. if (res.code == 200) {
  853. this.setState({
  854. wechat_nickName: res['nickname'],
  855. wechat_bind_color: 'rgba(113, 113, 113, 1)'
  856. });
  857. } else {
  858. this.Toast(res.message);
  859. }
  860. });
  861. });
  862. break;
  863. }
  864. }
  865. logout() {
  866. //清空存储的用户信息
  867. http_user.LoginOut().then((res) => {
  868. console.log('====================================');
  869. console.log('res', res);
  870. console.log('====================================');
  871. global.storage.remove({ key: 'userInfo' });
  872. this.clearPageToNext('Login');
  873. });
  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. this.Toast('修改手机号成功');
  924. this.setState({
  925. phone: phone_num,
  926. phone_bind_result: result,
  927. show_bind_phone: true
  928. });
  929. } else {
  930. this.Toast('修改手机号失败');
  931. }
  932. }
  933. personinfoback() {
  934. // this.props.navigation.state.params.infoback();
  935. DeviceEventEmitter.emit('infoback');
  936. this.props.navigation.goBack();
  937. }
  938. formaterDate(date) {
  939. var date = new Date(date);
  940. var Y = date.getFullYear() + '';
  941. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '';
  942. var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
  943. this.setState({
  944. birthday_year: Y,
  945. birthday_month: M,
  946. birthday_day: D
  947. });
  948. return Y + '-' + M + '-' + D;
  949. }
  950. upload_head(file_path) {
  951. //上传成功但是没拿到数据
  952. http_user.uploadImage(file_path).then((res) => {
  953. //请求成功
  954. if (res.code == 200) {
  955. this.setState({
  956. photo_uri: { uri: res.data }
  957. });
  958. this.updateUserInfo({ avatar: res.data });
  959. } else {
  960. this.Toast('上传失败:' + res.message);
  961. }
  962. });
  963. }
  964. update_file_userinfo(map, res) {
  965. map.set('ageGroup', res.data.ageGroup);
  966. map.set('avatar', res.data.avatar);
  967. map.set('birthday', res.data.birthday);
  968. map.set('channel', res.data.channel);
  969. map.set('city', res.data.city);
  970. map.set('country', res.data.country);
  971. map.set('eid', res.data.eid);
  972. map.set('gmtCreated', res.data.gmtCreated);
  973. map.set('gmtModified', res.data.gmtModified);
  974. map.set('mobile', res.data.mobile);
  975. map.set('nickName', res.data.nickName);
  976. map.set('province', res.data.province);
  977. map.set('school', res.data.school);
  978. map.set('sex', res.data.sex);
  979. map.set('status', res.data.status);
  980. map.set('uid', res.data.uid);
  981. }
  982. }
  983. class BindPhoneSuccess extends BasePage {
  984. render() {
  985. if (this.props.show) {
  986. return (
  987. <View
  988. style={{
  989. position: 'absolute',
  990. width: '100%',
  991. height: '100%',
  992. backgroundColor: 'rgba(0, 0, 0, 0.5)'
  993. }}
  994. />
  995. );
  996. } else {
  997. return null;
  998. }
  999. }
  1000. }
  1001. const styles = StyleSheet.create({
  1002. item: {
  1003. flex: 1,
  1004. width: '100%',
  1005. flexDirection: 'row',
  1006. backgroundColor: 'white',
  1007. marginTop: 1,
  1008. backgroundColor: 'red'
  1009. },
  1010. item_text: {
  1011. flex: 3,
  1012. textAlignVertical: 'center',
  1013. color: 'black',
  1014. fontSize: 16
  1015. }
  1016. });