remindPeople.js 5.81 KB
/**
 * Created by Cassie on 2018/05/14
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Text,
    TouchableOpacity,
    Image,
    ScrollView,
    ActivityIndicator,
    InteractionManager
} from 'react-native';

import {zoomW,zoomH} from '../../utils/getSize';
import AppService from "../../service/AppService";
import {xnToast,NoDoublePress} from "../../utils/utils";

const back = require('../../img/returnB.png');
const avatar = require('../../img/avatar.png');

export default class RemindPeople extends Component {
    static navigationOptions = ({ navigation, screenProps }) => ({
        title:'选择要提醒的人',
        headerLeft:(<View style={{flex:1,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={{flex:1,display:'flex',flexDirection:'row'}} />)
    });

    constructor(props){
        super(props);
        this.state = {
            loading:false
        };
    };

    componentWillMount(){
        this.getList();
    };

    componentDidMount(){
        this.props.navigation.setParams({
            back:() => {
                NoDoublePress.onPress(() => {
                    InteractionManager.runAfterInteractions(() => {this.props.navigation.goBack();})
                })
            }
        });
    };
    /*获取列表*/
    getList(){
        this.setState({
            sheetList:[]
        });
        if(global.isConnected){
            let params = {
                taskId:this.props.navigation.state.params.id,
                includeOwner:false
            };
            this.setState({
                loading:true
            });
            AppService.getRemindPeople(params).then((data) => {
                this.setState({
                    loading:false
                });
                if(data.message){
                    xnToast(data.message);
                    return;
                }
                if(data.errors.length > 0){
                    xnToast(data.errors[0].message);
                }else{
                    this.setState({
                        sheetList:data.result
                    })
                }
            }).catch((error) => {
                this.setState({
                    loading:false
                });
                xnToast(error)
            })
        }else{
            xnToast('暂无网络连接,请稍后重试!')
        }
    };
    /*渲染列表*/
    renderItem(item,index){
        return(
            <TouchableOpacity activeOpacity={0.8} key={index} style={styles.targetItem} onPress={() => NoDoublePress.onPress(() => {this.selectPeople(item)})}>
                <View style={{width:(50/zoomH),height:(50/zoomH),borderRadius:(25/zoomH),display:'flex',justifyContent:'center',alignItems:'center',borderStyle:'solid',borderColor:'#ddd',borderWidth:StyleSheet.hairlineWidth}}>
                    <Image source={item.avatar ? {uri:item.avatar+'?x-oss-process=image/resize,w_500'}:avatar} style={{width:(50/zoomH),height:(50/zoomH),borderRadius:(25/zoomH)}} resizeMode="stretch" />
                </View>
                <View style={{flex:1,paddingLeft:(10/zoomW),display:'flex',justifyContent:'center'}}>
                    <Text style={{fontSize:17,color:'#000'}} numberOfLines={1}>{item.userName}</Text>
                </View>
            </TouchableOpacity>
        )
    };
    /*选择人员返回*/
    selectPeople(item){
        this.props.navigation.state.params.callback(item);
        InteractionManager.runAfterInteractions(() => {
            this.props.navigation.goBack();
        })
    };

    componentWillUnmount(){
        this.setState = (state,callback)=>{
            return;
        };
    };

    render(){
        return(
            <View style={styles.background}>
                <View style={{width:'100%',height:(20/zoomH)}} />
                <ScrollView style={{width:'100%'}}>
                    <View style={{width:'100%',height:(20/zoomH)}} />
                    {this.state.sheetList && this.state.sheetList.map((item,index) => this.renderItem(item,index))}
                </ScrollView>
                {this.state.loading && <View style={styles.loadingBg}>
                    <View style={styles.loadingBox}>
                        <ActivityIndicator size='large' color='#fff' />
                        <Text style={{fontSize:16,color:'#fff',marginTop:(6/zoomH)}}>加载中...</Text>
                    </View>
                </View>}
            </View>
        );
    }
}

const styles = StyleSheet.create({
    topIcon:{
        paddingLeft:(10/zoomW),
        paddingRight:(10/zoomW),
        height:'100%',
        display:'flex',
        justifyContent:'center'
    },
    background:{
        flex:1,
        backgroundColor:'#ececf1',
        display:'flex',
        alignItems:'center'
    },
    targetItem:{
        flex:1,
        display:'flex',
        flexDirection:'row',
        alignItems:'center',
        borderStyle:'solid',
        borderBottomWidth:StyleSheet.hairlineWidth,
        borderBottomColor:'#eee',
        paddingLeft:(15/zoomW),
        paddingRight:(15/zoomW),
        paddingTop:(10/zoomH),
        paddingBottom:(10/zoomH),
        backgroundColor:'#fff'
    },
    loadingBg:{
        position:'absolute',
        top:0,
        width:'100%',
        height:'100%',
        display:'flex',
        justifyContent:'center',
        alignItems:'center'
    },
    loadingBox:{
        width:(100/zoomW),
        height:(120/zoomH),
        backgroundColor:'rgba(0,0,0,.5)',
        borderRadius:8,
        display:'flex',
        alignItems:'center',
        justifyContent:'center'
    }
});