123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- 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 (
- <SafeAreaView style={public_css.body}>
- <ScrollView>
- <Pdf
- source={{uri: this.state.uri, cache: true}}
- onLoadComplete={(numberOfPages, filePath) => {
- 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}
- />
- </ScrollView>
- <View style={{height: 50, justifyContent: 'center'}}>
- <View style={{flexDirection: 'row'}}>
- <View
- style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
- <TouchableOpacity
- style={{
- alignItems: 'center',
- justifyContent: 'center',
- flexDirection: 'row',
- height: 40,
- width: 200,
- borderRadius: 8,
- borderColor: '#2A67FE',
- borderWidth: 1,
- }}
- onPress={() => {
- this.setState({
- isShow: true,
- });
- }}>
- <Image
- source={require('../../source/img/push.png')}
- style={{height: 22, width: 22, marginRight: 5}}
- />
- <Text style={{color: '#2A67FE'}}>再次推送</Text>
- </TouchableOpacity>
- </View>
- <View
- style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
- <TouchableOpacity
- style={{
- alignItems: 'center',
- justifyContent: 'center',
- flexDirection: 'row',
- height: 40,
- width: 200,
- backgroundColor: '#2A67FE',
- borderRadius: 8,
- }}
- onPress={() => {
- this.downloadFile();
- }}>
- <Image
- source={require('../../source/img/dowload.png')}
- style={{height: 22, width: 22, marginRight: 5}}
- />
- <Text style={{color: '#FFFFFF'}}>发票下载</Text>
- </TouchableOpacity>
- </View>
- </View>
- </View>
- <Modal
- popup
- visible={this.state.isShow}
- animationType="slide-up"
- onClose={this.getModalHide}
- maskClosable>
- <View style={{paddingVertical: 20, paddingHorizontal: 20}}>
- <WingBlank>
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'flex-start',
- borderBottomWidth: 1,
- borderColor: 'rgb(208,208,208)',
- }}>
- <View>
- <TouchableOpacity
- onPress={() => {
- this.getReceive(1);
- }}
- style={{
- alignItems: 'center',
- justifyContent: 'center',
- backgroundColor: this.state.receiveBack,
- width: 90,
- height: 40,
- borderRadius: 39,
- margin: 10,
- }}>
- <Text
- style={{
- color: this.state.receiveBackFont,
- fontWeight: 'bold',
- fontSize: 16,
- }}>
- 邮箱
- </Text>
- </TouchableOpacity>
- </View>
- <View>
- <TouchableOpacity
- onPress={() => {
- this.getReceive(2);
- }}
- style={{
- alignItems: 'center',
- justifyContent: 'center',
- backgroundColor: this.state.receiveBackCompany,
- width: 90,
- height: 40,
- borderRadius: 39,
- margin: 10,
- }}>
- <Text
- style={{
- color: this.state.receiveBackCompanyFont,
- fontWeight: 'bold',
- fontSize: 16,
- }}>
- 短信
- </Text>
- </TouchableOpacity>
- </View>
- </View>
- </WingBlank>
- <WingBlank>
- {this.state.receiveType === 1 ? (
- <View
- style={[
- public_css.view,
- public_css.lineTopBottom,
- {alignItems: 'center'},
- ]}>
- <View style={{flexDirection: 'row', alignItems: 'center'}}>
- <Text style={{color: 'red', marginRight: 5}}>*</Text>
- <Text style={{fontSize: 16}}>邮箱:</Text>
- </View>
- <TextInput
- style={public_css.textInputStyle}
- placeholder="请输入邮箱"
- clearButtonMode="while-editing"
- secureTextEntry={false}
- value={this.state.receiveAddress}
- onChangeText={(text) => {
- this.setState({
- receiveAddress: text,
- });
- }}
- />
- </View>
- ) : (
- <View
- style={[
- public_css.view,
- public_css.lineTopBottom,
- {alignItems: 'center'},
- ]}>
- <View style={{flexDirection: 'row', alignItems: 'center'}}>
- <Text style={{color: 'red', marginRight: 5}}>*</Text>
- <Text style={{fontSize: 16}}>手机号:</Text>
- </View>
- <TextInput
- style={public_css.textInputStyle}
- placeholder="请输入手机号码"
- clearButtonMode="while-editing"
- secureTextEntry={false}
- value={this.state.receiveAddress}
- onChangeText={(text) => {
- this.setState({
- receiveAddress: text,
- });
- }}
- />
- </View>
- )}
- </WingBlank>
- <View
- style={{
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- marginTop: 10,
- }}>
- <TouchableOpacity
- style={{
- alignItems: 'center',
- justifyContent: 'center',
- flexDirection: 'row',
- height: 40,
- width: 200,
- borderWidth: 1,
- borderColor: '#2A67FE',
- borderRadius: 8,
- }}
- onPress={() => {
- this.invoicePush();
- }}>
- <Image
- source={require('../../source/img/push.png')}
- style={{height: 22, width: 22, marginRight: 5}}
- />
- <Text style={{color: '#2A67FE'}}>推送</Text>
- </TouchableOpacity>
- </View>
- </View>
- {/*<Button type="primary" onPress={this.onClose2}>*/}
- {/* close modal*/}
- {/*</Button>*/}
- </Modal>
- </SafeAreaView>
- );
- }
- componentDidMount() {
- this.props.navigation.setOptions({
- headerRight: () => (
- <View style={{marginRight: 20}}>
- <TouchableOpacity
- style={{
- height: 30,
- width: 70,
- justifyContent: 'center',
- alignItems: 'center',
- }}
- onPress={() => {
- this.invoiceHongChong();
- }}>
- <Text style={{color: '#FD4444'}}>发票红冲</Text>
- </TouchableOpacity>
- </View>
- ),
- });
- }
- //发票红冲
- 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,
- },
- });
|