personal_information.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. TouchableOpacity,
  7. SafeAreaView,
  8. ScrollView,
  9. Alert,
  10. DeviceEventEmitter,
  11. } from 'react-native';
  12. import {WingBlank, WhiteSpace, Modal} from '@ant-design/react-native';
  13. import { ClearAll, IndividualStorageData, RetrieveData } from "../../data/storage";
  14. import {
  15. RequestNetwork,
  16. UploadImage,
  17. } from '../../data/encryption';
  18. import public_css from '../../source/css/public_css';
  19. import {ToastShow} from '../../components/toast/toast';
  20. import {rightArrowIcon} from '../../source/icon/icon';
  21. import {SvgXml} from 'react-native-svg';
  22. import ImagePicker from 'react-native-image-crop-picker';
  23. export default class personal_information extends Component {
  24. constructor(props) {
  25. super(props);
  26. this.props.navigation.dangerouslyGetParent().setOptions({
  27. tabBarVisible: false,
  28. });
  29. this.state = {
  30. headImage: '',
  31. userName: '',
  32. nickName: '',
  33. sex: '',
  34. companyName: '',
  35. address: '',
  36. phone: '',
  37. profiles: '',
  38. };
  39. }
  40. render() {
  41. return (
  42. <SafeAreaView style={public_css.body}>
  43. <ScrollView>
  44. <TouchableOpacity
  45. onPress={() => {
  46. this.selectHeadImage();
  47. }}>
  48. <View
  49. style={{
  50. marginTop: 20,
  51. height: 100,
  52. justifyContent: 'center',
  53. alignItems: 'center',
  54. }}>
  55. <View>
  56. {this.state.headImage !== '' &&
  57. this.state.headImage !== null ? (
  58. <Image
  59. source={{uri: this.state.headImage}}
  60. style={{
  61. width: 80,
  62. height: 80,
  63. borderRadius: 60,
  64. }}
  65. />
  66. ) : this.state.sex === 'M' ? (
  67. <Image
  68. source={require('../../source/img/personal/man.png')}
  69. style={{
  70. width: 80,
  71. height: 80,
  72. borderRadius: 60,
  73. }}
  74. />
  75. ) : (
  76. <Image
  77. source={require('../../source/img/personal/woman.png')}
  78. style={{
  79. width: 80,
  80. height: 80,
  81. borderRadius: 60,
  82. }}
  83. />
  84. )}
  85. </View>
  86. <View
  87. style={{
  88. position: 'relative',
  89. justifyContent: 'center',
  90. alignItems: 'center',
  91. backgroundColor: '#000000',
  92. width: 16,
  93. height: 16,
  94. borderRadius: 99,
  95. top: -15,
  96. left: 25,
  97. }}>
  98. <Image
  99. source={require('../../source/img/personal/camera.png')}
  100. style={{
  101. width: 10,
  102. height: 8.5,
  103. }}
  104. />
  105. </View>
  106. </View>
  107. </TouchableOpacity>
  108. <WingBlank>
  109. <View
  110. style={{
  111. justifyContent: 'space-between',
  112. alignItems: 'center',
  113. flexDirection: 'row',
  114. borderBottomWidth: 0.5,
  115. borderBottomColor: '#808080',
  116. height: 45,
  117. }}>
  118. <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>用户名</Text>
  119. <TouchableOpacity style={{flexDirection: 'row'}}>
  120. <Text
  121. ellipsizeMode={'tail'}
  122. numberOfLines={1}
  123. style={{
  124. width: 100,
  125. color: '#64646A',
  126. textAlign: 'right',
  127. marginRight: 20,
  128. }}>
  129. {this.state.userName}
  130. </Text>
  131. </TouchableOpacity>
  132. </View>
  133. </WingBlank>
  134. <WingBlank>
  135. <View
  136. style={{
  137. justifyContent: 'space-between',
  138. alignItems: 'center',
  139. flexDirection: 'row',
  140. borderBottomWidth: 0.5,
  141. borderBottomColor: '#808080',
  142. height: 45,
  143. }}>
  144. <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>昵称</Text>
  145. <TouchableOpacity
  146. style={{flexDirection: 'row'}}
  147. onPress={() => {
  148. this.props.navigation.navigate('change_nick_name', {
  149. data: this.state.nickName,
  150. isRefresh: () => {
  151. this.getUserInformation();
  152. },
  153. });
  154. }}>
  155. <Text
  156. ellipsizeMode={'tail'}
  157. numberOfLines={1}
  158. style={{width: 200, color: '#64646A', textAlign: 'right'}}>
  159. {this.state.nickName}
  160. </Text>
  161. <SvgXml height={20} xml={rightArrowIcon()} />
  162. </TouchableOpacity>
  163. </View>
  164. </WingBlank>
  165. <WingBlank>
  166. <View
  167. style={{
  168. justifyContent: 'space-between',
  169. alignItems: 'center',
  170. flexDirection: 'row',
  171. borderBottomWidth: 0.5,
  172. borderBottomColor: '#808080',
  173. height: 45,
  174. }}>
  175. <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>性别</Text>
  176. <TouchableOpacity
  177. style={{flexDirection: 'row'}}
  178. onPress={() => {
  179. this.props.navigation.navigate('change_sex', {
  180. data: this.state.sex,
  181. isRefresh: () => {
  182. this.getUserInformation();
  183. },
  184. });
  185. }}>
  186. <Text style={{color: '#64646A'}}>
  187. {this.state.sex === 'M' ? '男' : '女'}
  188. </Text>
  189. <SvgXml height={20} xml={rightArrowIcon()} />
  190. </TouchableOpacity>
  191. </View>
  192. </WingBlank>
  193. <WingBlank>
  194. <View
  195. style={{
  196. justifyContent: 'space-between',
  197. alignItems: 'center',
  198. flexDirection: 'row',
  199. borderBottomWidth: 0.5,
  200. borderBottomColor: '#808080',
  201. height: 45,
  202. }}>
  203. <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>公司</Text>
  204. <TouchableOpacity
  205. style={{flexDirection: 'row'}}
  206. onPress={() => {
  207. this.props.navigation.navigate('change_company', {
  208. data: this.state.companyName,
  209. isRefresh: () => {
  210. this.getUserInformation();
  211. },
  212. });
  213. }}>
  214. <Text
  215. ellipsizeMode={'tail'}
  216. numberOfLines={1}
  217. style={{width: 200, color: '#64646A', textAlign: 'right'}}>
  218. {this.state.companyName}
  219. </Text>
  220. <SvgXml height={20} xml={rightArrowIcon()} />
  221. </TouchableOpacity>
  222. </View>
  223. </WingBlank>
  224. <WingBlank>
  225. <View
  226. style={{
  227. justifyContent: 'space-between',
  228. alignItems: 'center',
  229. flexDirection: 'row',
  230. borderBottomWidth: 0.5,
  231. borderBottomColor: '#808080',
  232. height: 45,
  233. }}>
  234. <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>地址</Text>
  235. <TouchableOpacity
  236. style={{flexDirection: 'row'}}
  237. onPress={() => {
  238. this.props.navigation.navigate('change_address', {
  239. data: this.state.address,
  240. isRefresh: () => {
  241. this.getUserInformation();
  242. },
  243. });
  244. }}>
  245. <Text
  246. ellipsizeMode={'tail'}
  247. numberOfLines={1}
  248. style={{width: 200, color: '#64646A', textAlign: 'right'}}>
  249. {this.state.address}
  250. </Text>
  251. <SvgXml height={20} xml={rightArrowIcon()} />
  252. </TouchableOpacity>
  253. </View>
  254. </WingBlank>
  255. <WingBlank>
  256. <View
  257. style={{
  258. justifyContent: 'space-between',
  259. alignItems: 'center',
  260. flexDirection: 'row',
  261. borderBottomWidth: 0.5,
  262. borderBottomColor: '#808080',
  263. height: 45,
  264. }}>
  265. <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>手机号</Text>
  266. <TouchableOpacity style={{flexDirection: 'row'}}>
  267. <Text style={{color: '#64646A'}}>{this.state.phone}</Text>
  268. <SvgXml height={20} xml={rightArrowIcon()} />
  269. </TouchableOpacity>
  270. </View>
  271. </WingBlank>
  272. <WingBlank>
  273. <View
  274. style={{
  275. justifyContent: 'space-between',
  276. alignItems: 'center',
  277. flexDirection: 'row',
  278. }}>
  279. <Text style={{color: '#3C3C3C', fontWeight: 'bold'}}>
  280. 个人简介
  281. </Text>
  282. <TouchableOpacity
  283. style={{flexDirection: 'row', alignItems: 'center'}}
  284. onPress={() => {
  285. this.props.navigation.navigate('change_profiles', {
  286. data: this.state.profiles,
  287. isRefresh: () => {
  288. this.getUserInformation();
  289. },
  290. });
  291. }}>
  292. <Text
  293. ellipsizeMode={'tail'}
  294. numberOfLines={2}
  295. style={{width: 200, color: '#64646A', textAlign: 'right'}}>
  296. {this.state.profiles}
  297. </Text>
  298. <SvgXml height={20} xml={rightArrowIcon()} />
  299. </TouchableOpacity>
  300. </View>
  301. </WingBlank>
  302. </ScrollView>
  303. <WingBlank>
  304. <TouchableOpacity
  305. onPress={() => {
  306. this.loginOut();
  307. }}>
  308. <View
  309. style={{
  310. height: 50,
  311. borderRadius: 99,
  312. alignItems: 'center',
  313. justifyContent: 'center',
  314. borderWidth: 1,
  315. borderColor: '#CCCCCC',
  316. }}>
  317. <Text style={{color: '#64646A', fontSize: 16}}>退出登录</Text>
  318. </View>
  319. </TouchableOpacity>
  320. </WingBlank>
  321. <WhiteSpace />
  322. </SafeAreaView>
  323. );
  324. }
  325. //加载信息
  326. componentDidMount(): void {
  327. this.getUserInformation();
  328. }
  329. //设置头像
  330. selectHeadImage = () => {
  331. Modal.operation([
  332. {text: '拍照', onPress: () => this.openCamera()},
  333. {text: '相册', onPress: () => this.openPicker()},
  334. ]);
  335. };
  336. //拍照选择头像
  337. openCamera = () => {
  338. ImagePicker.openCamera({
  339. width: 300,
  340. height: 400,
  341. cropping: true,
  342. }).then((image) => {
  343. this.setState({
  344. headImage: image.path,
  345. });
  346. this.setImage(image);
  347. });
  348. };
  349. //相册选择头像
  350. openPicker = () => {
  351. ImagePicker.openPicker({
  352. width: 300,
  353. height: 400,
  354. cropping: true,
  355. }).then((image) => {
  356. // this.setState({
  357. // headImage: image.path,
  358. // });
  359. this.setImage(image);
  360. });
  361. };
  362. //设置头像
  363. setImage = async (image) => {
  364. let account = await RetrieveData('account');
  365. let token = await RetrieveData('token');
  366. if (token && account) {
  367. const url = '/auth/comm/user/avatar/update';
  368. let response = await UploadImage(
  369. url,
  370. token,
  371. {
  372. mobile: account,
  373. reqChannel: 3,
  374. },
  375. image,
  376. );
  377. if (response) {
  378. if (response.code === 0) {
  379. await this.getUserInformation();
  380. }
  381. }
  382. }
  383. };
  384. //获取用户信息
  385. getUserInformation = async () => {
  386. let account = await RetrieveData('account');
  387. let token = await RetrieveData('token');
  388. if (token && account) {
  389. const url = '/auth/comm/user/personalInfo/find';
  390. let response = await RequestNetwork(
  391. url,
  392. token,
  393. {
  394. mobile: account,
  395. },
  396. false,
  397. 2,
  398. );
  399. if (response) {
  400. console.log(response);
  401. if (response.code === 0) {
  402. let userHeadImg = {
  403. headImage: '',
  404. sex: 'M',
  405. nickName: '',
  406. companyName: '',
  407. profiles: '',
  408. address: '',
  409. phone: '',
  410. userName: '',
  411. };
  412. console.log(response);
  413. if (response.data !== null) {
  414. userHeadImg.headImage = response.data.avatar;
  415. userHeadImg.sex = response.data.sex;
  416. userHeadImg.nickName = response.data.nickName;
  417. userHeadImg.companyName = response.data.company;
  418. userHeadImg.profiles = response.data.personalProfile;
  419. userHeadImg.address = response.data.address;
  420. userHeadImg.phone = response.data.mobile;
  421. userHeadImg.userName = response.data.name;
  422. }
  423. await IndividualStorageData(
  424. 'userHeadImg',
  425. JSON.stringify(userHeadImg),
  426. );
  427. await IndividualStorageData(
  428. 'userInfo',
  429. JSON.stringify(response.data),
  430. );
  431. this.setState({
  432. nickName: userHeadImg.nickName,
  433. sex: userHeadImg.sex,
  434. companyName: userHeadImg.companyName,
  435. headImage: userHeadImg.headImage,
  436. profiles: userHeadImg.profiles,
  437. address: userHeadImg.address,
  438. phone: userHeadImg.phone,
  439. userName: userHeadImg.userName,
  440. });
  441. DeviceEventEmitter.emit('updateLoginInfo', true);
  442. }
  443. } else {
  444. ToastShow(1, '服务器故障!');
  445. }
  446. }
  447. };
  448. // 退出登录
  449. loginOut = () => {
  450. Alert.alert(
  451. '退出登录',
  452. '确定要退出登录吗!',
  453. [
  454. {
  455. text: '取消',
  456. onPress: () => console.log('Cancel Pressed'),
  457. style: 'cancel',
  458. },
  459. {text: '确定', onPress: () => this.cleanAll()},
  460. ],
  461. {cancelable: false},
  462. );
  463. };
  464. // 清空本地缓存
  465. cleanAll = async () => {
  466. await ClearAll();
  467. DeviceEventEmitter.emit('updateCompany');
  468. this.props.route.params.refresh(false);
  469. this.props.navigation.goBack();
  470. };
  471. }