addApprovePeople.js
7.51 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
* Created by Cassie on 2018/05/14
* 添加审批人员
*/
import React, {Component} from "react";
import {StyleSheet, View, Text, TouchableOpacity, Image, StatusBar, DeviceEventEmitter, ScrollView,NativeModules} from "react-native";
import {width,zoomW, zoomH} from "../../utils/getSize";
import {NoDoublePress} from "../../utils/utils";
const back = require('../../img/returnB.png');
const circleAdd = require('../../img/circleAdd.png');
const circleDel = require('../../img/circleDel.png');
const avatar = require('../../img/avatar.png');
const remove = require('../../img/remove.png');
const arrowH = require('../../img/arrow_h.png');
export default class AddApprovePeople extends Component {
constructor(props) {
super(props);
this.state = {
title:"添加审批人",
};
};
componentWillMount() {
this.setState({
approveEmployee: global.approveEmployee,
});
global.readApproveEmployee = global.approveEmployee;
if ( global.approveEmployee.length == 0) {
this.props.navigation.setParams({
color: 'rgba(0,190,60,.2)',
opacity: 1
});
this.setState({
canAdd: false
})
} else {
this.props.navigation.setParams({
color: 'rgba(0,190,60,1)',
opacity: 0.8
});
this.setState({
canAdd: true
})
}
this.props.navigation.setParams({
title: '添加审批人'
});
}
componentDidMount() {
this.props.navigation.setParams({
title:'添加审批人',
backgroundColor:'white',
titleColor:'black',
isBack:true,
});
let _this = this;
this.reloaEmployee = DeviceEventEmitter.addListener('reloaEmployee', function () {
_this.setState({
approveEmployee: global.readApproveEmployee,
});
});
};
/*渲染人员*/
renderPeople(item, index) {
return (
<View key={index} style={{flexDirection:'row',alignItems:'center'}}>
<View style = {[styles.avatarBox]}>
<View style={styles.avatarPic}>
<Image source={item.avatar ? {uri: item.avatar + '?x-oss-process=image/resize,w_500'} : avatar}
style={{width: (50 / zoomH), height: (50 / zoomH), borderRadius: (25 / zoomH)}}
resizeMode="cover"/>
<TouchableOpacity activeOpacity={0.8} style={{
paddingLeft: (10 / zoomH),
paddingBottom: (10 / zoomH),
position: 'absolute',
top: 0,
right: 0
}} onPress={() => NoDoublePress.onPress(() => {
this.delPerson(index)
})}>
<Image source={remove} style={{width: (18 / zoomH), height: (18 / zoomH)}}
resizeMode="contain"/>
</TouchableOpacity>
</View>
<Text style={{fontSize: 12, color: '#666', marginTop: (6 / zoomH)}}>{item.name}</Text>
</View>
{index!=4&&<Image style = {{width:30/zoomW}} source={arrowH} resizeMode={'contain'}></Image>}
</View>
)
};
finish(){
NoDoublePress.onPress(() => {
global.approveEmployee = this.state.approveEmployee;
DeviceEventEmitter.emit('reloaAddEmployee');
this.props.navigation.goBack();
})
}
/*跳转到通讯录*/
toPeopleList(){
NoDoublePress.onPress(() => {
NativeModules.security.getTenantName().then((result)=>{
global.tenantShortName = result;
//multiChoice通讯录是否支持多选
this.props.navigation.navigate('AddEmployee', {from: 'approveEmployee',multiChoice:false});
});
});
};
/*删除人员*/
delPerson(index) {
let approveEmployee = [];
if(this.state.approveEmployee.length == 0){
approveEmployee = JSON.parse(JSON.stringify(global.approveEmployee));
}else{
approveEmployee = JSON.parse(JSON.stringify(this.state.approveEmployee))
}
approveEmployee.splice(index, 1);
global.readApproveEmployee = approveEmployee;
this.setState({
approveEmployee: approveEmployee
});
};
componentWillUnmount() {
if (this.reloaEmployee) {
this.reloaEmployee.remove();
}
this.setState = (state, callback) => {
return;
};
};
render() {
return (
<View style={styles.background}>
<StatusBar
backgroundColor={'#FFFFFF'}
barStyle={"dark-content"}
networkActivityIndicatorVisible
/>
<ScrollView style={{width:'100%',flex: 1,marginBottom:48/zoomH}}>
<View style={styles.addContent}>
<Text style={{fontSize: 17, color: '#333', paddingTop: (15 / zoomW)}}>审批人</Text>
<View style={styles.addItem}>
{!!this.state.approveEmployee && this.state.approveEmployee.map((item, index) => this.renderPeople(item, index))}
{this.state.approveEmployee.length<5&&<TouchableOpacity style={styles.avatarBox} activeOpacity={0.8}
onPress={() => this.toPeopleList()}>
<Image source={circleAdd} style={{width: (50 / zoomH), height: (50 / zoomH)}}
resizeMode="contain"/>
</TouchableOpacity>}
</View>
</View>
</ScrollView>
<TouchableOpacity activeOpacity={0.6} style={{flex: 1,display:'flex',flexDirection:'row',alignItems:'center',justifyContent:'center',position:"absolute",bottom:0,width:"100%",backgroundColor:"#28C35A",height:(48/zoomH)}}
onPress={()=>this.finish()}>
<View>
<Text style={{fontSize:16,color:'#FFFFFF'}}>完成</Text>
</View>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
topIcon: {
paddingLeft: (10 / zoomW),
paddingRight: (10 / zoomW),
height: '100%',
display: 'flex',
justifyContent: 'center'
},
background: {
flex: 1,
backgroundColor: '#ececf1',
display: 'flex',
alignItems: 'center'
},
addContent: {
width: '100%',
backgroundColor: '#fff',
marginTop: (15 / zoomH),
padding: (15 / zoomW)
},
addItem: {
width: '100%',
display: 'flex',
flexDirection: 'row',
flexWrap: 'wrap'
},
avatarBox: {
marginTop: (5/ zoomW),
marginBottom: (5 / zoomW),
marginLeft:(width-30/zoomW-250/zoomH)/10,
marginRight:(width-30/zoomW-250/zoomH)/10,
borderRadius: 4,
display: 'flex',
alignItems: 'center',
paddingTop: (8 / zoomH)
},
avatarPic: {
width: (50 / zoomH),
height: (50 / zoomH),
borderRadius: (25 / zoomH)
}
});