personal_information.js 15 KB

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