<template>
    <div class='auxiliary-room'>
        <div class='title'>辅助用房统计表</div>
        <div class='count'>
            <div class='left'>
                总间数(间)
                <i>{{listSummary.rooms || '--'}}</i>
            </div>
            <div class='right'>
                总面积(㎡)
                <i>{{listSummary.area || '--'}}</i>
            </div>
        </div>
        <div class='table'>
            <div class='header'>
                <div class='floor'>楼层</div>
                <div class='rooms'>总间数(间)</div>
                <div class='area'>面积(㎡)</div>
                <div class='operate'>操作</div>
            </div>
            <div class='content'>
                <div class='info' v-for='(item,index) in list' :key='index'>
                    <div class='floor'>{{item.floor}}</div>
                    <div class='rooms'>{{item.afterkf}}</div>
                    <div class='area'>{{item.area}}</div>
                    <div class='operate' @click='showImage(item)'>查看分布图</div>
                </div>
                <!-- <div class='info' v-for='item in 5' :key='item'>
                    <div class='floor'>F6</div>
                    <div class='rooms'>{{item}}</div>
                    <div class='area'>36</div>
                    <div class='operate' @click='showImage(item)'>查看分布图</div>
                </div>-->
            </div>
        </div>
        <!-- 现场照片预览 -->
        <ImagePreview :key='imgKey' class='update-img-preview' :visible.sync='showImgPreview' :imgList='imgList' />
    </div>
</template>
<script>
/**
 * 辅助用房
 */
import Vue from 'vue'
import { Button } from 'vant'
Vue.use(Button)
import ImagePreview from '@/components/ImagePreview'
import { mapGetters } from 'vuex'

import { querygcfzyfhz } from '@/api/other'
import { queryPic } from '@/api/public'
export default {
    name: 'AuxiliaryRoom',
    props: {},
    components: { ImagePreview },
    data() {
        return {
            list: [], //列表数据
            listSummary: {}, //汇总
            showImgPreview: false, //是否展示图片预览
            imgList: [], //图片数组
            imgKey: `img${new Date().getTime()}`,
        }
    },
    computed: {
        ...mapGetters(['plazaId', 'floorsArr']),
    },
    created() {
        this.getList()
    },
    beforeMount() {},
    mounted() {},
    methods: {
        async getList() {
            let getParams = {
                plazaId: this.plazaId,
                orderBy: 'floor,1',
            }
            let res = await querygcfzyfhz({ getParams })
            if (!res?.data) {
                return false
            }
            this.list = res.data
            //   afterkf: 5
            //         area: 179.5
            //         floor: "B1"
            //         recordtime: 1596055219000
            //         region: "B1"
            //     siteid: "1000423"
            // this.listSummary
            let rooms = 0,
                area = 0
            res.data.map((item) => {
                rooms += item.afterkf
                area += item.area
            })
            area = Number(area.toFixed(2))
            this.listSummary = { rooms, area }
            console.log(res)
        },
        /**
         *  显示分布图
         */
        async showImage(data) {
            /*   code: "F5"
            gcname: "f5"
            gcode: "5F"
            gname: "f5"
            seq: 500 */
            // 获取楼层
            this.imgKey = `img${new Date().getTime()}`
            const floor = this.floorsArr.filter((i) => i.code === data.floor)[0].gname
            let getParams = {
                module: '1004', // 固定1004
                floor: floor,
                plazaId: this.plazaId,
            }
            let res = await queryPic({ getParams })
            if (!res?.data) {
                this.imgList = []
                return false
            }
            let imgList = []
            res.data.map((item) => {
                imgList.push(item.url)
            })
            this.imgList = imgList
            imgList.length && (this.showImgPreview = true)
        },
    },
}
</script>
<style lang='less' scoped>
.auxiliary-room {
    width: 100%;
    height: 100%;
    overflow: hidden;
    // background-color: cyan;
    padding: 16px;
    .title {
        width: 100%;
        height: 20px;
        font-size: 16px;
        font-weight: 500;
        color: #333333;
        line-height: 22px;
    }
    .count {
        margin-top: 15px;
        height: 20px;
        font-size: 14px;
        font-weight: 400;
        color: #666666;
        line-height: 20px;
        width: 100%;
        display: flex;
        justify-content: space-between;
        i {
            color: #333;
            font-weight: 500;
            margin-left: 8px;
        }
    }
    // 表格内容
    .table {
        width: 100%;
        height: calc(100% - 65px);
        margin-top: 10px;
        .header {
            width: 100%;
            height: 40px;
            font-size: 14px;
            font-weight: 400;
            color: #666666;
            line-height: 40px;
            display: flex;
            justify-content: space-between;
            background-color: #eff0f1;
            padding: 0 15px;
        }
        .content {
            height: calc(100% - 40px);
            overflow: auto;
        }
        .info {
            width: 100%;
            height: 40px;
            line-height: 40px;
            display: flex;
            justify-content: space-between;
            padding: 0 15px;
            font-size: 14px;
            font-weight: 400;
            color: #333333;
            border-bottom: 1px solid #eff0f1;
        }
        .header,
        .info {
            .floor {
                flex: 2;
            }
            .rooms {
                flex: 3;
            }
            .area {
                flex: 3;
            }
            .operate {
                flex: 3;
                color: #025baa;
            }
        }
        .header .operate {
            color: #666;
        }
    }
}
</style>