123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import React, {Component} from 'react';
- import {View, Text, DeviceEventEmitter} from 'react-native';
- import { List, Radio, Modal, Toast, Button} from '@ant-design/react-native';
- import {RetrieveData, IndividualStorageData} from '../../data/storage';
- import {GetDataPost} from '../../data/encryption';
- import {ShowToast} from '../../components/rootToast/root_toast';
- import loading_css from '../../source/css/loading_css';
- import Spinner from 'react-native-loading-spinner-overlay';
- const RadioItem = Radio.RadioItem;
- export default class enterprise_list extends Component {
- constructor(props) {
- super(props);
- this.props.navigation.dangerouslyGetParent().setOptions({
- tabBarVisible: false,
- });
- this.state={
- entItem: '',
- entsGroup : [],
- loadingText: 'loading',
- entTaxId: '',
- }
- //this._fetchDefaultEnt();
- this._fetchEntsData();
- }
- setLoadingStatus = (isLoading) => {
- this.setState({
- spinner: isLoading,
- });
- }
- //获取数据
- _fetchEntsData = async () => {
- this.setLoadingStatus(true);
- const entInfo = JSON.parse(await RetrieveData('defaultEnt'));
- //console.log(entInfo.entName);
- this.setState({entItem: entInfo});
- const res = await RetrieveData('token');
- const account = await RetrieveData('account');
- if (res && account) {
- let token = res.substring(1, res.length - 1);
- let mobile = account.substring(1, account.length - 1);
- const url = '/auth/ent/user/findManageInfoByMobile';
- let response = await GetDataPost(
- url,
- token,
- {
- mobile: mobile,
- },
- false,
- 2,
- );
- if (response.code != 0) {
- ShowToast(response.msg);
- this.setLoadingStatus(false);
- } else {
- //console.log(JSON.stringify(response.data.ents));
- this.setState({
- entsGroup: [...response.data.ents]
- });
- //console.log(JSON.stringify(this.state.entsGroup));
- this.setLoadingStatus(false);
- }
- }
- }
- //切换当前绑定企业
- onChange = async (value) => {
- console.log("checked: " + JSON.stringify(value.entTaxId));
- this.setState({loadingText: '切换中....'})
- this.setLoadingStatus(true);
- const res = await RetrieveData('token');
- const account = await RetrieveData('account');
- if (res && account) {
- let token = res.substring(1, res.length - 1);
- let mobile = account.substring(1, account.length - 1);
- const url = '/auth/comm/user/setDefaultChoose';
- let response = await GetDataPost(
- url,
- token,
- {
- mobile: mobile,
- defaultChoose: value.entTaxId
- },
- false,
- 1,
- );
- if (response.code != 0) {
- ShowToast(response.msg);
- this.setLoadingStatus(false);
- } else {
- //IndividualStorageData("defaultEnt", "hello");
- await IndividualStorageData('defaultEnt', JSON.stringify(value));
- //console.log(JSON.stringify(response.data.ents));
- this.setLoadingStatus(false);
- this.setState({
- entItem: value,
- loadingText: 'loading....'
- });
- DeviceEventEmitter.emit('updatePage', null);
- DeviceEventEmitter.emit('updateCurMon', null);
- this.props.navigation.goBack();
- this.props.navigation.navigate('home_navigation');
- }
- }
- };
- render() {
- return(
- <View>
- <Spinner
- visible={this.state.spinner}
- textContent={this.state.loadingText}
- textStyle={loading_css.spinnerTextStyle}
- />
- <View style={{height: 40, backgroundColor: '#fff', justifyContent: 'center', alignItems: 'center'}}>
- <Text>当前用户企业列表</Text>
- </View>
- <List style={{ marginTop: 12 }}>
- {this.state.entsGroup.map(i => (
- <RadioItem
- key={i.entTaxId}
- checked={i.entTaxId === this.state.entItem.entTaxId}
- onChange={event => {
- if (event.target.checked) {
- this.onChange(i)
- }
- }}
- >
- {i.entName}
- </RadioItem>
- ))}
- </List>
- </View>
- );
- }
- }
|