ResultModal.js 6.73 KB
import React, { Component} from 'react';
import {
    View,
    Text,
    StyleSheet,
    TouchableWithoutFeedback,
    PixelRatio,
    TouchableOpacity,
    Image, Platform
} from 'react-native';
import PropTypes from 'prop-types';
// import {FadeModal} from '../../utils/SceneConfig';
import {subList, getCorrect, getScore} from '../../utils/excer';
import {width, height} from '../../utils/getSize';
import {observer} from 'mobx-react/native'
const styles = StyleSheet.create({
    background: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: 'rgba(0,0,0,0.5)',
    },
    content: {
        width: width - 30,
        height: 355,
        backgroundColor: 'white',

        overflow: 'visible',
        borderBottomLeftRadius: 5,
        borderBottomRightRadius: 5,
        borderTopLeftRadius: 5,
        borderTopRightRadius: 5
    },
    topView: {
        height: 155,
        width: width - 30,
        backgroundColor: "rgb(218,77,79)",
        alignItems: 'center',
        justifyContent: 'center',
        borderTopLeftRadius: 5,
        borderTopRightRadius: 5
    },
    circle: {
        borderWidth: 3,
        borderColor: "#ffde02",
        width: 80,
        height: 80,
        borderRadius: 80,
        alignItems: 'center',
        justifyContent: 'center'
    },
    grade: {
        width: 50,
        height: 40,
        borderWidth: 1,
        backgroundColor: 'transparent',
        alignItems: 'center',
        justifyContent: 'center',
        borderTopWidth: 0,
        borderBottomWidth: 1 / PixelRatio.get(),
        borderLeftWidth: 0,
        borderRightWidth: 0,
        borderBottomColor: '#fff'
    },
    fontGrade: {
        fontSize: 25,
        fontWeight: 'bold',
        color: "#fff"
    },
    fontTitle: {
        fontSize: 15,
        color: '#fff',
        textAlign: 'center',
        marginTop: 5
    },
    body: {
        height: 200,
        width: width - 30,
        backgroundColor: 'rgb(254,255,255)',
        alignItems: 'center',
        borderBottomLeftRadius: 5,
        borderBottomRightRadius: 5,
        overflow: 'visible'
    },
    fontR: {
        fontSize: 14,
        fontWeight: 'bold',
        // textAlign:'center',
        color: '#e52d43',
        marginTop: 40
    },
    info: {
        flexDirection: 'row',
        flexWrap: 'wrap',
        width: width - 120,
        marginTop: 30
    },
    mCircle: {
        width: 35,
        height: 35,
        backgroundColor: '#e52d43',
        borderRadius: 17.5,
        margin: 7.5,
        alignItems: 'center',
        justifyContent: 'center'
    },
    font2: {
        fontSize: 14,
        color: 'white'
    },
    imgCeshi: {
        position: 'absolute',
        top: __IOS__ ? (height - 355 - 20) / 2 : (height - 355 - 40) / 2,
        left: (width - 180) / 2
    },
    circleBar: {
        width: width - 30,
        height: 20,
        position: 'absolute',
        top: 145,
        alignItems: 'center',
        flexDirection: 'row'
    },
    circleItem: {
        width: 14,
        height: 14,
        borderRadius: __IOS__ ? 14 : 7,
        backgroundColor: 'rgb(254,255,255)',
        marginLeft: 3,
        marginRight: 3
    }
});

const ceshijieguo = require('../../img/ceshijieguo.png');
const __IOS__ = Platform.OS == "ios";

@observer
export default class ResultModal extends Component {
    // static sceneConfig = FadeModal;
    // static contextTypes = {
    //     navigator: PropTypes.object,
    // };

    static navigationOptions = ({navigation, screenProps}) => ({
        header: null
    });
    constructor(props) {
        super(props);
    }

    dismiss = () => {
        this.props.navigation.pop();
        // const {navigator} = this.context;
        // navigator.pop();
        // global.cache.pointBalance = global.cache.pointBalance + getScore();
    };
    load = (id) => {
        // this.context.navigator.push({
        //     location: '/subject/exercises',
        //     passProps: {
        //         CurrentId:id,
        //         type:'resultModal',
        //         testTitle:this.props.testTitle
        //     }
        // })
        this.props.navigation.navigate('Exercises',{CurrentId:id, type:'resultModal', testTitle:this.props.testTitle});


    }
    dismissTo = () => {
        this.dismiss();
    };

    renderCircle = (v, i) => {
        if (v.value_correct) {
            return (
                <TouchableOpacity onPress={() => this.load(v.id)} style={styles.mCircle} key={i}>
                  <Text style={styles.font2}>{String(v.id)}</Text>
                </TouchableOpacity>
            )
        } else {
            return (
                <TouchableOpacity onPress={() => this.load(v.id)} style={[styles.mCircle, {backgroundColor: '#dddddd'}]}
                                  key={i}>
                  <Text style={styles.font2}>{String(v.id)}</Text>
                </TouchableOpacity>
            )
        }
    }

    componentWillMount() {
        // this.props.do()
        if (this.props.navigation.state.params.do){
            this.props.navigation.state.params.do();
        }

    }

    render() {
        console.log(subList);
        var num = Math.floor((width - 30) / 20);
        return (
            <TouchableWithoutFeedback onPress={this.dismissTo}>
              <View style={styles.background}>
                <TouchableWithoutFeedback>
                  <View style={styles.content}>

                    <View style={styles.topView}>
                      <View style={styles.circle}>
                        <View style={styles.grade}>
                          <Text style={styles.fontGrade}>{getScore()}</Text>
                        </View>
                        <Text style={styles.fontTitle}>积分</Text>
                      </View>
                    </View>

                    <View style={styles.body}>

                      <Text style={styles.fontR}>{getCorrect()}题,错{subList.length - getCorrect()}</Text>
                      <View style={styles.info}>
                          {
                              subList.slice(0).map((v, i) => this.renderCircle(v, i))
                          }
                      </View>
                    </View>
                    <View style={styles.circleBar}>
                        {
                            Object.keys(Array.from({length: num})).map((v, i) => <View
                                style={styles.circleItem} key={i}>

                            </View>)
                        }
                    </View>

                  </View>

                </TouchableWithoutFeedback>
                <Image
                    source={ceshijieguo}
                    style={styles.imgCeshi}
                />
              </View>
            </TouchableWithoutFeedback>
        );
    }
}