CouponAlertView.js 4.24 KB
'use strict';
import React from 'react';
import ReactNative, {
    View,
    Text,
    Image,
    StyleSheet,
    Dimensions,
    PixelRatio,
    TouchableOpacity,
    Alert,
} from 'react-native';

import Immutable, {Map} from 'immutable';

export default class CouponAlertView extends React.Component {
    constructor(props) {
        super(props);
        // this.getAlertType = this.getAlertType.bind(this);
    }

    render() {

        let {notSupportReasons, notSupportReasonsTitle, notSupportReasonsMessage} = this.props;

        let image = this.getAlertType(notSupportReasons);

        return(
            <View style={styles.container}>

                <TouchableOpacity style={styles.bgContainer} activeOpacity={1} onPress={() => {
                    this.props.onPressClose && this.props.onPressClose();}}>
                </TouchableOpacity>
                {
                    image ? 
                        <View style={styles.imageContainer}>
                            <Image style={styles.image} source={image}/>
                            <TouchableOpacity style={styles.closeBtnContainer} activeOpacity={1} onPress={() => {
                                this.props.onPressClose && this.props.onPressClose();}}>
                                <Image style={styles.closeBtn} source={require('../../images/close_btn.png')}  />
                            </TouchableOpacity>
                            {
                                notSupportReasons == '1' ? 
                                    <View style={styles.notSupportContainer}>
                                        <Text style={styles.notSupportTitle}>{notSupportReasonsTitle}</Text>
                                        <Text style={styles.notSupportMessage}>{notSupportReasonsMessage}</Text>
                                    </View>
                                : null
                            }
                        </View>
                    :
                    null
                }
            </View>
        );
    }


    /**
     *获取弹框背景图, //1:已领取  2:信息未完善  3:非VIP   4:非生日期间
     **/
    getAlertType(type){
        let img;
        switch(type){
            case '1':
                img = require('../../images/alert_getted.png');
                break;
            case '2':
                img = require('../../images/alert_complete.png');
                break;
            case '3':
                img = require('../../images/alert_vip.png');
                break;
            case '4':
                img = require('../../images/alert_notime.png');
                break;
        }
        return img;
    }
};

let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;

height = height - 44 * DEVICE_WIDTH_RATIO;

let styles = StyleSheet.create({
    container: {
        position:'absolute',
        top: 0,
        left: 0,
        height: height,
        width: width,
        justifyContent: 'center',
        alignItems: 'center',
    },

    bgContainer: {
        position:'absolute',
        top: 0,
        left: 0,
        backgroundColor:'rgba(44, 44, 44, 0.5)',
        height: height,
        width: width,
    },


    imageContainer: {
        width: 240 * DEVICE_WIDTH_RATIO,
        height: 240 * DEVICE_WIDTH_RATIO,
    },

    image: {
        position:'absolute',
        top: 0,
        left: 0,
        width: 240 * DEVICE_WIDTH_RATIO,
        height: 240 * DEVICE_WIDTH_RATIO,
    },

    closeBtnContainer: {
        position:'absolute',
        top: 24 * DEVICE_WIDTH_RATIO,
        right: 16 * DEVICE_WIDTH_RATIO,
    },

    closeBtn: {
        width: 16 * DEVICE_WIDTH_RATIO,
        height: 16 * DEVICE_WIDTH_RATIO,
    },

    notSupportContainer: {
        position:'absolute',
        top: 110 * DEVICE_WIDTH_RATIO,
        width: 240 * DEVICE_WIDTH_RATIO,
        alignItems: 'center',
        justifyContent: 'center',
    },

    notSupportTitle: {
        fontSize: 12,
        color: '#ffffff',
        fontWeight: 'bold',
        textAlign: 'center',
    },

    notSupportMessage: {
        fontSize: 9,
        color: '#ffffff',
        fontWeight: 'bold',
        textAlign: 'center',
        marginTop: 8 * DEVICE_WIDTH_RATIO,
        marginLeft: 5 * DEVICE_WIDTH_RATIO,
    },
});