invoice_application.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. import React, {Component} from 'react';
  2. import {
  3. Text,
  4. TextInput,
  5. TouchableOpacity,
  6. View,
  7. SafeAreaView,
  8. ScrollView,
  9. Image,
  10. Alert,
  11. } from 'react-native';
  12. import Spinner from 'react-native-loading-spinner-overlay';
  13. import loading_css from '../../source/css/loading_css';
  14. import public_css from '../../source/css/public_css';
  15. import {List, Picker, WhiteSpace, WingBlank} from '@ant-design/react-native';
  16. import {RetrieveData} from '../../data/storage';
  17. import {RequestNetwork} from '../../data/encryption';
  18. import {CleanAll} from '../../components/abnormalMessage/abnormal_message';
  19. import {ToastShow} from '../../components/toast/toast';
  20. export default class invoice_application extends Component {
  21. constructor(props) {
  22. super(props);
  23. this.state = {
  24. listData: [],
  25. invoiceCategoryList: [],
  26. invoiceCategory: '',
  27. invoiceCategoryText: '',
  28. invoiceTypeList: [],
  29. invoiceType: '',
  30. invoiceTypeText: '',
  31. invoiceInfo: [],
  32. userInfo: [],
  33. certificatesInfo: [],
  34. applyNumber: '',
  35. certificatesList: [],
  36. certificates: '',
  37. certificatesText: '居民身份证',
  38. certificatesNumber: '',
  39. agent: '',
  40. collectTicketsList: [
  41. {
  42. value: 1,
  43. label: '自行领取',
  44. },
  45. {
  46. value: 2,
  47. label: '快递配送',
  48. },
  49. ],
  50. collectTickets: 1,
  51. addressee: '',
  52. expressAddress: '',
  53. mobilePhone: '',
  54. fixedTelephone: '',
  55. postalCode: '',
  56. remark: '发票申领',
  57. spinner: false,
  58. };
  59. }
  60. render() {
  61. return (
  62. <SafeAreaView style={public_css.body}>
  63. <Spinner
  64. visible={this.state.spinner}
  65. textContent={'Loading...'}
  66. textStyle={loading_css.spinnerTextStyle}
  67. />
  68. <ScrollView>
  69. <Picker
  70. data={this.state.invoiceCategoryList}
  71. cols={1}
  72. value={[this.state.invoiceCategory]}
  73. onChange={(select) => this.invoiceCategoryChange(select)}>
  74. <List.Item arrow="horizontal" onPress={this.onPress}>
  75. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  76. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  77. <Text style={{fontSize: 16}}>发票类别:</Text>
  78. </View>
  79. </List.Item>
  80. </Picker>
  81. <Picker
  82. data={this.state.invoiceTypeList}
  83. cols={1}
  84. value={[this.state.invoiceType]}
  85. onChange={(select) => this.invoiceTypeChange(select)}>
  86. <List.Item arrow="horizontal" onPress={this.onPress}>
  87. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  88. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  89. <Text style={{fontSize: 16}}>发票种类:</Text>
  90. </View>
  91. </List.Item>
  92. </Picker>
  93. <WingBlank>
  94. <View style={[public_css.view, public_css.lineTopBottom]}>
  95. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  96. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  97. <Text style={{fontSize: 16}}>申领份数:</Text>
  98. </View>
  99. <TextInput
  100. style={[public_css.textInputStyle]}
  101. placeholder="请输入申领份数"
  102. clearButtonMode="while-editing"
  103. onChangeText={(text) => {
  104. this.setState({
  105. applyNumber: text,
  106. });
  107. }}
  108. />
  109. </View>
  110. </WingBlank>
  111. <Picker
  112. data={this.state.certificatesList}
  113. cols={1}
  114. value={[this.state.certificates]}
  115. onChange={(select) => this.certificatesChange(select)}>
  116. <List.Item arrow="horizontal" onPress={this.onPress}>
  117. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  118. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  119. <Text style={{fontSize: 16}}>证件类型:</Text>
  120. </View>
  121. </List.Item>
  122. </Picker>
  123. <WingBlank>
  124. <View style={[public_css.view, public_css.lineTopBottom]}>
  125. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  126. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  127. <Text style={{fontSize: 16}}>证件号码:</Text>
  128. </View>
  129. <TextInput
  130. style={[public_css.textInputStyle]}
  131. placeholder="请输入证件号码"
  132. clearButtonMode="while-editing"
  133. value={this.state.certificatesNumber}
  134. onChangeText={(text) => {
  135. this.setState({
  136. certificatesNumber: text,
  137. });
  138. }}
  139. />
  140. </View>
  141. </WingBlank>
  142. <WingBlank>
  143. <View style={[public_css.view, public_css.lineTopBottom]}>
  144. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  145. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  146. <Text style={{fontSize: 16}}>经办人:</Text>
  147. </View>
  148. <TextInput
  149. style={[public_css.textInputStyle]}
  150. placeholder="请输入经办人"
  151. clearButtonMode="while-editing"
  152. value={this.state.agent}
  153. onChangeText={(text) => {
  154. this.setState({
  155. agent: text,
  156. });
  157. }}
  158. />
  159. </View>
  160. </WingBlank>
  161. <Picker
  162. data={this.state.collectTicketsList}
  163. cols={1}
  164. value={[this.state.collectTickets]}
  165. onChange={(select) => this.collectTicketsChange(select)}>
  166. <List.Item arrow="horizontal" onPress={this.onPress}>
  167. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  168. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  169. <Text style={{fontSize: 16}}>领票方式:</Text>
  170. </View>
  171. </List.Item>
  172. </Picker>
  173. {this.state.collectTickets === 2 ? (
  174. <View>
  175. <WingBlank>
  176. <View style={[public_css.view, public_css.lineTopBottom]}>
  177. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  178. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  179. <Text style={{fontSize: 16}}>收件人:</Text>
  180. </View>
  181. <TextInput
  182. style={[public_css.textInputStyle]}
  183. placeholder="请输入收件人"
  184. clearButtonMode="while-editing"
  185. onChangeText={(text) => {
  186. this.setState({
  187. addressee: text,
  188. });
  189. }}
  190. />
  191. </View>
  192. </WingBlank>
  193. <WingBlank>
  194. <View style={[public_css.view, public_css.lineTopBottom]}>
  195. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  196. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  197. <Text style={{fontSize: 16}}>快递地址:</Text>
  198. </View>
  199. <TextInput
  200. style={[public_css.textInputStyle]}
  201. placeholder="请输入快递地址"
  202. clearButtonMode="while-editing"
  203. onChangeText={(text) => {
  204. this.setState({
  205. expressAddress: text,
  206. });
  207. }}
  208. />
  209. </View>
  210. </WingBlank>
  211. <WingBlank>
  212. <View style={[public_css.view, public_css.lineTopBottom]}>
  213. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  214. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  215. <Text style={{fontSize: 16}}>移动电话:</Text>
  216. </View>
  217. <TextInput
  218. style={[public_css.textInputStyle]}
  219. placeholder="请输入移动电话"
  220. clearButtonMode="while-editing"
  221. onChangeText={(text) => {
  222. this.setState({
  223. mobilePhone: text,
  224. });
  225. }}
  226. />
  227. </View>
  228. </WingBlank>
  229. <WingBlank>
  230. <View style={[public_css.view, public_css.lineTopBottom]}>
  231. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  232. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  233. <Text style={{fontSize: 16}}>固定电话:</Text>
  234. </View>
  235. <TextInput
  236. style={[public_css.textInputStyle]}
  237. placeholder="请输入固定电话"
  238. clearButtonMode="while-editing"
  239. onChangeText={(text) => {
  240. this.setState({
  241. fixedTelephone: text,
  242. });
  243. }}
  244. />
  245. </View>
  246. </WingBlank>
  247. <WingBlank>
  248. <View style={[public_css.view, public_css.lineTopBottom]}>
  249. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  250. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  251. <Text style={{fontSize: 16}}>邮政编码:</Text>
  252. </View>
  253. <TextInput
  254. style={[public_css.textInputStyle]}
  255. placeholder="请输入邮政编码"
  256. clearButtonMode="while-editing"
  257. onChangeText={(text) => {
  258. this.setState({
  259. postalCode: text,
  260. });
  261. }}
  262. />
  263. </View>
  264. </WingBlank>
  265. </View>
  266. ) : (
  267. <View />
  268. )}
  269. <WingBlank>
  270. <View style={[public_css.view, public_css.lineTopBottom]}>
  271. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  272. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  273. <Text style={{fontSize: 16}}>申领说明:</Text>
  274. </View>
  275. <TextInput
  276. style={[public_css.textInputStyle]}
  277. placeholder="请输入申领说明"
  278. clearButtonMode="while-editing"
  279. value={this.state.remark}
  280. onChangeText={(text) => {
  281. this.setState({
  282. remark: text,
  283. });
  284. }}
  285. />
  286. </View>
  287. </WingBlank>
  288. </ScrollView>
  289. <WingBlank>
  290. <View style={public_css.bottomStatus}>
  291. <TouchableOpacity
  292. style={[public_css.statusBtn, public_css.statusRBtn]}
  293. onPress={() => this.submitData()}>
  294. <Image
  295. source={require('../../source/img/productImg/confirm.png')}
  296. style={{width: 32, height: 32}}
  297. />
  298. <Text style={{color: '#fff'}}>申领</Text>
  299. </TouchableOpacity>
  300. </View>
  301. </WingBlank>
  302. <WhiteSpace />
  303. </SafeAreaView>
  304. );
  305. }
  306. // render加载完后调用
  307. async componentDidMount() {
  308. await this.getApplicationInfo();
  309. }
  310. // 获取申领基本信息
  311. getApplicationInfo = async () => {
  312. const company = JSON.parse(await RetrieveData('company'));
  313. const token = await RetrieveData('token');
  314. const account = await RetrieveData('account');
  315. if (token && account) {
  316. const url = '/sys/invoicePurchase/preInfo';
  317. let response = await RequestNetwork(
  318. url,
  319. token,
  320. {
  321. entTaxId: company.entTaxId,
  322. deviceType: company.defaultDeviceInfo.deviceType,
  323. taxDiscId: company.defaultDeviceInfo.taxDiscId,
  324. },
  325. false,
  326. 2,
  327. );
  328. if (response) {
  329. if (response.code === 0) {
  330. this.setState({
  331. invoiceInfo: response.data.pzhdInfos,
  332. userInfo: response.data.operatorInfos,
  333. certificatesInfo: response.data.papers,
  334. });
  335. this.getInvoiceCategory();
  336. this.getCertificates();
  337. this.getUserInfo();
  338. } else {
  339. await this.abnormalMessage(response);
  340. }
  341. }
  342. }
  343. };
  344. // 加载发票类别信息
  345. getInvoiceCategory = () => {
  346. let invoiceCategory = [];
  347. this.state.invoiceInfo.forEach((item) => {
  348. let status = invoiceCategory.some(
  349. (value) => value.value === item.invoiceCateCode,
  350. );
  351. if (!status) {
  352. invoiceCategory.push({
  353. value: item.invoiceCateCode,
  354. label: item.invoiceCateName,
  355. });
  356. }
  357. });
  358. this.setState({
  359. invoiceCategoryList: invoiceCategory,
  360. });
  361. };
  362. // 加载发票种类信息
  363. getInvoiceType = (type) => {
  364. let invoiceType = [];
  365. this.state.invoiceInfo.forEach((item) => {
  366. if (type === item.invoiceCateCode) {
  367. invoiceType.push({
  368. value: item.invoiceKindCode,
  369. label: item.invoiceKindName,
  370. });
  371. }
  372. });
  373. this.setState({
  374. invoiceTypeList: invoiceType,
  375. });
  376. };
  377. // 加载证件类型信息
  378. getCertificates = () => {
  379. let certificatesList = [];
  380. this.state.certificatesInfo.forEach((item) => {
  381. certificatesList.push({
  382. value: item.paperType,
  383. label: item.paperTypeChn,
  384. });
  385. });
  386. this.setState({
  387. certificatesList: certificatesList,
  388. });
  389. };
  390. // 加载人员信息
  391. getUserInfo = () => {
  392. if (this.state.userInfo.length > 0) {
  393. this.setState({
  394. certificatesNumber: this.state.userInfo[0].paperNumber,
  395. agent: this.state.userInfo[0].operatorName,
  396. certificates: this.state.userInfo[0].paperType,
  397. });
  398. }
  399. };
  400. // 发票类别选择
  401. invoiceCategoryChange = (select) => {
  402. let invoiceCategory = '';
  403. let invoiceCategoryText = '';
  404. if (select.length > 0) {
  405. invoiceCategory = select[0];
  406. let categoryText = this.state.invoiceCategoryList.filter((item) => {
  407. return item.value === invoiceCategory;
  408. });
  409. if (categoryText.length > 0) {
  410. invoiceCategoryText = categoryText[0].label;
  411. }
  412. }
  413. this.setState({
  414. invoiceCategory: invoiceCategory,
  415. invoiceCategoryText: invoiceCategoryText,
  416. });
  417. this.getInvoiceType(invoiceCategory);
  418. };
  419. //发票类型选择
  420. invoiceTypeChange = (select) => {
  421. let invoiceType = '';
  422. let invoiceTypeText = '';
  423. if (select.length > 0) {
  424. invoiceType = select[0];
  425. let typeText = this.state.invoiceTypeList.filter((item) => {
  426. return item.value === invoiceType;
  427. });
  428. if (typeText.length > 0) {
  429. invoiceTypeText = typeText[0].label;
  430. }
  431. }
  432. this.setState({
  433. invoiceType: invoiceType,
  434. invoiceTypeText: invoiceTypeText,
  435. });
  436. };
  437. // 证件类型选择
  438. certificatesChange = (select) => {
  439. let certificates = '';
  440. let certificatesText = '';
  441. if (select.length > 0) {
  442. certificates = select[0];
  443. let certificatesTypeText = this.state.certificatesList.filter((item) => {
  444. return item.value === certificates;
  445. });
  446. if (certificatesTypeText.length > 0) {
  447. certificatesText = certificatesTypeText[0].label;
  448. }
  449. }
  450. this.setState({
  451. certificates: certificates,
  452. certificatesText: certificatesText,
  453. });
  454. };
  455. // 领取方式选择
  456. collectTicketsChange = (select) => {
  457. let collectTickets = '';
  458. if (select.length > 0) {
  459. collectTickets = select[0];
  460. }
  461. this.setState({
  462. collectTickets: collectTickets,
  463. });
  464. };
  465. // 发票申领
  466. submitData = async () => {
  467. if (this.state.invoiceCategory === '') {
  468. ToastShow(1, '发票类别不能为空!');
  469. return;
  470. }
  471. if (this.state.invoiceType === '') {
  472. ToastShow(1, '发票种类不能为空!');
  473. return;
  474. }
  475. if (this.state.applyNumber === '') {
  476. ToastShow(1, '申领份数不能为空!');
  477. return;
  478. }
  479. if (this.state.certificates === '') {
  480. ToastShow(1, '证件类型不能为空!');
  481. return;
  482. }
  483. if (this.state.certificatesNumber === '') {
  484. ToastShow(1, '证件号码不能为空!');
  485. return;
  486. }
  487. if (this.state.agent === '') {
  488. ToastShow(1, '经办人不能为空!');
  489. return;
  490. }
  491. if (this.state.collectTickets === 2) {
  492. if (this.state.addressee === '') {
  493. ToastShow(1, '收件人不能为空!');
  494. return;
  495. }
  496. if (this.state.expressAddress === '') {
  497. ToastShow(1, '快递地址不能为空!');
  498. return;
  499. }
  500. if (this.state.mobilePhone === '') {
  501. ToastShow(1, '移动电话不能为空!');
  502. return;
  503. }
  504. if (this.state.fixedTelephone === '') {
  505. ToastShow(1, '固定电话不能为空!');
  506. return;
  507. }
  508. if (this.state.postalCode === '') {
  509. ToastShow(1, '邮政编码不能为空!');
  510. return;
  511. }
  512. }
  513. if (this.state.remark === '') {
  514. ToastShow(1, '申领说明不能为空!');
  515. return;
  516. }
  517. this.setLoadingStatus(true);
  518. const company = JSON.parse(await RetrieveData('company'));
  519. const token = await RetrieveData('token');
  520. const account = await RetrieveData('account');
  521. if (token && account) {
  522. const url = '/sys/invoicePurchase/apply';
  523. let response = await RequestNetwork(
  524. url,
  525. token,
  526. {
  527. entTaxId: company.entTaxId,
  528. deviceType: company.defaultDeviceInfo.deviceType,
  529. taxDiscId: company.defaultDeviceInfo.taxDiscId,
  530. invoiceKindCode: this.state.invoiceType,
  531. invoiceKindName: this.state.invoiceCategoryText,
  532. invoiceCateCode: this.state.invoiceCategory,
  533. invoiceCateName: this.state.invoiceTypeText,
  534. applyNum: this.state.applyNumber,
  535. operatorName: this.state.agent,
  536. paperType: this.state.certificates,
  537. paperTypeChn: this.state.certificatesText,
  538. paperNumber: this.state.certificatesNumber,
  539. remark: this.state.remark,
  540. getWay: this.state.collectTickets,
  541. receiverName: this.state.addressee,
  542. receiverAddress: this.state.expressAddress,
  543. mobilePhoneNumber: this.state.collectTickets,
  544. zipCode: this.state.collectTickets,
  545. fixedPhoneNumber: '',
  546. mobile: account,
  547. reqChannel: 3,
  548. },
  549. false,
  550. 1,
  551. );
  552. if (response) {
  553. if (response.code === 0) {
  554. this.setLoadingStatus(false);
  555. ToastShow(1, '申领成功!');
  556. this.props.route.params.setRefresh();
  557. this.props.navigation.goBack();
  558. } else {
  559. this.setLoadingStatus(false);
  560. await this.abnormalMessage(response);
  561. }
  562. }
  563. }
  564. };
  565. // 设置load层是否显示
  566. setLoadingStatus = (isLoading) => {
  567. this.setState({
  568. spinner: isLoading,
  569. });
  570. };
  571. // 处理网络请求数据
  572. abnormalMessage = async (jason) => {
  573. if (jason.code === 401) {
  574. await Alert.alert(
  575. '登录失效',
  576. '登录状态已失效,请重新登录!',
  577. [
  578. {
  579. text: '确定',
  580. onPress: () => {
  581. CleanAll();
  582. this.props.navigation.popToTop();
  583. },
  584. },
  585. ],
  586. {cancelable: false},
  587. );
  588. }
  589. if (jason.code === 403) {
  590. Alert.alert(
  591. '权限',
  592. '暂无权限操作此模块!',
  593. [
  594. {
  595. text: '确定',
  596. onPress: () => {
  597. this.props.navigation.goBack();
  598. },
  599. },
  600. ],
  601. {cancelable: false},
  602. );
  603. }
  604. if (jason.code !== 401 && jason.code !== 403) {
  605. ToastShow(1, jason.msg);
  606. }
  607. };
  608. }