/** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow */ import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View, Image, TouchableOpacity, ImageBackground, Button, StatusBar, Modal, TouchableHighlight, DeviceEventEmitter } from 'react-native'; import AndroidUtil from '../../util/AndroidUtil'; import BasePage from '../BasePage'; import CourseTitle from './CourseTitle'; import ChosePhoto from './ChosePhoto'; import RegionModal from './RegionModal'; import BirthdayModal from './BirthdayModal'; import GradeSelectionModal from './GradeSelectionModal'; import Header from './Header'; import PersonalInfoDialog from './PersonalInfoDialog'; import { NavigationActions, StackActions } from 'react-navigation'; import asyncStorage from '../utils/asyncStorage'; import user from '../services/user'; import wechat from '../utils/wechat'; type Props = {}; export default class PersonalInfo extends BasePage { state = { nickName: '初始昵称', schoolName: '未设置', provinceName: '广东省', citys: '深圳市', grade_text: '七年级', grade_index: 6, birthday_year: 0, birthday_month: 0, birthday_day: 0, birthday_time: 0, photo_uri: require('../images/userInfo/default_photo.png'), phone: '', phone_bind_color: '', wechat_nickName: '', wechat_bind_color: '' }; render() { return ( (this.dialog = view)} updateParentState={this.updateState.bind(this)} /> (this.chosephoto = view)} photoback={this.photoback.bind(this)} /> (this.regionmodal = view)} cityscommit={this.cityscommit.bind(this)} provinceName={this.state.provinceName} citys={this.state.citys} /> (this.gradeselectionModal = view)} commitGrade={this.commitGrade.bind(this)} grade_index={this.state.grade_index} /> (this.birthdaymodal = view)} birthdaycommit={this.birthdaycommit.bind(this)} year={this.state.birthday_year} month={this.state.birthday_month} day={this.state.birthday_day} /> this.goBack()} /> this.arrowpress(0)} > 修改头像 {this.getArraowImg(0)} this.arrowpress(1)} > {this.choseheadericon(1)} 昵称 {this.state.nickName} {this.getArraowImg(1)} this.arrowpress(2)} > {this.choseheadericon(2)} 生日 {this.state.birthday_time} {this.getArraowImg(2)} this.arrowpress(3)} > {this.choseheadericon(3)} 所在地区 {this.state.provinceName}-{this.state.citys} {this.getArraowImg(3)} this.arrowpress(4)} > {this.choseheadericon(4)} 我的学校 {this.state.schoolName} {this.getArraowImg(4)} this.arrowpress(5)} > {this.choseheadericon(5)} 我的年级 {this.state.grade_text} {this.getArraowImg(5)} this.arrowpress(6)} > {this.choseheadericon(6)} 我的手机号 {this.state.phone} {this.getArraowImg(6)} this.arrowpress(7)} > {this.choseheadericon(7)} 我的微信 {this.state.wechat_nickName} {this.getArraowImg(4)} this.logout()} > 退出登录 ); } componentWillMount() { var date = new Date(); var year = date.getFullYear().toString(); var month = (date.getMonth() + 1).toString(); var day = date.getDate().toString(); this.setState({ birthday_year: year, birthday_month: month, birthday_day: day, birthday_time: year + '年' + month + '月' + day + '日' }); if (this.state.phone == null || this.state.phone === '') { this.setState({ phone_bind_color: 'red', phone: '未绑定' }); } if (this.state.phone == null || this.state.phone === '') { this.setState({ wechat_bind_color: 'red', wechat_nickName: '未绑定' }); } } getArraowImg(type) { return ( this.arrowpress(type)} > ); } choseheadericon(type) { let headerpath; switch (type) { case 0: headerpath = require('../images/userInfo/headportrait.png'); break; case 1: headerpath = require('../images/userInfo/nickname.png'); break; case 2: headerpath = require('../images/userInfo/birthday.png'); break; case 3: headerpath = require('../images/userInfo/location.png'); break; case 4: headerpath = require('../images/userInfo/school.png'); break; case 5: headerpath = require('../images/userInfo/grade.png'); break; case 6: headerpath = require('../images/userInfo/phone.png'); break; case 7: headerpath = require('../images/userInfo/wechat.png'); break; } // alert(headerpath); return ( ); } arrowpress(type) { switch (type) { case 0: this.chosephoto.setModalVisible(true); break; case 1: this.dialog.setInfo('修改昵称', '昵称'); this.dialog.setModalVisible(true, 1); break; case 2: // alert("生日"); this.birthdaymodal.setModalVisible(true); break; case 3: this.regionmodal.setModalVisible(true); break; case 4: this.dialog.setInfo('我的学校', '学校名称'); this.dialog.setModalVisible(true, 2); break; case 5: this.gradeselectionModal.setModalVisible(true); break; //手机号 case 6: alert('手机号'); break; //微信 case 7: wechat.wechatLogin((result) => { console.log('openid:' + result['openid']); console.log('unionid:' + result['unionid']); console.log('nickname:' + result['nickname']); console.log('sex:' + result['sex']); console.log('avatar:' + result['province'] + result['city']); let opts = { method: 'PUT', body: { openId: result['openid'], unionId: result['unionid'], avatar: result['province'] + result['city'], sex: result['sex'], nickName: result['nickname'] } }; //接口不通 user.bind_wechat(opts).then((res) => { console.log(res); this.setState({ wechat_nickName: result['nickname'], wechat_bind_color: 'rgba(113, 113, 113, 1)' }); }); }); break; } } logout() { const resetAction = StackActions.reset({ index: 0, actions: [ NavigationActions.navigate({ routeName: 'Login' }) //要跳转到的页面名字 ] }); this.props.navigation.dispatch(resetAction); } updateState(input_text, type) { if (type == 1) { this.setState({ nickName: input_text }); this.updateUserInfo({ nickName: input_text }); } else if (type == 2) { this.setState({ schoolName: input_text }); this.updateUserInfo({ school: input_text }); } } cityscommit(provinces_name, citys_name) { this.setState({ provinceName: provinces_name, citys: citys_name }); this.updateUserInfo({ province: provinces_name, city: citys_name }); } commitGrade(text, index) { this.setState({ grade_text: text, grade_index: index }); this.updateUserInfo({ grade: index + 1 }); } birthdaycommit(year, month, day) { this.setState({ birthday_time: year + '年' + month + '月' + day + '日' }); var date = new Date(year + '-' + month + '-' + day); this.updateUserInfo({ birthday: date }); } photoback(photo_uri) { if (photo_uri == undefined || photo_uri === '' || photo_uri == null) { return; } this.setState({ photo_uri: { uri: photo_uri } }); } updateUserInfo(object) { let opts = { method: 'PUT', //请求方法 body: object //请求体 }; user.update_UserInfo(opts).then((res) => { console.log(res); }); } } const styles = StyleSheet.create({ item: { flex: 1, width: '100%', flexDirection: 'row', backgroundColor: 'white', marginTop: 1, backgroundColor: 'red' }, item_text: { flex: 3, textAlignVertical: 'center', color: 'black', fontSize: 16 } });