<template>
    <view>
        <view class="login_menu">
            <image class="logo" src="https://static.caimei365.com/app/img/supplier-login/logo_.png" mode="" @click="trampLink"></image>
            <view class="menu_slide">
                <scroll-view
                    scroll-x="true"
                    class="scroll-view"
                    @scroll="scroll"
                    :scroll-into-view="activeMenu"
                    :scroll-with-animation="true"
                >
                    <view
                        :id="'item' + item.id"
                        class="scroll_menu"
                        v-for="item in menuList"
                        @click="handlerActiveLink(item)"
                        :key="item.id"
                    >
                        {{ item.title }}
                    </view>
                </scroll-view>
            </view>
            <view class="check_menu" @click="scrollintoview">
                <text class="cell-more iconfont icon-xiayibu" :class="actbtn ? 'act-btn' : ''"></text>
            </view>
        </view>
        <MenuTopDropdown :show="dropdownShow" @close="closeTopDrop" translatey="100" height="260" maskTop="100">
            <view class="menuList">
                <button>全部目录</button>
                <button
                    type="default"
                    class="menu-btn"
                    :class="isActive === item.id ? 'isActive' : ''"
                    v-for="item in menuList"
                    :key="item.id"
                    @click="handlerNavLink(item)"
                >
                    {{ item.title }}
                </button>
            </view>
        </MenuTopDropdown>
    </view>
</template>

<script>
import MenuTopDropdown from './menuTopDropdown'
export default {
    components: {
        MenuTopDropdown
    },
    props: {
        menuList: {
            type: Array,
            default: () => []
        }
    },
    data() {
        return {
            activeMenu: '', // 滚动id
            dropdownShow: false,
            isActive: 0, // 活动链接
            actbtn: false
        }
    },
    watch: {},
    methods: {
        // 滚动菜单
        scroll($event) {
            this.activeMenu = ''
        },
        scrollintoview() {
            // this.activeMenu = 'item4'
            this.dropdownShow = !this.dropdownShow
            this.actbtn = !this.actbtn
        },
        closeTopDrop() {
            this.dropdownShow = false
            this.actbtn = false
        },
        handlerNavLink($event) {
            this.isActive = $event.id
            this.activeMenu = 'item' + $event.id
            this.dropdownShow = false
            this.actbtn = false
            this.$emit('scrollPage', this.activeMenu)
        },
        handlerActiveLink($event) {
            this.isActive = $event.id
            this.activeMenu = 'item' + $event.id
            this.$emit('scrollPage', this.activeMenu)
        },
        trampLink() {
            uni.navigateTo({
                url: '/pages/supplier/index/index'
            })
        }
    }
}
</script>

<style scoped lang="scss">
.login_menu {
    width: 100%;
    height: 100rpx;
    background-color: #fff;
    box-shadow: 0rpx 5rpx 14rpx 0rpx rgba(51, 51, 51, 0.12);
    box-sizing: border-box;
    padding: 26rpx 40rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 999;
}
.logo {
    width: 132rpx;
    height: 48rpx;
}
.scroll-view {
    white-space: nowrap;
    width: 100%;
}
.menu_slide {
    width: 530rpx;
    box-sizing: border-box;
    padding: 0 106rpx 0 40rpx;
    .scroll_menu {
        width: 150rpx;
        font-size: 28rpx;
        color: #333;
        display: inline-block;
        text-align: center;
        box-sizing: border-box;
        padding-left: 20rpx;
    }
}
.check_menu {
    position: absolute;
    top: 0;
    right: 0;
    width: 148rpx;
    height: 100rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    box-shadow: -10px 0px 10px 0 #fff;
}
.menuList {
    width: 100%;
    height: 100%;
    background-color: #fff;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    align-items: center;
    padding: 20rpx 0;
    box-sizing: border-box;
}
.menu-btn {
    width: 148rpx;
    height: 64rpx;
    background: #f5f5f5;
    border-radius: 32rpx;
    font-size: 24rpx;
    text-align: center;
    color: #666666;
    line-height: 64rpx;
}
.isActive {
    border: 1px solid #ff5b00;
    color: #ff5b00;
    background: #fff;
}
.iconfont {
    transition: 0.2s;
}
.icon-xiayibu {
    transform: rotate(90deg);
}
.act-btn {
    transform: rotate(270deg) !important;
}
</style>
