<!-- 数字翻牌器 -->
<template>
    <div class="number-flipper">
        <div class="up" v-if="title">
            <div class="i" />{{title}}
        </div>
        <div class="down">
            <num :number="relNumber" />
            <span class="unit">{{unit}}</span>
        </div>
    </div>
</template>

<script>
    import Num from './num.vue'
    export default {
        components: {
            Num,
        },
        props: {
            title: {
                type: String,
                default: '',
            },
            unit: {
                type: String,
                default: '',
            },
            number: {
                type: Number | String,
                default: 0,
            },
            // 小数位数
            point: {
                type:Number,
                default: 0,
            }
        },
        data() {
            return {
                relNumber: 0,
            }
        },
        watch: {
            number: {
                immediate: true,
                handler(val) {
                    this.relNumber = parseFloat(val).toFixed(this.point < 0 ? 0 : this.point);
                }
            }
        },
    }
</script>
<style lang="scss" scoped>
    .number-flipper {
        .up{
            color: $color-cyan;
            @extend %flex-center;
            margin-bottom: 0.5rem;
            
            .i {
                width: 0.2rem;
                height: 0.2rem;
                border-radius: 50%;
                background: $color-cyan;
                box-shadow: 0 0 0.12rem 0.15rem rgba($color: $color-cyan, $alpha: 0.3);
                margin-right: 0.5rem;
            }
        }
        
        .down{
            display: flex;
            justify-content: center;
            align-items: flex-end;
            .unit{
                font-size: 0.875rem;
                color: $color-cyan;
            }
        }
    }
</style>
