addEmployee.js 3.1 KB
import React, {Component} from "react";
import {
    StyleSheet,
    Text,
    TextInput,
    TouchableOpacity,
    View,
    Image,
    NativeModules,
    DeviceEventEmitter
} from "react-native";
import EmployeeList from "../public/EmployeeList";
import {zoomW, zoomH} from "../../utils/getSize";
import {NoDoublePress} from "../../utils/utils";

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

export default class AddEmployee 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 style={{display: 'flex', flexDirection: 'row'}}/>)

    });

    constructor(props) {
        super(props);
        this.state = {
            tenantId: global.tenantId,
            tenantName: global.tenantShortName
        };
    };

    componentDidMount() {
        this.props.navigation.setParams({
            back: () => {
                NoDoublePress.onPress(() => {
                    this.props.navigation.goBack();
                })
            }
        });
    };

    /*渲染员工*/
    renderEmployee = (data) => {
        if (this.props.navigation.state.params.from == 'doEmployee') {
            data.userRole = 'DEAL_USER';
            if (this.props.navigation.state.params.target) {
                global.linkDoEmployee.push(data);
            } else {
                global.doEmployee.push(data);
            }
            DeviceEventEmitter.emit('reloaEmployee');
        } else if (this.props.navigation.state.params.from == 'ccEmployee') {
            data.userRole = 'CC_USER';
            if (this.props.navigation.state.params.target) {
                global.linkCcEmployee.push(data);
            } else {
                global.ccEmployee.push(data);
            }
            DeviceEventEmitter.emit('reloaEmployee');
        }
        this.props.navigation.goBack();
    };

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

    render() {
        return (
            <View style={styles.body}>
                <EmployeeList tenantId={this.state.tenantId} name={this.state.tenantName} callback={this.renderEmployee}
                              employeeType="USER" from={this.props.navigation.state.params.from}
                              target={this.props.navigation.state.params.target ? this.props.navigation.state.params.target : null}/>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    topIcon: {
        paddingLeft: (10 / zoomW),
        paddingRight: (10 / zoomW),
        height: '100%',
        display: 'flex',
        alignItems: 'center'
    },
    body: {
        flex: 1,
        flexDirection: "column",
        backgroundColor: "#ecf0f3",
    }
});