invoice_inquiry_fail.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. import React, {Component} from 'react';
  2. import {
  3. ActivityIndicator,
  4. FlatList,
  5. RefreshControl,
  6. Text,
  7. View,
  8. } from 'react-native';
  9. import {List, Modal, SwipeAction} from '@ant-design/react-native';
  10. import moment from 'moment';
  11. import {RetrieveData} from '../../data/storage';
  12. import {GetDataPost} from '../../data/encryption';
  13. import invoice_inquiry_css from './invoice_inquiry_css';
  14. import {ShowToast} from '../../components/rootToast/root_toast';
  15. let pageNo = 1; //当前第几页
  16. let totalPage = 5; //总的页数
  17. export default class invoice_inquiry_fail extends Component {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. listData: [],
  22. search_data: '',
  23. showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  24. isLoading: false,
  25. visible1: false,
  26. };
  27. }
  28. render() {
  29. return (
  30. <View style={invoice_inquiry_css.container}>
  31. <FlatList
  32. data={this.state.listData}
  33. renderItem={item => this.renderItem(item)}
  34. refreshControl={
  35. <RefreshControl
  36. title={'加载中...'}
  37. colors={['#B7B7B7']} //此颜色无效
  38. tintColor={'#B7B7B7'}
  39. titleColor={'#B7B7B7'} //只有ios有效
  40. refreshing={this.state.isLoading}
  41. onRefresh={() => {
  42. this.initData();
  43. }}
  44. />
  45. }
  46. ListFooterComponent={this._renderFooter.bind(this)}
  47. onEndReached={this._onEndReached.bind(this)}
  48. onEndReachedThreshold={0.1}
  49. />
  50. </View>
  51. );
  52. }
  53. //初始化数据
  54. initData = () => {
  55. this.setState({
  56. listData: [],
  57. isLoading: false,
  58. showFoot: 0,
  59. });
  60. pageNo = 1;
  61. this.getSearchData();
  62. };
  63. //上拉加载
  64. _onEndReached() {
  65. if (this.state.showFoot === 0) {
  66. if (pageNo >= totalPage) {
  67. this.setState({showFoot: 1});
  68. return;
  69. } else {
  70. pageNo++;
  71. this.setState({showFoot: 2});
  72. //获取数据
  73. this.getSearchData();
  74. }
  75. }
  76. }
  77. //显示列表尾部
  78. _renderFooter() {
  79. if (this.state.showFoot === 1) {
  80. return (
  81. <View
  82. style={{
  83. height: 30,
  84. alignItems: 'center',
  85. justifyContent: 'flex-start',
  86. }}>
  87. <Text
  88. style={{
  89. color: '#999999',
  90. fontSize: 14,
  91. marginTop: 5,
  92. marginBottom: 5,
  93. }}>
  94. 没有更多数据了
  95. </Text>
  96. </View>
  97. );
  98. } else if (this.state.showFoot === 2) {
  99. return (
  100. <View style={invoice_inquiry_css.footer}>
  101. <ActivityIndicator />
  102. <Text>正在加载更多数据...</Text>
  103. </View>
  104. );
  105. } else if (this.state.showFoot === 0) {
  106. return (
  107. <View style={invoice_inquiry_css.footer}>
  108. <Text />
  109. </View>
  110. );
  111. }
  112. }
  113. //页面加载完成后加载数据
  114. componentDidMount(): void {
  115. this.props.children.getFailRef(this);
  116. this.getSearchData();
  117. }
  118. //页面销毁
  119. componentWillUnmount(): void {
  120. pageNo = 1;
  121. if (this.listener) {
  122. this.listener.remove();
  123. }
  124. }
  125. //获取查询数据
  126. getSearchData = async () => {
  127. let hongchongFlag = '';
  128. if (this.props.children.state.hongchongFlag != undefined) {
  129. if (this.props.children.state.hongchongFlag[0] != 2) {
  130. hongchongFlag = this.props.children.state.hongchongFlag[0];
  131. }
  132. }
  133. let beginTime = '';
  134. let endTime = '';
  135. if (this.props.children.state.beginDateTime != undefined) {
  136. beginTime = moment(this.props.children.state.beginDateTime).format(
  137. 'YYYY-MM-DD',
  138. );
  139. beginTime = beginTime + ' 00:00:00';
  140. }
  141. if (this.props.children.state.endDateTime != undefined) {
  142. endTime = moment(this.props.children.state.endDateTime).format(
  143. 'YYYY-MM-DD',
  144. );
  145. endTime = endTime + ' 23:59:59';
  146. }
  147. let account = await RetrieveData('account');
  148. let token = await RetrieveData('token');
  149. if (token && account) {
  150. account = account.substring(1, account.length - 1);
  151. token = token.substring(1, token.length - 1);
  152. const url = 'https://app.taxbk.cn:9443/sys/invoiceInfo/findPage';
  153. GetDataPost(
  154. url,
  155. token,
  156. {
  157. mobile: account,
  158. reqChannel: 3,
  159. pageNum: pageNo,
  160. pageSize: 10,
  161. status: 4,
  162. invoiceDateBegin: beginTime,
  163. invoiceDateEnd: endTime,
  164. customerName: this.props.children.state.customerName,
  165. customerEntTaxId: this.props.children.state.customerEntTaxId,
  166. invoiceCode: this.props.children.state.invoiceCode,
  167. invoiceNumber: this.props.children.state.invoiceNumber,
  168. hongchongFlag: hongchongFlag,
  169. },
  170. false,
  171. 2,
  172. ).then(res => {
  173. totalPage = res.data.pages;
  174. this.setList(res.data.records);
  175. });
  176. }
  177. };
  178. //设置列表list数据
  179. setList = data => {
  180. let listDatas = data.map((_, i) => ({
  181. key: data[i].invoiceId,
  182. invoiceCode: data[i].invoiceCode,
  183. invoiceNumber: data[i].invoiceNumber,
  184. invoiceDate: data[i].invoiceDate,
  185. customerName: data[i].customerName,
  186. customerEntTaxId: data[i].customerEntTaxId,
  187. totalAmountTaxes: data[i].totalAmountTaxes,
  188. invoiceReqFlowNo: data[i].invoiceReqFlowNo,
  189. }));
  190. let list = this.state.listData.concat(listDatas);
  191. this.setState({
  192. listData: list,
  193. showFoot: 0,
  194. });
  195. };
  196. //加载列表list数据
  197. renderItem = data => (
  198. <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
  199. <List.Item
  200. onLongPress={() => {
  201. this.showAlert(data.item);
  202. }}>
  203. <Text style={invoice_inquiry_css.itemTop}>
  204. {data.item.customerName}
  205. </Text>
  206. <View style={invoice_inquiry_css.itemView}>
  207. <Text style={invoice_inquiry_css.itemViewName}>
  208. 发票代码:
  209. <Text style={invoice_inquiry_css.itemViewText}>
  210. {data.item.invoiceCode}
  211. </Text>
  212. </Text>
  213. <Text style={invoice_inquiry_css.itemViewName}>
  214. 企业税号:
  215. <Text style={invoice_inquiry_css.itemViewText}>
  216. {data.item.customerEntTaxId}
  217. </Text>
  218. </Text>
  219. </View>
  220. <View style={invoice_inquiry_css.itemView}>
  221. <Text style={invoice_inquiry_css.itemViewName}>
  222. 发票号码:
  223. <Text style={invoice_inquiry_css.itemViewText}>
  224. {data.item.invoiceNumber}
  225. </Text>
  226. </Text>
  227. <Text style={invoice_inquiry_css.itemViewName}>
  228. 是否可红冲:
  229. <Text style={invoice_inquiry_css.itemViewText}>
  230. {data.item.hongchongFlag ? '是' : '否'}
  231. </Text>
  232. </Text>
  233. </View>
  234. <View style={invoice_inquiry_css.itemView}>
  235. <Text style={invoice_inquiry_css.itemViewName}>
  236. 价税合计:
  237. <Text style={invoice_inquiry_css.itemViewText}>
  238. {data.item.totalAmountTaxes
  239. .toString()
  240. .replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, '$1,')}
  241. </Text>
  242. </Text>
  243. <Text style={invoice_inquiry_css.itemViewName}>
  244. 开票日期:
  245. <Text style={invoice_inquiry_css.itemViewText}>
  246. {data.item.invoiceDate}
  247. </Text>
  248. </Text>
  249. </View>
  250. </List.Item>
  251. </SwipeAction>
  252. );
  253. //开票重试
  254. invoiceRetry = async (data) => {
  255. let account = await RetrieveData('account');
  256. let token = await RetrieveData('token');
  257. if (token && account) {
  258. account = account.substring(1, account.length - 1);
  259. token = token.substring(1, token.length - 1);
  260. const url = 'https://app.taxbk.cn:9443/sys/invoiceInfo/retry';
  261. GetDataPost(
  262. url,
  263. token,
  264. {
  265. mobile: account,
  266. reqChannel: 3,
  267. invoiceReqFlowNo: data.invoiceReqFlowNo,
  268. },
  269. false,
  270. 1,
  271. ).then(res => {
  272. console.log(res);
  273. if (res.code == 0) {
  274. ShowToast('开票重试提交成功!');
  275. this.initData();
  276. } else {
  277. ShowToast('开票重试提交失败!');
  278. this.initData();
  279. }
  280. });
  281. }
  282. };
  283. //显示红冲确认信息
  284. showAlert = data => {
  285. Modal.alert('开票失败重试', '是否确认重开此发票', [
  286. {
  287. text: '取消',
  288. // onPress: () => console.log('cancel'),
  289. style: 'cancel',
  290. },
  291. {text: '确认', onPress: () => this.invoiceRetry(data)},
  292. ]);
  293. };
  294. }