personal_information.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. import React, {Component} from 'react';
  2. import {View, Image, Text, TouchableOpacity} from 'react-native';
  3. import {Modal, Provider} from '@ant-design/react-native';
  4. import ImagePicker from 'react-native-image-crop-picker';
  5. import {RetrieveData} from '../../data/storage';
  6. import {GetDataPost, UploadImage} from '../../data/encryption';
  7. import {ShowToast} from '../../components/rootToast/root_toast';
  8. export default class personal_information extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.props.navigation.dangerouslyGetParent().setOptions({
  12. tabBarVisible: false,
  13. });
  14. this.state = {
  15. headImage: '',
  16. userName: '',
  17. nickName: '',
  18. sex: '',
  19. companyName: '',
  20. address: '',
  21. phone: '',
  22. profiles: '',
  23. };
  24. }
  25. render() {
  26. return (
  27. <Provider>
  28. <View>
  29. <View
  30. style={{
  31. justifyContent: 'space-between',
  32. alignItems: 'center',
  33. flexDirection: 'row',
  34. backgroundColor: '#ffffff',
  35. }}>
  36. <Text style={{marginLeft: 10}}>头像</Text>
  37. <TouchableOpacity onPress={() => this.selectHeadImage()}>
  38. <View
  39. style={{
  40. marginRight: 10,
  41. flexDirection: 'row',
  42. alignItems: 'center',
  43. }}>
  44. {this.state.headImage == '' ? (
  45. <Image
  46. source={require('../../source/img/personal/headImg.png')}
  47. style={{
  48. width: 55,
  49. height: 55,
  50. marginRight: 10,
  51. borderRadius: 50,
  52. }}
  53. />
  54. ) : (
  55. <Image
  56. source={{uri: this.state.headImage}}
  57. style={{
  58. width: 55,
  59. height: 55,
  60. margin: 10,
  61. borderRadius: 50,
  62. }}
  63. />
  64. )}
  65. <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
  66. </View>
  67. </TouchableOpacity>
  68. </View>
  69. <View
  70. style={{
  71. justifyContent: 'space-between',
  72. alignItems: 'center',
  73. flexDirection: 'row',
  74. backgroundColor: '#ffffff',
  75. marginTop: 5,
  76. height: 45,
  77. }}>
  78. <Text style={{marginLeft: 10}}>用户名</Text>
  79. <View
  80. style={{
  81. marginRight: 10,
  82. flexDirection: 'row',
  83. alignItems: 'center',
  84. }}>
  85. <Text style={{marginRight: 10}}>{this.state.userName}</Text>
  86. </View>
  87. </View>
  88. <TouchableOpacity
  89. style={{
  90. justifyContent: 'space-between',
  91. alignItems: 'center',
  92. flexDirection: 'row',
  93. backgroundColor: '#ffffff',
  94. marginTop: 5,
  95. height: 45,
  96. }}
  97. onPress={() => {
  98. this.props.navigation.navigate('change_nick_name', {data: this});
  99. }}>
  100. <Text style={{marginLeft: 10}}>昵称</Text>
  101. <View
  102. style={{
  103. marginRight: 10,
  104. flexDirection: 'row',
  105. alignItems: 'center',
  106. }}>
  107. <Text style={{marginRight: 10}}>{this.state.nickName}</Text>
  108. <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
  109. </View>
  110. </TouchableOpacity>
  111. <TouchableOpacity
  112. style={{
  113. justifyContent: 'space-between',
  114. alignItems: 'center',
  115. flexDirection: 'row',
  116. backgroundColor: '#ffffff',
  117. marginTop: 5,
  118. height: 45,
  119. }}
  120. onPress={() => {
  121. this.props.navigation.navigate('change_sex', {data: this});
  122. }}>
  123. <Text style={{marginLeft: 10}}>性别</Text>
  124. <View
  125. style={{
  126. marginRight: 10,
  127. flexDirection: 'row',
  128. alignItems: 'center',
  129. }}>
  130. <Text style={{marginRight: 10}}>
  131. {this.state.sex == 'M' ? '男' : '女'}
  132. </Text>
  133. <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
  134. </View>
  135. </TouchableOpacity>
  136. <TouchableOpacity
  137. style={{
  138. justifyContent: 'space-between',
  139. alignItems: 'center',
  140. flexDirection: 'row',
  141. backgroundColor: '#ffffff',
  142. marginTop: 5,
  143. height: 45,
  144. }}
  145. onPress={() => {
  146. this.props.navigation.navigate('change_company', {data: this});
  147. }}>
  148. <Text style={{marginLeft: 10}}>公司</Text>
  149. <View
  150. style={{
  151. marginRight: 10,
  152. flexDirection: 'row',
  153. alignItems: 'center',
  154. }}>
  155. <Text style={{marginRight: 10}}>{this.state.companyName}</Text>
  156. <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
  157. </View>
  158. </TouchableOpacity>
  159. <TouchableOpacity
  160. style={{
  161. justifyContent: 'space-between',
  162. alignItems: 'center',
  163. flexDirection: 'row',
  164. backgroundColor: '#ffffff',
  165. marginTop: 5,
  166. height: 45,
  167. }}
  168. onPress={() => {
  169. this.props.navigation.navigate('change_address', {data: this});
  170. }}>
  171. <Text style={{marginLeft: 10}}>地址</Text>
  172. <View
  173. style={{
  174. marginRight: 10,
  175. flexDirection: 'row',
  176. alignItems: 'center',
  177. }}>
  178. <Text style={{marginRight: 10}}>{this.state.address}</Text>
  179. <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
  180. </View>
  181. </TouchableOpacity>
  182. <TouchableOpacity
  183. style={{
  184. justifyContent: 'space-between',
  185. alignItems: 'center',
  186. flexDirection: 'row',
  187. backgroundColor: '#ffffff',
  188. marginTop: 5,
  189. height: 45,
  190. }}
  191. onPress={() => {
  192. this.props.navigation.navigate('change_phone', {data: this});
  193. }}>
  194. <Text style={{marginLeft: 10}}>手机号</Text>
  195. <View
  196. style={{
  197. marginRight: 10,
  198. flexDirection: 'row',
  199. alignItems: 'center',
  200. }}>
  201. <Text style={{marginRight: 10}}>{this.state.phone}</Text>
  202. <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
  203. </View>
  204. </TouchableOpacity>
  205. <TouchableOpacity
  206. style={{
  207. justifyContent: 'space-between',
  208. alignItems: 'center',
  209. flexDirection: 'row',
  210. backgroundColor: '#ffffff',
  211. marginTop: 5,
  212. height: 45,
  213. }}
  214. onPress={() => {
  215. this.props.navigation.navigate('change_profiles', {data: this});
  216. }}>
  217. <Text style={{marginLeft: 10}}>个人简介</Text>
  218. <View
  219. style={{
  220. marginRight: 10,
  221. flexDirection: 'row',
  222. alignItems: 'center',
  223. }}>
  224. <Text
  225. style={{marginRight: 10, width: 200}}
  226. ellipsizeMode={'tail'}
  227. numberOfLines={2}>
  228. {this.state.profiles}
  229. </Text>
  230. <Text style={{fontSize: 20, color: '#999999'}}>{'>'}</Text>
  231. </View>
  232. </TouchableOpacity>
  233. </View>
  234. </Provider>
  235. );
  236. }
  237. //加载信息
  238. componentDidMount(): void {
  239. this.getUserInformation();
  240. }
  241. //设置头像
  242. selectHeadImage = () => {
  243. Modal.operation([
  244. {text: '拍照', onPress: () => this.openCamera()},
  245. {text: '相册', onPress: () => this.openPicker()},
  246. ]);
  247. };
  248. //拍照选择头像
  249. openCamera = () => {
  250. ImagePicker.openCamera({
  251. width: 300,
  252. height: 400,
  253. cropping: true,
  254. }).then((image) => {
  255. this.setState({
  256. headImage: image.path,
  257. });
  258. this.setImage(image);
  259. });
  260. };
  261. //相册选择头像
  262. openPicker = () => {
  263. ImagePicker.openPicker({
  264. width: 300,
  265. height: 400,
  266. cropping: true,
  267. }).then((image) => {
  268. this.setState({
  269. headImage: image.path,
  270. });
  271. this.setImage(image);
  272. });
  273. };
  274. //设置头像
  275. setImage = async (image) => {
  276. let account = await RetrieveData('account');
  277. let token = await RetrieveData('token');
  278. if (token && account) {
  279. account = account.substring(1, account.length - 1);
  280. token = token.substring(1, token.length - 1);
  281. const url = 'https://app.taxbk.cn:9443/auth/comm/user/avatar/update';
  282. let response = await UploadImage(
  283. url,
  284. token,
  285. {
  286. mobile: account,
  287. reqChannel: 3,
  288. },
  289. image,
  290. );
  291. if (response) {
  292. if (response.code == 0) {
  293. ShowToast('修改头像成功!');
  294. }
  295. } else {
  296. ShowToast('服务器故障!');
  297. }
  298. }
  299. };
  300. //获取用户信息
  301. getUserInformation = async () => {
  302. let account = await RetrieveData('account');
  303. let token = await RetrieveData('token');
  304. if (token && account) {
  305. account = account.substring(1, account.length - 1);
  306. token = token.substring(1, token.length - 1);
  307. const url = 'https://app.taxbk.cn:9443/auth/comm/user/personalInfo/find';
  308. let response = await GetDataPost(
  309. url,
  310. token,
  311. {
  312. mobile: account,
  313. },
  314. false,
  315. 2,
  316. );
  317. if (response) {
  318. if (response.code == 0) {
  319. this.setState({
  320. nickName: response.data.nickName,
  321. sex: response.data.sex,
  322. companyName: response.data.company,
  323. headImage: 'https://app.taxbk.cn:9443' + response.data.avatar,
  324. profiles: response.data.personalProfile,
  325. address: response.data.address,
  326. phone: response.data.mobile,
  327. userName: response.data.name,
  328. });
  329. }
  330. } else {
  331. ShowToast('服务器故障!');
  332. }
  333. }
  334. };
  335. }