import React, {Component} from 'react'; import { Image, StyleSheet, Dimensions, ImageBackground, TouchableOpacity, ScrollView, Text, View, DeviceEventEmitter, } from 'react-native'; import {GetDataPost} from '../../data/encryption'; import {IndividualStorageData, RetrieveData} from '../../data/storage'; import {ShowToast} from '../../components/rootToast/root_toast'; 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: '首页', }; this.fetchDefaultEnt(); } componentDidMount() { this.getAuthority(); // 收到监听 this.listener = DeviceEventEmitter.addListener('updateCurMon', message => { // 收到监听后想做的事情 // 监听 this.fetchDefaultEnt(); //this.getKPStatsMonth(); }); } componentWillUnmount() { // 移除监听 if (this.listener) { this.listener.remove(); } this.setState = (state, callback) => { return; }; } render() { return ( 移动开票 省时省心 您身边的开票小能手 {this.state.landingStatus === 1 ? ( this.state.authority.includes('sys:invoice:add') ? ( { this.getLandingStatus(1); }}> 发票管理 ) : ( ) ) : ( { this.getLandingStatus(1); }}> 发票管理 )} {this.state.landingStatus === 1 ? ( this.state.authority.includes('sys:product:view') ? ( { this.getLandingStatus(2); }}> 商品管理 ) : ( ) ) : ( { this.getLandingStatus(2); }}> 商品管理 )} {this.state.landingStatus === 1 ? ( this.state.authority.includes('sys:customer:view') ? ( { this.getLandingStatus(3); }}> 客户管理 ) : ( ) ) : ( { this.getLandingStatus(3); }}> 客户管理 )} 本企业当前在线人数... 999人 本月情况 查看全部 开票总数 {/*剩余发票数量*/} {this.state.sumNum} 开票总额 {/*待勾选发票数*/} {this.state.totalAmt} 税额 {/*待勾选发票数*/} {this.state.totalTaxes} 新品推荐 查看全部 ); } //首页数据获取 getKPStatsMonth = async curEntId => { const res = await RetrieveData('token'); const account = await RetrieveData('account'); //const curEntId =await RetrieveData('defaultEnt'); if (res && account) { let token = res.substring(1, res.length - 1); const url = '/sys/invoiceInfo/getKPStatsMonth'; let response = await GetDataPost( url, token, { entTaxId: curEntId, }, false, 2, ); if (response.code != 0) { //console.log(response); this.setState({ sumNum: 0.0, totalAmt: 0.0, totalTaxes: 0.0, }); } else { this.setState({ sumNum: response.data.cnt, totalAmt: response.data.totalAmt, totalTaxes: response.data.totalTaxes, }); } } }; 获取当前默认绑定企业; 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 = '/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('invoice_product_list'); } if (type == 2) { this.props.navigation.navigate('product_infos'); } if (type == 3) { this.props.navigation.navigate('customer_information'); } } 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, }); } }; } const styles = StyleSheet.create({ homePageBak: { flexDirection: 'column', }, topImgBak: { height: 184, // backgroundColor: 'blue', }, topImgTxt: { flex: 3, justifyContent: 'center', marginLeft: 40, }, ydkpTxt: { fontSize: 32, color: '#fff', }, ydkpTips: { marginTop: 10, fontSize: 12, color: '#fff', }, topImg: { flex: 1, width: '100%', height: '100%', flexDirection: 'column', justifyContent: 'flex-end', }, whiteSpaces: { height: 30, flexDirection: 'row', borderTopLeftRadius: Dimensions.get('window').width * 0.8, borderTopRightRadius: Dimensions.get('window').width * 0.8, backgroundColor: '#fff', // alignSelf: 'flex-end', }, taxItemBak: { height: 145, backgroundColor: '#fff', flexDirection: 'column', // marginTop: 20, justifyContent: 'center', }, tapBtnBak: { flex: 5, flexDirection: 'row', justifyContent: 'space-around', // alignItems: 'center', }, tapBtnBakCol: { flexDirection: 'column', }, tapBtnImg: { width: 53, height: 53, }, userOnlineBak: { flex: 2, flexDirection: 'row', borderTopWidth: 1, borderTopColor: '#E0EEEE', alignItems: 'center', marginLeft: 10, marginRight: 10, }, tapBtnTips: { marginTop: 10, color: '#000', }, userOnlineLeft: { flex: 1, flexDirection: 'row', marginLeft: 10, }, userOnlineRight: { flex: 1, marginRight: 10, flexDirection: 'row', justifyContent: 'flex-end', }, yxTopicBak: { marginTop: 20, // height: 200, backgroundColor: '#fff', flexDirection: 'column', }, yxTopicTop: { height: 45, flexDirection: 'row', borderBottomWidth: 1, borderBottomColor: '#E0EEEE', alignItems: 'center', marginLeft: 10, marginRight: 10, }, yxTopicBottom: { // height: 260, flexDirection: 'row', // justifyContent: 'space-around', // alignItems: 'center', flexWrap: 'wrap', marginLeft: 10, marginRight: 10, marginBottom: 10, }, yxTopicItem: { width: 120, height: 120, marginTop: 10, marginLeft: 5, marginRight: 5, justifyContent: 'center', alignItems: 'center', }, yxTopicItem_1: {backgroundColor: 'rgba(116, 211, 255, 0.1)'}, yxTopicItem_2: {backgroundColor: 'rgba(255, 82, 71, 0.1)'}, yxTopicItem_3: {backgroundColor: 'rgba(200, 121, 255, 0.1)'}, yxTopicItemTextA: { color: 'rgba(51, 51, 51, 1)', fontWeight: '600', fontFamily: 'MicrosoftYaHei', fontSize: 17, }, yxTopicItemTextB: { color: 'rgba(102, 102, 102, 1)', fontFamily: 'MicrosoftYaHei', fontSize: 12, marginTop: 5, }, yxTopicItemTextC: { color: 'rgba(255, 75, 67, 1)', fontWeight: '600', fontFamily: 'MicrosoftYaHei', fontSize: 24, marginTop: 11, }, xpPushBak: { height: 292, marginTop: 20, backgroundColor: '#fff', flexDirection: 'column', }, xpPushTop: { height: 45, flexDirection: 'row', borderBottomWidth: 1, borderBottomColor: '#E0EEEE', alignItems: 'center', marginLeft: 10, marginRight: 10, }, xpPushBottom: {}, xpPushItem: { height: 148, marginTop: 20, marginRight: 24, marginLeft: 24, borderRadius: 10, backgroundColor: 'red', }, });