From f730ac905a77b97f133abcc43b8b9433b8a24a60 Mon Sep 17 00:00:00 2001 From: thuongtruong1009 Date: Tue, 7 Jun 2022 16:52:59 +0700 Subject: [PATCH] add category search feature --- src/components.d.ts | 2 + src/components/CGetCategoryChildren.vue | 72 ++++++++++++++++++++++++ src/components/head/CBMenuCategories.vue | 36 +++--------- src/components/partterns/PNotFound.vue | 2 +- src/pages/product/[product].vue | 5 +- src/pages/search/[keyword].vue | 10 +++- src/stores/product.ts | 14 ++--- 7 files changed, 102 insertions(+), 39 deletions(-) create mode 100644 src/components/CGetCategoryChildren.vue diff --git a/src/components.d.ts b/src/components.d.ts index d79003b..56d8bed 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -11,6 +11,7 @@ declare module 'vue' { CarbonLanguage: typeof import('~icons/carbon/language')['default'] CarbonMoon: typeof import('~icons/carbon/moon')['default'] CarbonSun: typeof import('~icons/carbon/sun')['default'] + CarbonWarning: typeof import('~icons/carbon/warning')['default'] CASellerList: typeof import('./components/admin/CASellerList.vue')['default'] CBAccount: typeof import('./components/buyer/CBAccount.vue')['default'] CBBanner: typeof import('./components/buyer/CBBanner.vue')['default'] @@ -41,6 +42,7 @@ declare module 'vue' { CCartItem: typeof import('./components/buyer/CCartItem.vue')['default'] CError: typeof import('./components/CError.vue')['default'] CExtension: typeof import('./components/CExtension.vue')['default'] + CGetCategoryChildren: typeof import('./components/CGetCategoryChildren.vue')['default'] CLoading: typeof import('./components/CLoading.vue')['default'] CMap: typeof import('./components/CMap.vue')['default'] Counter: typeof import('./components/Counter.vue')['default'] diff --git a/src/components/CGetCategoryChildren.vue b/src/components/CGetCategoryChildren.vue new file mode 100644 index 0000000..a576333 --- /dev/null +++ b/src/components/CGetCategoryChildren.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/src/components/head/CBMenuCategories.vue b/src/components/head/CBMenuCategories.vue index b5a5f32..0689ba4 100644 --- a/src/components/head/CBMenuCategories.vue +++ b/src/components/head/CBMenuCategories.vue @@ -5,49 +5,29 @@ import { useProduct } from '~/stores/product' const { t } = useI18n() const product = useProduct() -watch(async() => { +watchEffect(async() => { const { data } = await ProductRequest.getCategoriesChildrenById() product.category = data }) -const getLevel1 = async(id) => { - const { data } = await ProductRequest.getCategoriesChildrenById(id) - product.level1 = data - product.choicedList[0] = product.level1.parent -} - -const getLevel2 = async(id) => { - const { data } = await ProductRequest.getCategoriesChildrenById(id) - product.level2 = data - product.choicedList[1] = product.level2.parent -} - -const getLevel3 = async(id) => { - const { data } = await ProductRequest.getCategoriesChildrenById(id) - product.level3 = data - product.choicedList[2] = product.level3.parent -} - const isAppearMenu = ref(false) -const onAppearMenu = () => { +const appearMenu = () => { isAppearMenu.value = !isAppearMenu.value - if (!isAppearMenu.value) { - product.level1 = '' - product.level2 = '' - product.level3 = '' - } + product.level.level1 = '' + product.level.level2 = '' + product.level.level3 = '' } diff --git a/src/stores/product.ts b/src/stores/product.ts index 54095a8..97f6507 100644 --- a/src/stores/product.ts +++ b/src/stores/product.ts @@ -5,19 +5,17 @@ export const useProduct = defineStore('product', () => { // create new product in seller page const productName = ref('') const category = ref([]) - const level1 = ref([]) - const level2 = ref([]) - const level3 = ref([]) - const choicedList = reactive({ - 0: '', - 1: '', - 2: '', + const level = reactive({ + level1: '', + level2: '', + level3: '', }) + // search public product const productRequestID = ref() const shopRequestID = ref() - return { productName, category, level1, level2, level3, choicedList, productRequestID, shopRequestID } + return { productName, category, level, productRequestID, shopRequestID } }) if (import.meta.hot)