<template>
    <div class='box'>
        <div class='condition'>
            <p>
                <span style="margin-right: 12px">建筑名称</span>
                <el-select v-model='buildVlaue' placeholder='请选择'>
                    <el-option
                        v-for='item in options'
                        :key='item.BuildId'
                        :label='item.BuildLocalName'
                        :value='item.BuildId'
                    ></el-option>
                </el-select>
            </p>
        </div>
        <el-tabs v-model='activeName' @tab-click='handleClick' style="background:#fff">
            <el-tab-pane label='现场无法找到的资产' name='first'>
                <saga-nofind :buildVlaue='buildVlaue' :floorsObj='floorsObj'></saga-nofind>
            </el-tab-pane>
            <el-tab-pane label='未画入模型的资产' name='second'>
                <saga-nopaint :buildVlaue='buildVlaue' :floorsObj='floorsObj'></saga-nopaint>
            </el-tab-pane>
            <el-tab-pane label='无对应岗位的资产' name='third'>
                <saga-nomap :buildVlaue='buildVlaue' :floorsObj='floorsObj' :allFamilyObj='allFamilyObj'></saga-nomap>
            </el-tab-pane>
            <el-tab-pane label='未扫楼验证的资产' name='fourth'>
                <saga-verify :buildVlaue='buildVlaue' :floorsObj='floorsObj' :allEquipObj='allEquipObj'></saga-verify>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
import SagaNofind from './Nofind'
import SagaNopaint from './Nopaint'
import SagaNomap from './Nomap'
import SagaVerify from './Noverify'
import { mapGetters } from 'vuex'
//api
import {
    getBuildSelect, //根据项目ID获得建筑列表
    getAllbusiness,
    getAllFamily
} from '@/api/scan/request'
export default {
    name: 'build-assets',
    data() {
        return {
            activeName: 'first',
            buildVlaue: '',
            options: [],
            floorsObj: {},
            allFamilyObj: {}, 
            allEquipObj: {}
        }
    },
    computed: {
        ...mapGetters('layout', ['projectId', 'userId', 'secret'])
    },
    components: {
        SagaNofind,
        SagaNopaint,
        SagaNomap,
        SagaVerify
    },
    methods: {
        handleClick() {},
        //获取建筑列表
        getBuilding() {
            let param = {
                ProjId: this.projectId,
                UserId: this.userId
            }
            getBuildSelect(param).then(res => {
                if (res.data.Result == 'success') {
                    let data = res.data.BuildList
                    this.options = data
                    this.buildVlaue = data.length ? data[0].BuildId : ''
                }
            })
        },
        //获取所有楼层
        getFloors() {
            let param = {
                ProjId: this.projectId,
                secret: this.secret,
                id: this.projectId,
                type: ['Fl']
            }
            getAllbusiness(param).then(res => {
                if (res.data.Result == 'success') {
                    res.data.Content.forEach(item => {                        
                        this.floorsObj[item.infos.FloorID] = item.infos.FloorLocalName
                    })

                }
            })
        },
        //获取设备组
        getAllFamily() {
            getAllFamily().then(result => {
                    if (result.data.Result == "success") {
                        console.log(result.data.Content)
                        let list = result.data.Content;
                        list.forEach(ele => {
                            this.allFamilyObj[ele.code] = ele
                        })  
                        this.allEquipObj = {}
                        this.getEquip(list)              
                    }
                });
        },
        getEquip(list) {
            list.forEach(ele => {
                if(ele.content) {
                    ele.content.forEach(keng => {
                        this.allEquipObj[keng.code] = keng.name
                    })
                }
            })
        },
        async init() {
            await this.getAllFamily();
            await this.getFloors();
            await this.getBuilding()
        }
    },
    created() {
        this.init()
    },
    watch: {
        projectId(){
            this.init()
        }
    }
}
</script>

<style scoped lang='less'>
.box {
    .condition {
        padding: 10px;
        display: flex;
        border: 1px solid #dfe6ec;
        background:#fff;
        margin-bottom: 10px;
    }
    /deep/ .el-tabs__nav{
        margin-left: 10px;
    }
}
</style>

