addEmployee.js 4.09 KB
/**
 * Created by Cassie on 18/06/15
 */
import React, {Component} from "react";
import {
    StyleSheet,
    Text,
    StatusBar,
    TouchableOpacity,
    View,
    Image,
    DeviceEventEmitter
} from "react-native";
import Maillist from "./maillist";
import {zoomW, zoomH} from "../../utils/getSize";
import {NoDoublePress} from "../../utils/utils";

const search2 = require('../../img/search.png');

export default class AddEmployee extends Component {


    constructor(props) {
        super(props);
        this.state = {};
    };

    componentDidMount() {
        this.props.navigation.setParams({
            title:'通讯录',
            backgroundColor:'white',
            titleColor:'black',
            isBack:true,
            backClick:()=>{this.back()},
        });
    };
    back(){
        NoDoublePress.onPress(() => {
            DeviceEventEmitter.emit('reloaEmployee');
            this.props.navigation.goBack();
        })
    }
    search() {
        NoDoublePress.onPress(() => {
            this.toSearch = true;
            this.refs.mailList.toSearch();
            this.props.navigation.navigate('SearchPeople', {callback: this.searchBcak});
        })
    }
    //搜索选择回调
    searchBcak=(data)=>{
        if (data != undefined) {
            this.refs.mailList.selectItem(data);
        }
        this.toSearch = false;
    };

    /*渲染员工*/
    renderEmployee=(data)=>{
        let hash = {};
        for(let i=0;i<data.length;i++){
            if(data[i].userId == global.userId){
                data.splice(i,1);
                break;
            }
        }

        let selectEmployee = JSON.parse(JSON.stringify(global.doEmployee)).concat(data);
        global.doEmployee = [];
        global.selectedEmployee = [];
        global.selectedEmployee = selectEmployee;

        for(let i=0;i<selectEmployee.length;i++){
            if(!hash[selectEmployee[i].userId]){
                hash[selectEmployee[i].userId] = -1;
                global.doEmployee.push(selectEmployee[i])
            }
        }
        DeviceEventEmitter.emit('reloadAddEmployee');
        if(!this.toSearch){
            this.props.navigation.goBack();
        }
    };

    componentWillUnmount() {
        this.setState = (state, callback) => {
            return;
        };
    };

    render() {
        return (
            <View style={styles.background}>
                <StatusBar
                    backgroundColor={'#FFFFFF'}
                    barStyle={"dark-content"}
                    networkActivityIndicatorVisible
                />
                <TouchableOpacity activeOpacity={0.8} style={styles.searchBox}
                                  onPress={() => this.search()}>
                    <Image source={search2} style={{width: (13 / zoomH), height: (13 / zoomH)}} resizeMode="contain"/>
                    <View style={{flex: 1, marginLeft: (8 / zoomW)}}>
                        <Text style={{fontSize: 14, color: '#8e8e93'}}>搜索</Text>
                    </View>
                </TouchableOpacity>
                <Maillist ref="mailList" callback={this.renderEmployee} tenantId={global.tenantId} tenantShortName={global.tenantShortName} employeeType="USER" themeColor="#00be3c"/>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    topIcon: {
        paddingLeft: (10 / zoomW),
        paddingRight: (10 / zoomW),
        height: 46/zoomH,
        width:"100%",
        display: 'flex',
        flexDirection:"row",
        alignItems:'center',
        justifyContent: 'flex-start',
        marginBottom: 10/zoomH,
        borderWidth:0.5,
        borderColor:"#DDDDDD"
    },
    searchBox: {
        width: (345 / zoomW),
        height: (34 / zoomH),
        backgroundColor: '#eeeff3',
        borderRadius: 3,
        display: 'flex',
        flexDirection: 'row',
        alignItems: 'center',
        paddingLeft: (12.5 / zoomW),
        paddingRight: (12.5 / zoomW),
        marginLeft: (12.5 / zoomH),
        marginBottom: (12.5 / zoomH),
        marginTop: (7 / zoomH)
    },
    background: {
        flex: 1,
        backgroundColor: '#fff',
        display: 'flex'
    },
});