header-machine.vue 3.28 KB
<template>
    <section class="select-machine">
        <div class="current-machine" @click="onDropdown">
            <div class="icon">
                <img class="image" :src="selecteditem.image" alt="" />
            </div>
            <div class="description">
                <div class="name" v-text="selecteditem.name" />
                <div class="size" v-text="selecteditem.size" />
            </div>
            <div class="dropIcon">
                <img :src="selectIcon" alt="" />
            </div>
        </div>
        <div class="selectitems" v-show="isSelectitemsVisible" @mouseleave="onMouseout">
            <div v-for="item in items" :key="item" :index="item.key" class="select-item" @click="onSelect(item.key)">
                <div class="icon">
                    <img class="image" :src="item.image" alt="" />
                </div>
                <div class="description">
                    <div class="name" v-text="item.name" />
                    <div class="size" v-text="item.size" />
                </div>
            </div>
        </div>
    </section>
</template>
<script setup>
import DROPDOWNICON from '@/views/assets/images/header-machine/dropdown.png';
import DROPUPICON from '@/views/assets/images/header-machine/dropup.png';
import { ref } from 'vue';
import { storeToRefs } from 'pinia';
import { useCanvasHeaderMachineStore } from '@/views/stores/header/useCanvasHeaderMachineStore';

const store = useCanvasHeaderMachineStore();
const { items, handleSelect } = store;
const { selecteditem } = storeToRefs(store);

const isSelectitemsVisible = ref(false);
const selectIcon = ref(DROPDOWNICON);

const onSelect = (key) => {
    handleSelect(key);
};

const onDropdown = () => {
    isSelectitemsVisible.value = !isSelectitemsVisible.value;
    selectIcon.value = isSelectitemsVisible.value ? DROPUPICON : DROPDOWNICON;
};

const onMouseout = () => {
    isSelectitemsVisible.value = false;
    selectIcon.value = DROPDOWNICON;
};
</script>
<style lang="less" scoped>
.select-machine {
    width: 100%;
    .current-machine,
    .select-item {
        display: flex;
        align-items: center;
        width: 100%;
        height: 88px;
        padding: 0px 24px;
        font-weight: 400;
        cursor: pointer;
        .icon {
            width: 56px;
        }
        .description {
            width: 193px;
            margin-left: 12px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            .name {
                font-size: 15px;
            }
            .size {
                font-size: 14px;
                color: #c0c1c2;
            }
        }
        .dropIcon {
            line-height: 90px;
        }
        img {
            cursor: pointer;
            .image {
                width: 48px;
                height: 72px;
            }
        }
        &:hover {
            background-color: @header-machine-hover-color;
            color: @main-color !important;
        }
        &:hover .description .size {
            color: @main-color !important;
        }
    }
    .selectitems {
        background-color: #fff;
        border-top: 1px solid #eef0f2;
        border-radius: 0 0 8px 8px;
        width: 332px;
        height: calc(88px * 5);
        overflow-y: auto;
        overflow-x: hidden;
    }
}
</style>