import React, {Component} from 'react';
import {
ActivityIndicator,
FlatList,
RefreshControl,
Text,
View,
} from 'react-native';
import {List, SwipeAction} from '@ant-design/react-native';
import {RetrieveData} from '../../../data/storage';
import {RequestNetwork} from '../../../data/encryption';
import invoice_inquiry_css from './invoice_inquiry_css';
let pageNo = 1; //当前第几页
let totalPage = 5; //总的页数
export default class invoice_inquiry_ongoing extends Component {
constructor(props) {
super(props);
this.state = {
listData: [],
search_data: '',
showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
isLoading: false,
visible1: 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.getOnGoingRef(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'));
console.log('12345');
if (token && account) {
const url = '/sys/invoice/findPage';
let res = await RequestNetwork(
url,
token,
{
belongEntTaxId: company.entTaxId,
mobile: account,
reqChannel: 3,
pageNum: pageNo,
pageSize: 10,
status: 1,
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,
},
false,
2,
);
if (res) {
if (res.code === 0) {
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,
status: data[i].status,
}));
let list = this.state.listData.concat(listDatas);
this.setState({
listData: list,
showFoot: 0,
});
};
//加载列表list
renderItem = (data) => (
{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}
);
}