linkTarget.js 6.88 KB
/**
 * Created by Cassie on 2018/05/14
 */
import React, {Component} from "react";
import {StyleSheet, View, Text, StatusBar,TouchableOpacity, Image} from "react-native";
import {SwipeListView, SwipeRow} from "react-native-swipe-list-view";
import moment from "moment";
import {width, zoomW, zoomH} from "../../utils/getSize";
import {NoDoublePress} from "../../utils/utils";

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

export default class LinkTarget 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 = {
            from:this.props.navigation.state.params.from,
            sheetList: this.props.navigation.state.params.alreadyLinkList};
    };

    componentWillMount() {
        this.setState({
            from:this.props.navigation.state.params.from,
            sheetList: this.props.navigation.state.params.alreadyLinkList
        })
    };

    componentDidMount() {
       /* this.props.navigation.setParams({

        });*/
        this.props.navigation.setParams({
            title:'已关联任务',
            backgroundColor:'white',
            titleColor:'black',
            isBack:true,
            backClick:()=>{this.back()},
        });
    };
    back(){
        if(!this.state.from){
            this.props.navigation.state.params.callback(this.state.sheetList);
        }
        this.props.navigation.goBack();
    }
    /* 渲染列表*/
    keyExtractor = (item, index) => index;

    renderItem(rowData, rowMap) {
        return (
            <SwipeRow disableRightSwipe={true} rightOpenValue={-(60 / zoomW)}>
                {!this.state.from && <TouchableOpacity activeOpacity={0.8} style={styles.delBtn} onPress={() => NoDoublePress.onPress(() => {
                    this.delTarget(rowData, rowMap)
                })}>
                    <Image source={del} style={{width: (24 / zoomH), height: (24 / zoomH)}} resizeMode="contain"/>
                </TouchableOpacity>}
                <View style={styles.listItem}>
                    <View style={{
                        borderRadius: (30 / zoomH),
                        display: 'flex',
                        justifyContent: 'center',
                        alignItems: 'center',
                        borderStyle: 'solid',
                        borderColor: '#ddd',
                        borderWidth: StyleSheet.hairlineWidth
                    }}>
                        <View style={{
                            borderRadius: (30 / zoomH),
                            display: 'flex',
                            justifyContent: 'center',
                            alignItems: 'center',
                            borderStyle: 'solid',
                            borderColor: '#ddd',
                            borderWidth: StyleSheet.hairlineWidth
                        }}>
                            <Image
                                source={rowData.item.avarUrl ? {uri: rowData.item.avarUrl + '?x-oss-process=image/resize,w_500'} : avatar}
                                style={{width: (52 / zoomH), height: (52 / zoomH), borderRadius: (26 / zoomH)}}
                                resizeMode="cover"/>
                        </View>
                    </View>
                    <View style={styles.taskDetail}>
                        <Text style={{fontSize: 17, color: '#000'}} numberOfLines={1}>{rowData.item.objectName}</Text>
                        <Text style={{fontSize: 14, color: '#666'}}
                              numberOfLines={1}>{'结束时间:' + moment(Number(rowData.item.endTime)).format('YYYY-MM-DD HH:mm')}</Text>
                        {rowData.item.objectDescription && <Text style={{fontSize: 14, color: '#666'}}
                                                                 numberOfLines={1}>{'任务详情:' + rowData.item.objectDescription}</Text>}
                    </View>
                </View>
            </SwipeRow>
        )
    };

    /*删除关联任务*/
    delTarget(rowData, rowMap) {
        alert(rowData.index)
        let list = this.state.sheetList;
        rowMap[rowData.index].closeRow();
        list.splice(rowData.index, 1);
        this.setState({
            sheetList: list
        });
    };

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

    render() {
        return (
            <View style={styles.background}>
                <StatusBar
                    backgroundColor={'#FFFFFF'}
                    barStyle={"dark-content"}
                    networkActivityIndicatorVisible
                />
                <View style={{width: '100%', height: (10 / zoomH)}}/>
                <SwipeListView useFlatList={true} showsVerticalScrollIndicator={false} onRowOpen={(rowData, rowMap) => {
                    if (rowData != 0) {
                        rowMap[0].closeRow();
                    }
                }} keyExtractor={this.keyExtractor} data={this.state.sheetList}
                               renderItem={(rowData, rowMap) => this.renderItem(rowData, rowMap)}/>

            </View>
        );
    }
}

const styles = StyleSheet.create({
    topIcon: {
        paddingLeft: (10 / zoomW),
        paddingRight: (10 / zoomW),
        height: '100%',
        display: 'flex',
        justifyContent: 'center'
    },
    background: {
        flex: 1,
        backgroundColor: '#fff',
        display: 'flex',
        alignItems: 'center'
    },
    listItem: {
        width: width,
        height: (80 / zoomH),
        display: 'flex',
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
        borderStyle: 'solid',
        borderBottomWidth: StyleSheet.hairlineWidth,
        borderBottomColor: '#eee',
        paddingTop: (10 / zoomH),
        paddingBottom: (10 / zoomH),
        paddingLeft: (15 / zoomW),
        paddingRight: (15 / zoomW),
        backgroundColor: '#fff'
    },
    delBtn: {
        width: (60 / zoomW),
        height: '100%',
        display: 'flex',
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#ea281a',
        position: 'absolute',
        right: 0
    },
    taskDetail: {
        flex: 1,
        paddingLeft: (10 / zoomW)
    }
});