PersonalInfo.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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. Platform,
  11. StyleSheet,
  12. Text,
  13. View,
  14. Image,
  15. TouchableOpacity,
  16. ImageBackground,
  17. Button,
  18. StatusBar,
  19. Modal,
  20. TouchableHighlight,
  21. DeviceEventEmitter
  22. } from 'react-native';
  23. import AndroidUtil from '../../util/AndroidUtil';
  24. import BasePage from '../BasePage';
  25. import CourseTitle from './CourseTitle';
  26. import ChosePhoto from './ChosePhoto';
  27. import RegionModal from './RegionModal';
  28. import BirthdayModal from './BirthdayModal';
  29. import GradeSelectionModal from './GradeSelectionModal';
  30. import Header from './Header';
  31. import PersonalInfoDialog from './PersonalInfoDialog';
  32. import { NavigationActions, StackActions } from 'react-navigation';
  33. import asyncStorage from '../utils/asyncStorage';
  34. import user from '../services/user';
  35. type Props = {};
  36. export default class PersonalInfo extends BasePage {
  37. state = {
  38. nickName: '初始昵称',
  39. schoolName: '未设置',
  40. provinceName: '广东省',
  41. citys: '深圳市',
  42. grade_text: '七年级',
  43. grade_index: 6,
  44. birthday_year: 0,
  45. birthday_month: 0,
  46. birthday_day: 0,
  47. birthday_time: 0,
  48. photo_uri: require('../images/userInfo/default_photo.png')
  49. };
  50. render() {
  51. return (
  52. <View style={{ backgroundColor: '#F0F1F5', flex: 1 }}>
  53. <View style={{ width: '100%', height: this.getWindowHeight() }}>
  54. <PersonalInfoDialog
  55. ref={(view) => (this.dialog = view)}
  56. updateParentState={this.updateState.bind(this)}
  57. />
  58. <ChosePhoto ref={(view) => (this.chosephoto = view)} photoback={this.photoback.bind(this)} />
  59. <RegionModal
  60. ref={(view) => (this.regionmodal = view)}
  61. cityscommit={this.cityscommit.bind(this)}
  62. provinceName={this.state.provinceName}
  63. citys={this.state.citys}
  64. />
  65. <GradeSelectionModal
  66. ref={(view) => (this.gradeselectionModal = view)}
  67. commitGrade={this.commitGrade.bind(this)}
  68. grade_index={this.state.grade_index}
  69. />
  70. <BirthdayModal
  71. ref={(view) => (this.birthdaymodal = view)}
  72. birthdaycommit={this.birthdaycommit.bind(this)}
  73. year={this.state.birthday_year}
  74. month={this.state.birthday_month}
  75. day={this.state.birthday_day}
  76. />
  77. <StatusBar backgroundColor={'transparent'} translucent={true} />
  78. <View
  79. style={{
  80. flex: 1,
  81. flexDirection: 'column'
  82. }}
  83. >
  84. <ImageBackground
  85. source={require('../images/userInfo/top.png')}
  86. style={{
  87. flex: 2.8,
  88. width: '100%',
  89. backgroundColor: '#F0F1F5',
  90. height: '75%'
  91. }}
  92. imageStyle={{ resizeMode: 'cover' }}
  93. >
  94. <View
  95. style={{
  96. flex: 1,
  97. alignItems: 'center',
  98. justifyContent: 'center',
  99. flexDirection: 'column'
  100. }}
  101. >
  102. <CourseTitle
  103. style={{ flex: 4 }}
  104. width={this.getWindowWidth()}
  105. title="个人信息"
  106. lefttype={2}
  107. righttype={0}
  108. textcolor={'white'}
  109. backPress={() => this.goBack()}
  110. />
  111. <TouchableOpacity
  112. style={{
  113. flex: 1,
  114. backgroundColor: 'white',
  115. width: '90%',
  116. bottom: 0,
  117. alignItems: 'center',
  118. justifyContent: 'center',
  119. borderRadius: 20,
  120. overflow: 'hidden'
  121. }}
  122. activeOpacity={1}
  123. onPress={() => this.arrowpress(0)}
  124. >
  125. <View
  126. style={{
  127. flex: 1,
  128. borderRadius: 20,
  129. overflow: 'hidden',
  130. alignItems: 'center',
  131. justifyContent: 'center',
  132. flexDirection: 'row'
  133. }}
  134. >
  135. <View style={{ flex: 0.5 }} />
  136. <View
  137. style={{
  138. flex: 3,
  139. height: '100%',
  140. alignItems: 'center',
  141. justifyContent: 'center'
  142. }}
  143. >
  144. <Image
  145. style={{
  146. borderRadius: 50,
  147. width: '80%',
  148. height: '70%'
  149. // borderWidth: 3
  150. // borderColor: "red"
  151. }}
  152. source={this.state.photo_uri}
  153. />
  154. </View>
  155. <View
  156. style={{
  157. flex: 9,
  158. backgroundColor: 'white',
  159. height: '100%',
  160. justifyContent: 'center'
  161. }}
  162. >
  163. <Text style={{ left: 10, color: 'black', fontSize: 16 }}>修改头像</Text>
  164. </View>
  165. <View
  166. style={{
  167. flex: 1.5,
  168. height: '65%',
  169. alignItems: 'center',
  170. justifyContent: 'center'
  171. }}
  172. >
  173. {this.getArraowImg(0)}
  174. </View>
  175. </View>
  176. </TouchableOpacity>
  177. </View>
  178. </ImageBackground>
  179. <View style={{ flex: 0.5, backgroundColor: '#F0F1F5' }} />
  180. <View
  181. style={{
  182. width: '100%',
  183. flex: 4.3,
  184. alignItems: 'center',
  185. backgroundColor: '#F0F1F5'
  186. }}
  187. >
  188. <View
  189. style={{
  190. backgroundColor: 'rgb(242, 242, 242)',
  191. width: '90%',
  192. alignItems: 'center',
  193. justifyContent: 'center',
  194. height: '100%',
  195. overflow: 'hidden',
  196. borderRadius: 10
  197. }}
  198. >
  199. <View
  200. style={{
  201. width: '100%',
  202. alignItems: 'center',
  203. justifyContent: 'center',
  204. height: '100%'
  205. }}
  206. >
  207. <TouchableOpacity
  208. style={{
  209. flex: 1,
  210. marginVertical: 1,
  211. width: '100%',
  212. flexDirection: 'row',
  213. backgroundColor: 'white'
  214. }}
  215. activeOpacity={1}
  216. onPress={() => this.arrowpress(1)}
  217. >
  218. <View
  219. style={{
  220. flex: 2,
  221. alignItems: 'center',
  222. justifyContent: 'center'
  223. }}
  224. >
  225. {this.choseheadericon(1)}
  226. </View>
  227. <Text style={styles.item_text}>昵称</Text>
  228. <View
  229. style={{
  230. flex: 5,
  231. alignItems: 'flex-end'
  232. }}
  233. >
  234. <Text
  235. style={{
  236. flex: 1,
  237. fontSize: 15,
  238. textAlignVertical: 'center'
  239. }}
  240. numberOfLines={1}
  241. ellipsizeMode={'tail'}
  242. >
  243. {this.state.nickName}
  244. </Text>
  245. </View>
  246. <View
  247. style={{
  248. flex: 1.1,
  249. alignItems: 'center',
  250. justifyContent: 'center'
  251. }}
  252. >
  253. {this.getArraowImg(1)}
  254. </View>
  255. </TouchableOpacity>
  256. <TouchableOpacity
  257. style={{
  258. flex: 1,
  259. width: '100%',
  260. flexDirection: 'row',
  261. backgroundColor: 'white',
  262. marginVertical: 1
  263. }}
  264. activeOpacity={1}
  265. onPress={() => this.arrowpress(2)}
  266. >
  267. <View
  268. style={{
  269. flex: 2,
  270. alignItems: 'center',
  271. justifyContent: 'center'
  272. }}
  273. >
  274. {this.choseheadericon(2)}
  275. </View>
  276. <Text style={styles.item_text}>生日</Text>
  277. <View
  278. style={{
  279. flex: 5,
  280. alignItems: 'flex-end'
  281. }}
  282. >
  283. <Text
  284. style={{
  285. flex: 1,
  286. fontSize: 15,
  287. textAlignVertical: 'center'
  288. }}
  289. numberOfLines={1}
  290. ellipsizeMode={'tail'}
  291. >
  292. {this.state.birthday_time}
  293. </Text>
  294. </View>
  295. <View
  296. style={{
  297. flex: 1.1,
  298. alignItems: 'center',
  299. justifyContent: 'center'
  300. }}
  301. >
  302. {this.getArraowImg(2)}
  303. </View>
  304. </TouchableOpacity>
  305. <TouchableOpacity
  306. style={{
  307. flex: 1,
  308. width: '100%',
  309. flexDirection: 'row',
  310. backgroundColor: 'white',
  311. marginVertical: 1
  312. }}
  313. activeOpacity={1}
  314. onPress={() => this.arrowpress(3)}
  315. >
  316. <View
  317. style={{
  318. flex: 2,
  319. alignItems: 'center',
  320. justifyContent: 'center'
  321. }}
  322. >
  323. {this.choseheadericon(3)}
  324. </View>
  325. <Text style={styles.item_text}>所在地区</Text>
  326. <View
  327. style={{
  328. flex: 5,
  329. alignItems: 'flex-end'
  330. }}
  331. >
  332. <Text
  333. style={{
  334. flex: 1,
  335. fontSize: 15,
  336. textAlignVertical: 'center'
  337. }}
  338. numberOfLines={1}
  339. ellipsizeMode={'tail'}
  340. >
  341. {this.state.provinceName}-{this.state.citys}
  342. </Text>
  343. </View>
  344. <View
  345. style={{
  346. flex: 1.1,
  347. alignItems: 'center',
  348. justifyContent: 'center'
  349. }}
  350. >
  351. {this.getArraowImg(3)}
  352. </View>
  353. </TouchableOpacity>
  354. <TouchableOpacity
  355. style={{
  356. flex: 1,
  357. width: '100%',
  358. flexDirection: 'row',
  359. backgroundColor: 'white',
  360. marginVertical: 1
  361. }}
  362. activeOpacity={1}
  363. onPress={() => this.arrowpress(4)}
  364. >
  365. <View
  366. style={{
  367. flex: 2,
  368. alignItems: 'center',
  369. justifyContent: 'center'
  370. }}
  371. >
  372. {this.choseheadericon(4)}
  373. </View>
  374. <Text style={styles.item_text}>我的学校</Text>
  375. <View
  376. style={{
  377. flex: 5,
  378. alignItems: 'flex-end'
  379. }}
  380. >
  381. <Text
  382. style={{
  383. flex: 1,
  384. fontSize: 15,
  385. textAlignVertical: 'center'
  386. }}
  387. numberOfLines={1}
  388. ellipsizeMode={'tail'}
  389. >
  390. {this.state.schoolName}
  391. </Text>
  392. </View>
  393. <View
  394. style={{
  395. flex: 1.1,
  396. alignItems: 'center',
  397. justifyContent: 'center'
  398. }}
  399. >
  400. {this.getArraowImg(4)}
  401. </View>
  402. </TouchableOpacity>
  403. <TouchableOpacity
  404. style={{
  405. flex: 1,
  406. marginTop: 1,
  407. width: '100%',
  408. flexDirection: 'row',
  409. backgroundColor: 'white',
  410. marginVertical: 1
  411. }}
  412. activeOpacity={1}
  413. onPress={() => this.arrowpress(5)}
  414. >
  415. <View
  416. style={{
  417. flex: 2,
  418. alignItems: 'center',
  419. justifyContent: 'center'
  420. }}
  421. >
  422. {this.choseheadericon(5)}
  423. </View>
  424. <Text style={styles.item_text}>我的年级</Text>
  425. <View
  426. style={{
  427. flex: 5,
  428. alignItems: 'flex-end'
  429. }}
  430. >
  431. <Text
  432. style={{
  433. flex: 1.1,
  434. fontSize: 15,
  435. textAlignVertical: 'center'
  436. }}
  437. numberOfLines={1}
  438. ellipsizeMode={'tail'}
  439. >
  440. {this.state.grade_text}
  441. </Text>
  442. </View>
  443. <View
  444. style={{
  445. flex: 1.1,
  446. alignItems: 'center',
  447. justifyContent: 'center'
  448. }}
  449. >
  450. {this.getArraowImg(5)}
  451. </View>
  452. </TouchableOpacity>
  453. </View>
  454. </View>
  455. </View>
  456. <View
  457. style={{
  458. width: '100%',
  459. flex: 4,
  460. backgroundColor: '#F0F1F5',
  461. flexDirection: 'column'
  462. }}
  463. >
  464. <View style={{ flex: 2.5 }} />
  465. <View style={{ flex: 2, flexDirection: 'row' }}>
  466. <View style={{ flex: 1 }} />
  467. <View
  468. style={{
  469. flex: 7,
  470. width: '100%',
  471. height: '100%'
  472. }}
  473. >
  474. <TouchableOpacity
  475. activeOpacity={1}
  476. style={{
  477. flex: 2,
  478. width: '100%',
  479. alignItems: 'center',
  480. justifyContent: 'center',
  481. height: '100%'
  482. }}
  483. onPress={() => this.logout()}
  484. >
  485. <ImageBackground
  486. source={require('../images/userInfo/logoutbg1.png')}
  487. style={{
  488. flex: 1,
  489. width: '100%',
  490. alignItems: 'center',
  491. justifyContent: 'center',
  492. height: '100%'
  493. }}
  494. imageStyle={{ resizeMode: 'contain' }}
  495. >
  496. <Text
  497. style={{
  498. fontSize: 22,
  499. color: 'white',
  500. width: '100%',
  501. textAlign: 'center'
  502. }}
  503. >
  504. 退出登录
  505. </Text>
  506. </ImageBackground>
  507. </TouchableOpacity>
  508. <View style={{ flex: 1 }} />
  509. </View>
  510. <View style={{ flex: 1 }} />
  511. </View>
  512. <View style={{ flex: 0.8 }} />
  513. </View>
  514. </View>
  515. </View>
  516. </View>
  517. );
  518. }
  519. componentWillMount() {
  520. var date = new Date();
  521. var year = date.getFullYear().toString();
  522. var month = (date.getMonth() + 1).toString();
  523. var day = date.getDate().toString();
  524. this.setState({
  525. birthday_year: year,
  526. birthday_month: month,
  527. birthday_day: day,
  528. birthday_time: year + '年' + month + '月' + day + '日'
  529. });
  530. }
  531. getArraowImg(type) {
  532. return (
  533. <TouchableOpacity
  534. style={{
  535. width: '100%',
  536. height: '100%',
  537. alignItems: 'center',
  538. resizeMode: 'contain',
  539. justifyContent: 'center'
  540. }}
  541. onPress={() => this.arrowpress(type)}
  542. >
  543. <Image
  544. source={require('../images/userInfo/arrow.png')}
  545. style={{
  546. width: '20%',
  547. height: '30%'
  548. }}
  549. />
  550. </TouchableOpacity>
  551. );
  552. }
  553. choseheadericon(type) {
  554. let headerpath;
  555. switch (type) {
  556. case 0:
  557. headerpath = require('../images/userInfo/headportrait.png');
  558. break;
  559. case 1:
  560. headerpath = require('../images/userInfo/nickname.png');
  561. break;
  562. case 2:
  563. headerpath = require('../images/userInfo/birthday.png');
  564. break;
  565. case 3:
  566. headerpath = require('../images/userInfo/location.png');
  567. break;
  568. case 4:
  569. headerpath = require('../images/userInfo/school.png');
  570. break;
  571. case 5:
  572. headerpath = require('../images/userInfo/grade.png');
  573. break;
  574. }
  575. // alert(headerpath);
  576. return (
  577. <Image
  578. source={headerpath}
  579. style={{
  580. width: '60%',
  581. height: '60%',
  582. resizeMode: 'contain'
  583. }}
  584. />
  585. );
  586. }
  587. arrowpress(type) {
  588. switch (type) {
  589. case 0:
  590. this.chosephoto.setModalVisible(true);
  591. break;
  592. case 1:
  593. this.dialog.setInfo('修改昵称', '昵称');
  594. this.dialog.setModalVisible(true, 1);
  595. break;
  596. case 2:
  597. // alert("生日");
  598. this.birthdaymodal.setModalVisible(true);
  599. break;
  600. case 3:
  601. this.regionmodal.setModalVisible(true);
  602. break;
  603. case 4:
  604. this.dialog.setInfo('我的学校', '学校名称');
  605. this.dialog.setModalVisible(true, 2);
  606. break;
  607. case 5:
  608. this.gradeselectionModal.setModalVisible(true);
  609. break;
  610. }
  611. }
  612. logout() {
  613. const resetAction = StackActions.reset({
  614. index: 0,
  615. actions: [
  616. NavigationActions.navigate({ routeName: 'Login' }) //要跳转到的页面名字
  617. ]
  618. });
  619. this.props.navigation.dispatch(resetAction);
  620. }
  621. updateState(input_text, type) {
  622. if (type == 1) {
  623. this.setState({ nickName: input_text });
  624. this.updateUserInfo({ nickName: input_text });
  625. } else if (type == 2) {
  626. this.setState({ schoolName: input_text });
  627. this.updateUserInfo({ school: input_text });
  628. }
  629. }
  630. cityscommit(provinces_name, citys_name) {
  631. this.setState({
  632. provinceName: provinces_name,
  633. citys: citys_name
  634. });
  635. this.updateUserInfo({ province: provinces_name, city: citys_name });
  636. }
  637. commitGrade(text, index) {
  638. this.setState({
  639. grade_text: text,
  640. grade_index: index
  641. });
  642. this.updateUserInfo({ grade: index + 1 });
  643. }
  644. birthdaycommit(year, month, day) {
  645. this.setState({
  646. birthday_time: year + '年' + month + '月' + day + '日'
  647. });
  648. var date = new Date(year + '-' + month + '-' + day);
  649. this.updateUserInfo({ birthday: date });
  650. }
  651. photoback(photo_uri) {
  652. if (photo_uri == undefined || photo_uri === '' || photo_uri == null) {
  653. return;
  654. }
  655. this.setState({
  656. photo_uri: { uri: photo_uri }
  657. });
  658. }
  659. updateUserInfo(object) {
  660. let opts = {
  661. method: 'PUT', //请求方法
  662. body: object //请求体
  663. };
  664. user.update_UserInfo(opts).then((res) => {
  665. console.log(res);
  666. console.log('success');
  667. });
  668. }
  669. }
  670. const styles = StyleSheet.create({
  671. item: {
  672. flex: 1,
  673. width: '100%',
  674. flexDirection: 'row',
  675. backgroundColor: 'white',
  676. marginTop: 1,
  677. backgroundColor: 'red'
  678. },
  679. item_text: {
  680. flex: 3,
  681. textAlignVertical: 'center',
  682. color: 'black',
  683. fontSize: 16
  684. }
  685. });