345 lines
7.0 KiB
Vue
345 lines
7.0 KiB
Vue
<template>
|
|
<div class="mobile-container">
|
|
|
|
<!-- Header -->
|
|
<header class="header">
|
|
<div class="back-btn" @click="handleBackClick">
|
|
<el-icon><ArrowLeft /></el-icon>
|
|
</div>
|
|
<h1>{{ product.title || '商品详情' }}</h1>
|
|
<div class="actions">
|
|
<el-icon @click="handleFavoriteClick" :style="{ fontSize: '20px' }" :class="{ active: isFavorite }"><Star /></el-icon>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- Product Image -->
|
|
<div class="product-image-container">
|
|
<img
|
|
v-if="product.imageUrls && product.imageUrls.length > 0"
|
|
:src="product.imageUrls[0]"
|
|
:alt="product.title"
|
|
class="product-image"
|
|
/>
|
|
<div v-else class="product-image-placeholder">
|
|
<span class="product-letter">{{ product.title ? product.title[0] : '商' }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Product Info -->
|
|
<div class="product-info">
|
|
<div class="info-header">
|
|
<h2 class="product-name">{{ product.title }}</h2>
|
|
<div class="price-tag">¥{{ product.price }}</div>
|
|
</div>
|
|
<div class="shop-info">
|
|
<span class="shop-name">{{ product.shopName }}</span>
|
|
</div>
|
|
<div class="product-meta">
|
|
<div class="duration">
|
|
<el-icon><Clock /></el-icon>
|
|
<span>{{ product.approximateDuration }}</span>
|
|
</div>
|
|
<div class="stats">
|
|
<span class="like-count">
|
|
<el-icon><Star /></el-icon>
|
|
{{ product.likeCount }} 赞
|
|
</span>
|
|
<span class="collect-count">
|
|
<el-icon><Collection /></el-icon>
|
|
{{ product.collectCount }} 收藏
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
<el-tag v-for="(tag, index) in product.tagList" :key="index" size="small" effect="light" style="margin-right: 8px; margin-bottom: 8px">
|
|
{{ tag }}
|
|
</el-tag>
|
|
</div>
|
|
<p class="description">{{ product.description }}</p>
|
|
</div>
|
|
|
|
<!-- Action Buttons -->
|
|
<div class="action-buttons">
|
|
<el-button class="add-cart-btn" @click="handleAddToCart">
|
|
<el-icon><ShoppingCart /></el-icon>
|
|
添加到购物车
|
|
</el-button>
|
|
<el-button class="buy-now-btn" type="primary" @click="handleBuyNow">
|
|
<el-icon><Right /></el-icon>
|
|
立即购买
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, onMounted } from 'vue'
|
|
import { ArrowLeft, Star, Clock, Collection, ShoppingCart, Right } from '@element-plus/icons-vue'
|
|
import { useRouter, useRoute } from 'vue-router'
|
|
import { ElMessage } from 'element-plus'
|
|
import { productApi, type ProductVO } from '@/api/product'
|
|
|
|
const router = useRouter()
|
|
const route = useRoute()
|
|
|
|
const product = ref<ProductVO>({
|
|
id: 0,
|
|
shopId: 0,
|
|
shopName: '',
|
|
title: '',
|
|
description: '',
|
|
imageFileIds: '',
|
|
imageUrls: [],
|
|
price: 0,
|
|
tags: '',
|
|
tagList: [],
|
|
likeCount: 0,
|
|
collectCount: 0,
|
|
approximateDuration: '',
|
|
bookableArtists: '',
|
|
availableCoupons: '',
|
|
createTime: '',
|
|
updateTime: ''
|
|
})
|
|
|
|
const isFavorite = ref(false)
|
|
|
|
// 从后端获取商品详情
|
|
const fetchProductDetail = async () => {
|
|
const productId = route.params.id
|
|
console.log('产品ID:', productId)
|
|
|
|
try {
|
|
const response = await productApi.getProductById(Number(productId))
|
|
|
|
// 处理返回的数据
|
|
const productData = response as any
|
|
product.value = {
|
|
...productData,
|
|
imageUrls: productData.imageUrls || [],
|
|
tagList: productData.tagList || []
|
|
}
|
|
} catch (error) {
|
|
console.error('获取商品详情失败:', error)
|
|
ElMessage.error('未登录,请先登录')
|
|
}
|
|
}
|
|
|
|
const handleBackClick = () => {
|
|
console.log('返回按钮被点击')
|
|
router.back()
|
|
}
|
|
|
|
const handleFavoriteClick = () => {
|
|
isFavorite.value = !isFavorite.value
|
|
console.log('收藏状态:', isFavorite.value)
|
|
ElMessage.success(isFavorite.value ? '已收藏' : '已取消收藏')
|
|
}
|
|
|
|
const handleAddToCart = () => {
|
|
console.log('添加到购物车:', product.value.title)
|
|
ElMessage.success(`已将 ${product.value.title} 添加到购物车`)
|
|
}
|
|
|
|
const handleBuyNow = () => {
|
|
console.log('立即购买:', product.value.title)
|
|
// 这里可以跳转到订单确认页面
|
|
ElMessage.success('跳转到订单确认页面')
|
|
}
|
|
|
|
// 页面挂载时获取商品详情
|
|
onMounted(() => {
|
|
fetchProductDetail()
|
|
})
|
|
</script>
|
|
|
|
<style scoped>
|
|
.mobile-container {
|
|
min-height: 100vh;
|
|
background: #f5f5f5;
|
|
}
|
|
|
|
.header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 15px 20px;
|
|
border-bottom: 1px solid #f0f0f0;
|
|
background: white;
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 100;
|
|
}
|
|
|
|
.back-btn {
|
|
width: 40px;
|
|
height: 40px;
|
|
display: flex;
|
|
align-items: center;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 18px;
|
|
font-weight: bold;
|
|
margin: 0;
|
|
}
|
|
|
|
.actions {
|
|
width: 40px;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.actions .active {
|
|
color: #ff4d4f;
|
|
}
|
|
|
|
.product-image-container {
|
|
width: 100%;
|
|
height: 300px;
|
|
background: white;
|
|
position: relative;
|
|
}
|
|
|
|
.product-image {
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
}
|
|
|
|
.product-image-placeholder {
|
|
width: 100%;
|
|
height: 100%;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
font-size: 80px;
|
|
font-weight: bold;
|
|
color: rgba(0,0,0,0.1);
|
|
background: #f8f8f8;
|
|
}
|
|
|
|
.product-info {
|
|
padding: 20px;
|
|
background: white;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.info-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.product-name {
|
|
font-size: 20px;
|
|
font-weight: bold;
|
|
margin: 0;
|
|
flex: 1;
|
|
margin-right: 15px;
|
|
}
|
|
|
|
.price-tag {
|
|
font-size: 22px;
|
|
color: #ff4d4f;
|
|
font-weight: bold;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.shop-info {
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.shop-name {
|
|
font-size: 14px;
|
|
color: #666;
|
|
background: #f8f8f8;
|
|
padding: 4px 12px;
|
|
border-radius: 12px;
|
|
}
|
|
|
|
.product-meta {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 16px;
|
|
padding: 12px;
|
|
background: #f8f8f8;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.duration {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
font-size: 14px;
|
|
color: #666;
|
|
}
|
|
|
|
.stats {
|
|
display: flex;
|
|
gap: 16px;
|
|
}
|
|
|
|
.like-count, .collect-count {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
font-size: 14px;
|
|
color: #666;
|
|
}
|
|
|
|
.tags {
|
|
margin-bottom: 16px;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
}
|
|
|
|
.description {
|
|
color: #666;
|
|
line-height: 1.6;
|
|
font-size: 14px;
|
|
margin: 0;
|
|
}
|
|
|
|
.action-buttons {
|
|
padding: 20px;
|
|
display: flex;
|
|
gap: 15px;
|
|
background: white;
|
|
margin-top: 10px;
|
|
position: sticky;
|
|
bottom: 0;
|
|
z-index: 90;
|
|
border-top: 1px solid #f0f0f0;
|
|
}
|
|
|
|
.add-cart-btn, .buy-now-btn {
|
|
flex: 1;
|
|
height: 50px;
|
|
border-radius: 25px;
|
|
font-size: 16px;
|
|
font-weight: bold;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.add-cart-btn {
|
|
background-color: #f5f5f5;
|
|
border: 1px solid #e8e8e8;
|
|
color: #333;
|
|
}
|
|
|
|
.buy-now-btn {
|
|
background-color: #ff4d4f;
|
|
border: none;
|
|
color: white;
|
|
}
|
|
</style> |