<template>
    <div class="bim-setting-page">
        <div id="bimSettingContainer"></div>
        <model-floor-tree ref="modelFloorTree" :projectMessage="models" v-if="showTree"></model-floor-tree>
    </div>
</template>

<script>
import useUserStore from '@/store/modules/user'
import { listBimModel } from '@/api/bim/bimModel'
import ModelFloorTree from './ModelFloorTree.vue'
export default {
    components: {
        ModelFloorTree,
    },
    data() {
        return {
            userStore: {},
            isAdmin: false,
            projects: [],
            currentPrjId: null,
            currentComId: null,
            subDepts: [],
            models: [],
            showTree: false,
            initSuccess: false,
        }
    },
    beforeUnmount() {
        document.body.classList.remove('is-sapi')
    },
    mounted() {
        document.body.classList.add('is-sapi')
        this.userStore = useUserStore()
        this.isAdmin = this.userStore.isAdmin
        this.currentPrjId = this.userStore.currentPrjId
        this.currentComId = this.userStore.currentComId
        this.initLoadModel()
        this.initEngine()
    },
    methods: {
        initEngine() {
            window.api = new SAPI(
                {
                    serverIP: window.config.serverIP, //服务ip地址
                    port: window.config.port, //HTTP端口
                    useHttps: window.config.useHttps, //使用Https
                    container: 'bimSettingContainer', //[必须]容器id
                    secretKey: window.config.secretKey,
                    openEarth: window.config.openEarth, //[可选]开启Gis场景
                    bgColor: window.config.bgColor, //[可选]bim场景背景色, 传值即为纯色天空盒
                    tintColor: window.config.tintColor, //[可选]osgb单体化颜色
                    sceneTime: window.config.sceneTime, //[可选]分别为当前时间、日出时间、日落时间
                    cadMode: window.config.cadMode, // 是否是Cad图纸预览模式
                },
                () => {
                    this.initSuccess = true
                    console.log('初始化成功')
                }
            )
        },
        initLoadModel() {
            listBimModel({
                pageNum: 1,
                pageSize: 10,
                comId: this.currentComId,
                projectId: this.currentPrjId,
            }).then((d) => {
                this.models = d.rows || []
                if (this.models.length == 0) {
                    this.$model.msgError('暂无模型，请先关联模型')
                } else {
                    this.showTree = true
                }
            })
        },
    },
}
</script>

<style lang="scss">
.bim-setting-page {
    position: relative;
    height: 100%;
    #bimSettingContainer {
        height: 100%;
    }
}
body.is-sapi {
    .app-main {
        height: calc(100vh - 84px);
    }
}
</style>