BooleanCheckView.js 2.92 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    TouchableOpacity,
    Image,
} from 'react-native';

const checkedImg = require("../img/checked.png");
const unCheckedImg = require("../img/dati-xuanze-02.png");

export default class BooleanCheckView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            checked: null
        }
        this.attrData = this.props.attrData;

        this.extendData = JSON.parse(this.attrData.data);// null=无|true=是|false=否
    }

    componentWillMount() {
        this.setState({
            checked: this.extendData.booleanDefault
        })
        this.attrData.value = this.extendData.booleanDefault?"是":"否";
    }

    render() {
        let {name, code, type, description, isRequired, isPreview} = this.attrData;

        return (
            <View style={{flexDirection: 'row', width: '100%', backgroundColor: 'white', alignItems: 'center', paddingHorizontal: 5, paddingVertical: 10}}>
                <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)', marginLeft: 5}}>{name||""}</Text>
                <TouchableOpacity
                    style={{marginLeft: 10, flexDirection: 'row', alignItems: 'center'}}
                    activeOpacity={0.8}
                    onPress={()=>{
                        this.setState({
                            checked: true
                        });
                        this.attrData.value = "是";
                    }}
                >
                    <Image
                        source={this.state.checked ? checkedImg : unCheckedImg}
                        style={{
                            width: 20,
                            height: 20,
                            marginLeft: 8,
                            marginRight: 8
                        }}
                    />
                    <Text style={{fontSize: 14, color: 'rgba(0, 0, 0 , 1)', paddingVertical: 10}}></Text>
                </TouchableOpacity>
                <TouchableOpacity
                    style={{marginLeft: 10, flexDirection: 'row', alignItems: 'center'}}
                    activeOpacity={0.8}
                    onPress={()=>{
                        this.setState({
                            checked: false
                        });
                        this.attrData.value = "否";
                    }}
                >
                    <Image
                        source={(this.state.checked !== null && !this.state.checked) ? checkedImg : unCheckedImg}
                        style={{
                            width: 20,
                            height: 20,
                            marginLeft: 8,
                            marginRight: 8
                        }}
                    />
                    <Text style={{fontSize: 14, color: 'rgba(0, 0, 0 , 1)', paddingVertical: 10}}></Text>
                </TouchableOpacity>
            </View>
        );
    }
}