Blame view

src/components/CategoryList.vue 2.77 KB
sanmu authored
1
2
3
4
<template>
  <v-container>
    <div height="100" class="pa-2">
      <v-row>
sanmu authored
5
        <div class="tw-pr-0 tw-font-bold tw-w-[95px] tw-h-[36px] tw-leading-[36px]">Category:</div>
sanmu authored
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        <v-col class="pa-0">
          <v-btn
            v-for="(item, index) in categoryStore.list"
            :key="index"
            variant="text"
            @click="handleCategoryClick(item)"
            :color="
              categoryStore.selectedCategory === item.categoryDisplayName ? 'blue-accent-2' : ''
            "
          >
            {{ item.categoryDisplayName }}
          </v-btn>
        </v-col>
      </v-row>
      <v-row>
sanmu authored
21
        <div class="tw-pr-0 tw-font-bold tw-w-[95px] tw-h-[36px] tw-leading-[36px]"></div>
sanmu authored
22
        <v-col class="pa-0">
sanmu authored
23
          <v-divider></v-divider>
sanmu authored
24
25
26
27
28
29
30
31
32
33
34
          <v-btn
            v-for="(item, index) in subCategoryList"
            :key="index"
            variant="text"
            @click="handleSubCategoryClick(item.id)"
            :color="categoryStore.selectedSubCategory === item.id ? 'blue-accent-2' : ''"
          >
            {{ item.name }}
          </v-btn>
        </v-col>
      </v-row>
sanmu authored
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
      <v-row v-if="funcCategoryList.length">
        <div class="tw-pr-0 tw-font-bold tw-w-[95px] tw-h-[36px] tw-leading-[36px]"></div>
        <v-col class="pa-0">
          <v-divider></v-divider>
          <v-btn
            v-for="(item, index) in funcCategoryList"
            :key="index"
            variant="text"
            @click="handleFuncCategoryClick(item.id)"
            :color="categoryStore.selectedFuncCategory === item.id ? 'blue-accent-2' : ''"
          >
            {{ item.name }}
          </v-btn>
        </v-col>
      </v-row>
sanmu authored
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    </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)
}

const handleSubCategoryClick = (value: string) => {
  categoryStore.updateSubCategory(value)
}
sanmu authored
70
71
72
73
const handleFuncCategoryClick = (value: string) => {
  categoryStore.updateFuncCategory(value)
}
sanmu authored
74
75
76
77
78
79
80
81
82
const subCategoryList = computed(() => {
  if (categoryStore.selectedCategory) {
    const tmp = categoryStore.list.filter(
      (item) => item.categoryDisplayName === categoryStore.selectedCategory
    )
    return tmp?.[0]?.list || []
  }
  return []
})
sanmu authored
83
84
85
86
87
88
89
90
91
92

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