addEmployee.js
5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* Created by Cassie on 18/06/15
*/
import React, {Component} from "react";
import {
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
Image,
NativeModules,
DeviceEventEmitter
} from "react-native";
import Maillist from "./maillist";
import {zoomW, zoomH} from "../../utils/getSize";
import {NoDoublePress} from "../../utils/utils";
const back = require('../../img/returnB.png');
const search = require('../../img/SearchB.png');
export default class AddEmployee extends Component {
static navigationOptions = ({navigation, screenProps}) => ({
title:'通讯录',
headerLeft:(<View style={{flex: 1, 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={{flex: 1, display: 'flex', flexDirection: 'row'}}>
<TouchableOpacity style={styles.topIcon}
onPress={navigation.state.params ? navigation.state.params.search : null}>
<Image source={search} style={{width:(18/zoomW),height:(18/zoomW)}} resizeMode="contain" />
</TouchableOpacity>
</View>)
});
constructor(props) {
super(props);
this.state = {};
};
componentWillMount(){
this.from = this.props.navigation.state.params.from;
};
componentDidMount() {
this.props.navigation.setParams({
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 != ""){
this.refs.mailList.selectItem(data);
}
this.toSearch = false;
};
/*渲染员工*/
renderEmployee=(data)=>{
if(data.length ==0 ){
return;
}
for(let i=0;i<data.length;i++){
if(data[i].userId == global.userId){
data.splice(i,1);
break;
}
}
if (this.from == 'doEmployee') {
let selectEmployee = [];
let alreadyArr = global.readyCcEmployee;
let alreadyId = [];
let hash = {};
if(alreadyArr.length != 0){
for(let i=0;i<alreadyArr.length;i++){
alreadyId.push(alreadyArr[i].userId)
}
let resultData = [];
for(let i=0;i<data.length;i++){
data[i].userRole = 'DEAL_USER';
if(alreadyId.indexOf(data[i].userId) == -1){
resultData.push(data[i])
}
}
selectEmployee = JSON.parse(JSON.stringify(global.readyDoEmployee)).concat(resultData);
}else{
selectEmployee = JSON.parse(JSON.stringify(global.readyDoEmployee)).concat(data);
}
global.readyDoEmployee = [];
for(let i=0;i<selectEmployee.length;i++){
if(!hash[selectEmployee[i].userId]){
hash[selectEmployee[i].userId] = -1;
global.readyDoEmployee.push(selectEmployee[i])
}
}
} else if (this.from == 'ccEmployee') {
let selectEmployee = [];
let alreadyArr = global.readyDoEmployee;
let alreadyId = [];
let hash = {};
if(alreadyArr.length != 0){
for(let i=0;i<alreadyArr.length;i++){
alreadyId.push(alreadyArr[i].userId)
}
let resultData = [];
for(let i=0;i<data.length;i++){
data[i].userRole = 'CC_USER';
if(alreadyId.indexOf(data[i].userId) == -1){
resultData.push(data[i])
}
}
selectEmployee = JSON.parse(JSON.stringify(global.readyCcEmployee)).concat(resultData)
}else{
selectEmployee = JSON.parse(JSON.stringify(global.readyCcEmployee)).concat(data)
}
global.readyCcEmployee = [];
for(let i=0;i<selectEmployee.length;i++){
if(!hash[selectEmployee[i].userId]){
hash[selectEmployee[i].userId] = -1;
global.readyCcEmployee.push(selectEmployee[i])
}
}
}
DeviceEventEmitter.emit('reloaEmployee');
if(!this.toSearch){
this.props.navigation.goBack();
}
};
componentWillUnmount() {
this.setState = (state, callback) => {
return;
};
};
render() {
return (
<View style={styles.background}>
<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: '100%',
display: 'flex',
justifyContent: 'center'
},
background: {
flex: 1,
backgroundColor: '#fff',
display: 'flex'
},
});