home.js
10.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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**
* Created by Cassie on 2018/05/14
*/
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Image,
FlatList,
Modal,
Animated,
Platform
} from 'react-native';
import {SwipeListView} from 'react-native-swipe-list-view';
import PercentageCircle from 'react-native-percentage-circle';
import {width,height,zoomW,zoomH} from '../utils/getSize';
const back = require('../img/loadBack.png');
const search = require('../img/search.png');
const add = require('../img/cross.png');
const avatar = require('../img/avatar.jpg');
export default class Home 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'}}>
<TouchableOpacity style={styles.topIcon} onPress={navigation.state.params?navigation.state.params.back:null}>
<Image source={back} style={{width:(27/zoomH),height:(27/zoomH)}} resizeMode="contain" />
</TouchableOpacity>
<TouchableOpacity style={styles.topIcon} onPress={navigation.state.params?navigation.state.params.back:null}>
<Image source={add} style={{width:(27/zoomH),height:(27/zoomH)}} resizeMode="contain" />
</TouchableOpacity>
</View>)
});
constructor(props) {
super(props);
this.state = {
sheetList:[{name:'1111'},{name:'2222'},{name:'333'},{name:'444'},{name:'555'},{name:'666'},{name:'777'},{name:'888'},{name:'999'},{name:'000'}],
bottom:new Animated.Value(-(320/zoomH)),
showSetting:false,
percent:45
};
};
componentWillMount(){
};
/* 渲染列表*/
keyExtractor = (item,index) => index;
renderItem(rowData){
return(
<TouchableOpacity activeOpacity={1} style={{width:width,height:(80/zoomH),paddingLeft:(15/zoomH),paddingRight:(15/zoomW),backgroundColor:'#fff'}}>
<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>
{/*<Image source={search} style={{width:(52/zoomH),height:(52/zoomH),borderRadius:(26/zoomH)}} resizeMode="contain" />*/}
<View style={styles.cornerMark}>
<Text style={{fontSize:12,color:'#fff'}}>3</Text>
</View>
</View>
<View style={styles.taskDetail}>
<Text style={{fontSize:17,color:'#000'}} numberOfLines={1}>{rowData.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>
)
};
renderBtn(rowData,rowMap){
return(
<View style={styles.settingBtn}>
<TouchableOpacity activeOpacity={0.8} style={[styles.btnItem,{backgroundColor: 'rgba(0,190,60,.5)'}]} onPress={() => this.openModal(rowData,rowMap)}>
<Image source={search} style={{width: (26 / zoomW), height: (19 / zoomH)}} resizeMode="contain"/>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.8} style={[styles.btnItem,{backgroundColor: '#00be3c'}]}>
<Image source={search} style={{width: (26 / zoomW), height: (19 / zoomH)}} resizeMode="contain"/>
</TouchableOpacity>
</View>
)
};
/*打开操作模态框*/
openModal(rowData,rowMap){
rowMap[rowData.index].closeRow();
this.setState({
taskName:rowData.item.name
},function(){
this.setState({
showSetting:true
});
Animated.timing(
this.state.bottom,
{toValue:(10/zoomH)}
).start();
})
};
/*模态框取消操作*/
closeModal(){
this.setState({
showSetting:false,
taskName:'',
bottom:new Animated.Value(-(320/zoomH))
});
};
render(){
return(
<View style={styles.background}>
<TouchableOpacity activeOpacity={0.8} style={styles.searchBox}>
<Image source={search} style={{width:(13/zoomH),height:(13/zoomH)}} resizeMode="contain" />
<View style={{flex:1,marginLeft:(8/zoomW)}}>
<Text style={{fontSize:14,color:'#8e8e93'}}>搜索</Text>
</View>
</TouchableOpacity>
<SwipeListView useFlatList={true} onRowOpen={(rowData,rowMap) => {if(rowData != 0){rowMap[0].closeRow();}}} keyExtractor={this.keyExtractor} data={this.state.sheetList} renderItem={(rowData) => this.renderItem(rowData)} refreshing={false} onRefresh={() => {this.setState({sheetList:[]},function(){this.setState({sheetList:['0','0','0','0','0','0','0','0','0','0','0','0']})})}} renderHiddenItem={(item,rowMap) => this.renderBtn(item,rowMap)} rightOpenValue={-(150/zoomW)} />
<Modal animationType={'none'} visible={this.state.showSetting} transparent={true} onRequestClose={() => {}}>
<View style={styles.modalBg}>
<Animated.View style={{width:'100%',position:'absolute',left:(10/zoomW),bottom:this.state.bottom}}>
<View style={{width:'100%',backgroundColor:'#fff',borderRadius:12}}>
{!!this.state.taskName && <TouchableOpacity activeOpacity={0.8} style={[styles.settingItem,{height:(44/zoomH)}]}>
<Text style={{fontSize:12,color:'#999'}}>{this.state.taskName}</Text>
</TouchableOpacity>}
<TouchableOpacity activeOpacity={0.8} style={styles.settingItem}>
<Text style={{fontSize:18,color:'#000'}}>置顶</Text>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.8} style={styles.settingItem}>
<Text style={{fontSize:18,color:'#000'}}>延期</Text>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.8} style={styles.settingItem}>
<Text style={{fontSize:18,color:'#000'}}>终止</Text>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.8} style={[styles.settingItem,{borderBottomWidth:0}]}>
<Text style={{fontSize:18,color:'#000'}}>详情</Text>
</TouchableOpacity>
</View>
<View style={{width:'100%',backgroundColor:'#fff',borderRadius:12,marginTop:(12/zoomH)}}>
<TouchableOpacity activeOpacity={0.8} style={[styles.settingItem,{borderBottomWidth:0}]} onPress={() => this.closeModal()}>
<Text style={{fontSize:18,color:'#000'}}>取消</Text>
</TouchableOpacity>
</View>
</Animated.View>
</View>
</Modal>
</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),
backgroundColor:'#eeeff3',
borderRadius:3,
display:'flex',
flexDirection:'row',
alignItems:'center',
paddingLeft:(12.5/zoomW),
paddingRight:(12.5/zoomW)
},
listItem:{
flex:1,
display:'flex',
flexDirection:'row',
justifyContent:'center',
alignItems:'center',
borderStyle:'solid',
borderBottomWidth:StyleSheet.hairlineWidth,
borderBottomColor:'#eee',
paddingTop:(10/zoomH),
paddingBottom:(10/zoomH)
},
taskDetail:{
flex:1,
paddingLeft:(10/zoomW)
},
cornerMark:{
width:(18/zoomH),
height:(18/zoomH),
borderRadius:(9/zoomH),
backgroundColor:'#f43530',
display:'flex',
justifyContent:'center',
alignItems:'center',
position:'absolute',
top:0,
right:0
},
settingBtn:{
display:'flex',
flexDirection:'row',
alignItems:'center',
position:'absolute',
right:0
},
btnItem:{
width:(75/zoomW),
height:(80/zoomH),
display:'flex',
justifyContent:'center',
alignItems:'center'
},
modalBg:{
width:width,
height:height,
backgroundColor:'rgba(0,0,0,.5)',
paddingLeft:(10/zoomW),
paddingRight:(10/zoomW)
},
settingItem:{
width:'100%',
height:(50/zoomH),
borderStyle:'solid',
borderBottomColor:'#eee',
borderBottomWidth:StyleSheet.hairlineWidth,
display:'flex',
justifyContent:'center',
alignItems:'center'
}
});