invoice_inquiry_all.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 {RetrieveData} from '../../../data/storage';
  11. import {RequestNetwork} from '../../../data/encryption';
  12. import invoice_inquiry_css from './invoice_inquiry_css';
  13. import {ToastShow} from '../../../components/toast/toast';
  14. let pageNo = 1; //当前第几页
  15. let totalPage = 5; //总的页数
  16. export default class invoice_inquiry_all 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. visible1: false,
  25. };
  26. }
  27. render() {
  28. return (
  29. <View style={invoice_inquiry_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_inquiry_css.footer}>
  100. <ActivityIndicator />
  101. <Text>正在加载更多数据...</Text>
  102. </View>
  103. );
  104. } else if (this.state.showFoot === 0) {
  105. return (
  106. <View style={invoice_inquiry_css.footer}>
  107. <Text />
  108. </View>
  109. );
  110. }
  111. }
  112. //页面加载完成后加载数据
  113. componentDidMount(): void {
  114. this.props.children.getAllRef(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.beginDateText !== undefined) {
  129. if (this.props.children.state.beginDateText !== '开始时间') {
  130. beginTime = this.props.children.state.beginDateText + ' 00:00:00';
  131. }
  132. }
  133. if (this.props.children.state.endDateText !== undefined) {
  134. if (this.props.children.state.endDateText !== '结束时间') {
  135. endTime = this.props.children.state.endDateText + ' 23:59:59';
  136. }
  137. }
  138. let account = await RetrieveData('account');
  139. let token = await RetrieveData('token');
  140. let company = JSON.parse(await RetrieveData('company'));
  141. if (token && account) {
  142. let jason = {
  143. belongEntTaxId: company.entTaxId,
  144. mobile: account,
  145. reqChannel: 3,
  146. pageNum: pageNo,
  147. pageSize: 10,
  148. invoiceDateBegin: beginTime,
  149. invoiceDateEnd: endTime,
  150. invoiceCategory: this.props.children.state.invoiceCategory,
  151. customerName: this.props.children.state.customerName,
  152. customerEntTaxId: this.props.children.state.customerEntTaxId,
  153. invoiceCode: this.props.children.state.invoiceCode,
  154. invoiceNumber: this.props.children.state.invoiceNumber,
  155. };
  156. if (this.props.children.state.invoiceStatus !== null) {
  157. jason.status = this.props.children.state.invoiceStatus;
  158. }
  159. const url = '/sys/invoice/findPage';
  160. let res = await RequestNetwork(url, token, jason, false, 2);
  161. if (res) {
  162. console.log(res);
  163. if (res.code === 0) {
  164. totalPage = res.data.pages;
  165. this.setList(res.data.records);
  166. }
  167. }
  168. }
  169. };
  170. //设置列表list数据
  171. setList = (data) => {
  172. let listDatas = data.map((_, i) => ({
  173. key: data[i].invoiceId,
  174. invoiceType: data[i].invoiceType,
  175. invoiceCategory: data[i].invoiceCategory,
  176. invoiceCode: data[i].invoiceCode,
  177. invoiceNumber: data[i].invoiceNumber,
  178. invoiceDate: data[i].invoiceDate,
  179. customerName: data[i].customerName,
  180. customerEntTaxId: data[i].customerEntTaxId,
  181. totalAmountTaxes: data[i].totalAmountTaxes,
  182. invoiceReqFlowNo: data[i].invoiceReqFlowNo,
  183. status: data[i].status,
  184. pdfUrl: data[i].fileUrl,
  185. }));
  186. let list = this.state.listData.concat(listDatas);
  187. this.setState({
  188. listData: list,
  189. showFoot: 0,
  190. });
  191. };
  192. //加载列表list数据
  193. renderItem = (data) => (
  194. <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
  195. <List.Item
  196. style={{backgroundColor: '#F7F7F7'}}
  197. onPress={() => {
  198. if (data.item.pdfUrl === null || data.item.pdfUrl === '') {
  199. this.props.children.props.navigation.navigate('invoice_info', {
  200. data: data.item,
  201. });
  202. } else {
  203. this.props.children.props.navigation.navigate('preview_pdf', {
  204. url: data.item.pdfUrl,
  205. number: data.item.invoiceReqFlowNo,
  206. });
  207. }
  208. }}>
  209. <View style={{backgroundColor: '#ffffff'}}>
  210. <View style={{flexDirection: 'row', marginLeft: 5, marginTop: 5, marginBottom: 5}}>
  211. <View style={{flex: 1}}>
  212. <Text style={invoice_inquiry_css.listHead}>{data.item.customerName}</Text>
  213. </View>
  214. {data.item.invoiceType === 0 ? (
  215. <View style={invoice_inquiry_css.listBlueHead}>
  216. <Text style={{color: '#ffffff'}}>蓝字发票</Text>
  217. </View>
  218. ) : data.item.invoiceType === 1 ? (
  219. <View style={invoice_inquiry_css.listRedHead}>
  220. <Text style={{color: '#ffffff'}}>红字发票</Text>
  221. </View>
  222. ) : data.item.invoiceType === 2 ? (
  223. <View style={invoice_inquiry_css.listInvalidHead}>
  224. <Text style={{color: '#ffffff'}}>空白作废发票</Text>
  225. </View>
  226. ) : (
  227. <View />
  228. )}
  229. </View>
  230. <View style={{marginLeft: 5}}>
  231. {data.item.invoiceCategory === 1 ? (
  232. <View>
  233. <Text style={{color: '#898989'}}>增值税普通电子发票</Text>
  234. </View>
  235. ) : data.item.invoiceCategory === 2 ? (
  236. <View>
  237. <Text style={{color: '#898989'}}>增值税电子专用发票</Text>
  238. </View>
  239. ) : data.item.invoiceCategory === 3 ? (
  240. <View>
  241. <Text style={{color: '#898989'}}>增值税普通纸质发票</Text>
  242. </View>
  243. ) : data.item.invoiceCategory === 4 ? (
  244. <View>
  245. <Text style={{color: '#898989'}}>增值税专用纸质发票</Text>
  246. </View>
  247. ) : (
  248. <View />
  249. )}
  250. </View>
  251. <View style={{flexDirection: 'row', margin: 5}}>
  252. <View style={{flex: 1}}>
  253. <View style={{marginTop: 5}}>
  254. {data.item.status === 1 ? (
  255. <View style={invoice_inquiry_css.listBlueStatus}>
  256. <Text style={{color: '#2A67FE'}}>开票中</Text>
  257. </View>
  258. ) : data.item.status === 2 ? (
  259. <View style={invoice_inquiry_css.listRedStatus}>
  260. <Text style={{color: '#F06969'}}>开票失败</Text>
  261. </View>
  262. ) : data.item.status === 3 ? (
  263. <View style={invoice_inquiry_css.listBlueStatus}>
  264. <Text style={{color: '#2A67FE'}}>正数开具成功</Text>
  265. </View>
  266. ) : data.item.status === 4 ? (
  267. <View style={invoice_inquiry_css.listBlueStatus}>
  268. <Text style={{color: '#2A67FE'}}>负数开具成功</Text>
  269. </View>
  270. ) : data.item.status === 5 ? (
  271. <View style={invoice_inquiry_css.listBlueStatus}>
  272. <Text style={{color: '#2A67FE'}}>正数已作废</Text>
  273. </View>
  274. ) : data.item.status === 6 ? (
  275. <View style={invoice_inquiry_css.listBlueStatus}>
  276. <Text style={{color: '#2A67FE'}}>负数已作废</Text>
  277. </View>
  278. ) : data.item.status === 7 ? (
  279. <View style={invoice_inquiry_css.listBlueStatus}>
  280. <Text style={{color: '#2A67FE'}}>空白作废</Text>
  281. </View>
  282. ) : (
  283. <View />
  284. )}
  285. </View>
  286. <View style={{marginTop: 5}}>
  287. <Text style={{color: '#A0A0A0'}}>{data.item.invoiceDate}</Text>
  288. </View>
  289. </View>
  290. <View style={{flex: 1, flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'flex-end', marginRight: 5}}>
  291. <Text style={{color: '#393939', fontSize: 18, fontWeight: 'bold'}}>¥{data.item.totalAmountTaxes}</Text>
  292. </View>
  293. </View>
  294. </View>
  295. </List.Item>
  296. </SwipeAction>
  297. );
  298. //开票重试
  299. invoiceRetry = async (data) => {
  300. let account = await RetrieveData('account');
  301. let token = await RetrieveData('token');
  302. if (token && account) {
  303. const url = '/sys/invoice_info/retry';
  304. RequestNetwork(
  305. url,
  306. token,
  307. {
  308. mobile: account,
  309. reqChannel: 3,
  310. invoiceReqFlowNo: data.invoiceReqFlowNo,
  311. },
  312. false,
  313. 1,
  314. ).then(res => {
  315. if (res.code == 0) {
  316. ToastShow(1, '开票重试提交成功!');
  317. this.initData();
  318. } else {
  319. ToastShow(1, '开票重试提交失败!');
  320. this.initData();
  321. }
  322. });
  323. }
  324. };
  325. //显示红冲确认信息
  326. showAlert = (data) => {
  327. Modal.alert('开票失败重试', '是否确认重开此发票', [
  328. {
  329. text: '取消',
  330. // onPress: () => console.log('cancel'),
  331. style: 'cancel',
  332. },
  333. {text: '确认', onPress: () => this.invoiceRetry(data)},
  334. ]);
  335. };
  336. }