TagItemView.js 5.85 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    TouchableOpacity, Image, ScrollView, Modal, StyleSheet
} from 'react-native';
const defaultHeight = (30);
const HPading = (16);
const VPading = (6);

/**
 * 标签
 */
export default class TagItemView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            showModal:false,
            tagDataList:[],// 标签列表
        }
        this.attrData = this.props.attrData;
    }

    componentWillMount() {
    }

    showModal() {
        this.setState({
            showModal: true,
        });
    }

    /**
     * 模态框取消操作
     */
    closeModal() {
        this.setState({
            showModal: false,
        });
    }

    render() {

        let {name, labelName, labelColor} = this.attrData;

        return (
            <View>
                <TouchableOpacity
                    style={{width: '100%', backgroundColor: 'white', flexDirection: 'row', paddingVertical: 10, paddingHorizontal: 6, alignItems: 'center'}}
                    activeOpacity={0.8}
                    onPress={()=> {
                        this.showModal();
                    }}
                >
                    <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)'}}>{name|| '标签'}</Text>
                    <View style={{flex: 1, justifyContent: 'flex-end', alignItems: 'center', flexDirection: 'row'}}>
                        {!!labelName && labelName.length > 0 &&
                        <Text
                            style={{
                                fontSize: 14,
                                color: 'white',
                                backgroundColor: labelColor||'rgba(255, 141, 26, 1)',
                                paddingVertical: 3,
                                paddingHorizontal: 10,
                                borderRadius: 4
                            }}
                        >{labelName}</Text>}
                        {labelName === undefined || labelName.length === 0 &&
                        <Text style={{fontSize: 14, color: 'rgba(166, 166, 166, 1)'}}>添加标签</Text>}
                        <Image style={{width: 16, height: 16, marginLeft: 10}} source={require('../img/bread.png')} resizeMode={'contain'}/>
                    </View>
                </TouchableOpacity>
                <Modal animationType={"fade"} transparent={true} visible={this.state.showModal} onRequestClose={() => this.closeModal()}>
                    {/** 目录弹窗 */}
                    <View style={{flex: 1}}>
                        <TouchableOpacity style={styles.modalBg} activeOpacity={1} onPress={() => this.closeModal()}/>
                        {/** 实体内容 */}
                        <View style={styles.contentBg}>
                            {/** 标题栏 */}
                            <View style={styles.titleBar}>
                                <TouchableOpacity
                                    style={{paddingLeft: 15, paddingRight: 5}}
                                    activeOpacity={0.8}
                                    onPress={() => this.closeModal()}
                                >
                                    <Image style={{width: 14, height: 14}}
                                           source={require('../img/loadBack.png')}/>
                                </TouchableOpacity>
                                <Text style={styles.modelTitle}>添加标签</Text>
                                <TouchableOpacity
                                    style={{
                                        justifyContent: "center",
                                        alignItems: "center",
                                        paddingVertical: 3,
                                        paddingHorizontal: 8,
                                    }}
                                    activeOpacity={0.8}
                                    onPress={() => {
                                        this.props.navigation.navigate("CreateTagView");
                                        this.closeModal();
                                    }}
                                >
                                    <Text style={{fontSize: 16, color: global.homeColor}}>+新增</Text>
                                </TouchableOpacity>
                            </View>
                            <View style={{width: '100%', height: 1, backgroundColor: 'rgba(245,245,245,1)'}}/>
                            {/** 内容 */}
                            {!!this.state.tagDataList && this.state.tagDataList.length > 0 &&
                            }
                            {/*<ScrollView style={{flex: 1}} horizontal={false} showsVerticalScrollIndicator={false}>
                                {this.state.options && this.state.options.map((value, index) => this.renderCheckboxItem(value, index))}
                            </ScrollView>*/}
                        </View>
                    </View>
                </Modal>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    modalBg: {
        backgroundColor: 'rgba(0,0,0,.5)',
        width: '100%',
        height: '100%',
        display: 'flex',
        position: 'absolute'
    },
    contentBg: {
        width: '100%',
        flex: 1,
        marginTop: 122,
        backgroundColor: "rgba(255, 255, 255, 1)",
        borderTopLeftRadius: 16,
        borderTopRightRadius: 16
    },
    titleBar: {
        flexDirection: "row",
        justifyContent: "flex-start",
        alignItems: "center",
        marginTop: 15,
        marginBottom: 10,
        marginRight: 15
    },
    modelTitle: {
        flex: 1,
        color: "rgba(0, 0, 0, 1)",
        fontSize: 16,
        textAlign: "center",
        justifyContent: "center"
    },
    checkedBox: {
        width: 20,
        height: 20,
        marginLeft: 8,
        marginRight: 8
    },
});