alertError.js 3.84 KB
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Image,
    Text,
    TextInput,
    ScrollView,
    TouchableOpacity,
    DeviceEventEmitter,
    Modal,
    Animated,
    FlatList,
    InteractionManager,
    NativeModules,
    ActivityIndicator
} from 'react-native';
import {width,height,zoomW,zoomH} from '../../utils/getSize';
import {getTopHeight,xnToast,xnBorderWidth,NoDoublePress} from '../../utils/utils';
import AppService from '../../service/AppService'
import moment from 'moment'

const back = require('../../img/returnB.png');

export default class alertError extends Component {
    static navigationOptions = ({ navigation, screenProps }) => ({
        title: "公告通知",
        headerLeft:(<View style={{display:'flex',flexDirection:'row'}}>
            <TouchableOpacity style={styles.topIcon} onPress = {navigation.state.params?navigation.state.params.back:null} >
                <Image source={back} style={{width:(16/zoomH),height:(16/zoomH)}} resizeMode="contain" />
            </TouchableOpacity>
        </View>),
        headerRight:(
            <View></View>)
    });

    constructor(props) {
        super(props);
        this.state={
            type:this.props.navigation.state.params.type,

        }
    }

    componentDidMount(){
        this.props.navigation.setParams({

            back:()=>{
                this.props.navigation.goBack();
            }
        });


        if (this.state.type === 'noPermissions'){
            this.setState({detail:{}})
        }else{
            this.setState({
                loading:true
            });

            this.getAnnouncementDetail();
        }

    };

    //获取详情
    getAnnouncementDetail=()=>{

        this.setState({
            loading:false
        });
        AppService.getAnnouncementDetail({id:this.props.navigation.state.params.id}).then((data)=>{
            if(data.message){
                xnToast(data.message);
                return;
            }
            if(data.errors.length > 0){
                xnToast(data.errors[0].message);
            }else{

                this.setState({
                    detail:data.announcement,
                })
            }
        });
    }

    render(){
        if (this.state.detail){
            return(
                <View style={styles.background}>
                    <Image style={{width:70/zoomW,height:70/zoomW,marginTop:140/zoomH,marginBottom:30}} source={require('../../img/alertError.png')}/>
                    {this.state.type === 'noPermissions'&&<Text style={{color:'#999',fontSize:14}}>您还不是通知成员,无法查看本通知内容</Text>}
                    {this.state.type === 'isRevoke' &&<Text style={{color:'#999',fontSize:14}}>此公告已被发起人于{moment(Number(this.state.detail.revokeTime)).format('MM-DD HH:mm')}撤销</Text>}
                    {this.state.loading && <View style={styles.loadingBg}>
                        <ActivityIndicator size="large" />
                    </View>}
                </View>

            )
        }else {
            return (
                <View style={styles.background}>
                    {this.state.loading && <View style={styles.loadingBg}>
                        <ActivityIndicator size="large" />
                    </View>}
                </View>
            )
        }

    }

}

const styles = StyleSheet.create({
    topIcon:{
        paddingLeft:(10/zoomW),
        paddingRight:(10/zoomW),
        height:'100%',
        display:'flex',
        alignItems:'center'
    },
    background:{
        width:'100%',
        height:'100%',
        backgroundColor:'#fff',
        alignItems:'center',
        // justifyContent:'center'

    },
    loadingBg:{
        width:'100%',
        height:'100%',
        position:'absolute',
        display:'flex',
        alignItems:'center',
        justifyContent:'center'
    },
})