<template>
    <div id="sub-report">
        <KeepAlive>
            <router-view></router-view>
        </KeepAlive>
    </div>
</template>
<script>
import globalData from '@/components/common/globaldata/global.data';
import ajaxAuth from '@/script/api/auth.js';
export default {
    data() {
        return {
            buttonperm: [],
            items: [
            ]
        };
    },
    created() {
        console.log(process.env)
        console.log(this.$root);
        //    console.log(this.$root.parentStore.state);
        if (this.$root.parentStore) {
            let token = this.$root.parentStore.state.user.token;
            globalData.token = token;
            window.localStorage.setItem('token', token);
            globalData.initUserAuth();
            this.sleep(300); 
            this.userMenu();
           
                globalData.initSelfCityStation();
                globalData.initHmCityStation();
                globalData.getLocationAllInOne();
           
            this.sleep(300);
        }


    },
    methods: {
        sleep(delay) {
            var start = (new Date()).getTime();
            while ((new Date()).getTime() - start < delay) {
                continue;
            }
        },
        whilenode(treeMenu) {
            //遍历这颗树 
            let node = [];
            for (let i = 0; i < treeMenu.length; i++) {
                if (treeMenu[i].menuType == 'page' || treeMenu[i].menuType == 'iframe') {
                    //如果是true就是隐藏，不显示再右边菜单，但能用
                    let line = {
                        icon: treeMenu[i].icon,
                        index: treeMenu[i].menuUrl,
                        title: treeMenu[i].menuName
                        //subs: []
                    };
                    let subs = [];
                    if (null != treeMenu[i].childMenu && treeMenu[i].childMenu.length > 0) {
                        subs = this.whilenode(treeMenu[i].childMenu);
                    }
                    if (subs.length > 0) {
                        //console.log(children);
                        line.subs = subs;
                    }
                    node = node.concat(line);
                } else {
                    this.buttonperm.push(treeMenu[i].menuUrl);
                }
            }
            return node;
        },
        userMenu() {
            ajaxAuth
                .$ajaxSelectusermenu({
                    userId: this.$root.parentStore.state.user.id
                })
                .then(res => {
                    if (res.data.errno == 402 || res.data.errno == '402' || res.data.errno != 0) {
                        this.$message.warning('身份认证失败，请登陆！');
                        this.$router.push('/login');
                    } else {
                        this.items = this.whilenode(res.data.data.menuTree); //系统菜单加载
                        // console.log(this.items);
                        window.localStorage.setItem('menulist', JSON.stringify(res.data.data.menulist));
                        window.localStorage.setItem('buttonperm', JSON.stringify(this.buttonperm));
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        }
    },


}
</script>
<style>
.crumbs {
    margin: 10px 0;
    display: none !important;
}

/* @import "./assets/css/main.css";
@import "./assets/css/color-dark.css"; */
/*深色主题*/
/*@import "./assets/css/theme-green/color-green.css";   浅绿色主题*/
</style>