preview_pdf.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. import React, {Component} from 'react';
  2. import {
  3. StyleSheet,
  4. Dimensions,
  5. View,
  6. Text,
  7. SafeAreaView,
  8. ScrollView,
  9. TouchableOpacity,
  10. TextInput,
  11. Platform,
  12. Image,
  13. Alert,
  14. } from 'react-native';
  15. import Pdf from 'react-native-pdf';
  16. import public_css from '../../source/css/public_css';
  17. import {WhiteSpace, Modal, WingBlank} from '@ant-design/react-native';
  18. import {IndividualStorageData, RetrieveData} from '../../data/storage';
  19. import {GetNetworkUrl, RequestNetwork} from '../../data/encryption';
  20. import {ToastShow} from '../toast/toast';
  21. import RNFS from 'react-native-fs';
  22. import {CleanAll} from '../abnormalMessage/abnormal_message';
  23. import { CheckEmail, CheckPhoneNumber } from "../../source/inspect/inspect";
  24. export default class preview_pdf extends Component {
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. uri: this.props.route.params.url + '.pdf',
  29. number: this.props.route.params.number,
  30. cache: true,
  31. isShow: false,
  32. receiveType: 1,
  33. receiveAddress: '',
  34. receiveBack: 'rgba(42,103,254, 1)',
  35. receiveBackFont: '#ffffff',
  36. receiveBackCompany: 'rgba(42,103,254, 0.07)',
  37. receiveBackCompanyFont: '#2A67FE',
  38. };
  39. }
  40. render() {
  41. return (
  42. <SafeAreaView style={public_css.body}>
  43. <ScrollView>
  44. <Pdf
  45. source={{uri: this.state.uri, cache: true}}
  46. onLoadComplete={(numberOfPages, filePath) => {
  47. console.log(`number of pages: ${numberOfPages}`);
  48. }}
  49. onPageChanged={(page, numberOfPages) => {
  50. console.log(`current page: ${page}`);
  51. }}
  52. onError={(error) => {
  53. console.log(error);
  54. }}
  55. onPressLink={(uri) => {
  56. console.log(`Link presse: ${uri}`);
  57. }}
  58. style={styles.pdf}
  59. />
  60. </ScrollView>
  61. <View style={{height: 50, justifyContent: 'center'}}>
  62. <View style={{flexDirection: 'row'}}>
  63. <View
  64. style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
  65. <TouchableOpacity
  66. style={{
  67. alignItems: 'center',
  68. justifyContent: 'center',
  69. flexDirection: 'row',
  70. height: 40,
  71. width: 200,
  72. borderRadius: 8,
  73. borderColor: '#2A67FE',
  74. borderWidth: 1,
  75. }}
  76. onPress={() => {
  77. this.setState({
  78. isShow: true,
  79. });
  80. }}>
  81. <Image
  82. source={require('../../source/img/push.png')}
  83. style={{height: 22, width: 22, marginRight: 5}}
  84. />
  85. <Text style={{color: '#2A67FE'}}>再次推送</Text>
  86. </TouchableOpacity>
  87. </View>
  88. <View
  89. style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
  90. <TouchableOpacity
  91. style={{
  92. alignItems: 'center',
  93. justifyContent: 'center',
  94. flexDirection: 'row',
  95. height: 40,
  96. width: 200,
  97. backgroundColor: '#2A67FE',
  98. borderRadius: 8,
  99. }}
  100. onPress={() => {
  101. this.downloadFile();
  102. }}>
  103. <Image
  104. source={require('../../source/img/dowload.png')}
  105. style={{height: 22, width: 22, marginRight: 5}}
  106. />
  107. <Text style={{color: '#FFFFFF'}}>发票下载</Text>
  108. </TouchableOpacity>
  109. </View>
  110. </View>
  111. </View>
  112. <Modal
  113. popup
  114. visible={this.state.isShow}
  115. animationType="slide-up"
  116. onClose={this.getModalHide}
  117. maskClosable>
  118. <View style={{paddingVertical: 20, paddingHorizontal: 20}}>
  119. <WingBlank>
  120. <View
  121. style={{
  122. flexDirection: 'row',
  123. justifyContent: 'flex-start',
  124. borderBottomWidth: 1,
  125. borderColor: 'rgb(208,208,208)',
  126. }}>
  127. <View>
  128. <TouchableOpacity
  129. onPress={() => {
  130. this.getReceive(1);
  131. }}
  132. style={{
  133. alignItems: 'center',
  134. justifyContent: 'center',
  135. backgroundColor: this.state.receiveBack,
  136. width: 90,
  137. height: 40,
  138. borderRadius: 39,
  139. margin: 10,
  140. }}>
  141. <Text
  142. style={{
  143. color: this.state.receiveBackFont,
  144. fontWeight: 'bold',
  145. fontSize: 16,
  146. }}>
  147. 邮箱
  148. </Text>
  149. </TouchableOpacity>
  150. </View>
  151. <View>
  152. <TouchableOpacity
  153. onPress={() => {
  154. this.getReceive(2);
  155. }}
  156. style={{
  157. alignItems: 'center',
  158. justifyContent: 'center',
  159. backgroundColor: this.state.receiveBackCompany,
  160. width: 90,
  161. height: 40,
  162. borderRadius: 39,
  163. margin: 10,
  164. }}>
  165. <Text
  166. style={{
  167. color: this.state.receiveBackCompanyFont,
  168. fontWeight: 'bold',
  169. fontSize: 16,
  170. }}>
  171. 短信
  172. </Text>
  173. </TouchableOpacity>
  174. </View>
  175. </View>
  176. </WingBlank>
  177. <WingBlank>
  178. {this.state.receiveType === 1 ? (
  179. <View
  180. style={[
  181. public_css.view,
  182. public_css.lineTopBottom,
  183. {alignItems: 'center'},
  184. ]}>
  185. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  186. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  187. <Text style={{fontSize: 16}}>邮箱:</Text>
  188. </View>
  189. <TextInput
  190. style={public_css.textInputStyle}
  191. placeholder="请输入邮箱"
  192. clearButtonMode="while-editing"
  193. secureTextEntry={false}
  194. value={this.state.receiveAddress}
  195. onChangeText={(text) => {
  196. this.setState({
  197. receiveAddress: text,
  198. });
  199. }}
  200. />
  201. </View>
  202. ) : (
  203. <View
  204. style={[
  205. public_css.view,
  206. public_css.lineTopBottom,
  207. {alignItems: 'center'},
  208. ]}>
  209. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  210. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  211. <Text style={{fontSize: 16}}>手机号:</Text>
  212. </View>
  213. <TextInput
  214. style={public_css.textInputStyle}
  215. placeholder="请输入手机号码"
  216. clearButtonMode="while-editing"
  217. secureTextEntry={false}
  218. value={this.state.receiveAddress}
  219. onChangeText={(text) => {
  220. this.setState({
  221. receiveAddress: text,
  222. });
  223. }}
  224. />
  225. </View>
  226. )}
  227. </WingBlank>
  228. <View
  229. style={{
  230. flex: 1,
  231. justifyContent: 'center',
  232. alignItems: 'center',
  233. marginTop: 10,
  234. }}>
  235. <TouchableOpacity
  236. style={{
  237. alignItems: 'center',
  238. justifyContent: 'center',
  239. flexDirection: 'row',
  240. height: 40,
  241. width: 200,
  242. borderWidth: 1,
  243. borderColor: '#2A67FE',
  244. borderRadius: 8,
  245. }}
  246. onPress={() => {
  247. this.invoicePush();
  248. }}>
  249. <Image
  250. source={require('../../source/img/push.png')}
  251. style={{height: 22, width: 22, marginRight: 5}}
  252. />
  253. <Text style={{color: '#2A67FE'}}>推送</Text>
  254. </TouchableOpacity>
  255. </View>
  256. </View>
  257. {/*<Button type="primary" onPress={this.onClose2}>*/}
  258. {/* close modal*/}
  259. {/*</Button>*/}
  260. </Modal>
  261. </SafeAreaView>
  262. );
  263. }
  264. componentDidMount() {
  265. this.props.navigation.setOptions({
  266. headerRight: () => (
  267. <View style={{marginRight: 20}}>
  268. <TouchableOpacity
  269. style={{
  270. height: 30,
  271. width: 70,
  272. justifyContent: 'center',
  273. alignItems: 'center',
  274. }}
  275. onPress={() => {
  276. this.invoiceHongChong();
  277. }}>
  278. <Text style={{color: '#FD4444'}}>发票红冲</Text>
  279. </TouchableOpacity>
  280. </View>
  281. ),
  282. });
  283. }
  284. //发票红冲
  285. invoiceHongChong = async () => {
  286. await Alert.alert(
  287. '发票红冲',
  288. '是否红冲当前发票!',
  289. [
  290. {
  291. text: '取消',
  292. onPress: () => console.log('Cancel Pressed'),
  293. style: 'cancel',
  294. },
  295. {
  296. text: '确定',
  297. onPress: async () => {
  298. let account = await RetrieveData('account');
  299. let token = await RetrieveData('token');
  300. if (token && account) {
  301. const url = '/sys/invoice/quickyHongchong';
  302. let response = await RequestNetwork(
  303. url,
  304. token,
  305. {
  306. oriInvoiceReqFlowNo: this.state.number,
  307. mobile: account,
  308. reqChannel: 3,
  309. },
  310. false,
  311. 1,
  312. );
  313. if (response) {
  314. if (response.code === 0) {
  315. ToastShow(1, '红冲成功!');
  316. } else {
  317. ToastShow(1, response.msg);
  318. }
  319. }
  320. }
  321. },
  322. },
  323. ],
  324. {cancelable: false},
  325. );
  326. };
  327. //获取接收方式类型
  328. getReceive = (type) => {
  329. if (type === 1) {
  330. this.setState({
  331. receiveType: type,
  332. receiveBack: 'rgba(42,103,254, 1)',
  333. receiveBackFont: '#ffffff',
  334. receiveBackCompany: 'rgba(42,103,254, 0.07)',
  335. receiveBackCompanyFont: '#2A67FE',
  336. receiveAddress: '',
  337. });
  338. } else {
  339. this.setState({
  340. receiveType: type,
  341. receiveBack: 'rgba(42,103,254, 0.07)',
  342. receiveBackFont: '#2A67FE',
  343. receiveBackCompany: 'rgba(42,103,254, 1)',
  344. receiveBackCompanyFont: '#ffffff',
  345. receiveAddress: '',
  346. });
  347. }
  348. };
  349. // 发票信息再次推送
  350. invoicePush = async () => {
  351. if (this.state.receiveType === 1) {
  352. if (this.state.receiveAddress === '') {
  353. ToastShow(3, '邮箱信息不能为空!');
  354. return;
  355. } else {
  356. let {status, msg} = CheckEmail(`${this.state.receiveAddress}`);
  357. if (!status) {
  358. ToastShow(1, msg);
  359. return;
  360. }
  361. }
  362. } else {
  363. if (this.state.receiveAddress === '') {
  364. ToastShow(3, '手机号码信息不能为空!');
  365. return;
  366. } else {
  367. let {status, msg} = CheckPhoneNumber(`${this.state.receiveAddress}`);
  368. if (!status) {
  369. ToastShow(1, msg);
  370. return;
  371. }
  372. }
  373. }
  374. let account = await RetrieveData('account');
  375. let token = await RetrieveData('token');
  376. if (token && account) {
  377. const url = '/sys/invoice/delivery';
  378. let response = await RequestNetwork(
  379. url,
  380. token,
  381. {
  382. invoiceReqFlowNo: this.state.number,
  383. interactType: this.state.receiveType,
  384. interactTypeDetail: this.state.receiveAddress,
  385. reqChannel: 3,
  386. },
  387. false,
  388. 1,
  389. );
  390. if (response) {
  391. if (response.code === 0) {
  392. this.setState({
  393. isShow: false,
  394. });
  395. this.getReceive(1);
  396. ToastShow(1, '推送成功!');
  397. } else {
  398. ToastShow(1, response.msg);
  399. }
  400. }
  401. }
  402. };
  403. // modal隐藏
  404. getModalHide = () => {
  405. this.setState({
  406. isShow: false,
  407. });
  408. };
  409. // 发票文件下载
  410. downloadFile = () => {
  411. let name = this.state.uri.split('/');
  412. let fileName = name[name.length - 1];
  413. let dirs =
  414. Platform.OS === 'ios'
  415. ? RNFS.LibraryDirectoryPath
  416. : RNFS.ExternalDirectoryPath; //外部文件,
  417. dirs = dirs + '/' + fileName;
  418. let DownloadFileOptions = {
  419. fromUrl: this.state.uri, // URL to download file from
  420. toFile: dirs, // Local filesystem path to save the file to
  421. };
  422. let result = RNFS.downloadFile(DownloadFileOptions);
  423. result.promise.then((res) => {
  424. if (res.statusCode === 200) {
  425. Alert.alert(
  426. '下载成功',
  427. '发票下载成功,保存地址为' + dirs,
  428. [
  429. {
  430. text: '取消',
  431. onPress: () => console.log('Cancel Pressed'),
  432. style: 'cancel',
  433. },
  434. {
  435. text: '确定',
  436. onPress: async () => {
  437. console.log('OK Pressed');
  438. },
  439. },
  440. ],
  441. {cancelable: false},
  442. );
  443. }
  444. });
  445. };
  446. }
  447. const styles = StyleSheet.create({
  448. container: {
  449. flex: 1,
  450. justifyContent: 'flex-start',
  451. alignItems: 'center',
  452. marginTop: 25,
  453. },
  454. pdf: {
  455. flex: 1,
  456. width: Dimensions.get('window').width,
  457. height: Dimensions.get('window').height,
  458. },
  459. });