invoice_inquiry_completed.js 8.8 KB

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