123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- import React, {Component} from 'react';
- import {
- View,
- Image,
- Text,
- TouchableOpacity,
- SafeAreaView,
- ScrollView,
- Alert,
- DeviceEventEmitter,
- } from 'react-native';
- import {WingBlank, WhiteSpace, Modal} from '@ant-design/react-native';
- import { ClearAll, IndividualStorageData, RetrieveData } from "../../data/storage";
- import {
- RequestNetwork,
- UploadImage,
- } from '../../data/encryption';
- import public_css from '../../source/css/public_css';
- import {ToastShow} from '../../components/toast/toast';
- import {rightArrowIcon} from '../../source/icon/icon';
- import {SvgXml} from 'react-native-svg';
- import ImagePicker from 'react-native-image-crop-picker';
- 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 (
- <SafeAreaView style={public_css.body}>
- <ScrollView>
- <TouchableOpacity
- onPress={() => {
- this.selectHeadImage();
- }}>
- <View
- style={{
- marginTop: 20,
- height: 100,
- justifyContent: 'center',
- alignItems: 'center',
- }}>
- <View>
- {this.state.headImage !== '' &&
- this.state.headImage !== null ? (
- <Image
- source={{uri: this.state.headImage}}
- style={{
- width: 80,
- height: 80,
- borderRadius: 60,
- }}
- />
- ) : this.state.sex === 'M' ? (
- <Image
- source={require('../../source/img/personal/man.png')}
- style={{
- width: 80,
- height: 80,
- borderRadius: 60,
- }}
- />
- ) : (
- <Image
- source={require('../../source/img/personal/woman.png')}
- style={{
- width: 80,
- height: 80,
- borderRadius: 60,
- }}
- />
- )}
- </View>
- <View
- style={{
- position: 'relative',
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: '#000000',
- width: 16,
- height: 16,
- borderRadius: 99,
- top: -15,
- left: 25,
- }}>
- <Image
- source={require('../../source/img/personal/camera.png')}
- style={{
- width: 10,
- height: 8.5,
- }}
- />
- </View>
- </View>
- </TouchableOpacity>
- <WingBlank>
- <View
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- borderBottomWidth: 0.5,
- borderBottomColor: '#808080',
- height: 45,
- }}>
- <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>用户名</Text>
- <TouchableOpacity style={{flexDirection: 'row'}}>
- <Text
- ellipsizeMode={'tail'}
- numberOfLines={1}
- style={{
- width: 100,
- color: '#64646A',
- textAlign: 'right',
- marginRight: 20,
- }}>
- {this.state.userName}
- </Text>
- </TouchableOpacity>
- </View>
- </WingBlank>
- <WingBlank>
- <View
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- borderBottomWidth: 0.5,
- borderBottomColor: '#808080',
- height: 45,
- }}>
- <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>昵称</Text>
- <TouchableOpacity
- style={{flexDirection: 'row'}}
- onPress={() => {
- this.props.navigation.navigate('change_nick_name', {
- data: this.state.nickName,
- isRefresh: () => {
- this.getUserInformation();
- },
- });
- }}>
- <Text
- ellipsizeMode={'tail'}
- numberOfLines={1}
- style={{width: 200, color: '#64646A', textAlign: 'right'}}>
- {this.state.nickName}
- </Text>
- <SvgXml height={20} xml={rightArrowIcon()} />
- </TouchableOpacity>
- </View>
- </WingBlank>
- <WingBlank>
- <View
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- borderBottomWidth: 0.5,
- borderBottomColor: '#808080',
- height: 45,
- }}>
- <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>性别</Text>
- <TouchableOpacity
- style={{flexDirection: 'row'}}
- onPress={() => {
- this.props.navigation.navigate('change_sex', {
- data: this.state.sex,
- isRefresh: () => {
- this.getUserInformation();
- },
- });
- }}>
- <Text style={{color: '#64646A'}}>
- {this.state.sex === 'M' ? '男' : '女'}
- </Text>
- <SvgXml height={20} xml={rightArrowIcon()} />
- </TouchableOpacity>
- </View>
- </WingBlank>
- <WingBlank>
- <View
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- borderBottomWidth: 0.5,
- borderBottomColor: '#808080',
- height: 45,
- }}>
- <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>公司</Text>
- <TouchableOpacity
- style={{flexDirection: 'row'}}
- onPress={() => {
- this.props.navigation.navigate('change_company', {
- data: this.state.companyName,
- isRefresh: () => {
- this.getUserInformation();
- },
- });
- }}>
- <Text
- ellipsizeMode={'tail'}
- numberOfLines={1}
- style={{width: 200, color: '#64646A', textAlign: 'right'}}>
- {this.state.companyName}
- </Text>
- <SvgXml height={20} xml={rightArrowIcon()} />
- </TouchableOpacity>
- </View>
- </WingBlank>
- <WingBlank>
- <View
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- borderBottomWidth: 0.5,
- borderBottomColor: '#808080',
- height: 45,
- }}>
- <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>地址</Text>
- <TouchableOpacity
- style={{flexDirection: 'row'}}
- onPress={() => {
- this.props.navigation.navigate('change_address', {
- data: this.state.address,
- isRefresh: () => {
- this.getUserInformation();
- },
- });
- }}>
- <Text
- ellipsizeMode={'tail'}
- numberOfLines={1}
- style={{width: 200, color: '#64646A', textAlign: 'right'}}>
- {this.state.address}
- </Text>
- <SvgXml height={20} xml={rightArrowIcon()} />
- </TouchableOpacity>
- </View>
- </WingBlank>
- <WingBlank>
- <View
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- borderBottomWidth: 0.5,
- borderBottomColor: '#808080',
- height: 45,
- }}>
- <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>手机号</Text>
- <TouchableOpacity style={{flexDirection: 'row'}}>
- <Text style={{color: '#64646A'}}>{this.state.phone}</Text>
- <SvgXml height={20} xml={rightArrowIcon()} />
- </TouchableOpacity>
- </View>
- </WingBlank>
- <WingBlank>
- <View
- style={{
- justifyContent: 'space-between',
- alignItems: 'center',
- flexDirection: 'row',
- }}>
- <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>
- 个人简介
- </Text>
- <TouchableOpacity
- style={{flexDirection: 'row', alignItems: 'center'}}
- onPress={() => {
- this.props.navigation.navigate('change_profiles', {
- data: this.state.profiles,
- isRefresh: () => {
- this.getUserInformation();
- },
- });
- }}>
- <Text
- ellipsizeMode={'tail'}
- numberOfLines={2}
- style={{width: 200, color: '#64646A', textAlign: 'right'}}>
- {this.state.profiles}
- </Text>
- <SvgXml height={20} xml={rightArrowIcon()} />
- </TouchableOpacity>
- </View>
- </WingBlank>
- </ScrollView>
- <WingBlank>
- <TouchableOpacity
- onPress={() => {
- this.loginOut();
- }}>
- <View
- style={{
- height: 50,
- borderRadius: 99,
- alignItems: 'center',
- justifyContent: 'center',
- borderWidth: 1,
- borderColor: '#CCCCCC',
- }}>
- <Text style={{color: '#64646A', fontSize: 16}}>退出登录</Text>
- </View>
- </TouchableOpacity>
- </WingBlank>
- <WhiteSpace />
- </SafeAreaView>
- );
- }
- //加载信息
- 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) {
- const url = '/auth/comm/user/avatar/update';
- let response = await UploadImage(
- url,
- token,
- {
- mobile: account,
- reqChannel: 3,
- },
- image,
- );
- if (response) {
- if (response.code === 0) {
- await this.getUserInformation();
- }
- }
- }
- };
- //获取用户信息
- getUserInformation = async () => {
- let account = await RetrieveData('account');
- let token = await RetrieveData('token');
- if (token && account) {
- const url = '/auth/comm/user/personalInfo/find';
- let response = await RequestNetwork(
- url,
- token,
- {
- mobile: account,
- },
- false,
- 2,
- );
- if (response) {
- console.log(response);
- if (response.code === 0) {
- let userHeadImg = {
- headImage: '',
- sex: 'M',
- nickName: '',
- companyName: '',
- profiles: '',
- address: '',
- phone: '',
- userName: '',
- };
- console.log(response);
- if (response.data !== null) {
- userHeadImg.headImage = response.data.avatar;
- userHeadImg.sex = response.data.sex;
- userHeadImg.nickName = response.data.nickName;
- userHeadImg.companyName = response.data.company;
- userHeadImg.profiles = response.data.personalProfile;
- userHeadImg.address = response.data.address;
- userHeadImg.phone = response.data.mobile;
- userHeadImg.userName = response.data.name;
- }
- await IndividualStorageData(
- 'userHeadImg',
- JSON.stringify(userHeadImg),
- );
- await IndividualStorageData(
- 'userInfo',
- JSON.stringify(response.data),
- );
- this.setState({
- nickName: userHeadImg.nickName,
- sex: userHeadImg.sex,
- companyName: userHeadImg.companyName,
- headImage: userHeadImg.headImage,
- profiles: userHeadImg.profiles,
- address: userHeadImg.address,
- phone: userHeadImg.phone,
- userName: userHeadImg.userName,
- });
- DeviceEventEmitter.emit('updateLoginInfo', true);
- }
- } else {
- ToastShow(1, '服务器故障!');
- }
- }
- };
- // 退出登录
- loginOut = () => {
- Alert.alert(
- '退出登录',
- '确定要退出登录吗!',
- [
- {
- text: '取消',
- onPress: () => console.log('Cancel Pressed'),
- style: 'cancel',
- },
- {text: '确定', onPress: () => this.cleanAll()},
- ],
- {cancelable: false},
- );
- };
- // 清空本地缓存
- cleanAll = async () => {
- await ClearAll();
- DeviceEventEmitter.emit('updateCompany');
- this.props.route.params.refresh(false);
- this.props.navigation.goBack();
- };
- }
|