CategoryList.vue
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<template>
<v-container>
<div height="100" class="pa-2">
<v-row>
<div class="tw-pr-0 tw-font-bold tw-w-[95px] tw-h-[36px] tw-leading-[36px]">一级类别:</div>
<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>
<div class="tw-pr-0 tw-font-bold tw-w-[95px] tw-h-[36px] tw-leading-[36px]">二级类别:</div>
<v-col class="pa-0">
<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>
</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)
}
const subCategoryList = computed(() => {
if (categoryStore.selectedCategory) {
const tmp = categoryStore.list.filter(
(item) => item.categoryDisplayName === categoryStore.selectedCategory
)
return tmp?.[0]?.list || []
}
return []
})
</script>