Files
JayuCloud/Frontend/src/views/WishlistView.vue
T

172 lines
3.6 KiB
Vue
Raw Normal View History

<template>
<div class="mobile-container">
<!-- Header -->
<header class="header">
<div class="back-btn" @click="handleBackClick">
<el-icon><ArrowLeft /></el-icon>
</div>
<h1>Wishlist</h1>
<div class="empty"></div>
</header>
<!-- Wishlist Items -->
<div class="wishlist-items">
<div v-for="item in wishlistItems" :key="item.id" class="wishlist-item">
<div class="item-image" :style="{ backgroundColor: item.bgColor }">
<span>{{ item.name[0] }}</span>
</div>
<div class="item-details">
<h3 class="item-name">{{ item.name }}</h3>
<p class="item-price">${{ item.price }}</p>
<div class="item-actions">
<el-button size="small" type="primary" @click="handleAddToCart(item)">
Add to Cart
</el-button>
<el-icon class="delete-icon" @click="handleRemoveItem(item)"><Delete /></el-icon>
</div>
</div>
</div>
</div>
<!-- Empty Wishlist Message -->
<div v-if="wishlistItems.length === 0" class="empty-wishlist">
<el-icon :size="60"><Star /></el-icon>
<p>Your wishlist is empty</p>
<el-button type="primary" @click="handleBrowseProducts">
Browse Products
</el-button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ArrowLeft, Delete, Star } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const wishlistItems = ref([
{ id: 1, name: 'Watch', price: 40, bgColor: '#ffe4d6' },
{ id: 2, name: 'LG TV', price: 330, bgColor: '#f0d6ff' },
{ id: 3, name: 'Jacket', price: 50, bgColor: '#ffd6e2' },
{ id: 4, name: 'Nike Shoes', price: 430, bgColor: '#d6eaff' }
])
const handleBackClick = () => {
console.log('返回按钮被点击')
router.back()
}
const handleAddToCart = (item: any) => {
console.log('添加到购物车:', item.name)
}
const handleRemoveItem = (item: any) => {
console.log('从收藏夹移除:', item.name)
const index = wishlistItems.value.findIndex(i => i.id === item.id)
if (index > -1) {
wishlistItems.value.splice(index, 1)
}
}
const handleBrowseProducts = () => {
console.log('浏览商品')
router.push('/products')
}
</script>
<style scoped>
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 20px;
border-bottom: 1px solid #f0f0f0;
}
.back-btn {
width: 40px;
height: 40px;
display: flex;
align-items: center;
cursor: pointer;
}
.header h1 {
font-size: 18px;
font-weight: bold;
}
.empty {
width: 40px;
}
.wishlist-items {
padding: 20px;
padding-bottom: 20px;
}
.wishlist-item {
display: flex;
gap: 15px;
padding: 15px;
background: #f9f9f9;
border-radius: 15px;
margin-bottom: 15px;
}
.item-image {
width: 80px;
height: 80px;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
font-size: 30px;
font-weight: bold;
color: rgba(0,0,0,0.1);
}
.item-details {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.item-name {
font-size: 16px;
font-weight: bold;
margin: 0 0 5px 0;
}
.item-price {
color: var(--primary-color);
font-weight: bold;
margin: 0 0 10px 0;
}
.item-actions {
display: flex;
justify-content: space-between;
align-items: center;
}
.delete-icon {
color: #ff4757;
cursor: pointer;
font-size: 20px;
}
.empty-wishlist {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 60px 20px;
color: #999;
}
.empty-wishlist p {
margin: 20px 0;
font-size: 16px;
}
</style>