import React, {Component} from 'react'; import { StyleSheet, Dimensions, View, Text, SafeAreaView, ScrollView, TouchableOpacity, TextInput, Platform, Image, Alert, } from 'react-native'; import Pdf from 'react-native-pdf'; import public_css from '../../source/css/public_css'; import {WhiteSpace, Modal, WingBlank} from '@ant-design/react-native'; import {IndividualStorageData, RetrieveData} from '../../data/storage'; import {GetNetworkUrl, RequestNetwork} from '../../data/encryption'; import {ToastShow} from '../toast/toast'; import RNFS from 'react-native-fs'; import {CleanAll} from '../abnormalMessage/abnormal_message'; import { CheckEmail, CheckPhoneNumber } from "../../source/inspect/inspect"; export default class preview_pdf extends Component { constructor(props) { super(props); this.state = { uri: this.props.route.params.url + '.pdf', number: this.props.route.params.number, cache: true, isShow: false, receiveType: 1, receiveAddress: '', receiveBack: 'rgba(42,103,254, 1)', receiveBackFont: '#ffffff', receiveBackCompany: 'rgba(42,103,254, 0.07)', receiveBackCompanyFont: '#2A67FE', }; } render() { return ( { console.log(`number of pages: ${numberOfPages}`); }} onPageChanged={(page, numberOfPages) => { console.log(`current page: ${page}`); }} onError={(error) => { console.log(error); }} onPressLink={(uri) => { console.log(`Link presse: ${uri}`); }} style={styles.pdf} /> { this.setState({ isShow: true, }); }}> 再次推送 { this.downloadFile(); }}> 发票下载 { this.getReceive(1); }} style={{ alignItems: 'center', justifyContent: 'center', backgroundColor: this.state.receiveBack, width: 90, height: 40, borderRadius: 39, margin: 10, }}> 邮箱 { this.getReceive(2); }} style={{ alignItems: 'center', justifyContent: 'center', backgroundColor: this.state.receiveBackCompany, width: 90, height: 40, borderRadius: 39, margin: 10, }}> 短信 {this.state.receiveType === 1 ? ( * 邮箱: { this.setState({ receiveAddress: text, }); }} /> ) : ( * 手机号: { this.setState({ receiveAddress: text, }); }} /> )} { this.invoicePush(); }}> 推送 {/**/} ); } componentDidMount() { this.props.navigation.setOptions({ headerRight: () => ( { this.invoiceHongChong(); }}> 发票红冲 ), }); } //发票红冲 invoiceHongChong = async () => { await Alert.alert( '发票红冲', '是否红冲当前发票!', [ { text: '取消', onPress: () => console.log('Cancel Pressed'), style: 'cancel', }, { text: '确定', onPress: async () => { let account = await RetrieveData('account'); let token = await RetrieveData('token'); if (token && account) { const url = '/sys/invoice/quickyHongchong'; let response = await RequestNetwork( url, token, { oriInvoiceReqFlowNo: this.state.number, mobile: account, reqChannel: 3, }, false, 1, ); if (response) { if (response.code === 0) { ToastShow(1, '红冲成功!'); } else { ToastShow(1, response.msg); } } } }, }, ], {cancelable: false}, ); }; //获取接收方式类型 getReceive = (type) => { if (type === 1) { this.setState({ receiveType: type, receiveBack: 'rgba(42,103,254, 1)', receiveBackFont: '#ffffff', receiveBackCompany: 'rgba(42,103,254, 0.07)', receiveBackCompanyFont: '#2A67FE', receiveAddress: '', }); } else { this.setState({ receiveType: type, receiveBack: 'rgba(42,103,254, 0.07)', receiveBackFont: '#2A67FE', receiveBackCompany: 'rgba(42,103,254, 1)', receiveBackCompanyFont: '#ffffff', receiveAddress: '', }); } }; // 发票信息再次推送 invoicePush = async () => { if (this.state.receiveType === 1) { if (this.state.receiveAddress === '') { ToastShow(3, '邮箱信息不能为空!'); return; } else { let {status, msg} = CheckEmail(`${this.state.receiveAddress}`); if (!status) { ToastShow(1, msg); return; } } } else { if (this.state.receiveAddress === '') { ToastShow(3, '手机号码信息不能为空!'); return; } else { let {status, msg} = CheckPhoneNumber(`${this.state.receiveAddress}`); if (!status) { ToastShow(1, msg); return; } } } let account = await RetrieveData('account'); let token = await RetrieveData('token'); if (token && account) { const url = '/sys/invoice/delivery'; let response = await RequestNetwork( url, token, { invoiceReqFlowNo: this.state.number, interactType: this.state.receiveType, interactTypeDetail: this.state.receiveAddress, reqChannel: 3, }, false, 1, ); if (response) { if (response.code === 0) { this.setState({ isShow: false, }); this.getReceive(1); ToastShow(1, '推送成功!'); } else { ToastShow(1, response.msg); } } } }; // modal隐藏 getModalHide = () => { this.setState({ isShow: false, }); }; // 发票文件下载 downloadFile = () => { let name = this.state.uri.split('/'); let fileName = name[name.length - 1]; let dirs = Platform.OS === 'ios' ? RNFS.LibraryDirectoryPath : RNFS.ExternalDirectoryPath; //外部文件, dirs = dirs + '/' + fileName; let DownloadFileOptions = { fromUrl: this.state.uri, // URL to download file from toFile: dirs, // Local filesystem path to save the file to }; let result = RNFS.downloadFile(DownloadFileOptions); result.promise.then((res) => { if (res.statusCode === 200) { Alert.alert( '下载成功', '发票下载成功,保存地址为' + dirs, [ { text: '取消', onPress: () => console.log('Cancel Pressed'), style: 'cancel', }, { text: '确定', onPress: async () => { console.log('OK Pressed'); }, }, ], {cancelable: false}, ); } }); }; } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'flex-start', alignItems: 'center', marginTop: 25, }, pdf: { flex: 1, width: Dimensions.get('window').width, height: Dimensions.get('window').height, }, });