CategoryList.vue 3.95 KB
<template>
  <v-container>
    <div class="container">
      <v-row class="ma-0 pl-4 bg-grey-lighten-3 tw-leading-[64px] row">
        <div
          class="tw-pr-0 tw-font-bold tw-w-[160px] tw-h-[36px] tw-leading-[64px] text-grey-darken-3"
        >
          CATEGORY:
        </div>
        <v-col class="flex pa-0">
          <span
            :class="
              categoryStore.selectedCategory === item.categoryDisplayName ? 'active tab' : 'tab'
            "
            v-for="(item, index) in categoryStore.list"
            :key="index"
            @click="handleCategoryClick(item)"
          >
            <b class="tw-m-0 tw-inline">{{ item.categoryDisplayName }}</b>
          </span>
        </v-col>
      </v-row>
      <v-row class="pa-4 ma-0 bg-grey-lighten-4 deviceType">
        <div
          class="tw-pr-0 tw-font-bold tw-w-[130px] tw-h-[36px] tw-leading-[64px] text-grey-darken-3"
        >
          DEVICE TYPE:
        </div>
        <v-col class="pa-0">
          <span
            :class="
              categoryStore.selectedSubCategory === item.id
                ? 'active subTab text-body-1'
                : 'subTab text-body-1'
            "
            v-for="(item, index) in subCategoryList"
            :key="index"
            @click="handleSubCategoryClick(item.id)"
          >
            {{ item.name }}
          </span>
        </v-col>
      </v-row>
      <v-row v-if="funcCategoryList.length" class="pa-4 ma-0 bg-grey-lighten-4">
        <div
          class="tw-pr-0 tw-font-bold tw-w-[210px] tw-h-[36px] tw-leading-[36px] text-grey-darken-3"
        >
          MATERIAL FUNCTION:
        </div>
        <v-col class="pa-0">
          <span
            :class="
              categoryStore.selectedFuncCategory === item.id
                ? 'active subTab text-body-1'
                : 'subTab text-body-1'
            "
            v-for="(item, index) in funcCategoryList"
            :key="index"
            @click="handleFuncCategoryClick(item.id)"
          >
            {{ item.name }}
          </span>
        </v-col>
      </v-row>
    </div>
  </v-container>
</template>

<script setup lang="ts">
import { useCategoryStore } from '@/stores/category'
import type { CategoryRootType } from '@/type'
import { computed } from 'vue'

const categoryStore = useCategoryStore()

const handleCategoryClick = (item: CategoryRootType) => {
  categoryStore.updateCategory(item.categoryDisplayName)
  categoryStore.updateSubCategory(item.list[0].id)

  console.log(
    '%c [  ]-76',
    'font-size:13px; background:pink; color:#bf2c9f;',
    categoryStore.selectedCategory
  )
}

const handleSubCategoryClick = (value: string) => {
  categoryStore.updateSubCategory(value)
}

const handleFuncCategoryClick = (value: string) => {
  categoryStore.updateFuncCategory(value)
}

const subCategoryList = computed(() => {
  if (categoryStore.selectedCategory) {
    const tmp = categoryStore.list.filter(
      (item) => item.categoryDisplayName === categoryStore.selectedCategory
    )
    return tmp?.[0]?.list || []
  }
  return []
})

const funcCategoryList = computed(() => {
  if (categoryStore.selectedCategory) {
    const tmp = categoryStore.list.filter(
      (item) => item.categoryDisplayName === categoryStore.selectedCategory
    )
    return tmp?.[0]?.productFunctions || []
  }
  return []
})
</script>

<style scoped lang="scss">
.container {
  border: 1px solid #1f88e5;
}
.row {
  border-bottom: 1px solid #1f88e5;
}

.tab,
.subTab {
  display: inline-flex;
  cursor: pointer;
  margin-right: 4px;
  padding: 0 16px;

  &:hover,
  &.active {
    background: #1e88e5;
    color: #fff;
  }
}

.tab {
  display: inline-flex;

  &:hover,
  &.active {
    background: #1e88e5;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    height: 90%;
    line-height: 50px;
    color: #fff;
  }
}

.subTab {
  border-radius: 4px;
  padding: 4px 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.deviceType {
  border-bottom: 1px dashed rgb(178, 178, 178);
}
</style>