PersonalInfo.js 21 KB

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