invoice_inquiry_completed.js 7.3 KB

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