MobileCategoryList.vue
6.13 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<template>
<div class="pr-4 tw-h-[48px] tw-leading-[48px] tw-text-right border-b">
<span class="text-grey-darken-4 text-body-2" @click="drawerVis = !drawerVis"
>Filter <v-icon> mdi-filter-outline </v-icon></span
>
</div>
<!-- <div class="bg-grey-lighten-4 tw-w-full tw-h-3"></div> -->
<v-layout>
<v-navigation-drawer
@update:model-value="handleDrawerHide"
v-model="drawerVis"
location="bottom"
temporary
class="!tw-h-[800px]"
>
<v-row class="mb-4 ma-0">
<v-col
v-for="(item, index) in categoryStore.list"
:key="index"
cols="3"
@click="handleCategoryClick(item, index)"
>
<v-img
:src="
selectedCategory === item.categoryDisplayName
? CATEGORY_IMG[index].selected
: CATEGORY_IMG[index].normal
"
></v-img>
<!-- <v-img :src="item.normal" v-else></v-img> -->
<!-- <v-img :src="item.selected"></v-img> -->
<b class="tw-m-0 tw-inline">{{ item.categoryDisplayName }}</b>
</v-col>
</v-row>
<v-list density="compact" :selected="[selectedSubCategory]">
<v-list-subheader class="mb-2 !tw-font-bold text-subtitle-1">DEVICE TYPE</v-list-subheader>
<v-list-item
v-for="(item, i) in subCategoryList"
:key="item.id"
:value="item.id"
color="blue-darken-1"
@click="handleSubCategoryClick(item.id)"
>
<!-- <template v-slot:prepend>
<v-icon :icon="item.icon"></v-icon>
</template> -->
<v-list-item-title>{{ item.name }}</v-list-item-title>
</v-list-item>
</v-list>
<v-divider class="my-3" v-if="funcCategoryList.length"></v-divider>
<v-list density="compact" v-if="funcCategoryList.length" :selected="[selectedFuncCategory]">
<v-list-subheader class="mb-2 !tw-font-bold text-subtitle-1">DEVICE TYPE</v-list-subheader>
<v-list-item
v-for="(item, i) in funcCategoryList"
:key="item.id"
:value="item.id"
color="blue-darken-1"
@click="handleFuncCategoryClick(item.id)"
>
<!-- <template v-slot:prepend>
<v-icon :icon="item.icon"></v-icon>
</template> -->
<v-list-item-title>{{ item.name }}</v-list-item-title>
</v-list-item>
</v-list>
</v-navigation-drawer>
</v-layout>
</template>
<script setup lang="ts">
import { useCategoryStore } from '@/stores/category'
import { useProductListStore } from '@/stores/product_list'
import type { CategoryRootType } from '@/type'
import { computed, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
const categoryStore = useCategoryStore()
const productStore = useProductListStore()
const selected1 = ref('')
const drawerVis = ref(false)
const selectedCategory = ref('')
const selectedSubCategory = ref('')
const selectedFuncCategory = ref('')
const CATEGORY_IMG = [
{ normal: '/category/1.png', selected: '/category/1.1.png', name: 'Energy materials' },
{ normal: '/category/2.png', selected: '/category/2.1.png', name: 'Laboratory consumables' },
{ normal: '/category/3.png', selected: '/category/3.1.png', name: 'Low-dimensional materials' },
{ normal: '/category/4.png', selected: '/category/4.1.png', name: 'Equipment' }
]
const SEO = {
'Energy materials':
'Energy materials,Not specified,Battery accessories,Lithium-ion batteries,Capacitors,Sodium-ion batteries,Lithium-sulfur batteries,Potassium/magnesium/aluminum/zinc batteries,Air/fuel/solar,Analytical electrodes,Complete battery accessories',
'Laboratory consumables':
'Laboratory consumables,Not specified,Glass materials,Plastic materials,Metal materials,Ceramic materials,Paper film materials,Chemical materials,Tetrafluoro materials,Safety protection,Office supplies,Tools,Others',
'Low-dimensional materials':
',Low-dimensional materialsNot specified,Zero-dimensional carbon materials,One-dimensional carbon materials,Two-dimensional carbon materials,Three-dimensional carbon materials,Inorganic nanomaterials,Organic nanomaterials,Metal nanomaterials,Others',
Equipment:
'Equipment,Not specified,Equipment,Accessories & fixtures,Fuel cell manufacturing and testing equipment'
}
const handleDrawerHide = () => {
categoryStore.updateCategory(selectedCategory.value)
categoryStore.updateSubCategory(selectedSubCategory.value)
categoryStore.updateFuncCategory(selectedFuncCategory.value)
productStore.updatePageNo(1)
router.push({ query: { category: selectedCategory.value } })
const doc = document as any
const head = doc.getElementsByTagName('head')
const meta = doc.createElement('meta')
document.title = SEO[selectedCategory.value as keyof typeof SEO]
doc
.querySelector('meta[name="keywords"]')
.setAttribute('content', SEO[selectedCategory.value as keyof typeof SEO])
head[0].appendChild(meta)
}
const handleCategoryClick = (item: CategoryRootType, index: number) => {
selectedCategory.value = item.categoryDisplayName
selectedSubCategory.value = item.list[0].id
console.log('%c [ index ]-132', 'font-size:13px; background:pink; color:#bf2c9f;', index)
if (index === 0) {
selectedFuncCategory.value = item.productFunctions[0].id
console.log(
'%c [ selectedFuncCategory.value ]-134',
'font-size:13px; background:pink; color:#bf2c9f;',
selectedFuncCategory.value
)
}
}
const handleSubCategoryClick = (value: string) => {
selectedSubCategory.value = value
}
const handleFuncCategoryClick = (value: string) => {
selectedFuncCategory.value = value
}
const subCategoryList = computed(() => {
if (selectedCategory.value) {
const tmp = categoryStore.list.filter(
(item) => item.categoryDisplayName === selectedCategory.value
)
return tmp?.[0]?.list || []
}
return []
})
const funcCategoryList = computed(() => {
if (selectedCategory.value) {
const tmp = categoryStore.list.filter(
(item) => item.categoryDisplayName === selectedCategory.value
)
return tmp?.[0]?.productFunctions || []
}
return []
})
</script>
<style lang="less" scoped></style>