import React, {Component} from 'react'; import { Image, TouchableOpacity, ScrollView, Text, View, DeviceEventEmitter, } from 'react-native'; import NetInfo from '@react-native-community/netinfo'; import {GetDataPost} from '../../data/encryption'; import {IndividualStorageData, RetrieveData} from '../../data/storage'; import {ShowToast} from '../../components/rootToast/root_toast'; import Swiper from 'react-native-swiper'; import {NoticeBar, WhiteSpace} from '@ant-design/react-native'; import home_css from './home_css'; import moment from 'moment'; export default class home_page extends Component { constructor(props) { super(props); this.state = { name: '', info: '', totalAmt: 0.0, totalTaxes: 0.0, sumNum: 0.0, authority: '', landingStatus: 0, //登陆状态,0:表示未登陆,1:表示已登陆 curCompany: '首页', userType: 2, online: 0, //网络链接,0:表示网络链接失败,1:表示网络链接正常 onlineEntNum: 0, //在线企业数 allEntNum: 0, //所有企业数 serverNum: 0, //服务器数量 shelvesEntNum: 0, //月新增上架企业数 invoicedQuantity: 0, //月累计开票数量 invoicedAmount: 0.0, //月累计开票金额 onlineServiceProviderNum: 0, //服务商在线数量 allServiceProviderNum: 0, //服务商总数 serverOnlineEntNum: 0, //在线企业数 serverAllEntNum: 0, //所有企业数 onlinePersonnelNum: 0, //在线人员数量 allRegisterPersonnelNum: 0, //总注册人数 }; this.fetchDefaultEnt(); } render() { return ( Hello Swiper Beautiful And simple alert('click')} marqueeProps={{loop: true, style: {fontSize: 12, color: 'red'}}}> Notice: The arrival time of incomes and transfers of Yu 'E Bao will be delayed during National Day. {this.state.landingStatus === 1 ? ( this.state.authority.includes('sys:entInfo:preInit') ? ( { this.getLandingStatus(1); }}> 企业上架 ) : ( ) ) : ( { this.getLandingStatus(1); }}> 企业上架 )} {this.state.landingStatus === 1 ? ( { this.getLandingStatus(2); }}> 人员管理 ) : ( { this.getLandingStatus(2); }}> 人员管理 )} {this.state.landingStatus === 1 ? ( { this.getLandingStatus(3); }}> 操作审计 ) : ( { this.getLandingStatus(3); }}> 操作审计 )} {this.state.landingStatus === 1 ? ( this.state.authority.includes('sys:entInfo:pageByMachineId') ? ( { this.getLandingStatus(4); }}> 企业列表 ) : ( ) ) : ( { this.getLandingStatus(4); }}> 企业列表 )} {this.state.landingStatus === 1 ? ( this.state.authority.includes('sys:invoice:view') ? ( { this.getLandingStatus(6); }}> 开票列表 ) : ( ) ) : ( { this.getLandingStatus(6); }}> 开票列表 )} {this.state.landingStatus === 1 ? ( this.state.authority.includes('sys:hongchong:view') ? ( { this.getLandingStatus(8); }}> 红冲列表 ) : ( ) ) : ( { this.getLandingStatus(8); }}> 红冲列表 )} {this.state.landingStatus === 1 ? ( this.state.authority.includes('isp:machineInfo:view') ? ( { this.getLandingStatus(5); }}> 服务器列表 ) : ( ) ) : ( { this.getLandingStatus(5); }}> 服务器列表 )} {this.state.landingStatus === 1 ? ( this.state.authority.includes('isp:info:list:view') ? ( { this.getLandingStatus(7); }}> 服务商列表 ) : ( ) ) : ( { this.getLandingStatus(7); }}> 服务商列表 )} {/* {*/} {/* this.getLandingStatus(15);*/} {/* }}>*/} {/* */} {/* 测试*/} {/**/} {this.state.userType == 2 ? ( {this.state.onlineEntNum} 在线企业数 {this.state.allEntNum} 所有企业数 {this.state.serverNum} 服务器数量 {this.state.shelvesEntNum} 月新增上架企业数 {this.state.invoicedQuantity} 月累计开票数量 {this.state.invoicedAmount} 月累计开票金额 ) : ( )} {this.state.userType == 3 ? ( {this.state.onlineServiceProviderNum} 服务商在线数量 {this.state.allServiceProviderNum} 服务商总数 {this.state.serverOnlineEntNum} 企业在线数量 {this.state.serverAllEntNum} 企业总数 {this.state.onlinePersonnelNum} 在线人员数量 {this.state.allRegisterPersonnelNum} 总注册人数 ) : ( )} {this.state.online == 1 ? ( 网络 已连接 ) : ( 网络 未连接 )} 税控 未连接 ); } componentDidMount() { console.disableYellowBox = true; NetInfo.fetch().done((status) => { if (status.type != 'none') { this.setState({ online: 1, }); } }); this.setLoginType(); this.getAuthority(); this.getHomeData(); // 收到监听 this.listener = DeviceEventEmitter.addListener( 'updateCurMon', (message) => { // 收到监听后想做的事情 // 监听 this.fetchDefaultEnt(); }, ); } componentWillUnmount() { // 移除监听 if (this.listener) { this.listener.remove(); } this.setState = (state, callback) => { return; }; } //根据登陆帐号获取帐号类型 setLoginType = async () => { let userType = await RetrieveData('usertype'); userType = userType.substring(1, userType.length - 1); this.setState({ userType: userType, }); }; //获取当前默认绑定企业 fetchDefaultEnt = async () => { //const defaultFirm =await RetrieveData('defaultEnt'); //console.log( "default ent:" + JSON.stringify(defaultFirm)); //console.log( "default ent:"); 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 = 'https://app.taxbk.cn:9443/auth/comm/user/findDefaultChoose'; let response = await GetDataPost( url, token, { mobile: mobile, }, false, 2, ); if (response.code != 0) { ShowToast(response.msg); } else { this.setState({curCompany: response.data.entName}); //console.log("当前默认绑定企业: "+JSON.stringify(response.data)); await IndividualStorageData( 'defaultEnt', JSON.stringify(response.data), ); // await this.getKPStatsMonth(response.data.entTaxId); this.props.navigation.setOptions({ headerTitleAlign: 'center', headerTitle: (props) => { return ( {this.state.curCompany ? this.state.curCompany : '首页'} { const res = await RetrieveData('token'); const account = await RetrieveData('account'); if (res && account) { this.props.navigation.navigate('enterprise_list'); } else { ShowToast('请先登录'); } }}> {/**/} ); }, headerStyle: {backgroundColor: '#00A2FE', borderWidth: 0}, }); } } else { this.setState({ sumNum: 0.0, totalAmt: 0.0, totalTaxes: 0.0, curCompany: '首页', }); this.props.navigation.setOptions({ headerTitle: (props) => { //console.log("==="+ this.state.curCompany); return ( {this.state.curCompany ? this.state.curCompany : '首页'} ); }, headerTintColor: '#fff', }); } }; //判断是否登陆 getLandingStatus = async (type) => { const account = await RetrieveData('account'); if (account) { this.setState({ landingStatus: 1, }); if (type == 1) { this.props.navigation.navigate('enterprise_shelves'); } if (type == 2) { this.props.navigation.navigate('personnel_list'); } if (type == 3) { this.props.navigation.navigate('operation_audit_list'); } if (type == 4) { this.props.navigation.navigate('enterprise_information'); } if (type == 5) { this.props.navigation.navigate('server_list'); } if (type == 6) { this.props.navigation.navigate('invoice_inquiry'); } if (type == 7) { this.props.navigation.navigate('service_provider_list'); } if (type == 8) { this.props.navigation.navigate('invoice_inquiry_red_rush'); } if (type == 15) { this.props.navigation.navigate('Test'); } } else { this.setState({ landingStatus: 0, }); this.props.navigation.navigate('login_head'); } }; //获取权限信息 getAuthority = async () => { const authority = await RetrieveData('authority'); if (authority) { this.setState({ authority: authority, landingStatus: 1, }); } }; //获取首页数据 getHomeData = async () => { let account = await RetrieveData('account'); let token = await RetrieveData('token'); if (token && account) { account = account.substring(1, account.length - 1); token = token.substring(1, token.length - 1); const url = 'https://app.taxbk.cn:9443/sys/stat/home'; GetDataPost( url, token, { mobile: account, }, false, 2, ).then((res) => { this.setState({ onlineEntNum: res.data.onlineEntCnt, allEntNum: res.data.entCnt, shelvesEntNum: res.data.newInitEntCnt, invoicedAmount: res.data.monthInvoiceAmt, serverNum: res.data.machineCnt, invoicedQuantity: res.data.monthInvoiceCnt, serverOnlineEntNum: res.data.onlineEntCnt, serverAllEntNum: res.data.entCnt, allRegisterPersonnelNum: res.data.userCnt, allServiceProviderNum: res.data.ispCnt, onlinePersonnelNum: res.data.onlineUserCnt, onlineServiceProviderNum: res.data.onlineIspCnt, }); }); } }; }