<template>
    <view class="container">
        <cu-custom id="custom"
            bgImage="https://yostest175549.obs.cn-east-2.myhuaweicloud.com:443/202306151686796745663B52544232.png"
            :isBack="true">
            <block slot="backText">返回</block>
            <block slot="content">
                设备中心
            </block>
        </cu-custom>
        <list ref="设备列表" v-show="PageCur == '设备列表'" :istabbar="true" />
		<my-map ref="设备地图" v-show="PageCur == '设备地图'" />


        <view v-if="istabbar" class="cu-bar tabbar bg-white foot" style="z-index: 100000;">
            <view v-for="item in pageList" :key="item.label"
                :class="PageCur == item.label ? 'action pitch-on-color' : 'action text-gray'">
                <view class="iconfont" :class="item.icon" @click="changePage(item.label)" />
                {{ item.label }}
            </view>
        </view>
    </view>
</template>

<script>
import list from "./modules/list"
import myMap from "../../pages/facility/my-map.vue";


export default {
    components: { list, myMap },
    name: "facility",
    data() {
        return {
            istabbar: false,
            PageCur: "",
            pageList: []
        }
    },
    mounted() {
        let authList = uni.getStorageSync('authList')['设备中心'],
            pageList = [{
                label: "设备列表",
                icon: "icon-xunjianzhongxin"
            }, {
                label: "设备地图",
                icon: "icon-ditu-xuanzhong"
            }].filter(v => authList[v.label] && authList[v.label].option.some(s => s == 'read'));
        if (pageList.length) {
            this.pageList = pageList;
            this.PageCur = pageList[0].label;
            this.istabbar = pageList.length > 1;
            this.loadElement();
        } else {
            uni.showToast({
                title: '未查询到可用应用',
                icon: "none",
                mask: true,
            });
        }
    },
    methods: {
        changePage(page) {
            this.PageCur = page;
            this.loadElement()
        },
        loadElement(forcedUpdating) {
            let page = this.$refs[this.PageCur];
            if (page.uninitialized || forcedUpdating) page.init();
        }
    }
}
</script>

<style lang="scss" scoped></style>
