invoice_stock.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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 {ToastShow} from '../../../components/toast/toast';
  23. import {InvoiceType, Distribute} from '../../../utils/config';
  24. import {CleanAll} from '../../../components/abnormalMessage/abnormal_message';
  25. import Spinner from 'react-native-loading-spinner-overlay';
  26. import loading_css from '../../../source/css/loading_css';
  27. export default class invoice_stock extends Component {
  28. constructor(props) {
  29. super(props);
  30. this.props.navigation.dangerouslyGetParent().setOptions({
  31. tabBarVisible: false,
  32. });
  33. this.state = {
  34. isShowSearch: false,
  35. beginDate: '',
  36. endDate: '',
  37. beginDateString: '',
  38. endDateString: '',
  39. invoiceList: [],
  40. isRefreshing: false,
  41. pageNum: 1, //当前页码
  42. pageSize: 10, //每页数量
  43. totalPage: 10, //总页数
  44. showFoot: 0,
  45. monthDate: {},
  46. invoiceTypeList: InvoiceType(),
  47. invoiceType: '1',
  48. distributeStatusList: Distribute(),
  49. distributeStatus: '0',
  50. spinner: false,
  51. isNextPage: false, // 是否有下一页
  52. isPreviousPage: false, // 是否有上一页
  53. };
  54. }
  55. render() {
  56. let draw = (
  57. <View style={public_css.body}>
  58. <View style={{flex: 1}}>
  59. <Picker
  60. value={[this.state.invoiceType]}
  61. data={this.state.invoiceTypeList}
  62. cols={1}
  63. onChange={(select) => this.invoiceTypeChange(select)}>
  64. <List.Item arrow="horizontal" onPress={this.onPress}>
  65. 发票类型:
  66. </List.Item>
  67. </Picker>
  68. </View>
  69. <View style={public_css.bottomStatus}>
  70. <View
  71. style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
  72. <TouchableOpacity
  73. style={{
  74. borderWidth: 1,
  75. borderRadius: 30,
  76. borderColor: '#8B8B8B',
  77. width: 100,
  78. height: 40,
  79. justifyContent: 'center',
  80. alignItems: 'center',
  81. }}
  82. onPress={() => {
  83. this.searchDataEmpty();
  84. }}>
  85. <Text style={{color: '#262626'}}>重置</Text>
  86. </TouchableOpacity>
  87. </View>
  88. <View
  89. style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
  90. <TouchableOpacity
  91. style={{
  92. borderWidth: 1,
  93. borderRadius: 30,
  94. borderColor: '#2A67FE',
  95. backgroundColor: '#2A67FE',
  96. width: 100,
  97. height: 40,
  98. justifyContent: 'center',
  99. alignItems: 'center',
  100. }}
  101. onPress={() => this.searchData()}>
  102. <Text style={{color: '#FFFFFF'}}>查询</Text>
  103. </TouchableOpacity>
  104. </View>
  105. </View>
  106. </View>
  107. );
  108. return (
  109. <Provider>
  110. <SafeAreaView style={public_css.body}>
  111. <Spinner
  112. visible={this.state.spinner}
  113. textContent={'Loading...'}
  114. textStyle={loading_css.spinnerTextStyle}
  115. />
  116. <Drawer
  117. sidebar={draw}
  118. position="right"
  119. open={this.state.isShowSearch}
  120. drawerRef={(el) => (this.drawer = el)}
  121. onOpenChange={(open) => this.openStatus(open)}
  122. drawerBackgroundColor="#ccc"
  123. drawerWidth={300}>
  124. <FlatList
  125. data={this.state.invoiceList}
  126. renderItem={(item) => this.renderItem(item)}
  127. refreshControl={
  128. <RefreshControl
  129. title={'加载中...'}
  130. colors={['#B7B7B7']} //此颜色无效
  131. tintColor={'#B7B7B7'}
  132. titleColor={'#B7B7B7'} //只有ios有效
  133. refreshing={this.state.isRefreshing}
  134. onRefresh={() => this.onRefresh()}
  135. />
  136. }
  137. ListFooterComponent={() => this.renderFooter()}
  138. />
  139. </Drawer>
  140. </SafeAreaView>
  141. </Provider>
  142. );
  143. }
  144. // render加载完后调用
  145. async componentDidMount() {
  146. this.setLoadingStatus(true);
  147. await this.getDistributeList();
  148. }
  149. //判断是否点击了查询
  150. shouldComponentUpdate(
  151. nextProps: Readonly<P>,
  152. nextState: Readonly<S>,
  153. nextContext: any,
  154. ): boolean {
  155. if (nextProps.route.params != undefined) {
  156. if (nextProps.route.params.isShow) {
  157. this.setState({
  158. isShowSearch: true,
  159. });
  160. this.drawer.openDrawer();
  161. this.props.navigation.setParams({
  162. isShow: false,
  163. });
  164. }
  165. }
  166. return true;
  167. }
  168. // 获取发票分发列表
  169. getDistributeList = async () => {
  170. const company = JSON.parse(await RetrieveData('company'));
  171. const token = await RetrieveData('token');
  172. const account = await RetrieveData('account');
  173. if (token && account) {
  174. const url = '/sys/invoiceExt/purchaseQuery';
  175. let response = await RequestNetwork(
  176. url,
  177. token,
  178. {
  179. entTaxId: company.entTaxId,
  180. deviceType: company.defaultDeviceInfo.deviceType,
  181. taxDiscId: company.defaultDeviceInfo.taxDiscId,
  182. invoiceCategory: this.state.invoiceType,
  183. },
  184. false,
  185. 2,
  186. );
  187. if (response) {
  188. console.log(response);
  189. if (response.code === 0) {
  190. this.setLoadingStatus(false);
  191. if (response.data.purchaseDetailVOs.length > 0) {
  192. this.setState({
  193. isRefreshing: false,
  194. totalPage: response.data.purchaseDetailVOs.length,
  195. });
  196. this.setList(response.data.purchaseDetailVOs);
  197. } else {
  198. this.setState({
  199. showFoot: 0,
  200. isRefreshing: false,
  201. });
  202. }
  203. } else {
  204. this.setLoadingStatus(false);
  205. await this.abnormalMessage(response);
  206. }
  207. }
  208. }
  209. };
  210. //设置抬头列表
  211. setList = (data) => {
  212. let invoiceType = '';
  213. if (data[0].invoiceCategory === 1) {
  214. invoiceType = '增值税普通电子发票';
  215. }
  216. if (data[0].invoiceCategory === 2) {
  217. invoiceType = '增值税电子专用发票';
  218. }
  219. if (data[0].invoiceCategory === 3) {
  220. invoiceType = '增值税普通纸质发票';
  221. }
  222. if (data[0].invoiceCategory === 4) {
  223. invoiceType = '增值税专用纸质发票';
  224. }
  225. let invoiceList = data[0].purchaseRecords;
  226. let listData = invoiceList.map((_, i) => ({
  227. invoiceCategory: invoiceType,
  228. invoiceCode: invoiceList[i].invoiceCode,
  229. invoiceStartNo: invoiceList[i].invoiceStartNo,
  230. invoiceEndNo: invoiceList[i].invoiceEndNo,
  231. invoicePurchaseQuantity: invoiceList[i].invoicePurchaseQuantity,
  232. invoiceSurplusQuantity: invoiceList[i].invoiceSurplusQuantity,
  233. invoicePurchaseDate: invoiceList[i].invoicePurchaseDate,
  234. invoicePurchaseOperator: invoiceList[i].invoicePurchaseOperator,
  235. }));
  236. let list = this.state.invoiceList.concat(listData);
  237. console.log(list);
  238. this.setState({
  239. invoiceList: list,
  240. showFoot: 0,
  241. });
  242. };
  243. //查询菜单开关状态
  244. openStatus = (open) => {
  245. if (open) {
  246. } else {
  247. // this.props.children.setClickNum();
  248. }
  249. };
  250. //获取查询发票类型
  251. invoiceTypeChange = (select) => {
  252. let invoiceType = '';
  253. if (select.length > 0) {
  254. invoiceType = select[0];
  255. }
  256. this.setState({
  257. invoiceType: invoiceType,
  258. });
  259. };
  260. //查询
  261. searchData = async () => {
  262. this.setState({
  263. isShowSearch: false,
  264. invoiceList: [],
  265. showFoot: 0,
  266. });
  267. this.setLoadingStatus(true);
  268. await this.getDistributeList();
  269. };
  270. //清空查询数据
  271. searchDataEmpty = async () => {
  272. this.setState({
  273. invoiceType: '1',
  274. invoiceList: [],
  275. showFoot: 0,
  276. });
  277. await this.getDistributeList();
  278. };
  279. // 加载list项
  280. renderItem = (data) => (
  281. <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
  282. <List.Item style={{backgroundColor: '#F7F7F7'}}>
  283. <View style={{backgroundColor: 'white', marginTop: 10}}>
  284. <View style={{margin: 10}}>
  285. <Text style={{fontSize: 15, fontWeight: 'bold', color: '#050505'}}>
  286. 发票类别:{data.item.invoiceCategory}
  287. </Text>
  288. <Text style={{color: '#898989', marginTop: 5}}>
  289. 发票代码:{data.item.invoiceCode}
  290. </Text>
  291. <Text style={{color: '#898989', marginTop: 5}}>
  292. 发票起始号码:{data.item.invoiceStartNo}
  293. </Text>
  294. <Text style={{color: '#898989', marginTop: 5}}>
  295. 发票终止号码:{data.item.invoiceEndNo}
  296. </Text>
  297. <Text style={{color: '#898989', marginTop: 5}}>
  298. 申领份数:{data.item.invoicePurchaseQuantity}
  299. </Text>
  300. <Text style={{color: '#898989', marginTop: 5}}>
  301. 剩余份数:{data.item.invoiceSurplusQuantity}
  302. </Text>
  303. <Text style={{color: '#898989', marginTop: 5}}>
  304. 领购日期:{data.item.invoicePurchaseDate}
  305. </Text>
  306. <Text style={{color: '#898989', marginTop: 5}}>
  307. 领购人员:{data.item.invoicePurchaseOperator}
  308. </Text>
  309. </View>
  310. </View>
  311. </List.Item>
  312. </SwipeAction>
  313. );
  314. // 下拉刷新
  315. onRefresh = async () => {
  316. this.setState({
  317. isRefreshing: true,
  318. showFoot: 1,
  319. invoiceList: [],
  320. });
  321. await this.getDistributeList();
  322. };
  323. // list尾部组件
  324. renderFooter() {
  325. if (this.state.showFoot === 0) {
  326. return (
  327. <View
  328. style={{height: 30, alignItems: 'center', justifyContent: 'center'}}>
  329. <Text
  330. style={{
  331. color: '#999999',
  332. fontSize: 14,
  333. marginTop: 5,
  334. marginBottom: 5,
  335. }}>
  336. 没有更多数据了
  337. </Text>
  338. </View>
  339. );
  340. } else if (this.state.showFoot === 1) {
  341. return (
  342. <View style={{alignItems: 'center', justifyContent: 'center'}}>
  343. <ActivityIndicator />
  344. <Text>正在加载...</Text>
  345. </View>
  346. );
  347. } else if (this.state.showFoot === 2) {
  348. return (
  349. <View
  350. style={{height: 30, alignItems: 'center', justifyContent: 'center'}}>
  351. <Text
  352. style={{
  353. color: '#999999',
  354. fontSize: 14,
  355. marginTop: 5,
  356. marginBottom: 5,
  357. }}>
  358. 上拉加载
  359. </Text>
  360. </View>
  361. );
  362. }
  363. }
  364. // 设置load层是否显示
  365. setLoadingStatus = (isLoading) => {
  366. this.setState({
  367. spinner: isLoading,
  368. });
  369. };
  370. // 处理网络请求数据
  371. abnormalMessage = async (jason) => {
  372. if (jason.code === 401) {
  373. await Alert.alert(
  374. '登录失效',
  375. '登录状态已失效,请重新登录!',
  376. [
  377. {
  378. text: '确定',
  379. onPress: () => {
  380. CleanAll();
  381. this.props.navigation.popToTop();
  382. },
  383. },
  384. ],
  385. {cancelable: false},
  386. );
  387. }
  388. if (jason.code === 403) {
  389. Alert.alert(
  390. '权限',
  391. '暂无权限操作此模块!',
  392. [
  393. {
  394. text: '确定',
  395. onPress: () => {
  396. this.props.navigation.goBack();
  397. },
  398. },
  399. ],
  400. {cancelable: false},
  401. );
  402. }
  403. if (jason.code !== 401 && jason.code !== 403) {
  404. ToastShow(1, jason.msg);
  405. }
  406. };
  407. }