enterpriseList.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import React, {Component} from 'react';
  2. import {View, Text, DeviceEventEmitter} from 'react-native';
  3. import { List, Radio, Modal, Toast, Button} from '@ant-design/react-native';
  4. import {RetrieveData, IndividualStorageData} from '../../data/storage';
  5. import {GetDataPost} from '../../data/encryption';
  6. import {ShowToast} from '../../components/rootToast/root_toast';
  7. import loading_css from '../../source/css/loading_css';
  8. import Spinner from 'react-native-loading-spinner-overlay';
  9. const RadioItem = Radio.RadioItem;
  10. export default class enterprise_list extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.props.navigation.dangerouslyGetParent().setOptions({
  14. tabBarVisible: false,
  15. });
  16. this.state={
  17. entItem: '',
  18. entsGroup : [],
  19. loadingText: 'loading',
  20. entTaxId: '',
  21. }
  22. //this._fetchDefaultEnt();
  23. this._fetchEntsData();
  24. }
  25. setLoadingStatus = (isLoading) => {
  26. this.setState({
  27. spinner: isLoading,
  28. });
  29. }
  30. //获取数据
  31. _fetchEntsData = async () => {
  32. this.setLoadingStatus(true);
  33. const entInfo = JSON.parse(await RetrieveData('defaultEnt'));
  34. //console.log(entInfo.entName);
  35. this.setState({entItem: entInfo});
  36. const res = await RetrieveData('token');
  37. const account = await RetrieveData('account');
  38. if (res && account) {
  39. let token = res.substring(1, res.length - 1);
  40. let mobile = account.substring(1, account.length - 1);
  41. const url = '/auth/ent/user/findManageInfoByMobile';
  42. let response = await GetDataPost(
  43. url,
  44. token,
  45. {
  46. mobile: mobile,
  47. },
  48. false,
  49. 2,
  50. );
  51. if (response.code != 0) {
  52. ShowToast(response.msg);
  53. this.setLoadingStatus(false);
  54. } else {
  55. //console.log(JSON.stringify(response.data.ents));
  56. this.setState({
  57. entsGroup: [...response.data.ents]
  58. });
  59. //console.log(JSON.stringify(this.state.entsGroup));
  60. this.setLoadingStatus(false);
  61. }
  62. }
  63. }
  64. //切换当前绑定企业
  65. onChange = async (value) => {
  66. console.log("checked: " + JSON.stringify(value.entTaxId));
  67. this.setState({loadingText: '切换中....'})
  68. this.setLoadingStatus(true);
  69. const res = await RetrieveData('token');
  70. const account = await RetrieveData('account');
  71. if (res && account) {
  72. let token = res.substring(1, res.length - 1);
  73. let mobile = account.substring(1, account.length - 1);
  74. const url = '/auth/comm/user/setDefaultChoose';
  75. let response = await GetDataPost(
  76. url,
  77. token,
  78. {
  79. mobile: mobile,
  80. defaultChoose: value.entTaxId
  81. },
  82. false,
  83. 1,
  84. );
  85. if (response.code != 0) {
  86. ShowToast(response.msg);
  87. this.setLoadingStatus(false);
  88. } else {
  89. //IndividualStorageData("defaultEnt", "hello");
  90. await IndividualStorageData('defaultEnt', JSON.stringify(value));
  91. //console.log(JSON.stringify(response.data.ents));
  92. this.setLoadingStatus(false);
  93. this.setState({
  94. entItem: value,
  95. loadingText: 'loading....'
  96. });
  97. DeviceEventEmitter.emit('updatePage', null);
  98. DeviceEventEmitter.emit('updateCurMon', null);
  99. this.props.navigation.goBack();
  100. this.props.navigation.navigate('home_navigation');
  101. }
  102. }
  103. };
  104. render() {
  105. return(
  106. <View>
  107. <Spinner
  108. visible={this.state.spinner}
  109. textContent={this.state.loadingText}
  110. textStyle={loading_css.spinnerTextStyle}
  111. />
  112. <View style={{height: 40, backgroundColor: '#fff', justifyContent: 'center', alignItems: 'center'}}>
  113. <Text>当前用户企业列表</Text>
  114. </View>
  115. <List style={{ marginTop: 12 }}>
  116. {this.state.entsGroup.map(i => (
  117. <RadioItem
  118. key={i.entTaxId}
  119. checked={i.entTaxId === this.state.entItem.entTaxId}
  120. onChange={event => {
  121. if (event.target.checked) {
  122. this.onChange(i)
  123. }
  124. }}
  125. >
  126. {i.entName}
  127. </RadioItem>
  128. ))}
  129. </List>
  130. </View>
  131. );
  132. }
  133. }