application_info.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. TouchableOpacity,
  5. Image,
  6. Text,
  7. SafeAreaView,
  8. FlatList,
  9. ActivityIndicator,
  10. Alert,
  11. RefreshControl,
  12. } from 'react-native';
  13. import {
  14. DatePicker,
  15. Drawer,
  16. List,
  17. Provider,
  18. WingBlank,
  19. SwipeAction,
  20. Picker,
  21. WhiteSpace,
  22. } from '@ant-design/react-native';
  23. import public_css from '../../source/css/public_css';
  24. import {RetrieveData} from '../../data/storage';
  25. import {RequestNetwork} from '../../data/encryption';
  26. import {GetMonthDate, GetDateString} from '../../utils/date';
  27. import {ToastShow} from '../../components/toast/toast';
  28. import {InvoiceType, ApplicationStatus} from '../../utils/config';
  29. import {CleanAll} from '../../components/abnormalMessage/abnormal_message';
  30. import Spinner from 'react-native-loading-spinner-overlay';
  31. import loading_css from '../../source/css/loading_css';
  32. export default class application_info extends Component {
  33. constructor(props) {
  34. super(props);
  35. this.props.navigation.dangerouslyGetParent().setOptions({
  36. tabBarVisible: false,
  37. });
  38. this.state = {
  39. isShowSearch: false,
  40. beginDate: '',
  41. endDate: '',
  42. beginDateString: '',
  43. endDateString: '',
  44. invoiceList: [],
  45. isRefreshing: false,
  46. pageNum: 1, //当前页码
  47. pageSize: 10, //每页数量
  48. totalPage: 10, //总页数
  49. showFoot: 0,
  50. monthDate: {},
  51. invoiceTypeList: InvoiceType(),
  52. invoiceType: '1',
  53. applicationStatusList: ApplicationStatus(),
  54. applicationStatus: '0',
  55. spinner: false,
  56. isNextPage: false, // 是否有下一页
  57. isPreviousPage: false, // 是否有上一页
  58. };
  59. }
  60. render() {
  61. let draw = (
  62. <View style={public_css.body}>
  63. <View style={{flex: 1}}>
  64. <View>
  65. <List>
  66. <DatePicker
  67. value={this.state.beginDate}
  68. mode="date"
  69. defaultDate={new Date()}
  70. onChange={(time) => this.beginTimeChange(time)}
  71. format="YYYY-MM-DD">
  72. <List.Item arrow="horizontal">开始时间</List.Item>
  73. </DatePicker>
  74. </List>
  75. </View>
  76. <View>
  77. <List>
  78. <DatePicker
  79. value={this.state.endDate}
  80. mode="date"
  81. defaultDate={new Date()}
  82. minDate={this.state.beginDate}
  83. onChange={(time) => this.endTimeChange(time)}
  84. format="YYYY-MM-DD">
  85. <List.Item arrow="horizontal">结束时间</List.Item>
  86. </DatePicker>
  87. </List>
  88. </View>
  89. <Picker
  90. value={[this.state.invoiceType]}
  91. data={this.state.invoiceTypeList}
  92. cols={1}
  93. onChange={(select) => this.invoiceTypeChange(select)}>
  94. <List.Item arrow="horizontal" onPress={this.onPress}>
  95. 发票类型:
  96. </List.Item>
  97. </Picker>
  98. <Picker
  99. data={this.state.applicationStatusList}
  100. cols={1}
  101. value={[this.state.applicationStatus]}
  102. onChange={(select) => this.applicationStatusChange(select)}>
  103. <List.Item arrow="horizontal" onPress={this.onPress}>
  104. 申领状态:
  105. </List.Item>
  106. </Picker>
  107. </View>
  108. <View style={public_css.bottomStatus}>
  109. <View
  110. style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
  111. <TouchableOpacity
  112. style={{
  113. borderWidth: 1,
  114. borderRadius: 30,
  115. borderColor: '#8B8B8B',
  116. width: 120,
  117. height: 40,
  118. justifyContent: 'center',
  119. alignItems: 'center',
  120. }}
  121. onPress={() => {
  122. this.searchDataEmpty();
  123. }}>
  124. <Text style={{color: '#262626'}}>重置</Text>
  125. </TouchableOpacity>
  126. </View>
  127. <View
  128. style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
  129. <TouchableOpacity
  130. style={{
  131. borderWidth: 1,
  132. borderRadius: 30,
  133. borderColor: '#2A67FE',
  134. backgroundColor: '#2A67FE',
  135. width: 120,
  136. height: 40,
  137. justifyContent: 'center',
  138. alignItems: 'center',
  139. }}
  140. onPress={() => this.searchData()}>
  141. <Text style={{color: '#FFFFFF'}}>查询</Text>
  142. </TouchableOpacity>
  143. </View>
  144. </View>
  145. </View>
  146. );
  147. return (
  148. <Provider>
  149. <SafeAreaView style={public_css.body}>
  150. <Spinner
  151. visible={this.state.spinner}
  152. textContent={'Loading...'}
  153. textStyle={loading_css.spinnerTextStyle}
  154. />
  155. <Drawer
  156. sidebar={draw}
  157. position="right"
  158. open={this.state.isShowSearch}
  159. drawerRef={(el) => (this.drawer = el)}
  160. onOpenChange={(open) => this.openStatus(open)}
  161. drawerBackgroundColor="#ccc"
  162. drawerWidth={300}>
  163. <FlatList
  164. data={this.state.invoiceList}
  165. renderItem={(item) => this.renderItem(item)}
  166. refreshControl={
  167. <RefreshControl
  168. title={'加载中...'}
  169. colors={['#B7B7B7']} //此颜色无效
  170. tintColor={'#B7B7B7'}
  171. titleColor={'#B7B7B7'} //只有ios有效
  172. refreshing={this.state.isRefreshing}
  173. onRefresh={() => this.onRefresh()}
  174. />
  175. }
  176. ListFooterComponent={() => this.renderFooter()}
  177. onEndReached={() => this.onReached()}
  178. onEndReachedThreshold={0.1}
  179. />
  180. <WingBlank>
  181. <View style={public_css.bottomStatus}>
  182. <TouchableOpacity
  183. style={[public_css.statusBtn, public_css.statusRBtn]}
  184. onPress={() =>
  185. this.props.navigation.navigate('invoice_application', {
  186. setRefresh: () => {
  187. this.setRefresh();
  188. },
  189. })
  190. }>
  191. <Image
  192. source={require('../../source/img/productImg/confirm.png')}
  193. style={{width: 32, height: 32}}
  194. />
  195. <Text style={{color: '#fff'}}>发票申领</Text>
  196. </TouchableOpacity>
  197. </View>
  198. </WingBlank>
  199. <WhiteSpace />
  200. </Drawer>
  201. </SafeAreaView>
  202. </Provider>
  203. );
  204. }
  205. // render加载完后调用
  206. async componentDidMount() {
  207. this.setLoadingStatus(true);
  208. let date = GetMonthDate();
  209. this.setState({
  210. monthDate: date,
  211. beginDate: date.startDate,
  212. endDate: date.endDate,
  213. beginDateString: date.startDateString,
  214. endDateString: date.endDateString,
  215. });
  216. await this.getApplicationList();
  217. }
  218. //判断是否点击了查询
  219. shouldComponentUpdate(
  220. nextProps: Readonly<P>,
  221. nextState: Readonly<S>,
  222. nextContext: any,
  223. ): boolean {
  224. if (nextProps.route.params != undefined) {
  225. if (nextProps.route.params.isShow) {
  226. this.setState({
  227. isShowSearch: true,
  228. });
  229. this.drawer.openDrawer();
  230. this.props.navigation.setParams({
  231. isShow: false,
  232. });
  233. }
  234. }
  235. return true;
  236. }
  237. // 获取发票申领列表
  238. getApplicationList = async () => {
  239. const company = JSON.parse(await RetrieveData('company'));
  240. const token = await RetrieveData('token');
  241. const account = await RetrieveData('account');
  242. if (token && account) {
  243. const url = '/sys/invoicePurchase/statusInfos';
  244. let response = await RequestNetwork(
  245. url,
  246. token,
  247. {
  248. entTaxId: company.entTaxId,
  249. deviceType: company.defaultDeviceInfo.deviceType,
  250. taxDiscId: company.defaultDeviceInfo.taxDiscId,
  251. invoiceCategory: this.state.invoiceType,
  252. applyDateBegin: this.state.beginDateString,
  253. applyDateEnd: this.state.endDateString,
  254. handleStatus: this.state.applicationStatus,
  255. pageNum: this.state.pageNum,
  256. pageSize: this.state.pageSize,
  257. mobile: account,
  258. },
  259. false,
  260. 2,
  261. );
  262. if (response) {
  263. if (response.code === 0) {
  264. this.setState({
  265. isNextPage: response.data.hasNext,
  266. isPreviousPage: response.data.hasPrv,
  267. });
  268. this.setLoadingStatus(false);
  269. if (response.data.statusInfoVOs.length > 0) {
  270. this.setState({
  271. isRefreshing: false,
  272. totalPage: response.data.statusInfoVOs.length,
  273. });
  274. this.setList(response.data.statusInfoVOs);
  275. } else {
  276. this.setState({
  277. showFoot: 0,
  278. isRefreshing: false,
  279. });
  280. }
  281. } else {
  282. this.setLoadingStatus(false);
  283. await this.abnormalMessage(response);
  284. }
  285. }
  286. }
  287. };
  288. //设置抬头列表
  289. setList = (data) => {
  290. let listData = data.map((_, i) => ({
  291. key: data[i].applySerialNumber,
  292. invoiceKindCode: data[i].invoiceKindCode,
  293. invoiceKindName: data[i].invoiceKindName,
  294. invoiceCateCode: data[i].invoiceCateCode,
  295. invoiceCateName: data[i].invoiceCateName,
  296. applyNum: data[i].applyNum,
  297. applyDate: data[i].applyDate,
  298. handleStatus: data[i].handleStatus,
  299. handleInformation: data[i].handleInformation,
  300. resultEnterFlag: data[i].resultEnterFlag,
  301. details: data[i].details,
  302. }));
  303. let list = this.state.invoiceList.concat(listData);
  304. let showFoot = 0;
  305. if (this.state.isNextPage) {
  306. showFoot = 2;
  307. }
  308. this.setState({
  309. invoiceList: list,
  310. showFoot: showFoot,
  311. });
  312. };
  313. //查询菜单开关状态
  314. openStatus = (open) => {
  315. if (open) {
  316. } else {
  317. // this.props.children.setClickNum();
  318. }
  319. };
  320. //获取查询开始时间
  321. beginTimeChange = (time) => {
  322. let date = GetDateString(time);
  323. this.setState({
  324. beginDate: time,
  325. beginDateString: date,
  326. });
  327. };
  328. //获取查询结束时间
  329. endTimeChange = (time) => {
  330. let date = GetDateString(time);
  331. this.setState({
  332. endDate: time,
  333. endDateString: date,
  334. });
  335. };
  336. //获取查询发票类型
  337. invoiceTypeChange = (select) => {
  338. let invoiceType = '';
  339. if (select.length > 0) {
  340. invoiceType = select[0];
  341. }
  342. this.setState({
  343. invoiceType: invoiceType,
  344. });
  345. };
  346. //获取查询发票类型
  347. applicationStatusChange = (select) => {
  348. let applicationStatus = '';
  349. if (select.length > 0) {
  350. applicationStatus = select[0];
  351. }
  352. this.setState({
  353. applicationStatus: applicationStatus,
  354. });
  355. };
  356. //查询
  357. searchData = async () => {
  358. this.setState({
  359. isShowSearch: false,
  360. invoiceList: [],
  361. showFoot: 0,
  362. isNextPage: false,
  363. isPreviousPage: false,
  364. });
  365. this.setLoadingStatus(true);
  366. await this.getApplicationList();
  367. };
  368. //清空查询数据
  369. searchDataEmpty = async () => {
  370. let date = GetMonthDate();
  371. this.setState({
  372. monthDate: date,
  373. beginDate: date.startDate,
  374. endDate: date.endDate,
  375. beginDateString: date.startDateString,
  376. endDateString: date.endDateString,
  377. invoiceType: '1',
  378. applicationStatus: '0',
  379. invoiceList: [],
  380. showFoot: 0,
  381. isNextPage: false,
  382. isPreviousPage: false,
  383. pageNum: 1,
  384. });
  385. await this.getApplicationList();
  386. };
  387. // 加载list项
  388. renderItem = (data) => (
  389. <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
  390. <List.Item style={{backgroundColor: '#F7F7F7'}}>
  391. <View style={{backgroundColor: 'white', marginTop: 10}}>
  392. <View style={{margin: 10}}>
  393. <Text style={{fontSize: 15, fontWeight: 'bold', color: '#050505'}}>
  394. 发票类别:{data.item.invoiceCateName}
  395. </Text>
  396. <Text style={{color: '#898989', marginTop: 5}}>
  397. 申领份数:{data.item.applyNum}
  398. </Text>
  399. <Text style={{color: '#898989', marginTop: 5}}>
  400. 申领时间:{data.item.applyDate}
  401. </Text>
  402. <Text style={{color: '#898989', marginTop: 5}}>
  403. 处理时间:{data.item.handleDate}
  404. </Text>
  405. <Text style={{color: '#898989', marginTop: 5}}>
  406. 处理状态:
  407. {data.item.handleStatus === '0'
  408. ? '申领中'
  409. : data.item.handleStatus === '1'
  410. ? '成功'
  411. : data.item.handleStatus === '2'
  412. ? '失败'
  413. : ''}
  414. </Text>
  415. <Text style={{color: '#898989', marginTop: 5}}>
  416. 处理信息:{data.item.handleInformation}
  417. </Text>
  418. </View>
  419. <View style={{flexDirection: 'row', margin: 10}}>
  420. <View style={{flex: 1}}>
  421. {data.item.handleStatus === '1' ? (
  422. data.item.resultEnterFlag === 'N' ? (
  423. <TouchableOpacity
  424. style={{
  425. flex: 1,
  426. borderWidth: 1,
  427. justifyContent: 'center',
  428. alignItems: 'center',
  429. borderColor: '#2A67FE',
  430. borderRadius: 30,
  431. height: 30,
  432. marginLeft: 5,
  433. width: 150,
  434. }}
  435. onPress={() => {
  436. this.applicationConfirmation(data);
  437. }}>
  438. <Text style={{color: '#2A67FE'}}>申领确认</Text>
  439. </TouchableOpacity>
  440. ) : (
  441. <View />
  442. )
  443. ) : (
  444. <View />
  445. )}
  446. </View>
  447. <View style={{flex: 1}}>
  448. {data.item.handleStatus === '0' ? (
  449. <TouchableOpacity
  450. style={{
  451. flex: 1,
  452. borderWidth: 1,
  453. justifyContent: 'center',
  454. alignItems: 'center',
  455. borderColor: '#CCCCCC',
  456. borderRadius: 30,
  457. height: 30,
  458. width: 150,
  459. }}
  460. onPress={() => {
  461. this.applicationCancel(data);
  462. }}>
  463. <Text style={{color: '#666666'}}>申领撤销</Text>
  464. </TouchableOpacity>
  465. ) : (
  466. <View />
  467. )}
  468. </View>
  469. </View>
  470. </View>
  471. </List.Item>
  472. </SwipeAction>
  473. );
  474. // 下拉刷新
  475. onRefresh = async () => {
  476. this.setState({
  477. isRefreshing: true,
  478. showFoot: 1,
  479. invoiceList: [],
  480. isNextPage: false,
  481. isPreviousPage: false,
  482. pageNum: 1,
  483. });
  484. await this.getApplicationList();
  485. };
  486. // list尾部组件
  487. renderFooter() {
  488. if (this.state.showFoot === 0) {
  489. return (
  490. <View
  491. style={{height: 30, alignItems: 'center', justifyContent: 'center'}}>
  492. <Text
  493. style={{
  494. color: '#999999',
  495. fontSize: 14,
  496. marginTop: 5,
  497. marginBottom: 5,
  498. }}>
  499. 没有更多数据了
  500. </Text>
  501. </View>
  502. );
  503. } else if (this.state.showFoot === 1) {
  504. return (
  505. <View style={{alignItems: 'center', justifyContent: 'center'}}>
  506. <ActivityIndicator />
  507. <Text>正在加载...</Text>
  508. </View>
  509. );
  510. } else if (this.state.showFoot === 2) {
  511. return (
  512. <View
  513. style={{height: 30, alignItems: 'center', justifyContent: 'center'}}>
  514. <Text
  515. style={{
  516. color: '#999999',
  517. fontSize: 14,
  518. marginTop: 5,
  519. marginBottom: 5,
  520. }}>
  521. 上拉加载
  522. </Text>
  523. </View>
  524. );
  525. }
  526. }
  527. //列表末尾控制,若请求到的数据数据少于一页,则默认没有更多数据了
  528. onReached = async () => {
  529. if (this.state.showFoot === 2 && this.state.isNextPage) {
  530. if (this.state.pageNum >= this.state.totalPage) {
  531. this.setState({showFoot: 0});
  532. } else {
  533. this.setState({
  534. pageNum: this.state.pageNum + 1,
  535. showFoot: 1,
  536. });
  537. //获取数据
  538. await this.getApplicationList();
  539. }
  540. } else {
  541. return;
  542. }
  543. };
  544. // 申领成功后返回刷新
  545. setRefresh = async () => {
  546. await this.getApplicationList();
  547. };
  548. // 申领确认
  549. applicationConfirmation = async (data) => {
  550. const company = JSON.parse(await RetrieveData('company'));
  551. const token = await RetrieveData('token');
  552. const account = await RetrieveData('account');
  553. if (token && account) {
  554. const url = '/sys/invoicePurchase/confirm';
  555. let response = await RequestNetwork(
  556. url,
  557. token,
  558. {
  559. entTaxId: company.entTaxId,
  560. deviceType: company.defaultDeviceInfo.deviceType,
  561. taxDiscId: company.defaultDeviceInfo.taxDiscId,
  562. invoiceCateCode: data.item.invoiceCateCode,
  563. invoiceCateName: data.item.invoiceCateName,
  564. applySerialNumber: data.item.key,
  565. mobile: account,
  566. reqChannel: 3,
  567. details: [
  568. {
  569. invoiceBeginNo: data.item.details[0].invoiceBeginNo,
  570. invoiceNums: data.item.details[0].invoiceNums,
  571. invoiceEndNo: data.item.details[0].invoiceEndNo,
  572. invoiceCode: data.item.details[0].invoiceCode,
  573. },
  574. ],
  575. },
  576. false,
  577. 1,
  578. );
  579. if (response) {
  580. if (response.code === 0) {
  581. ToastShow(1, '申领确认成功!');
  582. await this.searchDataEmpty();
  583. } else {
  584. ToastShow(1, '申领确认失败!');
  585. }
  586. }
  587. }
  588. };
  589. //申领撤销
  590. applicationCancel = async (data) => {
  591. const company = JSON.parse(await RetrieveData('company'));
  592. const token = await RetrieveData('token');
  593. const account = await RetrieveData('account');
  594. if (token && account) {
  595. const url = '/sys/invoicePurchase/revoke';
  596. let response = await RequestNetwork(
  597. url,
  598. token,
  599. {
  600. entTaxId: company.entTaxId,
  601. deviceType: company.defaultDeviceInfo.deviceType,
  602. taxDiscId: company.defaultDeviceInfo.taxDiscId,
  603. invoiceCateCode: data.item.invoiceCateCode,
  604. invoiceCateName: data.item.invoiceCateName,
  605. applySerialNumber: data.item.key,
  606. mobile: account,
  607. reqChannel: 3,
  608. },
  609. false,
  610. 1,
  611. );
  612. if (response) {
  613. if (response.code === 0) {
  614. if (response.code === 0) {
  615. ToastShow(1, '申领撤销成功!');
  616. await this.searchDataEmpty();
  617. } else {
  618. ToastShow(1, '申领撤销失败!');
  619. }
  620. }
  621. }
  622. }
  623. };
  624. // 设置load层是否显示
  625. setLoadingStatus = (isLoading) => {
  626. this.setState({
  627. spinner: isLoading,
  628. });
  629. };
  630. // 处理网络请求数据
  631. abnormalMessage = async (jason) => {
  632. if (jason.code === 401) {
  633. await Alert.alert(
  634. '登录失效',
  635. '登录状态已失效,请重新登录!',
  636. [
  637. {
  638. text: '确定',
  639. onPress: () => {
  640. CleanAll();
  641. this.props.navigation.popToTop();
  642. },
  643. },
  644. ],
  645. {cancelable: false},
  646. );
  647. }
  648. if (jason.code === 403) {
  649. Alert.alert(
  650. '权限',
  651. '暂无权限操作此模块!',
  652. [
  653. {
  654. text: '确定',
  655. onPress: () => {
  656. this.props.navigation.goBack();
  657. },
  658. },
  659. ],
  660. {cancelable: false},
  661. );
  662. }
  663. if (jason.code !== 401 && jason.code !== 403) {
  664. ToastShow(1, jason.msg);
  665. }
  666. };
  667. }