<template>
    <div class="rules">
        <on-line v-if="type == 'onLine' || !type" :dataList="dataList" />
        <off-line v-if="type == 'offLine' || !type" :dataList="dataList" />
        <vip-off-line v-if="type == 'vipOffLine' || !type" :dataList="dataList" />
    </div>
</template>

<script>
import { sysConfigList } from './api'
import setLoading from '@/utils/loading'
import OnLine from './components/onLine'
import OffLine from './components/offLine'
import vipOffLine from './components/vipOffLine'
export default {
    components: { OnLine, OffLine, vipOffLine },
    data() {
        let query = this.$route.query
        return {
            type: query.type || null,
            dataList: {}
        }
    },
    mounted() {
        let params = this.$route.query
        if(params.Authorization) {
            localStorage.setItem('Authorization', decodeURI(params.Authorization))
            localStorage.setItem('userInfo', decodeURI(params.Authorization))
        }
        document.title = '规则'
        this.__init()
    },
    methods: {
        async __init() {
            setLoading(true)
            await sysConfigList().then(res => {
                const result = res.data
                if(result.code == 200) {
                    const { data } = result
                    const dataList = {}
                    data.forEach(item => {
                        switch(item.paramName) {
                            case 'advance_sign_in_minutes':
                                // 老师正常打卡时间，为课程当天，距离开课时间前{}分钟
                                dataList.advance_sign_in_minutes = item.paranValue
                                break;
                            case 'attendance_range':
                                dataList.attendance_range = item.paranValue
                                break;
                            case 'enable_student_attendance_time_range_vip':
                                dataList.enable_student_attendance_time_range_vip = item.paranValue
                                break;
                            case 'enable_student_attendance_befor_course_start_time_range_vip':
                                dataList.enable_student_attendance_befor_course_start_time_range_vip = item.paranValue
                                break;
                            case 'attendance_range_vip':
                                dataList.attendance_range_vip = item.paranValue
                                break;
                        }
                    });
                    this.dataList = dataList
                }
            })
            setLoading(false)
        }
    }
}
</script>

<style lang="less" scoped>
.rules {
    background: #ffffff;
}
table {
    border: 0;
    font-size: 12px;
    border-color: #cccccc;
    th {
        text-align: center;
    }
    th, td {
        padding: 5px;
    }
    tr:nth-child(even) {
        background-color: #f1f1f1;
    }
}
table + table {
    margin-top: .15rem;
}
.r {
    color: red;
}
</style>
