ApprovalUserAdd.js
4.6 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 tdzl2003 on 12/18/16.
*/
import React, {Component} from "react";
import {
Image,
TouchableOpacity,
View,
StyleSheet,
Text,
Alert
} from "react-native";
const addImg = require('../img/add-icon.png');
const deleteImg = require('../img/delete.png');
export default class ApprovalUserAdd extends Component {
constructor(props){
super(props);
this.state = {
tenantId:global.tenantId,
tenantName:global.tenantShortName,
userList : []
};
}
render() {
return (
<View style={styles.addList}>
{ this.state.userList.map((v, i) => this._renderUser(v, i))}
<View style={styles.addItem}>
<TouchableOpacity style={styles.addItemLayout} onPress={()=>{this.addUser()}}>
<View style={[styles.addItemImg,styles.addItemImgOp]}><Image style={{ width:12,height:12}} source={addImg} resizeMode="contain"/></View>
<View style={styles.addItemName}><Text style={[styles.addItemNameText,styles.addItemNameTextOp]}>添加</Text></View>
</TouchableOpacity>
</View>
</View>
);
}
_renderUser = (v, i) =>{
return (
<View style={styles.addItem} key={i}>
<View style={styles.addItemLayout}>
<View style={styles.addItemImg}>
{!v.avatar&&<Text style={styles.addItemImageText}>{v.shortName}</Text>}
{v.avatar&& <Image style={styles.addItemImage} source={{uri:v.avatar}} resizeMode="contain"></Image>}
</View>
<View style={styles.addItemName}><Text style={styles.addItemNameText}>{v.name}</Text></View>
<TouchableOpacity style={styles.addItemDelete} onPress={(v)=>{this._delete(v,i)}}>
<Image style={styles.addItemDeleteIcon} source={deleteImg} resizeMode="contain"/>
</TouchableOpacity>
</View>
</View>
)
};
addUser=()=>{
this.props.navigation.navigate("Employee",{status:"add",callback:this.callback,tenantId:this.state.tenantId,tenantName:this.state.tenantName})
};
_delete=(v,i)=>{
let _this=this;
Alert.alert(
'删除',
'确定删除?',
[
{text: '取消', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: '确定', onPress: () => {
let userList=this.state.userList;
userList.splice(i,1);
this.setState({
userList:userList
});
}},
]
)
};
callback=(data)=>{
console.log(data);
let _this=this;
let userList=this.state.userList;
if(data.name.length>2){
data.shortName=data.name.substring(data.name.length-2)
} else {
data.shortName=data.name;
}
userList.push(data);
this.setState({
userList:userList
});
}
}
const styles = StyleSheet.create({
addList:{
flexDirection:"row",
paddingTop:10,
flexWrap:"wrap",
},
addItem:{
width:"20%",
height:70,
marginBottom:10,
justifyContent:"center",
flexDirection:"row",
},
addItemLayout:{
height:70,
width:50,
},
addItemImg:{
height:50,
width:50,
justifyContent:"center",
alignItems:"center",
borderRadius:3,
backgroundColor: "#39f",
},
addItemImageText:{
color:"#fff",
fontSize:10,
},
addItemImage:{
height:50,
width:50,
},
addItemName:{
height:20,
width:50,
justifyContent:"center",
flexDirection:"row",
},
addItemNameText:{
fontSize:12,
color:"#333333",
textAlign: "center",
padding:3,
},
addItemDelete:{
position: "absolute",
width:10,
height:10,
right:-5,
top:-5,
},
addItemDeleteIcon:{
width:10,
height:10
},
addItemImgOp:{
borderWidth:1,
borderColor:"#999",
backgroundColor: "transparent",
},
addItemNameTextOp:{
color:"#999",
},
btn:{
height:50,
backgroundColor:"#39f",
justifyContent:"center",
alignItems:"center",
},
btnText:{
color:"#fff",
fontSize:18
}
});