123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- import React, {Component} from 'react';
- import {View, Image, Text, TouchableOpacity} from 'react-native';
- import {Modal, Provider} from '@ant-design/react-native';
- import ImagePicker from 'react-native-image-crop-picker';
- import {RetrieveData} from '../../data/storage';
- import {GetDataPost, UploadImage, GetNetworkUrl} from '../../data/encryption';
- import {ShowToast} from '../../components/rootToast/root_toast';
- export default class personal_information extends Component {
- constructor(props) {
- super(props);
- this.props.navigation.dangerouslyGetParent().setOptions({
- tabBarVisible: false,
- });
- this.state = {
- headImage: '',
- userName: '',
- nickName: '',
- sex: '',
- companyName: '',
- address: '',
- phone: '',
- profiles: '',
- };
- }
- render() {
- return (
- <Provider>
- <View>
- <View
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- backgroundColor: '#ffffff',
- }}>
- <Text style={{marginLeft: 10}}>头像</Text>
- <TouchableOpacity onPress={() => this.selectHeadImage()}>
- <View
- style={{
- marginRight: 10,
- flexDirection: 'row',
- alignItems: 'center',
- }}>
- {this.state.headImage == '' ? (
- <Image
- source={require('../../source/img/personal/headImg.png')}
- style={{
- width: 55,
- height: 55,
- marginRight: 10,
- borderRadius: 50,
- }}
- />
- ) : (
- <Image
- source={{uri: this.state.headImage}}
- style={{
- width: 55,
- height: 55,
- margin: 10,
- borderRadius: 50,
- }}
- />
- )}
- <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
- </View>
- </TouchableOpacity>
- </View>
- <View
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- backgroundColor: '#ffffff',
- marginTop: 5,
- height: 45,
- }}>
- <Text style={{marginLeft: 10}}>用户名</Text>
- <View
- style={{
- marginRight: 10,
- flexDirection: 'row',
- alignItems: 'center',
- }}>
- <Text style={{marginRight: 10}}>{this.state.userName}</Text>
- </View>
- </View>
- <TouchableOpacity
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- backgroundColor: '#ffffff',
- marginTop: 5,
- height: 45,
- }}
- onPress={() => {
- this.props.navigation.navigate('change_nick_name', {data: this});
- }}>
- <Text style={{marginLeft: 10}}>昵称</Text>
- <View
- style={{
- marginRight: 10,
- flexDirection: 'row',
- alignItems: 'center',
- }}>
- <Text style={{marginRight: 10}}>{this.state.nickName}</Text>
- <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
- </View>
- </TouchableOpacity>
- <TouchableOpacity
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- backgroundColor: '#ffffff',
- marginTop: 5,
- height: 45,
- }}
- onPress={() => {
- this.props.navigation.navigate('change_sex', {data: this});
- }}>
- <Text style={{marginLeft: 10}}>性别</Text>
- <View
- style={{
- marginRight: 10,
- flexDirection: 'row',
- alignItems: 'center',
- }}>
- <Text style={{marginRight: 10}}>
- {this.state.sex == 'M' ? '男' : '女'}
- </Text>
- <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
- </View>
- </TouchableOpacity>
- <TouchableOpacity
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- backgroundColor: '#ffffff',
- marginTop: 5,
- height: 45,
- }}
- onPress={() => {
- this.props.navigation.navigate('change_company', {data: this});
- }}>
- <Text style={{marginLeft: 10}}>公司</Text>
- <View
- style={{
- marginRight: 10,
- flexDirection: 'row',
- alignItems: 'center',
- }}>
- <Text style={{marginRight: 10}}>{this.state.companyName}</Text>
- <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
- </View>
- </TouchableOpacity>
- <TouchableOpacity
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- backgroundColor: '#ffffff',
- marginTop: 5,
- height: 45,
- }}
- onPress={() => {
- this.props.navigation.navigate('change_address', {data: this});
- }}>
- <Text style={{marginLeft: 10}}>地址</Text>
- <View
- style={{
- marginRight: 10,
- flexDirection: 'row',
- alignItems: 'center',
- }}>
- <Text style={{marginRight: 10}}>{this.state.address}</Text>
- <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
- </View>
- </TouchableOpacity>
- <TouchableOpacity
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- backgroundColor: '#ffffff',
- marginTop: 5,
- height: 45,
- }}
- onPress={() => {
- this.props.navigation.navigate('change_phone', {data: this});
- }}>
- <Text style={{marginLeft: 10}}>手机号</Text>
- <View
- style={{
- marginRight: 10,
- flexDirection: 'row',
- alignItems: 'center',
- }}>
- <Text style={{marginRight: 10}}>{this.state.phone}</Text>
- <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
- </View>
- </TouchableOpacity>
- <TouchableOpacity
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- backgroundColor: '#ffffff',
- marginTop: 5,
- height: 45,
- }}
- onPress={() => {
- this.props.navigation.navigate('change_profiles', {data: this});
- }}>
- <Text style={{marginLeft: 10}}>个人简介</Text>
- <View
- style={{
- marginRight: 10,
- flexDirection: 'row',
- alignItems: 'center',
- }}>
- <Text
- style={{marginRight: 10, width: 200}}
- ellipsizeMode={'tail'}
- numberOfLines={2}>
- {this.state.profiles}
- </Text>
- <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
- </View>
- </TouchableOpacity>
- </View>
- </Provider>
- );
- }
- //加载信息
- componentDidMount(): void {
- this.getUserInformation();
- }
- //设置头像
- selectHeadImage = () => {
- Modal.operation([
- {text: '拍照', onPress: () => this.openCamera()},
- {text: '相册', onPress: () => this.openPicker()},
- ]);
- };
- //拍照选择头像
- openCamera = () => {
- ImagePicker.openCamera({
- width: 300,
- height: 400,
- cropping: true,
- }).then(image => {
- this.setState({
- headImage: image.path,
- });
- this.setImage(image);
- });
- };
- //相册选择头像
- openPicker = () => {
- ImagePicker.openPicker({
- width: 300,
- height: 400,
- cropping: true,
- }).then(image => {
- this.setState({
- headImage: image.path,
- });
- this.setImage(image);
- });
- };
- //设置头像
- setImage = async image => {
- let account = await RetrieveData('account');
- let token = await RetrieveData('token');
- if (token && account) {
- account = account.substring(1, account.length - 1);
- token = token.substring(1, token.length - 1);
- const url = '/auth/comm/user/avatar/update';
- let response = await UploadImage(
- url,
- token,
- {
- mobile: account,
- reqChannel: 3,
- },
- image,
- );
- if (response) {
- if (response.code == 0) {
- ShowToast('修改头像成功!');
- }
- } else {
- ShowToast('服务器故障!');
- }
- }
- };
- //获取用户信息
- getUserInformation = async () => {
- let account = await RetrieveData('account');
- let token = await RetrieveData('token');
- if (token && account) {
- account = account.substring(1, account.length - 1);
- token = token.substring(1, token.length - 1);
- const url = '/auth/comm/user/personalInfo/find';
- let response = await GetDataPost(
- url,
- token,
- {
- mobile: account,
- },
- false,
- 2,
- );
- if (response) {
- if (response.code == 0) {
- this.setState({
- nickName: response.data.nickName,
- sex: response.data.sex,
- companyName: response.data.company,
- headImage: GetNetworkUrl() + response.data.avatar,
- profiles: response.data.personalProfile,
- address: response.data.address,
- phone: response.data.mobile,
- userName: response.data.name,
- });
- }
- } else {
- ShowToast('服务器故障!');
- }
- }
- };
- }
|