import React, {Component} from 'react'; import { View, Text, ActivityIndicator, FlatList, RefreshControl, } from 'react-native'; import {List, SwipeAction, Modal} from '@ant-design/react-native'; import {RetrieveData} from '../../../data/storage'; import {RequestNetwork} from '../../../data/encryption'; import invoice_inquiry_css from './invoice_inquiry_css'; import {ToastShow} from '../../../components/toast/toast'; let pageNo = 1; //当前第几页 let totalPage = 5; //总的页数 export default class invoice_inquiry_completed extends Component { constructor(props) { super(props); this.state = { listData: [], status: 0, search_data: '', showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中 isLoading: false, isOpen: false, visible1: false, }; } render() { return ( this.renderItem(item)} refreshControl={ { this.initData(); }} /> } ListFooterComponent={this._renderFooter.bind(this)} onEndReached={this._onEndReached.bind(this)} onEndReachedThreshold={0.1} /> ); } //显示红冲确认信息 showAlert = (data) => { Modal.alert('发票红冲', '是否确认红冲此发票', [ { text: '取消', // onPress: () => console.log('cancel'), style: 'cancel', }, {text: '确认', onPress: () => this.invoice_red_rush(data)}, ]); }; //初始化数据 initData = () => { this.setState({ listData: [], isLoading: false, showFoot: 0, status: 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.getCompletedRef(this); this.getSearchData(); } //页面销毁 componentWillUnmount(): void { pageNo = 1; } //获取查询数据 getSearchData = async () => { let beginTime = ''; let endTime = ''; if (this.props.children.state.beginDateText !== undefined) { if (this.props.children.state.beginDateText !== '开始时间') { beginTime = this.props.children.state.beginDateText + ' 00:00:00'; } } if (this.props.children.state.endDateText !== undefined) { if (this.props.children.state.endDateText !== '结束时间') { endTime = this.props.children.state.endDateText + ' 23:59:59'; } } let account = await RetrieveData('account'); let token = await RetrieveData('token'); let company = JSON.parse(await RetrieveData('company')); if (token && account) { let jason = { belongEntTaxId: company.entTaxId, mobile: account, reqChannel: 3, pageNum: pageNo, pageSize: 10, invoiceDateBegin: beginTime, invoiceDateEnd: endTime, invoiceCategory: this.props.children.state.invoiceCategory, customerName: this.props.children.state.customerName, customerEntTaxId: this.props.children.state.customerEntTaxId, invoiceCode: this.props.children.state.invoiceCode, invoiceNumber: this.props.children.state.invoiceNumber, }; if (this.props.children.state.invoiceStatus !== null) { jason.status = this.props.children.state.invoiceStatus; } const url = '/sys/invoice/findPage'; let res = await RequestNetwork(url, token, jason, false, 2); if (res) { console.log('完成'); if (res.code === 0) { totalPage = res.data.pages; this.setList(res.data.records); } } } }; //设置列表list数据 setList = (data) => { let listDatas = data.map((_, i) => ({ key: data[i].invoiceId, invoiceType: data[i].invoiceType, invoiceCategory: data[i].invoiceCategory, invoiceCode: data[i].invoiceCode, invoiceNumber: data[i].invoiceNumber, invoiceDate: data[i].invoiceDate, customerName: data[i].customerName, customerEntTaxId: data[i].customerEntTaxId, totalAmountTaxes: data[i].totalAmountTaxes, invoiceReqFlowNo: data[i].invoiceReqFlowNo, hongchongFlag: data[i].hongchongFlag, status: data[i].status, pdfUrl: data[i].pdfUrl, })); let list = this.state.listData.concat(listDatas); this.setState({ listData: list, showFoot: 0, }); }; //设置列表list数据 renderItem = (data) => ( { console.log(data.item); if (data.item.pdfUrl === null || data.item.pdfUrl === '') { this.props.children.props.navigation.navigate('invoice_info', { data: data.item, }); } else { this.props.children.props.navigation.navigate('preview_pdf', { url: data.item.pdfUrl, number: data.item.invoiceReqFlowNo, }); } }}> {data.item.customerName} {data.item.invoiceType === 0 ? ( 蓝字发票 ) : data.item.invoiceType === 1 ? ( 红字发票 ) : data.item.invoiceType === 2 ? ( 空白作废发票 ) : ( )} {data.item.invoiceCategory === 1 ? ( 增值税普通电子发票 ) : data.item.invoiceCategory === 2 ? ( 增值税电子专用发票 ) : data.item.invoiceCategory === 3 ? ( 增值税普通纸质发票 ) : data.item.invoiceCategory === 4 ? ( 增值税专用纸质发票 ) : ( )} {data.item.status === 1 ? ( 开票中 ) : data.item.status === 2 ? ( 开票失败 ) : data.item.status === 3 ? ( 正数开具成功 ) : data.item.status === 4 ? ( 负数开具成功 ) : data.item.status === 5 ? ( 正数已作废 ) : data.item.status === 6 ? ( 负数已作废 ) : data.item.status === 7 ? ( 空白作废 ) : ( )} {data.item.invoiceDate} ¥{data.item.totalAmountTaxes} ); //发票红冲 invoice_red_rush = async (data) => { let account = await RetrieveData('account'); let token = await RetrieveData('token'); if (token && account) { const url = '/sys/hongchongInfo/save'; RequestNetwork( url, token, { mobile: account, reqChannel: 3, oriInvoiceReqFlowNo: data.invoiceReqFlowNo, }, false, 1, ).then((res) => { console.log(res); if (res.code == 0) { ToastShow(1, '发票红冲申请提交成功!'); this.initData(); } else { ToastShow(1, '发票红冲申请提交失败!'); this.initData(); } }); } }; //发票在线查看 see_invoice = (data) => { this.props.children.props.navigation.navigate('preview_pdf', data); }; }