<template>
    <el-radio-group v-model="nearRadio" size="small" @change="getDate">
        <el-radio-button label="all">全部</el-radio-button>
        <el-radio-button  v-for="(item, index) in nearShowData" :key="item.id" :label="item.label">{{item.text}}</el-radio-button>   
    </el-radio-group>
</template>

<script>
import TimeFormat from '../TimeFormat'
export default {
    name: 'NearRadio',
    model: {
        prop: 'TIME',
        event: 'change'
    },
    props: {
        TIEM: Object,
        defaultTime: {
            type: Array,
            default:() => {
                return ['1h','24h','toady','yesterday','week','lastweek','7d','14d','30d','month','lastmonth']
            } 
        }
    },
    data() {
        return {
            nearRadio: "all",
            nearOriginalData: [
                {
                    id: 0,
                    label: '1h',
                    text: '最近一小时'
                },{
                    id: 1,
                    label: '24h',
                    text: '最近24小时'
                },{
                    id: 2,
                    label: 'toady',
                    text: '今日'
                },{
                    id: 3,
                    label: 'yesterday',
                    text: '昨日'
                },{
                    id: 4,
                    label: 'week',
                    text: '本周'
                },{
                    id: 5,
                    label: 'lastweek',
                    text: '上周'
                },{
                    id: 6,
                    label: '7d',
                    text: '最近7天'
                },{
                    id: 7,
                    label: '14d',
                    text: '最近14天'
                },{
                    id: 8,
                    label: '30d',
                    text: '最近30天'
                },{
                    id: 9,
                    label: 'month',
                    text: '本月'
                },{
                    id: 10,
                    label: 'lastmonth',
                    text: '上月'
                },
            ],
        }
    },
    computed: {
        nearShowData() {
            let defaultArr = this.defaultTime
            let originalArr = this.nearOriginalData
            let newArr = []
            defaultArr.map((item, index) => {
                let arr = originalArr.filter((value, i) => {
                    return value.label == item  
                })
                newArr = newArr.concat(arr)
            })
            return newArr
        }
    },
    methods: {
        getDate(e) {
            let obj = ''
            switch(e) {
                case 'all':
                    console.log('全部')
                    break;
                case '1h':
                    obj = TimeFormat.getOneHour()
                    break;
                case '24h':
                    obj = TimeFormat.get24Hours()
                    break;
                case 'toady':
                    obj = TimeFormat.getToday()
                    break; 
                case 'yesterday':
                    obj = TimeFormat.getYesterday()
                    break;
                case 'week':
                    obj = TimeFormat.getCurrWeekDays()
                    break;
                case 'lastweek':
                    obj = TimeFormat.getLastWeekDays()
                    break;
                case '7d':
                    obj = TimeFormat.getNear7Days()
                    break;
                case '14d':
                    obj = TimeFormat.getNear14Days()
                    break;
                case '30d':
                    obj = TimeFormat.getNear30Days()
                    break;
                case 'month':
                    obj = TimeFormat.getCurrMonthDays()
                    break;
                case 'lastmonth':
                    obj = TimeFormat.getLastMonthDays()
                    break;   
            }
            this.$emit('change', obj)
        }
    }
}
</script>

<style>

</style>