home.js 15.1 KB
/**
 * Created by Cassie on 2018/05/14
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Text,
    TouchableOpacity,
    Image,
    FlatList,
    Modal,
    Animated,
    TextInput,
    InteractionManager
} from 'react-native';
import {SwipeListView,SwipeRow} from 'react-native-swipe-list-view';
import PercentageCircle from 'react-native-percentage-circle';

import {width,height,zoomW,zoomH} from '../utils/getSize';
import {getHeaderPadding} from '../utils/utils';

const back = require('../img/returnB.png');
const search = require('../img/search.png');
const addTarget = require('../img/addTarget.png');
const lookTarget = require('../img/lookTarget.png');
const avatar = require('../img/avatar.png');
const targetMore = require('../img/targetMore.png');
const done = require('../img/done.png');
const submitsuccess = require('../img/submitsuccess.png');

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.close: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={lookTarget} style={{width:(26/zoomH),height:(26/zoomH)}} resizeMode="contain" />
            </TouchableOpacity>
            <TouchableOpacity style={styles.topIcon} onPress={navigation.state.params?navigation.state.params.addTarget:null}>
                <Image source={addTarget} style={{width:(26/zoomH),height:(26/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)),
            // top:new Animated.Value(-(200/zoomH)),
            top:0,
            showSetting:false,
            showSettingItem:true,
            percent:45
        };
    };

    componentWillMount(){

    };

    componentDidMount(){
        this.props.navigation.setParams({
            close:()=>{
                InteractionManager.runAfterInteractions(() => {NativeModules.system.navTo("BACK");})
            },
            addTarget:()=>{
                InteractionManager.runAfterInteractions(() => {this.props.navigation.navigate('AddTarget');})
            }
        });
    };

    /* 渲染列表*/
    keyExtractor = (item,index) => index;
    renderItem(rowData,rowMap){
        return(
        <SwipeRow disableRightSwipe={true} rightOpenValue={-(150/zoomW)}>
            <View style={styles.settingBtn}>
                <TouchableOpacity activeOpacity={0.8} style={[styles.btnItem,{backgroundColor:'rgba(0,190,60,.5)'}]} onPress={() => this.openModal(rowData,rowMap)}>
                    <Image source={targetMore} style={{width:(26/zoomW),height:(19/zoomH)}} resizeMode="contain"/>
                </TouchableOpacity>
                <TouchableOpacity activeOpacity={0.8} style={[styles.btnItem,{backgroundColor: '#00be3c'}]}>
                    <Image source={done} style={{width:(26/zoomW), height:(19/zoomH)}} resizeMode="contain"/>
                </TouchableOpacity>
            </View>
            <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>
        </SwipeRow>
        )
    };
    /*打开操作模态框*/
    openModal(rowData,rowMap){
        this.setState({
            taskName:rowData.item.name
        },function(){
            this.setState({
                showSetting:true
            });
            Animated.timing(
                this.state.bottom,
                {toValue:(10/zoomH)}
            ).start();
        });
        InteractionManager.runAfterInteractions(() => {
            rowMap[rowData.index].closeRow();
        });
    };
    /*模态框取消操作*/
    closeModal(){
        this.setState({
            showSetting:false,
            taskName:'',
            bottom:new Animated.Value(-(320/zoomH))
        });
    };
    /*打开具体操作*/
    openSetting(){
        this.closeModal();
        InteractionManager.runAfterInteractions(() => {
            this.setState({
                showSettingItem:true
            });
            Animated.timing(
                this.state.top,
                {toValue:getHeaderPadding()}
            ).start();
        });
    }

    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,rowMap) => this.renderItem(rowData,rowMap)} refreshing={false} onRefresh={() => {this.setState({sheetList:[]},function(){this.setState({sheetList:['0','0','0','0','0','0','0','0','0','0','0','0']})})}} />
                <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} onPress={() => this.openSetting()}>
                                    <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>
                <Modal animationType={'none'} visible={this.state.showSettingItem} transparent={true} onRequestClose={() => {}}>
                    <View style={styles.modalBg}>
                        <Animated.View style={[styles.settingModal,{top:this.state.top}]}>
                            <View style={{height:(30/zoomH),display:'flex',flexDirection:'row',alignItems:'center'}}>
                                <Image source={submitsuccess} style={{width:(20/zoomH),height:(20/zoomH),marginRight:(6/zoomW)}} resizeMode="contain" />
                                <Text style={{fontSize:14,color:'#333'}}>太棒了,您完成了任务</Text>
                            </View>
                            {/*<TextInput placeholder='输入内容' multiline={true} placeholderTextColor='#999' style={[styles.settingContent,{height:(120/zoomH)}]} underlineColorAndroid="transparent"  clearButtonMode="while-editing" onFocus={() => {this.setState({allWord:10000})}} onChangeText={(value) => {this.setState({content:value})}} />*/}
                            <TextInput placeholder='输入内容' multiline={true} placeholderTextColor='#999' style={[styles.settingContent,{height:(90/zoomH),borderBottomLeftRadius:0,borderBottomRightRadius:0}]} underlineColorAndroid="transparent"  clearButtonMode="while-editing" onFocus={() => {this.setState({allWord:10000})}} onChangeText={(value) => {this.setState({content:value})}} />
                            <View style={styles.pickerTime}>

                            </View>
                            <View style={styles.settingBottom}>
                                <TouchableOpacity activeOpacity={0.8} style={{flex:1,display:'flex',justifyContent:'center',alignItems:'center',borderRightWidth:StyleSheet.hairlineWidth,borderRightColor:'#666',borderStyle:'solid'}}>
                                    <Text style={{fontSize:14,color:'#333'}}>取消</Text>
                                </TouchableOpacity>
                                <TouchableOpacity activeOpacity={0.8} style={{flex:1,display:'flex',justifyContent:'center',alignItems:'center'}}>
                                    <Text style={{fontSize:14,color:'#333'}}>完成</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),
        display:'flex',
        alignItems:'center'
    },
    settingItem:{
        width:'100%',
        height:(50/zoomH),
        borderStyle:'solid',
        borderBottomColor:'#eee',
        borderBottomWidth:StyleSheet.hairlineWidth,
        display:'flex',
        justifyContent:'center',
        alignItems:'center'
    },
    settingModal:{
        width:(300/zoomW),
        height:(200/zoomH),
        backgroundColor:'#f0eff5',
        borderRadius:4,
        paddingTop:(6/zoomH),
        paddingLeft:(15/zoomW),
        paddingRight:(15/zoomW),
        position:'absolute'
    },
    settingContent:{
        textAlignVertical:'top',
        padding:(10/zoomH),
        backgroundColor:'#fff',
        borderRadius:4
    },
    pickerTime:{
        width:'100%',
        height:(30/zoomH),
        backgroundColor:'#fff',
        borderTopWidth:StyleSheet.hairlineWidth,
        borderTopColor:'#999',
        borderStyle:'solid',
        borderBottomLeftRadius:4,
        borderBottomRightRadius:4
    },
    settingBottom:{
        width:(300/zoomW),
        height:(36/zoomH),
        borderTopWidth:StyleSheet.hairlineWidth,
        borderTopColor:'#666',
        borderStyle:'solid',
        position:'absolute',
        left:0,
        bottom:0,
        display:'flex',
        flexDirection:'row'
    }
});