home.js 10.6 KB
/**
 * 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'
    }
});