invoice_inquiry_completed.js 7.3 KB

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