123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623 |
- import React, {Component} from 'react';
- import {
- Text,
- TextInput,
- TouchableOpacity,
- View,
- SafeAreaView,
- ScrollView,
- Image,
- Alert,
- } from 'react-native';
- import Spinner from 'react-native-loading-spinner-overlay';
- import loading_css from '../../source/css/loading_css';
- import public_css from '../../source/css/public_css';
- import {List, Picker, WhiteSpace, WingBlank} from '@ant-design/react-native';
- import {RetrieveData} from '../../data/storage';
- import {RequestNetwork} from '../../data/encryption';
- import {CleanAll} from '../../components/abnormalMessage/abnormal_message';
- import {ToastShow} from '../../components/toast/toast';
- export default class invoice_application extends Component {
- constructor(props) {
- super(props);
- this.state = {
- listData: [],
- invoiceCategoryList: [],
- invoiceCategory: '',
- invoiceCategoryText: '',
- invoiceTypeList: [],
- invoiceType: '',
- invoiceTypeText: '',
- invoiceInfo: [],
- userInfo: [],
- certificatesInfo: [],
- applyNumber: '',
- certificatesList: [],
- certificates: '',
- certificatesText: '居民身份证',
- certificatesNumber: '',
- agent: '',
- collectTicketsList: [
- {
- value: 1,
- label: '自行领取',
- },
- {
- value: 2,
- label: '快递配送',
- },
- ],
- collectTickets: 1,
- addressee: '',
- expressAddress: '',
- mobilePhone: '',
- fixedTelephone: '',
- postalCode: '',
- remark: '发票申领',
- spinner: false,
- };
- }
- render() {
- return (
- <SafeAreaView style={public_css.body}>
- <Spinner
- visible={this.state.spinner}
- textContent={'Loading...'}
- textStyle={loading_css.spinnerTextStyle}
- />
- <ScrollView>
- <Picker
- data={this.state.invoiceCategoryList}
- cols={1}
- value={[this.state.invoiceCategory]}
- onChange={(select) => this.invoiceCategoryChange(select)}>
- <List.Item arrow="horizontal" onPress={this.onPress}>
- <View style={{flexDirection: 'row', alignItems: 'center'}}>
- <Text style={{color: 'red', marginRight: 5}}>*</Text>
- <Text style={{fontSize: 16}}>发票类别:</Text>
- </View>
- </List.Item>
- </Picker>
- <Picker
- data={this.state.invoiceTypeList}
- cols={1}
- value={[this.state.invoiceType]}
- onChange={(select) => this.invoiceTypeChange(select)}>
- <List.Item arrow="horizontal" onPress={this.onPress}>
- <View style={{flexDirection: 'row', alignItems: 'center'}}>
- <Text style={{color: 'red', marginRight: 5}}>*</Text>
- <Text style={{fontSize: 16}}>发票种类:</Text>
- </View>
- </List.Item>
- </Picker>
- <WingBlank>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <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"
- onChangeText={(text) => {
- this.setState({
- applyNumber: text,
- });
- }}
- />
- </View>
- </WingBlank>
- <Picker
- data={this.state.certificatesList}
- cols={1}
- value={[this.state.certificates]}
- onChange={(select) => this.certificatesChange(select)}>
- <List.Item arrow="horizontal" onPress={this.onPress}>
- <View style={{flexDirection: 'row', alignItems: 'center'}}>
- <Text style={{color: 'red', marginRight: 5}}>*</Text>
- <Text style={{fontSize: 16}}>证件类型:</Text>
- </View>
- </List.Item>
- </Picker>
- <WingBlank>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <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"
- value={this.state.certificatesNumber}
- onChangeText={(text) => {
- this.setState({
- certificatesNumber: text,
- });
- }}
- />
- </View>
- </WingBlank>
- <WingBlank>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <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"
- value={this.state.agent}
- onChangeText={(text) => {
- this.setState({
- agent: text,
- });
- }}
- />
- </View>
- </WingBlank>
- <Picker
- data={this.state.collectTicketsList}
- cols={1}
- value={[this.state.collectTickets]}
- onChange={(select) => this.collectTicketsChange(select)}>
- <List.Item arrow="horizontal" onPress={this.onPress}>
- <View style={{flexDirection: 'row', alignItems: 'center'}}>
- <Text style={{color: 'red', marginRight: 5}}>*</Text>
- <Text style={{fontSize: 16}}>领票方式:</Text>
- </View>
- </List.Item>
- </Picker>
- {this.state.collectTickets === 2 ? (
- <View>
- <WingBlank>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <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"
- onChangeText={(text) => {
- this.setState({
- addressee: text,
- });
- }}
- />
- </View>
- </WingBlank>
- <WingBlank>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <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"
- onChangeText={(text) => {
- this.setState({
- expressAddress: text,
- });
- }}
- />
- </View>
- </WingBlank>
- <WingBlank>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <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"
- onChangeText={(text) => {
- this.setState({
- mobilePhone: text,
- });
- }}
- />
- </View>
- </WingBlank>
- <WingBlank>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <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"
- onChangeText={(text) => {
- this.setState({
- fixedTelephone: text,
- });
- }}
- />
- </View>
- </WingBlank>
- <WingBlank>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <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"
- onChangeText={(text) => {
- this.setState({
- postalCode: text,
- });
- }}
- />
- </View>
- </WingBlank>
- </View>
- ) : (
- <View />
- )}
- <WingBlank>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <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"
- value={this.state.remark}
- onChangeText={(text) => {
- this.setState({
- remark: text,
- });
- }}
- />
- </View>
- </WingBlank>
- </ScrollView>
- <WingBlank>
- <View style={public_css.bottomStatus}>
- <TouchableOpacity
- style={[public_css.statusBtn, public_css.statusRBtn]}
- onPress={() => this.submitData()}>
- <Image
- source={require('../../source/img/productImg/confirm.png')}
- style={{width: 32, height: 32}}
- />
- <Text style={{color: '#fff'}}>申领</Text>
- </TouchableOpacity>
- </View>
- </WingBlank>
- <WhiteSpace />
- </SafeAreaView>
- );
- }
- // render加载完后调用
- async componentDidMount() {
- await this.getApplicationInfo();
- }
- // 获取申领基本信息
- getApplicationInfo = async () => {
- const company = JSON.parse(await RetrieveData('company'));
- const token = await RetrieveData('token');
- const account = await RetrieveData('account');
- if (token && account) {
- const url = '/sys/invoicePurchase/preInfo';
- let response = await RequestNetwork(
- url,
- token,
- {
- entTaxId: company.entTaxId,
- deviceType: company.defaultDeviceInfo.deviceType,
- taxDiscId: company.defaultDeviceInfo.taxDiscId,
- },
- false,
- 2,
- );
- if (response) {
- if (response.code === 0) {
- this.setState({
- invoiceInfo: response.data.pzhdInfos,
- userInfo: response.data.operatorInfos,
- certificatesInfo: response.data.papers,
- });
- this.getInvoiceCategory();
- this.getCertificates();
- this.getUserInfo();
- } else {
- await this.abnormalMessage(response);
- }
- }
- }
- };
- // 加载发票类别信息
- getInvoiceCategory = () => {
- let invoiceCategory = [];
- this.state.invoiceInfo.forEach((item) => {
- let status = invoiceCategory.some(
- (value) => value.value === item.invoiceCateCode,
- );
- if (!status) {
- invoiceCategory.push({
- value: item.invoiceCateCode,
- label: item.invoiceCateName,
- });
- }
- });
- this.setState({
- invoiceCategoryList: invoiceCategory,
- });
- };
- // 加载发票种类信息
- getInvoiceType = (type) => {
- let invoiceType = [];
- this.state.invoiceInfo.forEach((item) => {
- if (type === item.invoiceCateCode) {
- invoiceType.push({
- value: item.invoiceKindCode,
- label: item.invoiceKindName,
- });
- }
- });
- this.setState({
- invoiceTypeList: invoiceType,
- });
- };
- // 加载证件类型信息
- getCertificates = () => {
- let certificatesList = [];
- this.state.certificatesInfo.forEach((item) => {
- certificatesList.push({
- value: item.paperType,
- label: item.paperTypeChn,
- });
- });
- this.setState({
- certificatesList: certificatesList,
- });
- };
- // 加载人员信息
- getUserInfo = () => {
- if (this.state.userInfo.length > 0) {
- this.setState({
- certificatesNumber: this.state.userInfo[0].paperNumber,
- agent: this.state.userInfo[0].operatorName,
- certificates: this.state.userInfo[0].paperType,
- });
- }
- };
- // 发票类别选择
- invoiceCategoryChange = (select) => {
- let invoiceCategory = '';
- let invoiceCategoryText = '';
- if (select.length > 0) {
- invoiceCategory = select[0];
- let categoryText = this.state.invoiceCategoryList.filter((item) => {
- return item.value === invoiceCategory;
- });
- if (categoryText.length > 0) {
- invoiceCategoryText = categoryText[0].label;
- }
- }
- this.setState({
- invoiceCategory: invoiceCategory,
- invoiceCategoryText: invoiceCategoryText,
- });
- this.getInvoiceType(invoiceCategory);
- };
- //发票类型选择
- invoiceTypeChange = (select) => {
- let invoiceType = '';
- let invoiceTypeText = '';
- if (select.length > 0) {
- invoiceType = select[0];
- let typeText = this.state.invoiceTypeList.filter((item) => {
- return item.value === invoiceType;
- });
- if (typeText.length > 0) {
- invoiceTypeText = typeText[0].label;
- }
- }
- this.setState({
- invoiceType: invoiceType,
- invoiceTypeText: invoiceTypeText,
- });
- };
- // 证件类型选择
- certificatesChange = (select) => {
- let certificates = '';
- let certificatesText = '';
- if (select.length > 0) {
- certificates = select[0];
- let certificatesTypeText = this.state.certificatesList.filter((item) => {
- return item.value === certificates;
- });
- if (certificatesTypeText.length > 0) {
- certificatesText = certificatesTypeText[0].label;
- }
- }
- this.setState({
- certificates: certificates,
- certificatesText: certificatesText,
- });
- };
- // 领取方式选择
- collectTicketsChange = (select) => {
- let collectTickets = '';
- if (select.length > 0) {
- collectTickets = select[0];
- }
- this.setState({
- collectTickets: collectTickets,
- });
- };
- // 发票申领
- submitData = async () => {
- if (this.state.invoiceCategory === '') {
- ToastShow(1, '发票类别不能为空!');
- return;
- }
- if (this.state.invoiceType === '') {
- ToastShow(1, '发票种类不能为空!');
- return;
- }
- if (this.state.applyNumber === '') {
- ToastShow(1, '申领份数不能为空!');
- return;
- }
- if (this.state.certificates === '') {
- ToastShow(1, '证件类型不能为空!');
- return;
- }
- if (this.state.certificatesNumber === '') {
- ToastShow(1, '证件号码不能为空!');
- return;
- }
- if (this.state.agent === '') {
- ToastShow(1, '经办人不能为空!');
- return;
- }
- if (this.state.collectTickets === 2) {
- if (this.state.addressee === '') {
- ToastShow(1, '收件人不能为空!');
- return;
- }
- if (this.state.expressAddress === '') {
- ToastShow(1, '快递地址不能为空!');
- return;
- }
- if (this.state.mobilePhone === '') {
- ToastShow(1, '移动电话不能为空!');
- return;
- }
- if (this.state.fixedTelephone === '') {
- ToastShow(1, '固定电话不能为空!');
- return;
- }
- if (this.state.postalCode === '') {
- ToastShow(1, '邮政编码不能为空!');
- return;
- }
- }
- if (this.state.remark === '') {
- ToastShow(1, '申领说明不能为空!');
- return;
- }
- this.setLoadingStatus(true);
- const company = JSON.parse(await RetrieveData('company'));
- const token = await RetrieveData('token');
- const account = await RetrieveData('account');
- if (token && account) {
- const url = '/sys/invoicePurchase/apply';
- let response = await RequestNetwork(
- url,
- token,
- {
- entTaxId: company.entTaxId,
- deviceType: company.defaultDeviceInfo.deviceType,
- taxDiscId: company.defaultDeviceInfo.taxDiscId,
- invoiceKindCode: this.state.invoiceType,
- invoiceKindName: this.state.invoiceCategoryText,
- invoiceCateCode: this.state.invoiceCategory,
- invoiceCateName: this.state.invoiceTypeText,
- applyNum: this.state.applyNumber,
- operatorName: this.state.agent,
- paperType: this.state.certificates,
- paperTypeChn: this.state.certificatesText,
- paperNumber: this.state.certificatesNumber,
- remark: this.state.remark,
- getWay: this.state.collectTickets,
- receiverName: this.state.addressee,
- receiverAddress: this.state.expressAddress,
- mobilePhoneNumber: this.state.collectTickets,
- zipCode: this.state.collectTickets,
- fixedPhoneNumber: '',
- mobile: account,
- reqChannel: 3,
- },
- false,
- 1,
- );
- if (response) {
- if (response.code === 0) {
- this.setLoadingStatus(false);
- ToastShow(1, '申领成功!');
- this.props.route.params.setRefresh();
- this.props.navigation.goBack();
- } else {
- this.setLoadingStatus(false);
- await this.abnormalMessage(response);
- }
- }
- }
- };
- // 设置load层是否显示
- setLoadingStatus = (isLoading) => {
- this.setState({
- spinner: isLoading,
- });
- };
- // 处理网络请求数据
- abnormalMessage = async (jason) => {
- if (jason.code === 401) {
- await Alert.alert(
- '登录失效',
- '登录状态已失效,请重新登录!',
- [
- {
- text: '确定',
- onPress: () => {
- CleanAll();
- this.props.navigation.popToTop();
- },
- },
- ],
- {cancelable: false},
- );
- }
- if (jason.code === 403) {
- Alert.alert(
- '权限',
- '暂无权限操作此模块!',
- [
- {
- text: '确定',
- onPress: () => {
- this.props.navigation.goBack();
- },
- },
- ],
- {cancelable: false},
- );
- }
- if (jason.code !== 401 && jason.code !== 403) {
- ToastShow(1, jason.msg);
- }
- };
- }
|