selectTarget.js
7.89 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
/**
* Created by Cassie on 2018/05/14
*/
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Image,
TextInput,
ScrollView,
Platform,
InteractionManager
} from 'react-native';
import PercentageCircle from 'react-native-percentage-circle';
import {width,zoomW,zoomH} from '../../utils/getSize';
const back = require('../../img/returnB.png');
const avatar = require('../../img/avatar.png');
const allDel = require('../../img/allDel.png');
const search = require('../../img/search.png');
const submitsuccess = require('../../img/submitsuccess.png');
export default class SelectTarget 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'}}>
{navigation.state.params && <TouchableOpacity activeOpacity={navigation.state.params.opacity} style={styles.topIcon} onPress={navigation.state.params.addTeam}>
<Text style={{fontSize:16,color:navigation.state.params.color}}>选择</Text>
</TouchableOpacity>}
</View>)
});
constructor(props){
super(props);
this.state = {
name:'',
sheetList:[{name:'0'},{name:'1'},{name:'2'},{name:'3'},{name:'4'},{name:'5'},{name:'6'},{name:'7'}],
percent:30,
indexList:[]
};
};
componentDidMount(){
this.props.navigation.setParams({
color:'rgba(0,190,60,.5)',
opacity:1,
back:()=>{
InteractionManager.runAfterInteractions(() => {this.props.navigation.goBack();})
},
addTeam:()=>{
}
});
};
/*一键删除功能*/
showDel(type,content){
if(Platform.OS == 'android'){
if(content.length != 0){
this.setState({
type:type
})
}else{
this.setState({
type:''
})
}
}
};
/*渲染列表*/
renderItem(item,index){
return(
<TouchableOpacity key={index} activeOpacity={0.8} style={{width:width,height:(100/zoomH),paddingLeft:(15/zoomH),paddingRight:(15/zoomH),display:'flex',flexDirection:'row',alignItems:'center'}} onPress={() => this.selectItem(index)}>
<View style={{width:(24/zoomH),height:(24/zoomH),marginRight:(15/zoomW)}}>
<View style={styles.selectDot} />
{this.state.indexList.indexOf(index) !=-1 && <Image source={submitsuccess} style={{width:(24/zoomH),height:(24/zoomH),position:'absolute',top:0}} resizeMode="center" />}
</View>
<View style={styles.listItem}>
<View style={{borderRadius:(30/zoomH),display:'flex',justifyContent:'center',alignItems:'center',borderStyle:'solid',borderColor:'#ddd',borderWidth:StyleSheet.hairlineWidth}}>
<PercentageCircle collapsable={false} radius={(28/zoomH)} percent={this.state.percent} color={'#28c35a'} borderWidth={(2/zoomH)}>
<Image source={avatar} style={{width:(52/zoomH),height:(52/zoomH),borderRadius:(26/zoomH)}} resizeMode="contain" />
<View style={{width:(52/zoomH),height:(52/zoomH),borderRadius:(26/zoomH),position:'absolute',display:'flex',justifyContent:'center',alignItems:'center',backgroundColor:'rgba(0,0,0,.2)'}}>
<Text style={{fontSize:14,color:'#fff'}}>{this.state.percent}%</Text>
</View>
</PercentageCircle>
</View>
<View style={styles.taskDetail}>
<Text style={{fontSize:17,color:'#000'}} numberOfLines={1}>{item.name}</Text>
<Text style={{fontSize:14,color:'#666'}} numberOfLines={1}>结束时间:04-30 16:00</Text>
<Text style={{fontSize:14,color:'#666'}} numberOfLines={1}>报销金额:共308,餐饮200,路费108</Text>
</View>
</View>
</TouchableOpacity>
)
};
/*选择任务*/
selectItem(index){
let indexList = this.state.indexList;
if(indexList.indexOf(index) == -1){
indexList.push(index);
}else{
indexList.splice(indexList.indexOf(index),1);
}
this.setState({
indexList:indexList
});
if(this.state.indexList.length != 0){
this.props.navigation.setParams({
color:'rgba(0,190,60,1)'
});
}else{
this.props.navigation.setParams({
color:'rgba(0,190,60,.5)'
});
}
}
render(){
return(
<View style={styles.background}>
<View style={styles.searchBox}>
<Image source={search} style={{width:(13/zoomH),height:(13/zoomH)}} resizeMode="contain" />
<TextInput returnKeyType="search" placeholder='搜索' placeholderTextColor='#8e8e93' style={styles.searchText} underlineColorAndroid="transparent" clearButtonMode="while-editing" onChangeText={(value) => this.setState({name:value},function(){this.showDel('name',this.state.name)})} onFocus={() => this.showDel('name',this.state.name)} onBlur={() => {this.setState({type:''})}} defaultValue={this.state.name} />
{this.state.type == 'name' && <TouchableOpacity style={{height:'100%',position:'absolute',right:0,display:'flex',justifyContent:'center'}} onPress={() => this.setState({name:'',type:''})}>
<Image source={allDel} style={{width:(16/zoomH),height:(48/zoomH),marginLeft:(10/zoomW),marginRight:(10/zoomW)}} resizeMode="center" />
</TouchableOpacity>}
</View>
<View style={{width:(345/zoomW)}}>
<Text style={{fontSize:12,color:'#666',paddingTop:(5/zoomH),paddingRight:(5/zoomH)}}>可关联任务</Text>
</View>
<ScrollView>
{this.state.sheetList && this.state.sheetList.map((item,index) => this.renderItem(item,index))}
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
topIcon:{
paddingLeft:(10/zoomW),
paddingRight:(10/zoomW),
height:'100%',
display:'flex',
alignItems:'center'
},
background:{
flex:1,
backgroundColor:'#fff',
display:'flex',
alignItems:'center'
},
searchBox:{
width:(345/zoomW),
height:(34/zoomH),
borderRadius:3,
backgroundColor:'#eeeff3',
display:'flex',
flexDirection:'row',
alignItems:'center',
paddingLeft:(12/zoomW)
},
searchText:{
flex:1,
fontSize:14,
color:'#000',
padding:0,
paddingLeft:(8/zoomW)
},
listItem:{
flex:1,
height:(80/zoomH),
display:'flex',
flexDirection:'row',
justifyContent:'center',
alignItems:'center',
borderStyle:'solid',
borderBottomWidth:StyleSheet.hairlineWidth,
borderBottomColor:'#eee',
backgroundColor:'#fff'
},
taskDetail:{
flex:1,
paddingLeft:(10/zoomW)
},
selectDot:{
width:(24/zoomH),
height:(24/zoomH),
borderRadius:(12/zoomH),
borderWidth:StyleSheet.hairlineWidth,
borderColor:'#ddd',
borderStyle:'solid',
marginRight:(15/zoomW)
}
});