|
|
|
@@ -1,125 +1,116 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div class="mobile-container">
|
|
|
|
|
<header class="header">
|
|
|
|
|
<a-button type="text" @click="handleBackClick">
|
|
|
|
|
<LeftOutlined :style="{ fontSize: '20px' }" />
|
|
|
|
|
</a-button>
|
|
|
|
|
<h1>{{ product.title || product.name || '作品详情' }}</h1>
|
|
|
|
|
<div class="detail-page">
|
|
|
|
|
<header class="detail-header">
|
|
|
|
|
<a-button type="text" @click="router.back()"><LeftOutlined /></a-button>
|
|
|
|
|
<h1>{{ productTitle }}</h1>
|
|
|
|
|
<a-button type="text" @click="handleFavoriteClick">
|
|
|
|
|
<component :is="isFavorite ? StarFilled : StarOutlined" :class="['header-star', { active: isFavorite }]" />
|
|
|
|
|
<component :is="isFavorite ? StarFilled : StarOutlined" :class="{ active: isFavorite }" />
|
|
|
|
|
</a-button>
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
<main class="content">
|
|
|
|
|
<a-result
|
|
|
|
|
v-if="loadError"
|
|
|
|
|
status="warning"
|
|
|
|
|
title="暂时无法查看作品详情"
|
|
|
|
|
:sub-title="loadError"
|
|
|
|
|
>
|
|
|
|
|
<main class="detail-content">
|
|
|
|
|
<a-result v-if="loadError" status="warning" title="暂时无法查看作品详情" :sub-title="loadError">
|
|
|
|
|
<template #extra>
|
|
|
|
|
<a-button type="primary" @click="handleBackClick">返回上一页</a-button>
|
|
|
|
|
<a-button type="primary" @click="router.back()">返回上一页</a-button>
|
|
|
|
|
</template>
|
|
|
|
|
</a-result>
|
|
|
|
|
|
|
|
|
|
<template v-else>
|
|
|
|
|
<section class="hero-card">
|
|
|
|
|
<a-carousel v-if="productImages.length > 1" autoplay dots>
|
|
|
|
|
<div v-for="(image, index) in productImages" :key="index" class="carousel-slide">
|
|
|
|
|
<img :src="image" :alt="product.title || product.name" class="product-image" />
|
|
|
|
|
</div>
|
|
|
|
|
</a-carousel>
|
|
|
|
|
<div v-else class="single-image">
|
|
|
|
|
<img :src="productImages[0] || DEFAULT_PRODUCT_IMAGE" :alt="product.title || product.name" class="product-image" />
|
|
|
|
|
</div>
|
|
|
|
|
<section class="media-section">
|
|
|
|
|
<img :src="productImages[0] || DEFAULT_PRODUCT_IMAGE" :alt="productTitle" />
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section class="info-card">
|
|
|
|
|
<div class="info-header">
|
|
|
|
|
<section class="info-section">
|
|
|
|
|
<div class="title-row">
|
|
|
|
|
<div>
|
|
|
|
|
<h2 class="product-name">{{ product.title || product.name }}</h2>
|
|
|
|
|
<p class="product-price">¥{{ Number(product.price || 0).toFixed(2) }}</p>
|
|
|
|
|
<h2>{{ productTitle }}</h2>
|
|
|
|
|
<p class="price">¥{{ Number(product.price || 0).toFixed(2) }}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<a-tag color="blue">{{ product.approximateDuration || '时长待确认' }}</a-tag>
|
|
|
|
|
<a-tag color="blue">{{ product.approximateDuration || '以门店确认为准' }}</a-tag>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="metric-row">
|
|
|
|
|
<button class="metric-card" type="button" @click="openShopDetail" :disabled="!shopInfo?.id">
|
|
|
|
|
<div class="metrics">
|
|
|
|
|
<button type="button" @click="openShopDetail" :disabled="!shopInfo?.id">
|
|
|
|
|
<ShopOutlined />
|
|
|
|
|
<div>
|
|
|
|
|
<span class="metric-label">所属门店</span>
|
|
|
|
|
<strong>{{ shopInfo?.shopName || '暂未绑定门店' }}</strong>
|
|
|
|
|
</div>
|
|
|
|
|
<span>门店</span>
|
|
|
|
|
<strong>{{ shopInfo?.shopName || '暂未绑定门店' }}</strong>
|
|
|
|
|
</button>
|
|
|
|
|
<div class="metric-card">
|
|
|
|
|
<div>
|
|
|
|
|
<TeamOutlined />
|
|
|
|
|
<div>
|
|
|
|
|
<span class="metric-label">可约美甲师</span>
|
|
|
|
|
<strong>{{ artistCountText }}</strong>
|
|
|
|
|
</div>
|
|
|
|
|
<span>可约美甲师</span>
|
|
|
|
|
<strong>{{ artistCountText }}</strong>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="metric-card">
|
|
|
|
|
<div>
|
|
|
|
|
<CalendarOutlined />
|
|
|
|
|
<div>
|
|
|
|
|
<span class="metric-label">最早可约</span>
|
|
|
|
|
<strong>{{ earliestBookableText }}</strong>
|
|
|
|
|
</div>
|
|
|
|
|
<span>可约时间</span>
|
|
|
|
|
<strong>{{ earliestBookableText }}</strong>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-if="shopInfo" class="shop-summary" @click="openShopDetail">
|
|
|
|
|
<div class="shop-summary-title">{{ shopInfo.shopName }}</div>
|
|
|
|
|
<div class="shop-summary-text">{{ shopInfo.address || '门店地址待完善' }}</div>
|
|
|
|
|
<div class="shop-summary-text">{{ shopInfo.businessHours || '营业时间待完善' }}</div>
|
|
|
|
|
<div v-if="shopInfo" class="shop-panel" @click="openShopDetail">
|
|
|
|
|
<strong>{{ shopInfo.shopName }}</strong>
|
|
|
|
|
<span>{{ shopInfo.address || '门店地址待完善' }}</span>
|
|
|
|
|
<span>{{ shopInfo.businessHours || '营业时间待完善' }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="stats-row">
|
|
|
|
|
<button type="button" class="stat-btn" @click="handleLikeClick">
|
|
|
|
|
<component :is="isLiked ? HeartFilled : HeartOutlined" :class="{ active: isLiked }" />
|
|
|
|
|
<span>{{ product.likeCount || 0 }} 点赞</span>
|
|
|
|
|
<div class="actions-row">
|
|
|
|
|
<button type="button" :class="{ active: isLiked }" @click="handleLikeClick">
|
|
|
|
|
<component :is="isLiked ? HeartFilled : HeartOutlined" />
|
|
|
|
|
{{ product.likeCount || 0 }} 点赞
|
|
|
|
|
</button>
|
|
|
|
|
<button type="button" class="stat-btn" @click="handleFavoriteClick">
|
|
|
|
|
<component :is="isFavorite ? StarFilled : StarOutlined" :class="{ active: isFavorite }" />
|
|
|
|
|
<span>{{ product.collectCount || 0 }} 收藏</span>
|
|
|
|
|
<button type="button" :class="{ active: isFavorite }" @click="handleFavoriteClick">
|
|
|
|
|
<component :is="isFavorite ? StarFilled : StarOutlined" />
|
|
|
|
|
{{ product.collectCount || 0 }} 收藏
|
|
|
|
|
</button>
|
|
|
|
|
<div class="stat-btn static">
|
|
|
|
|
<ClockCircleOutlined />
|
|
|
|
|
<span>{{ product.approximateDuration || '时长待定' }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="tags">
|
|
|
|
|
<a-tag
|
|
|
|
|
v-for="tag in product.tagInfos || []"
|
|
|
|
|
:key="tag.id"
|
|
|
|
|
:style="{
|
|
|
|
|
color: tag.textColor || '#333',
|
|
|
|
|
backgroundColor: tag.bgColor || '#f0f0f0',
|
|
|
|
|
borderColor: tag.borderColor || '#f0f0f0'
|
|
|
|
|
}"
|
|
|
|
|
>
|
|
|
|
|
{{ tag.tagName }}
|
|
|
|
|
</a-tag>
|
|
|
|
|
<a-tag v-if="!product.tagInfos?.length" color="default">暂无标签</a-tag>
|
|
|
|
|
<a-tag v-for="tag in product.tagInfos || []" :key="tag.id">{{ tag.tagName }}</a-tag>
|
|
|
|
|
<a-tag v-if="!product.tagInfos?.length">暂无标签</a-tag>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="description-block">
|
|
|
|
|
<h3>作品介绍</h3>
|
|
|
|
|
<p>{{ product.description || '店家还没补充作品说明。' }}</p>
|
|
|
|
|
<div class="description">
|
|
|
|
|
<h3>款式说明</h3>
|
|
|
|
|
<p>{{ product.description || '店家暂未补充作品说明。' }}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section class="comment-section">
|
|
|
|
|
<div class="section-head">
|
|
|
|
|
<h3>作品评论</h3>
|
|
|
|
|
<span>{{ comments.length }} 条</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="comment-editor">
|
|
|
|
|
<a-textarea v-model:value="commentText" :maxlength="300" :rows="3" :placeholder="replyTarget ? `回复 ${replyTarget.userNickname || '用户'}` : '说说你的看法'" />
|
|
|
|
|
<div class="comment-tools">
|
|
|
|
|
<a-button v-if="replyTarget" type="text" @click="replyTarget = null">取消回复</a-button>
|
|
|
|
|
<a-button type="primary" :loading="submittingComment" @click="submitComment">发布</a-button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<a-empty v-if="!comments.length" description="还没有评论,来写第一条吧" />
|
|
|
|
|
<div v-for="comment in comments" :key="comment.id" class="comment-item">
|
|
|
|
|
<div class="comment-main">
|
|
|
|
|
<strong>{{ comment.userNickname || '用户' }}</strong>
|
|
|
|
|
<span>{{ formatTime(comment.createTime) }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<p>{{ comment.commentContent }}</p>
|
|
|
|
|
<button type="button" @click="replyTarget = comment">回复</button>
|
|
|
|
|
<div v-if="comment.replies?.length" class="reply-list">
|
|
|
|
|
<div v-for="reply in comment.replies" :key="reply.id" class="reply-item">
|
|
|
|
|
<strong>{{ reply.userNickname || '用户' }}</strong>
|
|
|
|
|
<span>{{ reply.commentContent }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</template>
|
|
|
|
|
</main>
|
|
|
|
|
|
|
|
|
|
<footer v-if="!loadError" class="action-buttons">
|
|
|
|
|
<a-button class="add-cart-btn" size="large" @click="handleAddToCart">
|
|
|
|
|
<ShoppingCartOutlined />
|
|
|
|
|
加入购物车
|
|
|
|
|
</a-button>
|
|
|
|
|
<a-button class="buy-now-btn" type="primary" size="large" @click="handleBuyNow">
|
|
|
|
|
<ThunderboltOutlined />
|
|
|
|
|
立即预约
|
|
|
|
|
</a-button>
|
|
|
|
|
<footer v-if="!loadError" class="detail-footer">
|
|
|
|
|
<a-button size="large" @click="handleAddToCart"><ShoppingCartOutlined />加入购物车</a-button>
|
|
|
|
|
<a-button type="primary" size="large" @click="handleBuyNow"><ThunderboltOutlined />立即预约</a-button>
|
|
|
|
|
</footer>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
@@ -129,7 +120,6 @@ import { computed, inject, onMounted, ref } from 'vue'
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
|
|
import {
|
|
|
|
|
CalendarOutlined,
|
|
|
|
|
ClockCircleOutlined,
|
|
|
|
|
HeartFilled,
|
|
|
|
|
HeartOutlined,
|
|
|
|
|
LeftOutlined,
|
|
|
|
@@ -142,6 +132,7 @@ import {
|
|
|
|
|
} from '@ant-design/icons-vue'
|
|
|
|
|
import { message } from 'ant-design-vue'
|
|
|
|
|
import { cartApi } from '@/api/cart'
|
|
|
|
|
import { commentApi, type CommentVO } from '@/api/comment'
|
|
|
|
|
import { fileApi } from '@/api/file'
|
|
|
|
|
import { productApi, type ProductVO } from '@/api/product'
|
|
|
|
|
import { productLikeApi } from '@/api/productLike'
|
|
|
|
@@ -160,97 +151,25 @@ const product = ref<ProductVO>({} as ProductVO)
|
|
|
|
|
const shopInfo = ref<ShopVO | null>(null)
|
|
|
|
|
const productImages = ref<string[]>([])
|
|
|
|
|
const imageIdCache = ref<Record<string, string>>({})
|
|
|
|
|
const comments = ref<CommentVO[]>([])
|
|
|
|
|
const commentText = ref('')
|
|
|
|
|
const replyTarget = ref<CommentVO | null>(null)
|
|
|
|
|
const submittingComment = ref(false)
|
|
|
|
|
const isFavorite = ref(false)
|
|
|
|
|
const isLiked = ref(false)
|
|
|
|
|
const loadError = ref('')
|
|
|
|
|
|
|
|
|
|
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
|
|
|
|
|
const productTitle = computed(() => product.value.title || product.value.name || '作品详情')
|
|
|
|
|
const artistCount = computed(() => {
|
|
|
|
|
if (typeof product.value.availableBookableArtistCount === 'number') {
|
|
|
|
|
return product.value.availableBookableArtistCount
|
|
|
|
|
}
|
|
|
|
|
const rawValue = product.value.bookableArtists || ''
|
|
|
|
|
return rawValue
|
|
|
|
|
.split(',')
|
|
|
|
|
.map(id => id.trim())
|
|
|
|
|
.filter(Boolean).length
|
|
|
|
|
if (typeof product.value.availableBookableArtistCount === 'number') return product.value.availableBookableArtistCount
|
|
|
|
|
return String(product.value.bookableArtists || '').split(',').map(id => id.trim()).filter(Boolean).length
|
|
|
|
|
})
|
|
|
|
|
const artistCountText = computed(() => {
|
|
|
|
|
if (artistCount.value > 0) {
|
|
|
|
|
return `${artistCount.value} 位`
|
|
|
|
|
}
|
|
|
|
|
return product.value.bookableArtistRestricted ? '暂无' : '门店安排'
|
|
|
|
|
})
|
|
|
|
|
const earliestBookableText = computed(() => estimateEarliestBookable(shopInfo.value?.businessHours))
|
|
|
|
|
|
|
|
|
|
const parseTimeRange = (businessHours?: string): { start: string; end: string } | null => {
|
|
|
|
|
if (!businessHours) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
const normalized = businessHours.replace(/\s+/g, '')
|
|
|
|
|
const matched = normalized.match(/(\d{1,2}:\d{2}).*?(\d{1,2}:\d{2})/)
|
|
|
|
|
if (!matched) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
const [, start, end] = matched
|
|
|
|
|
if (!start || !end) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
return { start, end }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formatDateTime = (date: Date) => {
|
|
|
|
|
const month = `${date.getMonth() + 1}`.padStart(2, '0')
|
|
|
|
|
const day = `${date.getDate()}`.padStart(2, '0')
|
|
|
|
|
const hour = `${date.getHours()}`.padStart(2, '0')
|
|
|
|
|
const minute = `${date.getMinutes()}`.padStart(2, '0')
|
|
|
|
|
return `${month}-${day} ${hour}:${minute}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const estimateEarliestBookable = (businessHours?: string) => {
|
|
|
|
|
const timeRange = parseTimeRange(businessHours)
|
|
|
|
|
if (!timeRange) {
|
|
|
|
|
return businessHours || '以门店安排为准'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const startParts = timeRange.start.split(':').map(Number)
|
|
|
|
|
const endParts = timeRange.end.split(':').map(Number)
|
|
|
|
|
const startHour = startParts[0]
|
|
|
|
|
const startMinute = startParts[1]
|
|
|
|
|
const endHour = endParts[0]
|
|
|
|
|
const endMinute = endParts[1]
|
|
|
|
|
if ([startHour, startMinute, endHour, endMinute].some(value => value === undefined || Number.isNaN(value))) {
|
|
|
|
|
return businessHours || '以门店安排为准'
|
|
|
|
|
}
|
|
|
|
|
const safeStartHour = startHour ?? 0
|
|
|
|
|
const safeStartMinute = startMinute ?? 0
|
|
|
|
|
const safeEndHour = endHour ?? 0
|
|
|
|
|
const safeEndMinute = endMinute ?? 0
|
|
|
|
|
const candidate = new Date(Date.now() + 30 * 60 * 1000)
|
|
|
|
|
|
|
|
|
|
const openTime = new Date(candidate)
|
|
|
|
|
openTime.setHours(safeStartHour, safeStartMinute, 0, 0)
|
|
|
|
|
|
|
|
|
|
const closeTime = new Date(candidate)
|
|
|
|
|
closeTime.setHours(safeEndHour, safeEndMinute, 0, 0)
|
|
|
|
|
|
|
|
|
|
if (candidate <= openTime) {
|
|
|
|
|
return `今天 ${timeRange.start}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (candidate >= closeTime) {
|
|
|
|
|
const nextOpen = new Date(openTime)
|
|
|
|
|
nextOpen.setDate(nextOpen.getDate() + 1)
|
|
|
|
|
return `明天 ${timeRange.start}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return formatDateTime(candidate)
|
|
|
|
|
}
|
|
|
|
|
const artistCountText = computed(() => artistCount.value > 0 ? `${artistCount.value} 位` : (product.value.bookableArtistRestricted ? '暂无可约' : '门店安排'))
|
|
|
|
|
const earliestBookableText = computed(() => shopInfo.value?.businessHours || '以门店安排为准')
|
|
|
|
|
|
|
|
|
|
const requireLogin = (actionText: string) => {
|
|
|
|
|
if (isLoggedIn.value) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (isLoggedIn.value) return true
|
|
|
|
|
message.info(`${actionText}前请先登录`)
|
|
|
|
|
router.push('/')
|
|
|
|
|
return false
|
|
|
|
@@ -262,426 +181,172 @@ const loadProductImages = async () => {
|
|
|
|
|
productImages.value = [DEFAULT_PRODUCT_IMAGE]
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const urls: string[] = []
|
|
|
|
|
for (const id of fileIds) {
|
|
|
|
|
try {
|
|
|
|
|
if (!imageIdCache.value[id]) {
|
|
|
|
|
imageIdCache.value[id] = await fileApi.getSignedUrl(id) as unknown as string
|
|
|
|
|
}
|
|
|
|
|
if (imageIdCache.value[id]) {
|
|
|
|
|
urls.push(imageIdCache.value[id])
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取作品图片失败:', error)
|
|
|
|
|
}
|
|
|
|
|
if (!imageIdCache.value[id]) imageIdCache.value[id] = await fileApi.getSignedUrl(id) as unknown as string
|
|
|
|
|
if (imageIdCache.value[id]) urls.push(imageIdCache.value[id])
|
|
|
|
|
} catch {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
productImages.value = urls.length ? urls : [DEFAULT_PRODUCT_IMAGE]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const loadShopInfo = async (shopId?: IdType | null) => {
|
|
|
|
|
if (!shopId) {
|
|
|
|
|
shopInfo.value = null
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const response = await shopApi.getShopById(shopId)
|
|
|
|
|
shopInfo.value = response || null
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取门店信息失败:', error)
|
|
|
|
|
shopInfo.value = null
|
|
|
|
|
}
|
|
|
|
|
shopInfo.value = shopId ? await shopApi.getShopById(shopId).catch(() => null) : null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const checkWishlistStatus = async () => {
|
|
|
|
|
if (!isLoggedIn.value || !product.value.id) {
|
|
|
|
|
isFavorite.value = false
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const status = await wishlistApi.checkWishlist(product.value.id)
|
|
|
|
|
isFavorite.value = Boolean(status)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取收藏状态失败:', error)
|
|
|
|
|
isFavorite.value = false
|
|
|
|
|
}
|
|
|
|
|
const loadComments = async () => {
|
|
|
|
|
if (!product.value.id) return
|
|
|
|
|
comments.value = await commentApi.listByProduct(product.value.id).catch(() => [])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const checkLikeStatus = async () => {
|
|
|
|
|
const checkInteractionStatus = async () => {
|
|
|
|
|
if (!isLoggedIn.value || !product.value.id) {
|
|
|
|
|
isFavorite.value = false
|
|
|
|
|
isLiked.value = false
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const status = await productLikeApi.checkLikeStatus(product.value.id)
|
|
|
|
|
isLiked.value = Boolean(status)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取点赞状态失败:', error)
|
|
|
|
|
isLiked.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resolveLoadError = (error: any) => {
|
|
|
|
|
const status = error?.response?.status
|
|
|
|
|
if (status === 404) {
|
|
|
|
|
return '这件作品可能已下架或不存在。'
|
|
|
|
|
}
|
|
|
|
|
if (status === 401) {
|
|
|
|
|
return '作品详情暂时无法加载,请稍后重试。'
|
|
|
|
|
}
|
|
|
|
|
return error?.message || '网络有点忙,请稍后再试。'
|
|
|
|
|
const [favorite, liked] = await Promise.all([
|
|
|
|
|
wishlistApi.checkWishlist(product.value.id).catch(() => false),
|
|
|
|
|
productLikeApi.checkLikeStatus(product.value.id).catch(() => false)
|
|
|
|
|
])
|
|
|
|
|
isFavorite.value = Boolean(favorite)
|
|
|
|
|
isLiked.value = Boolean(liked)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fetchProductDetail = async () => {
|
|
|
|
|
loadError.value = ''
|
|
|
|
|
try {
|
|
|
|
|
const productId = toOptionalIdString(route.params.id)
|
|
|
|
|
if (!productId) {
|
|
|
|
|
throw new Error('作品ID不存在')
|
|
|
|
|
}
|
|
|
|
|
if (!productId) throw new Error('作品不存在')
|
|
|
|
|
const response = await productApi.getProductById(productId)
|
|
|
|
|
if (!response?.id) {
|
|
|
|
|
throw new Error('未找到对应作品')
|
|
|
|
|
}
|
|
|
|
|
if (!response?.id) throw new Error('作品不存在或已下架')
|
|
|
|
|
product.value = response
|
|
|
|
|
await Promise.all([
|
|
|
|
|
loadProductImages(),
|
|
|
|
|
loadShopInfo(response.shopId),
|
|
|
|
|
checkWishlistStatus(),
|
|
|
|
|
checkLikeStatus()
|
|
|
|
|
])
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取作品详情失败:', error)
|
|
|
|
|
loadError.value = resolveLoadError(error)
|
|
|
|
|
await Promise.all([loadProductImages(), loadShopInfo(response.shopId), checkInteractionStatus(), loadComments()])
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
loadError.value = error?.message || '网络异常,请稍后再试'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleBackClick = () => {
|
|
|
|
|
router.back()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const openShopDetail = () => {
|
|
|
|
|
if (!shopInfo.value?.id) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
router.push(`/shop/${shopInfo.value.id}`)
|
|
|
|
|
if (shopInfo.value?.id) router.push(`/shop/${shopInfo.value.id}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleFavoriteClick = async () => {
|
|
|
|
|
if (!product.value.id || !requireLogin('收藏作品')) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithGlobalLoading(async () => {
|
|
|
|
|
if (isFavorite.value) {
|
|
|
|
|
await wishlistApi.removeFromWishlist(product.value.id)
|
|
|
|
|
product.value.collectCount = Math.max(0, Number(product.value.collectCount || 0) - 1)
|
|
|
|
|
message.success('已取消收藏')
|
|
|
|
|
} else {
|
|
|
|
|
await wishlistApi.addToWishlist(product.value.id)
|
|
|
|
|
product.value.collectCount = Number(product.value.collectCount || 0) + 1
|
|
|
|
|
message.success('已加入收藏')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (!product.value.id || !requireLogin('收藏作品')) return
|
|
|
|
|
await runWithGlobalLoading(async () => {
|
|
|
|
|
if (isFavorite.value) {
|
|
|
|
|
await wishlistApi.removeFromWishlist(product.value.id)
|
|
|
|
|
product.value.collectCount = Math.max(0, Number(product.value.collectCount || 0) - 1)
|
|
|
|
|
message.success('已取消收藏')
|
|
|
|
|
} else {
|
|
|
|
|
await wishlistApi.addToWishlist(product.value.id)
|
|
|
|
|
product.value.collectCount = Number(product.value.collectCount || 0) + 1
|
|
|
|
|
message.success('已加入收藏')
|
|
|
|
|
}
|
|
|
|
|
isFavorite.value = !isFavorite.value
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('收藏操作失败:', error)
|
|
|
|
|
message.error('收藏操作失败,请稍后重试')
|
|
|
|
|
}
|
|
|
|
|
}).catch((error: any) => message.error(error?.message || '收藏操作失败'))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleLikeClick = async () => {
|
|
|
|
|
if (!product.value.id || !requireLogin('点赞作品')) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await runWithGlobalLoading(async () => {
|
|
|
|
|
if (isLiked.value) {
|
|
|
|
|
await productLikeApi.unlikeProduct(product.value.id)
|
|
|
|
|
product.value.likeCount = Math.max(0, Number(product.value.likeCount || 0) - 1)
|
|
|
|
|
message.success('已取消点赞')
|
|
|
|
|
} else {
|
|
|
|
|
await productLikeApi.likeProduct(product.value.id)
|
|
|
|
|
product.value.likeCount = Number(product.value.likeCount || 0) + 1
|
|
|
|
|
message.success('已点赞')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (!product.value.id || !requireLogin('点赞作品')) return
|
|
|
|
|
await runWithGlobalLoading(async () => {
|
|
|
|
|
if (isLiked.value) {
|
|
|
|
|
await productLikeApi.unlikeProduct(product.value.id)
|
|
|
|
|
product.value.likeCount = Math.max(0, Number(product.value.likeCount || 0) - 1)
|
|
|
|
|
message.success('已取消点赞')
|
|
|
|
|
} else {
|
|
|
|
|
await productLikeApi.likeProduct(product.value.id)
|
|
|
|
|
product.value.likeCount = Number(product.value.likeCount || 0) + 1
|
|
|
|
|
message.success('已点赞')
|
|
|
|
|
}
|
|
|
|
|
isLiked.value = !isLiked.value
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('点赞操作失败:', error)
|
|
|
|
|
message.error('点赞操作失败,请稍后重试')
|
|
|
|
|
}
|
|
|
|
|
}).catch((error: any) => message.error(error?.message || '点赞操作失败'))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleAddToCart = async () => {
|
|
|
|
|
if (!product.value.id || !requireLogin('加入购物车')) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await runWithGlobalLoading(() => cartApi.addToCart({ productId: product.value.id, quantity: 1 }))
|
|
|
|
|
await updateCartCount()
|
|
|
|
|
message.success(`已将 ${product.value.title || product.value.name || '作品'} 加入购物车`)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('加入购物车失败:', error)
|
|
|
|
|
message.error('加入购物车失败,请稍后重试')
|
|
|
|
|
}
|
|
|
|
|
if (!product.value.id || !requireLogin('加入购物车')) return
|
|
|
|
|
await runWithGlobalLoading(() => cartApi.addToCart({ productId: product.value.id, quantity: 1 }))
|
|
|
|
|
await updateCartCount()
|
|
|
|
|
message.success('已加入购物车')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleBuyNow = async () => {
|
|
|
|
|
if (!product.value.id || !requireLogin('预约下单')) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (!product.value.id || !requireLogin('预约下单')) return
|
|
|
|
|
await handleAddToCart()
|
|
|
|
|
router.push('/cart')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const submitComment = async () => {
|
|
|
|
|
if (!product.value.id || !requireLogin('发表评论')) return
|
|
|
|
|
const content = commentText.value.trim()
|
|
|
|
|
if (!content) return message.warning('请输入评论内容')
|
|
|
|
|
submittingComment.value = true
|
|
|
|
|
try {
|
|
|
|
|
await runWithGlobalLoading(() => cartApi.addToCart({ productId: product.value.id, quantity: 1 }))
|
|
|
|
|
await updateCartCount()
|
|
|
|
|
router.push('/cart')
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('立即预约失败:', error)
|
|
|
|
|
message.error('操作失败,请稍后重试')
|
|
|
|
|
await commentApi.create({
|
|
|
|
|
productId: product.value.id,
|
|
|
|
|
shopId: product.value.shopId,
|
|
|
|
|
parentCommentId: replyTarget.value?.id,
|
|
|
|
|
commentContent: content
|
|
|
|
|
})
|
|
|
|
|
commentText.value = ''
|
|
|
|
|
replyTarget.value = null
|
|
|
|
|
await loadComments()
|
|
|
|
|
message.success('评论已发布')
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
message.error(error?.message || '评论发布失败')
|
|
|
|
|
} finally {
|
|
|
|
|
submittingComment.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formatTime = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : ''
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
void fetchProductDetail()
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.mobile-container {
|
|
|
|
|
min-height: 100vh;
|
|
|
|
|
background: #f5f5f5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.header {
|
|
|
|
|
position: sticky;
|
|
|
|
|
top: 0;
|
|
|
|
|
z-index: 100;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
padding: 10px 16px;
|
|
|
|
|
background: rgba(255, 255, 255, 0.96);
|
|
|
|
|
backdrop-filter: blur(10px);
|
|
|
|
|
border-bottom: 1px solid #f0f0f0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.header h1 {
|
|
|
|
|
flex: 1;
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.header-star {
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
color: #8b8b9a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.header-star.active {
|
|
|
|
|
color: #f7b500;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.content {
|
|
|
|
|
padding: 16px 16px 108px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.hero-card,
|
|
|
|
|
.info-card {
|
|
|
|
|
max-width: 1040px;
|
|
|
|
|
margin: 0 auto 16px;
|
|
|
|
|
border-radius: 20px;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
background: white;
|
|
|
|
|
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.carousel-slide,
|
|
|
|
|
.single-image {
|
|
|
|
|
aspect-ratio: 16 / 11;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.product-image {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
object-fit: cover;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.info-card {
|
|
|
|
|
padding: 24px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.info-header {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: flex-start;
|
|
|
|
|
gap: 16px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.product-name {
|
|
|
|
|
margin: 0 0 8px;
|
|
|
|
|
font-size: 26px;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
color: #1f1f1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.product-price {
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-size: 28px;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
color: #ff4d4f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.metric-row {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
|
|
|
gap: 12px;
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.metric-card {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 10px;
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding: 14px;
|
|
|
|
|
border: 1px solid #edf0f5;
|
|
|
|
|
border-radius: 16px;
|
|
|
|
|
background: #fafcff;
|
|
|
|
|
text-align: left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.metric-card:disabled {
|
|
|
|
|
cursor: default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.metric-card :deep(svg) {
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
color: #1677ff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.metric-label {
|
|
|
|
|
display: block;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
color: #8b8b9a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.metric-card strong {
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
color: #1f1f1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.shop-summary {
|
|
|
|
|
margin-top: 18px;
|
|
|
|
|
padding: 16px 18px;
|
|
|
|
|
border-radius: 18px;
|
|
|
|
|
background: linear-gradient(135deg, #f8fbff 0%, #eef4ff 100%);
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.shop-summary-title {
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
color: #1f1f1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.shop-summary-text {
|
|
|
|
|
margin-top: 6px;
|
|
|
|
|
color: #666;
|
|
|
|
|
line-height: 1.6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.stats-row {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.stat-btn {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
padding: 10px 14px;
|
|
|
|
|
border: 1px solid #edf0f5;
|
|
|
|
|
border-radius: 999px;
|
|
|
|
|
background: white;
|
|
|
|
|
color: #666;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.stat-btn :deep(svg) {
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.stat-btn :deep(.active),
|
|
|
|
|
.stat-btn :deep(svg.active) {
|
|
|
|
|
color: #ff4d4f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.stat-btn .active {
|
|
|
|
|
color: #ff4d4f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.stat-btn.static {
|
|
|
|
|
cursor: default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tags {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.description-block {
|
|
|
|
|
margin-top: 24px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.description-block h3 {
|
|
|
|
|
margin: 0 0 12px;
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.description-block p {
|
|
|
|
|
margin: 0;
|
|
|
|
|
color: #666;
|
|
|
|
|
line-height: 1.8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.action-buttons {
|
|
|
|
|
position: fixed;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
z-index: 120;
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
padding: 16px;
|
|
|
|
|
background: rgba(255, 255, 255, 0.96);
|
|
|
|
|
backdrop-filter: blur(10px);
|
|
|
|
|
border-top: 1px solid #f0f0f0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.action-buttons :deep(.ant-btn) {
|
|
|
|
|
flex: 1;
|
|
|
|
|
height: 48px;
|
|
|
|
|
border-radius: 999px;
|
|
|
|
|
font-size: 15px;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@media (max-width: 767px) {
|
|
|
|
|
.metric-row {
|
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.stats-row {
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.detail-page { min-height: 100vh; background: #f6f7f9; }
|
|
|
|
|
.detail-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: rgba(255,255,255,.96); border-bottom: 1px solid #eceff3; backdrop-filter: blur(10px); }
|
|
|
|
|
.detail-header h1 { flex: 1; margin: 0; font-size: 17px; text-align: center; color: #20232a; }
|
|
|
|
|
.detail-header .active { color: #e65d7a; }
|
|
|
|
|
.detail-content { max-width: 1040px; margin: 0 auto; padding: 18px 16px 118px; }
|
|
|
|
|
.media-section { overflow: hidden; border-radius: 8px; background: #fff; }
|
|
|
|
|
.media-section img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; }
|
|
|
|
|
.info-section, .comment-section { margin-top: 14px; padding: 22px; border-radius: 8px; background: #fff; border: 1px solid #edf0f4; }
|
|
|
|
|
.title-row { display: flex; justify-content: space-between; gap: 16px; }
|
|
|
|
|
.title-row h2 { margin: 0 0 8px; font-size: 24px; color: #20232a; }
|
|
|
|
|
.price { margin: 0; font-size: 26px; font-weight: 700; color: #d94f69; }
|
|
|
|
|
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
|
|
|
|
|
.metrics > div, .metrics > button { display: grid; gap: 4px; padding: 14px; border: 1px solid #edf0f4; border-radius: 8px; background: #fbfcfe; text-align: left; }
|
|
|
|
|
.metrics svg { color: #3b82f6; }
|
|
|
|
|
.metrics span { font-size: 12px; color: #7b8494; }
|
|
|
|
|
.metrics strong { color: #20232a; }
|
|
|
|
|
.shop-panel { display: grid; gap: 6px; margin-top: 18px; padding: 16px; border-radius: 8px; background: #f7f9fc; cursor: pointer; color: #5f6876; }
|
|
|
|
|
.shop-panel strong { color: #20232a; }
|
|
|
|
|
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
|
|
|
|
|
.actions-row button { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border: 1px solid #edf0f4; border-radius: 999px; background: #fff; color: #5f6876; }
|
|
|
|
|
.actions-row button.active { color: #d94f69; border-color: #ffd7e0; background: #fff5f7; }
|
|
|
|
|
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
|
|
|
|
|
.description { margin-top: 22px; }
|
|
|
|
|
.description h3, .section-head h3 { margin: 0; font-size: 18px; color: #20232a; }
|
|
|
|
|
.description p { margin: 10px 0 0; color: #5f6876; line-height: 1.8; }
|
|
|
|
|
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
|
|
|
|
|
.section-head span { color: #7b8494; }
|
|
|
|
|
.comment-editor { padding: 14px; border: 1px solid #edf0f4; border-radius: 8px; background: #fbfcfe; }
|
|
|
|
|
.comment-tools { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
|
|
|
|
|
.comment-item { padding: 16px 0; border-bottom: 1px solid #edf0f4; }
|
|
|
|
|
.comment-item:last-child { border-bottom: 0; }
|
|
|
|
|
.comment-main { display: flex; justify-content: space-between; gap: 12px; color: #7b8494; }
|
|
|
|
|
.comment-main strong { color: #20232a; }
|
|
|
|
|
.comment-item p { margin: 8px 0; color: #3b4350; line-height: 1.7; }
|
|
|
|
|
.comment-item button { padding: 0; border: 0; background: transparent; color: #3b82f6; cursor: pointer; }
|
|
|
|
|
.reply-list { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: #f7f9fc; }
|
|
|
|
|
.reply-item { display: flex; gap: 8px; padding: 6px 0; color: #5f6876; }
|
|
|
|
|
.reply-item strong { color: #20232a; }
|
|
|
|
|
.detail-footer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; gap: 12px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); border-top: 1px solid #eceff3; backdrop-filter: blur(10px); }
|
|
|
|
|
.detail-footer :deep(.ant-btn) { flex: 1; height: 46px; border-radius: 999px; font-weight: 700; }
|
|
|
|
|
@media (max-width: 720px) { .metrics { grid-template-columns: 1fr; } .title-row { flex-direction: column; } }
|
|
|
|
|
</style>
|
|
|
|
|