<template>
    <div class="rules" v-if="showData">
        <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 { sysTenantConfig } from './api'
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: {},
            showData: false,
        }
    },
    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() {
            try {
                this.showData = false
                let offRes = await await sysTenantConfig({ group: "OFFLINE" })
                const offData = offRes.data || []
                offData.forEach(off => {
                    this.dataList[off.paramName] = off.paranValue
                });

                let onRes = await await sysTenantConfig({ group: "ONLINE" })
                const forwardRes = await sysTenantConfig({ group: "DAYA_BASIC" });
                const onData = onRes.data || []
                onData.forEach(on => {
                    this.dataList[on.paramName] = on.paranValue
                })
                const forwardData = forwardRes.data || []
                forwardData.forEach(forward => {
                    this.dataList[forward.paramName] = forward.paranValue
                })
                this.showData = true
            } catch(e) {}
        }
    }
}
</script>