import React, {Component} from 'react'; import { ActivityIndicator, FlatList, RefreshControl, Text, View, } from 'react-native'; import {List, SwipeAction} from '@ant-design/react-native'; import moment from 'moment'; import {RetrieveData} from '../../data/storage'; import {GetDataPost} from '../../data/encryption'; import invoice_red_rush_css from './invoice_red_rush_css'; let pageNo = 1; //当前第几页 let totalPage = 5; //总的页数 export default class invoice_inquiry_fail extends Component { constructor(props) { super(props); this.state = { listData: [], search_data: '', showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中 isLoading: false, }; } render() { return ( this.renderItem(item)} refreshControl={ { this.initData(); }} /> } ListFooterComponent={this._renderFooter.bind(this)} onEndReached={this._onEndReached.bind(this)} onEndReachedThreshold={0.1} /> ); } //初始化数据 initData = () => { this.setState({ listData: [], isLoading: false, showFoot: 0, }); pageNo = 1; this.getSearchData(); }; //上拉加载 _onEndReached() { if (this.state.showFoot === 0) { if (pageNo >= totalPage) { this.setState({showFoot: 1}); return; } else { pageNo++; this.setState({showFoot: 2}); //获取数据 this.getSearchData(); } } } //列表尾部显示 _renderFooter() { if (this.state.showFoot === 1) { return ( 没有更多数据了 ); } else if (this.state.showFoot === 2) { return ( 正在加载更多数据... ); } else if (this.state.showFoot === 0) { return ( ); } } //页面加载完后显示数据 componentDidMount(): void { this.props.children.getFailRef(this); this.getSearchData(); } //页面销毁 componentWillUnmount(): void { pageNo = 1; } //获取查询数据 getSearchData = async () => { let beginTime = ''; let endTime = ''; if (this.props.children.state.beginDateTime != undefined) { beginTime = moment(this.props.children.state.beginDateTime).format( 'YYYY-MM-DD', ); beginTime = beginTime + ' 00:00:00'; } if (this.props.children.state.endDateTime != undefined) { endTime = moment(this.props.children.state.endDateTime).format( 'YYYY-MM-DD', ); endTime = endTime + ' 23:59:59'; } 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/hongchongInfo/findPage'; GetDataPost( url, token, { mobile: account, reqChannel: 3, pageNum: pageNo, pageSize: 10, invoiceDateBegin: beginTime, invoiceDateEnd: endTime, belongEntTaxId: this.props.children.state.belongEntTaxId, invoiceCode: this.props.children.state.invoiceCode, invoiceNumber: this.props.children.state.invoiceNumber, }, false, 2, ).then(res => { totalPage = res.data.pages; this.setList(res.data.records); }); } }; //设置列表list数据 setList = data => { let listDatas = data.map((_, i) => ({ key: data[i].hcId, invoiceReqFlowNo: data[i].invoiceReqFlowNo, oriInvoiceReqFlowNo: data[i].oriInvoiceReqFlowNo, oriInvoiceCode: data[i].oriInvoiceCode, oriInvoiceNumber: data[i].oriInvoiceNumber, belongEntTaxId: data[i].belongEntTaxId, belongEntName: data[i].belongEntName, customerName: data[i].customerName, totalAmountTaxes: data[i].totalAmountTaxes, invoiceCode: data[i].invoiceCode, invoiceNumber: data[i].invoiceNumber, invoiceDate: data[i].invoiceDate, pdfUrl: data[i].pdfUrl, customerSpUrl: data[i].customerSpUrl, retryFlag: data[i].retryFlag, })); let list = this.state.listData.concat(listDatas); this.setState({ listData: list, showFoot: 0, }); }; //设置列表list数据 renderItem = data => ( {}}> {data.item.customerName} 企业名称: {data.item.belongEntName} 企业税号: {data.item.belongEntTaxId} 发票代码: {data.item.invoiceCode} 发票号码: {data.item.invoiceNumber} 红冲金额: {data.item.totalAmountTaxes .toString() .replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, '$1,')} 开票日期: {data.item.invoiceDate} ); }