notification.js 5.25 KB
/**
 * Created by Cassie on 2018/05/14
 * 通知人员
 */
import React, {Component} from 'react';
import {
    StyleSheet,
    View,
    ActivityIndicator,
    StatusBar,
} from 'react-native';
import ScrollableTabView, {DefaultTabBar} from 'react-native-scrollable-tab-view';
import {width, height, zoomW, zoomH} from '../../utils/getSize';
import {xnToast, xnBorderWidth} from '../../utils/utils';
import AppService from "../../service/AppService";
import NotificationList from './notificationList';


export default class Notifications extends Component {

    constructor(props) {
        super(props);
        this.state = {
            loading:false,
            confirmUserCount:0,
            unConfirmUserCount:0,
            sheetList: [1, 2, 3],
            unconfirmedList: [],
            confirmedList: [],
        };

    }
    componentWillMount() {
        this.getUserList(false);
    }

    getUserList = (isConfirm) => {
        let _this = this;
        let vm = {
            pageSize:0,
            announcementId:this.props.navigation.state.params.id,
            isConfirm:isConfirm
        };
        // newState.sendAjax();
        console.log(vm.announcementId);
        this.setState({
            loading:true,
            confirmedList:[],
            unconfirmedList:[]
        });
        AppService.findAnnouncementUserList(vm).then(data => {
            // newState.backAjax();
            this.setState({
                loading:false
            });
            if (data.errors == null || data.errors.length > 0) {
                xnToast(data.errors[0].message);
                return
            }
            if(isConfirm){
                _this.setState({
                    confirmUserCount:data.confirmUserCount?data.confirmUserCount:0,
                    unConfirmUserCount:data.unConfirmUserCount,
                    confirmedList:data.result
                });
            }else{
                _this.setState({
                    confirmUserCount:data.confirmUserCount?data.confirmUserCount:0,
                    unConfirmUserCount:data.unConfirmUserCount,
                    unconfirmedList:data.result
                });
            }
            console.log(_this);
        })
    };
    componentDidMount() {
        this.props.navigation.setParams({
            title:'通知人员',
            backgroundColor:'white',
            titleColor:'black',
            isBack:true,
            back:()=>{
                this.props.navigation.goBack();
            },
        });
    };

    render() {
        return (
            <View style={styles.background}>
                <StatusBar
                    backgroundColor={'#FFFFFF'}
                    barStyle={"dark-content"}
                    networkActivityIndicatorVisible
                />

                <View style={{height: xnBorderWidth()}}></View>
                <View style={{height: (10 / zoomW), backgroundColor: '#ffffff'}}></View>

                <ScrollableTabView renderTabBar={() => <DefaultTabBar style={styles.tabStyle}/>}
                                   tabBarUnderlineStyle={styles.tabBarLine}
                                   tabBarActiveTextColor="#000000"
                                   tabBarInactiveTextColor="#000000"
                                   tabBarTextStyle={{fontSize: 14}}
                                       onChangeTab={(obj) => {
                                       if (obj.i === 1) {
                                           this.getUserList(true);
                                       } else {
                                           this.getUserList(false);
                                       }
                                   }}
                >
                    <NotificationList tabLabel={this.state.unConfirmUserCount == null?'0人未确认':this.state.unConfirmUserCount+'人未确认'} unconfirmedList={this.state.unconfirmedList}
                                      navigation={this.props.navigation} getUserList = {this.getUserList}
                                     />
                    <NotificationList tabLabel={this.state.confirmUserCount== null?'0人已确认':this.state.confirmUserCount+'人已确认'} confirmedList={this.state.confirmedList}
                                      navigation={this.props.navigation}  getUserList = {this.getUserList}/>
                </ScrollableTabView>
                {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: '#ececf1',
    },

    tabStyle: {
        height: (40 / zoomH),
        backgroundColor: '#ffffff',
        elevation: 0
    },
    tabBarLine: {
        width: (40 / zoomW),
        backgroundColor: '#00BE3C',
        height: 3,
        borderRadius: 8,
        left: '20%',
    },
    loadingBg:{
        width:'100%',
        height:'100%',
        position:'absolute',
        display:'flex',
        alignItems:'center',
        justifyContent:'center'
    },
})