From 64868b47b327a05da72b6fc1aaba2b044aaf8e19 Mon Sep 17 00:00:00 2001 From: dzl <786316265@qq.com> Date: Sat, 11 Oct 2025 17:32:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 6 ++ src/views/CouponManage.vue | 82 +++++++++++++++ src/views/ProductCategory.vue | 154 ++++------------------------- src/views/ProductCategoryFinal.vue | 26 ++--- src/views/Shop.vue | 6 +- 5 files changed, 116 insertions(+), 158 deletions(-) create mode 100644 src/views/CouponManage.vue diff --git a/src/router/index.js b/src/router/index.js index 7204c4b..a157b40 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -231,6 +231,12 @@ const routes = [ meta: {title: '支付确认'}, props: route => ({orderId: route.query.orderId}) }, + { + path: '/coupon', + name: 'Coupon', + component: () => import('@/views/CouponManage.vue'), + meta: {title: '优惠券', requiresAuth: true} + }, { path: '/:pathMatch(.*)*', name: 'NotFound', diff --git a/src/views/CouponManage.vue b/src/views/CouponManage.vue new file mode 100644 index 0000000..ca6ec3f --- /dev/null +++ b/src/views/CouponManage.vue @@ -0,0 +1,82 @@ + + + + + diff --git a/src/views/ProductCategory.vue b/src/views/ProductCategory.vue index bbdd0d4..a9d1e7d 100644 --- a/src/views/ProductCategory.vue +++ b/src/views/ProductCategory.vue @@ -3,7 +3,7 @@
返回 - + @@ -55,140 +55,11 @@ const categoryChoice = ref(0) const barItems = ref([ { - name: '数码产品', + name: '', relative: [{ - name: '华为', - img: '/imgs/shop/shumachanping/1.png' - },{ - name: '苹果', - img: '/imgs/shop/shumachanping/2.png' - },{ - name: '小米', - img: '/imgs/shop/shumachanping/3.png' - },{ - name: '荣耀', - img: '/imgs/shop/shumachanping/4.png' - },{ - name: 'iqoo', - img: '/imgs/shop/shumachanping/5.png' - },{ - name: 'realme', - img: '/imgs/shop/shumachanping/6.png' - },{ - name: 'vivo', - img: '/imgs/shop/shumachanping/7.png' - },{ - name: 'oppo', - img: '/imgs/shop/shumachanping/8.png' - },{ - name: '三星', - img: '/imgs/shop/shumachanping/9.png' - }] - },{ - name: '食品饮料', - relative: [] - },{ - name: '服装配饰', - relative: [] - },{ - name: '手机', - relative: [{ - name: '华为', - img: '/imgs/shop/shumachanping/1.png' - },{ - name: '苹果', - img: '/imgs/shop/shumachanping/2.png' - },{ - name: '小米', - img: '/imgs/shop/shumachanping/3.png' - },{ - name: '荣耀', - img: '/imgs/shop/shumachanping/4.png' - },{ - name: 'iqoo', - img: '/imgs/shop/shumachanping/5.png' - },{ - name: 'realme', - img: '/imgs/shop/shumachanping/6.png' - },{ - name: 'vivo', - img: '/imgs/shop/shumachanping/7.png' - },{ - name: 'oppo', - img: '/imgs/shop/shumachanping/8.png' - },{ - name: '三星', - img: '/imgs/shop/shumachanping/9.png' - }] - },{ - name: '家装', - relative: [{ - name: '灵感美图', + name: '', img: '' }] - },{ - name: '箱包', - relative: [] - },{ - name: '内衣', - relative: [] - },{ - name: '洗护', - relative: [] - },{ - name: '鞋靴', - relative: [] - },{ - name: '美妆', - relative: [] - },{ - name: '保健', - relative: [] - },{ - name: '图书', - relative: [] - },{ - name: '车品', - relative: [] - },{ - name: '图书', - relative: [] - },{ - name: '车品', - relative: [] - },{ - name: '医药', - relative: [] - },{ - name: '奢品', - relative: [] - },{ - name: '饰品', - relative: [] - },{ - name: '百货', - relative: [] - },{ - name: '女装', - relative: [] - },{ - name: '母婴', - relative: [] - },{ - name: '男装', - relative: [] - },{ - name: '运动', - relative: [] - },{ - name: '电器', - relative: [] - },{ - name: '生鲜', - relative: [] - },{ - name: '数码', - relative: [] } ]) @@ -197,11 +68,24 @@ const loading = ref(false) const loadingMore = ref(false) const page = ref(1) const hasMore = ref(true) -const selectedCategory = ref(barItems.value[0].name) +// const selectedCategory = ref(barItems.value[0].name) +const selectedCategory = ref('') const searchKeyword = ref('') const sortBy = ref('') +const getCategory = async () => { + try { + const {data} = await api.get('/category') + barItems.value = data.data + selectedCategory.value = barItems.value[0].name + getProducts(false) + } catch (error) { + ElMessage.error('获取分类失败') + console.error('获取分类失败:', error) + } +} + const selectCategory = (index) => { searchKeyword.value = '' categoryChoice.value = index @@ -222,7 +106,7 @@ const getProducts = async (isLoadMore = false) => { params: { page: page.value, limit: 20, - category: selectedCategory.value === 'all' ? '' : selectedCategory.value, + category: selectedCategory.value, search: searchKeyword.value, sort: sortBy.value } @@ -269,7 +153,7 @@ watch(searchKeyword, (newVal, oldVal) => { }) onMounted(() => { - getProducts() + getCategory() }) diff --git a/src/views/ProductCategoryFinal.vue b/src/views/ProductCategoryFinal.vue index 7d9dd6a..77bb377 100644 --- a/src/views/ProductCategoryFinal.vue +++ b/src/views/ProductCategoryFinal.vue @@ -23,7 +23,7 @@
-
+
你有优惠券待领取
@@ -57,11 +57,13 @@ import api from '@/utils/api' import { getImageUrl } from '@/config' import { useUserStore } from '@/stores/user'; -const userStore = useUserStore(); +const userStore = useUserStore(); const route = useRoute() -const searchKeyword = ref(route.params.name) +// const secondCategory = ref(route.params.name) + +const searchKeyword = ref('') const sortBy = ref('') const products = ref([]) @@ -70,7 +72,7 @@ const loading = ref(false) const loadingMore = ref(false) const page = ref(1) const hasMore = ref(true) -const selectedCategory = ref('all') +const selectedCategory = ref(route.params.name) const couponExist = ref(false) @@ -173,22 +175,6 @@ const getProducts = async (isLoadMore = false) => { } } -const getCoupon = async () => { - try { - console.log(userStore) - const {data} = await api.get(`/coupon/${userStore.user.id}`) - if (data.success) { - ElMessage.success('优惠券领取成功') - isCouponExist() - } else { - ElMessage.error(data.msg || '优惠券领取失败') - } - } catch (error) { - ElMessage.error('优惠券领取失败') - console.error('优惠券领取失败:', error) - } -} - const isCouponExist = async () => { try { const {data} = await api.get(`/coupon`) diff --git a/src/views/Shop.vue b/src/views/Shop.vue index 2ffdc57..1cd5f90 100644 --- a/src/views/Shop.vue +++ b/src/views/Shop.vue @@ -16,7 +16,7 @@
-
+
提示
@@ -202,10 +202,10 @@ onMounted(() => { .shop-tips { align-self: center; - margin-top: 28px; + margin-top: 15px; border-radius: 5px; height: 30px; - width: 330px; + width: auto; } .tips-imgs {