PersonalInfo.js 22 KB

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