<template>
    <div class="page-table-template" style='display: flex;flex-direction: column;flex-grow: 1;flex-shrink: 1;'>
        <el-table :data='tableData' style='width: 100%' border class='data-table' v-loading='loading'>
            <el-table-column header-align='center' align='center' prop='BuildName' label='建筑'></el-table-column>、
            <el-table-column header-align='center' align='center' prop='floorName' label='楼层'></el-table-column>
            <el-table-column header-align='center' align='center' prop='FamilyName' label='设备族'></el-table-column>
            <el-table-column header-align='center' align='center' prop='FmId' label='本地编码' width='250'></el-table-column>
            <el-table-column header-align='center' align='center' prop='FmName' label='本地名称'></el-table-column>
            <el-table-column header-align='center' align='center' prop='FmName' label='所在元空间'></el-table-column>
            <el-table-column header-align='center' align='center' prop='FmName' label='对应设备类'></el-table-column>
            <el-table-column header-align='center' align='center' prop='bimXY' label='BIM模型中坐标'></el-table-column>
            <el-table-column header-align='center' align='center' prop='PointName' label='操作' width='220'>
                <template slot-scope='scope'>
                    <el-button type='primary' plain size='mini' @click='look(scope.row)'>查看</el-button>
                    <el-button type='primary' plain size='mini' @click='post(scope.row)'>岗位</el-button>
                    <el-button type='danger' plain size='mini' @click='del(scope.row)'>删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <base-pagination class='data-table-pagination' :currentPages='pageNum' :total='total' @pageChanged='pageChanged'></base-pagination>
        <saga-dialog ref='dialog' :iframeSrc='iframeSrc'></saga-dialog>
    </div>
</template>

<script>
import { mapGetters } from 'vuex'
import SagaDialog from './Frame'
//api
import {
    getErrAssets, //获取异常资产type不同不同tab
    delErrAssets,
    getSpaceId
} from '@/api/scan/request'
export default {
    name: 'noverify',
    data() {
        return {
            loading: false,
            tableData: [],
            total: 0,
            pageNum: 1,
            pageSize: 10,
            iframeSrc: ''
        }
    },
    props: {
        buildVlaue: {
            default: ''
        },
        floorsObj: {
            default: {}
        }
    },
    components: {
        SagaDialog
    },
    computed: {
        ...mapGetters('peojMess', ['projectId', 'userId', 'secret'])
    },
    methods: {
        look(row) {
            this.iframeSrc =
                process.env.BASE_URL +
                ':8889/#/details?perjectId=' +
                this.projectId +
                '&secret=' +
                this.secret +
                '&FmId=' +
                row.FmId +
                '&type=1&code=' +
                row.Family
            this.$refs['dialog'].show()
        },
        post(row) {
            this.iframeSrc =
                process.env.BASE_URL +
                ':8889/#/details?perjectId=' +
                this.projectId +
                '&secret=' +
                this.secret +
                '&FmId=' +
                row.FmId +
                '&type=1&code=' +
                row.Family
            this.$refs['dialog'].show()
        },
        del(row) {
            this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    let param = {
                        ProjId: this.projectId,
                        UserId: this.userId
                    }
                    let paramList = [row.FmId]
                    delErrAssets(param, paramList).then(result => {
                        if (result.data.Result == 'success') {
                            this.getAsset()
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            })
                        }
                    })
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
        },
        pageChanged(page, size) {
            this.pageNum = page
            this.pageSize = size
            this.getAsset()
        },
        getAsset() {
            this.loading = true
            let param = {
                BuildId: this.buildVlaue || undefined,
                PageNum: this.pageNum,
                PageSize: this.pageSize,
                Type: 4,
                ProjId: this.projectId,
                UserId: this.userId,
                CodeType: 1
            }
            getErrAssets(param).then(res => {
                                    // this.tableData = list
                if (res.data.Result == 'success') {
                    this.loading = false
                    let list = res.data.FmList
                    list.forEach((ele, index) => {
                        ele.floorName = this.floorsObj[ele.FloorId] || '--'
                        ele.bimXY = (ele.X || '空') + ',' + (ele.Y || '空')
                    })
                    this.total = res.data.Count
                    this.tableData = list
                    // this.getSpaceId()
                }
            })
        },
        getSpaceId() {
            let param = {},
                idArr = [],
                i = 0,
                dataArr = this.tableData
            for (; i < dataArr.length; i++) {
                if (dataArr[i].EquipmentId) {
                    idArr.push({
                        from_id: dataArr[i].EquipmentId,
                        graph_id: 'GtEquipinSpace001',
                        rel_type: '1'
                    })
                }
            }
            param = {
                perjectId: this.projectId,
                secret: this.secret,
                list: idArr
            }
            getSpaceId(param).then(res => {
                let data = res.data,
                    spaceArr = [],
                    j = 0
                if (data.Result == 'success') {
                    for (; j < data.Content.length; j++) {     
                        console.log('space**********')                   
                        console.log(data.Content)
                        // if (data.Content[j].Count != 0) {
                        //     spaceArr.push({
                        //         id: data.Content[j].Content[0].to_id
                        //     })
                        //     dataArr.map(item => {
                        //         if (item.EquipmentId == data.Content[j].Content[0].from_id) {
                        //             item.spaceId = data.Content[j].Content[0].to_id
                        //         }
                        //         return item
                        //     })
                        // }
                    }
                    console.log(dataArr, 'dataArr')
                    // this.getSpaceName(spaceArr)
                } else {
                }
            })
        }
    },
    watch: {
        buildVlaue() {
            this.getAsset()
        }
    }
}
</script>

<style scoped lang='less'>
</style>
