import React, {Component} from 'react';
import {
ActivityIndicator,
FlatList,
RefreshControl,
Text,
View,
} from 'react-native';
import {List, Modal, SwipeAction} from '@ant-design/react-native';
import moment from 'moment';
import {RetrieveData} from '../../data/storage';
import {GetDataPost} from '../../data/encryption';
import invoice_inquiry_css from './invoice_inquiry_css';
import {ShowToast} from '../../components/rootToast/root_toast';
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,
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.getFailRef(this);
this.getSearchData();
}
//页面销毁
componentWillUnmount(): void {
pageNo = 1;
if (this.listener) {
this.listener.remove();
}
}
//获取查询数据
getSearchData = async () => {
let hongchongFlag = '';
if (this.props.children.state.hongchongFlag != undefined) {
if (this.props.children.state.hongchongFlag[0] != 2) {
hongchongFlag = this.props.children.state.hongchongFlag[0];
}
}
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 = '/sys/invoiceInfo/findPage';
GetDataPost(
url,
token,
{
mobile: account,
reqChannel: 3,
pageNum: pageNo,
pageSize: 10,
status: 4,
invoiceDateBegin: beginTime,
invoiceDateEnd: endTime,
customerName: this.props.children.state.customerName,
customerEntTaxId: this.props.children.state.customerEntTaxId,
invoiceCode: this.props.children.state.invoiceCode,
invoiceNumber: this.props.children.state.invoiceNumber,
hongchongFlag: hongchongFlag,
},
false,
2,
).then(res => {
totalPage = res.data.pages;
this.setList(res.data.records);
});
}
};
//设置列表list数据
setList = data => {
let listDatas = data.map((_, i) => ({
key: data[i].invoiceId,
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,
}));
let list = this.state.listData.concat(listDatas);
this.setState({
listData: list,
showFoot: 0,
});
};
//加载列表list数据
renderItem = data => (
{
this.showAlert(data.item);
}}>
{data.item.customerName}
发票代码:
{data.item.invoiceCode}
企业税号:
{data.item.customerEntTaxId}
发票号码:
{data.item.invoiceNumber}
是否可红冲:
{data.item.hongchongFlag ? '是' : '否'}
价税合计:
{data.item.totalAmountTaxes
.toString()
.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, '$1,')}
开票日期:
{data.item.invoiceDate}
);
//开票重试
invoiceRetry = async (data) => {
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 = '/sys/invoiceInfo/retry';
GetDataPost(
url,
token,
{
mobile: account,
reqChannel: 3,
invoiceReqFlowNo: data.invoiceReqFlowNo,
},
false,
1,
).then(res => {
if (res.code == 0) {
ShowToast('开票重试提交成功!');
this.initData();
} else {
ShowToast('开票重试提交失败!');
this.initData();
}
});
}
};
//显示红冲确认信息
showAlert = data => {
Modal.alert('开票失败重试', '是否确认重开此发票', [
{
text: '取消',
// onPress: () => console.log('cancel'),
style: 'cancel',
},
{text: '确认', onPress: () => this.invoiceRetry(data)},
]);
};
}