/**
*@author:Guoxiaohuan
*@date:2020.06.02
*@info：楼层列表
*/
<template>
    <div class='floor-box'>
        <div class='floor-list'>
            <i class='el-icon-caret-top icon-top' v-if='showT' @click='removeTop(num)'></i>
            <i class='el-icon-caret-top icon-top' v-else style='color:#ccc'></i>
            <div class='floor-out'>
                <div class='floor-center'>
                    <div
                        class='floor-item'
                        :class='item==floorId?"isActive":""'
                        @click='tabFloor(item,index)'
                        v-for='(item,index) in floorsArr'
                        :key='index'
                    >{{item}}</div>
                </div>
            </div>
            <i class='el-icon-caret-bottom icon-bottom' v-if='showB' @click='removeBottom(num)'></i>
            <i class='el-icon-caret-bottom icon-bottom' v-else style='color:#ccc'></i>
        </div>
    </div>
</template>
<script>
import { animate } from '@/utils/animate.js'
import { mapGetters } from 'vuex'
export default {
    data() {
        return {
            floorId: '',
            showT: true,
            showB: true,
            num: 0
        }
    },
    mounted() {
        this.removeBottom(-5)
        this.tabFloor()
    },
    computed: {
        ...mapGetters(['floorsArr'])
    },
    methods: {
        tabFloor(item = '1F', index) {
            this.showT = true
            this.showB = true
            this.$cookie.set('floorNow', item, 3)
            this.floorId = this.$cookie.get('floorNow') || item
            console.log(index)
            this.$emit('emitFloor', index + 1)
        },
        removeTop(num) {
            this.num = num
            var inner = document.querySelectorAll('.floor-item')
            var innerbox = document.querySelector('.floor-center')
            if (this.num < 0) {
                this.num++
            } else {
                this.num = 0
                this.showT = false
            }
            if (this.num <= 0) {
                animate(innerbox, { marginTop: 28 * this.num }, 500, function() {})
            }
        },
        removeBottom(num) {
            console.log(num)
            this.num = num
            var inner = document.querySelectorAll('.floor-item')
            var innerbox = document.querySelector('.floor-center')
            if (this.num > -(inner.length - 4)) {
                this.num--
            } else {
                this.num = -(inner.length - 4)
                this.showB = false
            }
            if (this.num > -(inner.length - 4)) {
                animate(innerbox, { marginTop: 28 * this.num }, 500, function() {})
            }
        }
    }
}
</script>
<style lang="less" scoped>
.floor-box {
    position: fixed;
    right: 32px;
    top: 196px;
    .floor-list {
        width: 44px;
        height: 212px;
        background: rgba(255, 255, 255, 1);
        box-shadow: 0px 2px 15px 0px rgba(31, 36, 41, 0.08);
        border-radius: 2px;
        position: relative;
        padding: 28px 4px;
        text-align: center;
        .floor-out {
            height: 160px;
            overflow: hidden;
            overflow-y: auto;
            position: relative;
            &::-webkit-scrollbar {
                display: none;
            }

            .floor-center {
                .floor-item {
                    width: 36px;
                    height: 28px;
                    margin: 3px 0;
                    cursor: pointer;
                }
            }
        }

        .icon-top {
            text-align: center;
            font-size: 18px;
            margin: 0 auto;
            display: flex;
            justify-content: center;
            position: absolute;
            top: 0;
            right: 0;
            width: 100%;
            cursor: pointer;
            margin-top: 5px;
        }
        .icon-bottom {
            text-align: center;
            font-size: 18px;
            margin: 0 auto;
            display: flex;
            justify-content: center;
            position: absolute;
            bottom: 0;
            right: 0;
            width: 100%;
            margin-bottom: 5px;
            cursor: pointer;
            line-height: 28px;
        }
        .isActive {
            border-radius: 4px;
            color: #025baa;
            background: #e1f2ff;
            line-height: 28px;
        }
    }
}
</style>