invoice_distribution.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. TouchableOpacity,
  5. Text,
  6. SafeAreaView,
  7. FlatList,
  8. ActivityIndicator,
  9. Alert,
  10. RefreshControl,
  11. } from 'react-native';
  12. import {
  13. Drawer,
  14. List,
  15. Provider,
  16. SwipeAction,
  17. Picker,
  18. } from '@ant-design/react-native';
  19. import public_css from '../../source/css/public_css';
  20. import {RetrieveData} from '../../data/storage';
  21. import {RequestNetwork} from '../../data/encryption';
  22. import {GetMonthDate} from '../../utils/date';
  23. import {ToastShow} from '../../components/toast/toast';
  24. import {InvoiceType, Distribute} from '../../utils/config';
  25. import {CleanAll} from '../../components/abnormalMessage/abnormal_message';
  26. import Spinner from 'react-native-loading-spinner-overlay';
  27. import loading_css from '../../source/css/loading_css';
  28. export default class application_info extends Component {
  29. constructor(props) {
  30. super(props);
  31. this.props.navigation.dangerouslyGetParent().setOptions({
  32. tabBarVisible: false,
  33. });
  34. this.state = {
  35. isShowSearch: false,
  36. beginDate: '',
  37. endDate: '',
  38. beginDateString: '',
  39. endDateString: '',
  40. invoiceList: [],
  41. isRefreshing: false,
  42. pageNum: 1, //当前页码
  43. pageSize: 10, //每页数量
  44. totalPage: 10, //总页数
  45. showFoot: 0,
  46. monthDate: {},
  47. invoiceTypeList: InvoiceType(),
  48. invoiceType: '1',
  49. distributeStatusList: Distribute(),
  50. distributeStatus: '0',
  51. spinner: false,
  52. isNextPage: false, // 是否有下一页
  53. isPreviousPage: false, // 是否有上一页
  54. };
  55. }
  56. render() {
  57. let draw = (
  58. <View style={public_css.body}>
  59. <View style={{flex: 1}}>
  60. <Picker
  61. value={[this.state.invoiceType]}
  62. data={this.state.invoiceTypeList}
  63. cols={1}
  64. onChange={(select) => this.invoiceTypeChange(select)}>
  65. <List.Item arrow="horizontal" onPress={this.onPress}>
  66. 发票类型:
  67. </List.Item>
  68. </Picker>
  69. <Picker
  70. data={this.state.distributeStatusList}
  71. cols={1}
  72. value={[this.state.distributeStatus]}
  73. onChange={(select) => this.distributeStatusChange(select)}>
  74. <List.Item arrow="horizontal" onPress={this.onPress}>
  75. 分发状态:
  76. </List.Item>
  77. </Picker>
  78. </View>
  79. <View style={public_css.bottomStatus}>
  80. <View
  81. style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
  82. <TouchableOpacity
  83. style={{
  84. borderWidth: 1,
  85. borderRadius: 30,
  86. borderColor: '#8B8B8B',
  87. width: 100,
  88. height: 40,
  89. justifyContent: 'center',
  90. alignItems: 'center',
  91. }}
  92. onPress={() => {
  93. this.searchDataEmpty();
  94. }}>
  95. <Text style={{color: '#262626'}}>重置</Text>
  96. </TouchableOpacity>
  97. </View>
  98. <View
  99. style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
  100. <TouchableOpacity
  101. style={{
  102. borderWidth: 1,
  103. borderRadius: 30,
  104. borderColor: '#2A67FE',
  105. backgroundColor: '#2A67FE',
  106. width: 100,
  107. height: 40,
  108. justifyContent: 'center',
  109. alignItems: 'center',
  110. }}
  111. onPress={() => this.searchData()}>
  112. <Text style={{color: '#FFFFFF'}}>查询</Text>
  113. </TouchableOpacity>
  114. </View>
  115. </View>
  116. </View>
  117. );
  118. return (
  119. <Provider>
  120. <SafeAreaView style={public_css.body}>
  121. <Spinner
  122. visible={this.state.spinner}
  123. textContent={'Loading...'}
  124. textStyle={loading_css.spinnerTextStyle}
  125. />
  126. <Drawer
  127. sidebar={draw}
  128. position="right"
  129. open={this.state.isShowSearch}
  130. drawerRef={(el) => (this.drawer = el)}
  131. onOpenChange={(open) => this.openStatus(open)}
  132. drawerBackgroundColor="#ccc"
  133. drawerWidth={300}>
  134. <FlatList
  135. data={this.state.invoiceList}
  136. renderItem={(item) => this.renderItem(item)}
  137. refreshControl={
  138. <RefreshControl
  139. title={'加载中...'}
  140. colors={['#B7B7B7']} //此颜色无效
  141. tintColor={'#B7B7B7'}
  142. titleColor={'#B7B7B7'} //只有ios有效
  143. refreshing={this.state.isRefreshing}
  144. onRefresh={() => this.onRefresh()}
  145. />
  146. }
  147. ListFooterComponent={() => this.renderFooter()}
  148. onEndReached={() => this.onReached()}
  149. onEndReachedThreshold={0.1}
  150. />
  151. </Drawer>
  152. </SafeAreaView>
  153. </Provider>
  154. );
  155. }
  156. // render加载完后调用
  157. async componentDidMount() {
  158. this.setLoadingStatus(true);
  159. let date = GetMonthDate();
  160. this.setState({
  161. monthDate: date,
  162. beginDate: date.startDate,
  163. endDate: date.endDate,
  164. beginDateString: date.startDateString,
  165. endDateString: date.endDateString,
  166. });
  167. await this.getDistributeList();
  168. }
  169. //判断是否点击了查询
  170. shouldComponentUpdate(
  171. nextProps: Readonly<P>,
  172. nextState: Readonly<S>,
  173. nextContext: any,
  174. ): boolean {
  175. if (nextProps.route.params != undefined) {
  176. if (nextProps.route.params.isShow) {
  177. this.setState({
  178. isShowSearch: true,
  179. });
  180. this.drawer.openDrawer();
  181. this.props.navigation.setParams({
  182. isShow: false,
  183. });
  184. }
  185. }
  186. return true;
  187. }
  188. // 获取发票分发列表
  189. getDistributeList = async () => {
  190. const company = JSON.parse(await RetrieveData('company'));
  191. const token = await RetrieveData('token');
  192. const account = await RetrieveData('account');
  193. if (token && account) {
  194. const url = '/sys/invoicePurchase/distributeInfos';
  195. let response = await RequestNetwork(
  196. url,
  197. token,
  198. {
  199. entTaxId: company.entTaxId,
  200. deviceType: company.defaultDeviceInfo.deviceType,
  201. taxDiscId: company.defaultDeviceInfo.taxDiscId,
  202. invoiceCategory: this.state.invoiceType,
  203. distributeStatus: this.state.distributeStatus,
  204. pageNo: this.state.pageNum,
  205. pageSize: this.state.pageSize,
  206. mobile: account,
  207. },
  208. false,
  209. 2,
  210. );
  211. if (response) {
  212. if (response.code === 0) {
  213. this.setState({
  214. isNextPage: response.data.hasNext,
  215. isPreviousPage: response.data.hasPrv,
  216. });
  217. this.setLoadingStatus(false);
  218. if (response.data.distributeVOs.length > 0) {
  219. this.setState({
  220. isRefreshing: false,
  221. totalPage: response.data.distributeVOs.length,
  222. });
  223. this.setList(response.data.distributeVOs);
  224. } else {
  225. this.setState({
  226. showFoot: 0,
  227. isRefreshing: false,
  228. });
  229. }
  230. } else {
  231. this.setLoadingStatus(false);
  232. await this.abnormalMessage(response);
  233. }
  234. }
  235. }
  236. };
  237. //设置抬头列表
  238. setList = (data) => {
  239. let listData = [];
  240. data.map((item, index) => {
  241. let data = {
  242. key: index,
  243. invoiceCateCode: item.invoiceCateCode,
  244. invoiceCateName: item.invoiceCateName,
  245. invoiceCode: item.invoiceCode,
  246. invoiceBeginNo: item.invoiceBeginNo,
  247. invoiceEndNo: item.invoiceEndNo,
  248. surplusNum: item.surplusNum,
  249. invoicePurchaseDate: item.invoicePurchaseDate,
  250. effectiveDate: item.effectiveDate,
  251. administratorsCode: item.administratorsCode,
  252. taxPanel: item.taxPanel,
  253. };
  254. listData = listData.concat(data);
  255. });
  256. let showFoot = 0;
  257. if (this.state.isNextPage) {
  258. showFoot = 2;
  259. }
  260. this.setState({
  261. invoiceList: listData,
  262. showFoot: showFoot,
  263. });
  264. };
  265. //查询菜单开关状态
  266. openStatus = (open) => {
  267. if (open) {
  268. } else {
  269. // this.props.children.setClickNum();
  270. }
  271. };
  272. //获取查询发票类型
  273. invoiceTypeChange = (select) => {
  274. let invoiceType = '';
  275. if (select.length > 0) {
  276. invoiceType = select[0];
  277. }
  278. this.setState({
  279. invoiceType: invoiceType,
  280. });
  281. };
  282. //获取查询发票分发状态
  283. distributeStatusChange = (select) => {
  284. let distributeStatus = '';
  285. if (select.length > 0) {
  286. distributeStatus = select[0];
  287. }
  288. this.setState({
  289. distributeStatus: distributeStatus,
  290. });
  291. };
  292. //查询
  293. searchData = async () => {
  294. this.setState({
  295. isShowSearch: false,
  296. invoiceList: [],
  297. showFoot: 0,
  298. isNextPage: false,
  299. isPreviousPage: false,
  300. });
  301. this.setLoadingStatus(true);
  302. await this.getDistributeList();
  303. };
  304. //清空查询数据
  305. searchDataEmpty = async () => {
  306. this.setState({
  307. invoiceType: '1',
  308. distributeStatus: '0',
  309. invoiceList: [],
  310. showFoot: 0,
  311. isNextPage: false,
  312. isPreviousPage: false,
  313. pageNum: 1,
  314. });
  315. await this.getDistributeList();
  316. };
  317. // 加载list项
  318. renderItem = (data) => (
  319. <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
  320. <List.Item style={{backgroundColor: '#F7F7F7'}}>
  321. <View style={{backgroundColor: 'white', marginTop: 10}}>
  322. <View style={{margin: 10}}>
  323. <Text style={{fontSize: 15, fontWeight: 'bold', color: '#050505'}}>
  324. 发票类别:{data.item.invoiceCateName}
  325. </Text>
  326. <Text style={{color: '#898989', marginTop: 5}}>
  327. 发票代码:{data.item.invoiceCode}
  328. </Text>
  329. <Text style={{color: '#898989', marginTop: 5}}>
  330. 发票起始号码:{data.item.invoiceBeginNo}
  331. </Text>
  332. <Text style={{color: '#898989', marginTop: 5}}>
  333. 发票终止号码:{data.item.invoiceEndNo}
  334. </Text>
  335. <Text style={{color: '#898989', marginTop: 5}}>
  336. 剩余份数:{data.item.surplusNum}
  337. </Text>
  338. <Text style={{color: '#898989', marginTop: 5}}>
  339. 领购日期:{data.item.invoicePurchaseDate}
  340. </Text>
  341. </View>
  342. <View style={{flexDirection: 'row', margin: 10}}>
  343. <View style={{flex: 1}} />
  344. <View style={{flex: 1}}>
  345. <TouchableOpacity
  346. style={{
  347. flex: 1,
  348. borderWidth: 1,
  349. justifyContent: 'center',
  350. alignItems: 'center',
  351. borderColor: '#2A67FE',
  352. borderRadius: 30,
  353. height: 30,
  354. marginLeft: 5,
  355. width: 150,
  356. }}
  357. onPress={() => {
  358. this.confirmDistribution(data);
  359. }}>
  360. <Text style={{color: '#2A67FE'}}>确认分发</Text>
  361. </TouchableOpacity>
  362. </View>
  363. </View>
  364. </View>
  365. </List.Item>
  366. </SwipeAction>
  367. );
  368. // 下拉刷新
  369. onRefresh = async () => {
  370. this.setState({
  371. isRefreshing: true,
  372. showFoot: 1,
  373. invoiceList: [],
  374. isNextPage: false,
  375. isPreviousPage: false,
  376. pageNum: 1,
  377. });
  378. await this.getDistributeList();
  379. };
  380. // list尾部组件
  381. renderFooter() {
  382. if (this.state.showFoot === 0) {
  383. return (
  384. <View
  385. style={{height: 30, alignItems: 'center', justifyContent: 'center'}}>
  386. <Text
  387. style={{
  388. color: '#999999',
  389. fontSize: 14,
  390. marginTop: 5,
  391. marginBottom: 5,
  392. }}>
  393. 没有更多数据了
  394. </Text>
  395. </View>
  396. );
  397. } else if (this.state.showFoot === 1) {
  398. return (
  399. <View style={{alignItems: 'center', justifyContent: 'center'}}>
  400. <ActivityIndicator />
  401. <Text>正在加载...</Text>
  402. </View>
  403. );
  404. } else if (this.state.showFoot === 2) {
  405. return (
  406. <View
  407. style={{height: 30, alignItems: 'center', justifyContent: 'center'}}>
  408. <Text
  409. style={{
  410. color: '#999999',
  411. fontSize: 14,
  412. marginTop: 5,
  413. marginBottom: 5,
  414. }}>
  415. 上拉加载
  416. </Text>
  417. </View>
  418. );
  419. }
  420. }
  421. //列表末尾控制,若请求到的数据数据少于一页,则默认没有更多数据了
  422. onReached = async () => {
  423. if (this.state.showFoot === 2 && this.state.isNextPage) {
  424. if (this.state.pageNum >= this.state.totalPage) {
  425. this.setState({showFoot: 0});
  426. } else {
  427. this.setState({
  428. pageNum: this.state.pageNum + 1,
  429. showFoot: 1,
  430. });
  431. //获取数据
  432. await this.getDistributeList();
  433. }
  434. } else {
  435. return;
  436. }
  437. };
  438. // 确认分发
  439. confirmDistribution = async (data) => {
  440. const company = JSON.parse(await RetrieveData('company'));
  441. const token = await RetrieveData('token');
  442. const account = await RetrieveData('account');
  443. if (token && account) {
  444. const url = '/sys/invoicePurchase/distribute';
  445. let response = await RequestNetwork(
  446. url,
  447. token,
  448. {
  449. entTaxId: company.entTaxId,
  450. deviceType: company.defaultDeviceInfo.deviceType,
  451. taxDiscId: company.defaultDeviceInfo.taxDiscId,
  452. invoiceCateCode: data.item.invoiceCateCode,
  453. surplusNum: data.item.surplusNum,
  454. invoiceCode: data.item.invoiceCode,
  455. invoiceBeginNo: data.item.invoiceBeginNo,
  456. invoiceEndNo: data.item.invoiceEndNo,
  457. distributeNum: data.item.surplusNum,
  458. mobile: account,
  459. reqChannel: 3,
  460. },
  461. false,
  462. 1,
  463. );
  464. if (response) {
  465. if (response.code === 0) {
  466. ToastShow(1, '发票分发成功!');
  467. await this.searchDataEmpty();
  468. } else {
  469. ToastShow(1, '发票分发失败!');
  470. }
  471. }
  472. }
  473. };
  474. // 设置load层是否显示
  475. setLoadingStatus = (isLoading) => {
  476. this.setState({
  477. spinner: isLoading,
  478. });
  479. };
  480. // 处理网络请求数据
  481. abnormalMessage = async (jason) => {
  482. if (jason.code === 401) {
  483. await Alert.alert(
  484. '登录失效',
  485. '登录状态已失效,请重新登录!',
  486. [
  487. {
  488. text: '确定',
  489. onPress: () => {
  490. CleanAll();
  491. this.props.navigation.popToTop();
  492. },
  493. },
  494. ],
  495. {cancelable: false},
  496. );
  497. }
  498. if (jason.code === 403) {
  499. Alert.alert(
  500. '权限',
  501. '暂无权限操作此模块!',
  502. [
  503. {
  504. text: '确定',
  505. onPress: () => {
  506. this.props.navigation.goBack();
  507. },
  508. },
  509. ],
  510. {cancelable: false},
  511. );
  512. }
  513. if (jason.code !== 401 && jason.code !== 403) {
  514. ToastShow(1, jason.msg);
  515. }
  516. };
  517. }