import React, {Component} from 'react'; import { Image, StyleSheet, Dimensions, ImageBackground, TouchableOpacity, ScrollView, Text, View, DeviceEventEmitter, SafeAreaView, Alert, } from 'react-native'; import {RequestNetwork} from '../../data/encryption'; import {IndividualStorageData, RetrieveData} from '../../data/storage'; import LinearGradient from 'react-native-linear-gradient'; import Swiper from 'react-native-swiper'; import public_css from '../../source/css/public_css'; import {noticeIcon, homeArrow} from '../../source/icon/icon'; import {SvgXml} from 'react-native-svg'; import {CleanAll} from '../../components/abnormalMessage/abnormal_message'; import {ToastShow} from '../../components/toast/toast'; import {WhiteSpace, WingBlank, Carousel} from '@ant-design/react-native'; import { GetMonthDate } from "../../utils/date"; export default class home_page extends Component { constructor(props) { super(props); this.state = { pageNo: 1, name: '', info: '', totalAmt: 0.0, totalTaxes: 0.0, sumNum: 0.0, authority: '', landingStatus: 0, //登录状态,0:表示未登录,1:表示已登录 curCompany: '首页', fontStatus: '更多', monthTotal: 0.0, monthTotalTaxes: 0.0, list: [1, 2, 3], statisticsData: {}, activityList: [], invoiceNumber: 0, }; } render() { return ( {/*{this.state.list.map((item, index) => {*/} {/* return (*/} {/* */} {/* */} {/* */} {/* );*/} {/*})}*/} {/* {*/} {/* this.props.navigation.navigate('loan');*/} {/* }}>*/} {/* */} {/**/} {this.state.landingStatus === 1 ? ( { 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.getLandingStatus(4); }}> 待开抬头 ) : ( { this.getLandingStatus(4); }}> 待开抬头 )} {this.state.landingStatus === 1 ? ( { this.getLandingStatus(5); }}> 待开发票 ) : ( { this.getLandingStatus(5); }}> 待开发票 )} {this.state.landingStatus === 1 ? ( { this.getLandingStatus(6); }}> 发票领购 ) : ( { this.getLandingStatus(6); }}> 发票领购 )} {this.state.landingStatus === 1 ? ( { this.getLandingStatus(7); }}> 发票分发 ) : ( { this.getLandingStatus(7); }}> 发票分发 )} {this.state.landingStatus === 1 ? ( { this.getLandingStatus(8); }}> 发票查询 ) : ( { this.getLandingStatus(8); }}> 发票查询 )} {this.state.activityList.map((item) => { return ( { this.props.navigation.navigate('activity', { data: { title: item.campaignName, desc: item.campaignDesc, number: item.campaignId, url: item.detailUrl, }, }); }}> ); })} {/**/} 本月概览 { this.props.navigation.navigate('home_amount_statistics'); }}> 查看更多 {/**/} {/* 开票总数*/} {/* /!*剩余发票数量*!/*/} {/* */} {/* {this.state.statisticsInfo.monthTotal}*/} {/* */} {/**/} 开票总数 {this.state.invoiceNumber} 开票总额 {this.state.monthTotal} 税额 {this.state.monthTotalTaxes} 未税金额 累计成功开票未税金额(元) {this.state.statisticsData.monthTotal} 专票开票未税金额(元) {this.state.statisticsData.monthZhuanpiaoTotal} 普票开票未税金额(元) {this.state.statisticsData.monthPupiaoTotal} 累计税额 累计开票税额(元) {this.state.statisticsData.monthTotalTaxes} 专票开票税额(元) {this.state.statisticsData.monthZhuanpiaoTotalTaxes} 普票开票税额(元) {this.state.statisticsData.monthPupiaoTotalTaxes} {/**/} {/* */} {/* */} {/* */} {/* */} {/* 新品推荐*/} {/* */} {/* */} {/* */} {/* */} {/* 查看全部*/} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/* {*/} {/* this.props.navigation.navigate('recommend_home');*/} {/* }}>*/} {/* */} {/* */} {/* */} {/* */} {/**/} ); } // render加载完后调用 async componentDidMount() { await this.getAuthority(); await this.getCompanyInfo(); await this.getInvoiceStatistics(); await this.getLoanList(); await this.getInvoiceNumber(); // 收到监听 this.listener = DeviceEventEmitter.addListener( 'updateCompany', (message) => { // 收到监听后想做的事情 // 监听 this.getCompanyInfo(); this.getInvoiceStatistics(); this.getInvoiceNumber(); //this.getKPStatsMonth(); }, ); this.listenerStatistics = DeviceEventEmitter.addListener( 'updateStatistics', (message) => { // 收到监听后想做的事情 // 监听 this.getInvoiceStatistics(); this.getInvoiceNumber(); }, ); } componentWillUnmount() { // 移除监听 if (this.listener) { this.listener.remove(); } if (this.listenerStatistics) { this.listenerStatistics.remove(); } this.setState = (state, callback) => { return; }; } //首页数据获取 getKPStatsMonth = async (curEntId) => { const token = await RetrieveData('token'); const account = await RetrieveData('account'); //const curEntId =await RetrieveData('defaultEnt'); if (token && account) { const url = '/sys/invoice_info/getKPStatsMonth'; let response = await RequestNetwork( 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, }); } } }; // 获取当前默认绑定企业 getCompanyInfo = async () => { let company = await RetrieveData('company'); if (company) { company = JSON.parse(company); } this.props.navigation.setOptions({ headerTitleAlign: 'left', headerTitle: (props) => { return ( { if (company) { this.props.navigation.navigate('enterprise_list', { getCompanyInfo: () => { this.getCompanyInfo(); }, }); } else { await this.getLandingStatus(-1); } }}> {company ? company.entName : '未登录'} {/**/} {/* */} {/**/} {/**/} {/* */} {/**/} { this.props.navigation.navigate('notice'); }}> ); }, headerStyle: {backgroundColor: '#ffffff', borderWidth: 0}, }); await this.getInvoiceStatistics(); }; //判断是否登录 getLandingStatus = async (type) => { const account = await RetrieveData('account'); if (account) { this.setState({ landingStatus: 1, }); if (type === 1) { this.props.navigation.navigate('invoice'); } if (type === 2) { this.props.navigation.navigate('invoice_qrcode'); } if (type === 3) { this.props.navigation.navigate('buyer_invoice'); } if (type === 4) { this.props.navigation.navigate('invoice_head_list'); } if (type === 5) { this.props.navigation.navigate('wait_invoice_list'); } if (type === 6) { this.props.navigation.navigate('application_info'); } if (type === 7) { this.props.navigation.navigate('invoice_distribution'); } if (type === 8) { this.props.navigation.navigate('electronics_ordinary_invoice'); } } else { this.setState({ landingStatus: 0, }); this.props.navigation.navigate('login', { refresh: (type) => { this.refresh(type); }, }); } }; refresh = async type => { await this.getCompanyInfo(); DeviceEventEmitter.emit('updateLoginInfo', type); }; //获取权限信息 getAuthority = async () => { const authority = await RetrieveData('authority'); if (authority) { this.setState({ authority: authority, landingStatus: 1, }); } }; //获取首页统计数据 getInvoiceStatistics = async () => { let company = await RetrieveData('company'); if (company) { company = JSON.parse(company); } const token = await RetrieveData('token'); if (token && company) { const url = '/sys/stat/toInvoice'; let response = await RequestNetwork( url, token, { entTaxId: company.entTaxId, }, false, 2, ); if (response) { if (response.code === 0) { this.setState({ monthTotal: response.data.monthTotal, monthTotalTaxes: response.data.monthTotalTaxes, statisticsData: response.data, }); } else { await this.abnormalMessage(response); } } } }; //获取发票数量统计 getInvoiceNumber = async () => { let company = await RetrieveData('company'); if (company) { company = JSON.parse(company); } const token = await RetrieveData('token'); const account = await RetrieveData('account'); if (token && company) { let date = GetMonthDate(); const url = '/sys/invoiceExt/reports'; let response = await RequestNetwork( url, token, { entTaxId: company.entTaxId, deviceType: company.defaultDeviceInfo.deviceType, taxDiscId: company.defaultDeviceInfo.taxDiscId, mobile: account, invoiceDateBegin: date.startDateTime, invoiceDateEnd: date.endDateTime, reqChannel: 3, }, false, 2, ); if (response) { if (response.code === 0) { this.setState({ invoiceNumber: response.data.totalFapiaoCnt, }); } } } }; // 处理网络请求数据 abnormalMessage = async (jason) => { if (jason.code === 401) { await Alert.alert( '登录失效', '登录状态已失效,请重新登录!', [ { text: '确定', onPress: () => { CleanAll(); this.props.navigation.popToTop(); }, }, ], {cancelable: false}, ); } if (jason.code === 403) { Alert.alert( '权限', '暂无权限操作此模块!', [ { text: '确定', onPress: () => { this.props.navigation.goBack(); }, }, ], {cancelable: false}, ); } if (jason.code !== 401 && jason.code !== 403) { ToastShow(1, jason.msg); } }; //获取数据 getLoanList = async () => { const url = '/marketing/campaign/findPage'; let response = await RequestNetwork( url, null, { campaignName: '', valid: true, pageNum: 1, pageSize: 5, }, false, 2, ); if (response) { if (response.code === 0) { let list = []; response.data.records.map((item) => { if (item.campaignId !== '4efc6f48fed8ce0457fc4abaf3470a82') { list = list.concat(item); } }); this.setState({ activityList: list, }); } } }; } const windowWidth = Dimensions.get('window').width; const styles = StyleSheet.create({ homePageBak: { flexDirection: 'column', }, taxItemBak: { display: 'flex', flexDirection: 'row', flexWrap: 'wrap', paddingTop: 15, backgroundColor: '#FFFFFF', }, tapBtnBakCol: { display: 'flex', flexDirection: 'column', width: windowWidth / 4, height: 80, alignItems: 'center', justifyContent: 'center', marginBottom: 15, }, tapBtnImg: { width: 53, height: 53, }, tapBtnTips: { color: '#000', }, userOnlineLeft: { flex: 1, flexDirection: 'row' }, userOnlineRight: { flex: 1, marginRight: 10, flexDirection: 'row', justifyContent: 'flex-end', }, yxTopicBak: { marginTop: 20, // height: 200, backgroundColor: '#fff', flexDirection: 'column', }, yxTopicTop: { height: 45, flexDirection: 'row', alignItems: 'center', paddingLeft: 10, paddingRight: 10, }, yxTopicBottom: { display: 'flex', flexDirection: 'row', flexWrap: 'wrap', paddingBottom: 15, }, yxTopicItem: { width: (windowWidth - 60) / 3, height: 70, borderRadius: 5, marginLeft: 10, marginRight: 10, }, yc_inner: { width: '100%', height: '100%', display: 'flex', flexDirection: 'column', borderRadius: 5, justifyContent: 'center', paddingLeft: 12, }, yxTopicItemTextA: { color: '#FFFFFF', fontWeight: '600', fontSize: 12, }, yxTopicItemTextB: { color: '#FFFFFF', fontSize: 16, marginTop: 5, }, yxTopicItemTextC: { color: '#FFFFFF', fontSize: 16, marginTop: 5, }, 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, }, containerHorizontal: { flexGrow: 1, alignItems: 'center', justifyContent: 'center', height: 150, }, containerVertical: { flexGrow: 1, alignItems: 'center', justifyContent: 'center', height: 150, }, text: { color: '#fff', fontSize: 36, }, // zj wrapper: { height: 170, }, wrapper1: { height: 140, marginTop: 15, }, carousel: { width: '100%', height: 170, backgroundColor: '#fff', paddingLeft: 12, paddingRight: 12, overflow: 'hidden', }, carousel1: { width: '100%', height: '100%', backgroundColor: '#fff', paddingLeft: 12, paddingRight: 12, overflow: 'hidden', }, banner_box: { paddingTop: 15, }, banner_img: { height: '100%', width: '100%', borderRadius: 14, }, line_des: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', height: 55, backgroundColor: '#ffffff', paddingLeft: 20, paddingRight: 20, }, line_item: { display: 'flex', flexDirection: 'row', alignItems: 'center', }, font_item: { color: '#3B3B3B', fontSize: 12, fontWeight: 'bold', marginLeft: 12, }, font_item_right: { color: '#2A67FE', fontSize: 14, fontWeight: 'bold', }, main_title: { paddingLeft: 12, fontWeight: 'bold', color: '#464646', fontSize: 16, }, });