Files
JayuCloud/YumiNail-Frontend/src/views/ShopDetailView.vue
T

517 lines
13 KiB
Vue
Raw Normal View History

2026-02-26 23:28:24 +08:00
<template>
<div class="shop-detail">
<div class="header-bg"></div>
<header class="header">
<a-button class="back-btn" type="text" @click="handleBackClick">
<LeftOutlined :style="{ fontSize: '20px' }" />
</a-button>
<h1>店铺详情</h1>
<div class="header-placeholder"></div>
</header>
<div class="shop-content">
<a-card :bordered="false" class="shop-card">
<div class="shop-info">
<div class="shop-header">
<div class="shop-icon-wrapper">
<ShopOutlined class="shop-icon" />
</div>
<div class="shop-header-content">
<h2 class="shop-name" @click="copyToClipboard(shopInfo.shopName, '店名')" style="cursor: pointer;">
{{ shopInfo.shopName }}
<span class="copy-icon">📋</span>
</h2>
<p class="shop-address" @click="copyToClipboard(shopInfo.address, '地址')" style="cursor: pointer;">
{{ shopInfo.address }}
<span class="copy-icon">📋</span>
</p>
<p v-if="distanceText" class="shop-distance">{{ distanceText }}</p>
2026-02-26 23:28:24 +08:00
</div>
</div>
<div class="shop-details">
<div class="detail-item">
<div class="detail-label">营业时间</div>
<div class="detail-value">{{ shopInfo.businessHours }}</div>
</div>
<div class="detail-item">
<div class="detail-label">店铺描述</div>
<div class="detail-value">{{ shopInfo.description }}</div>
</div>
</div>
<a-button class="contact-btn" type="primary" block @click="openManagerContact">
一键联系店长
</a-button>
<div v-if="hasLocation" class="map-actions">
<a-button block @click="openMapPreview">查看地图位置</a-button>
<a-button block @click="openNavigation('TENCENT')">腾讯地图导航</a-button>
<a-button block @click="openNavigation('AMAP')">高德地图导航</a-button>
</div>
<!-- 店铺环境图轮播 -->
2026-02-26 23:28:24 +08:00
<div class="shop-images" v-if="shopImages.length > 0">
<h3 class="section-title">店铺环境图</h3>
<div class="image-carousel">
2026-03-05 16:28:05 +08:00
<a-carousel autoplay :autoplay-speed="3000" dots>
<div v-for="(url, index) in shopImages" :key="index" class="carousel-item" @click="showImageModal(url)">
<img :src="url" :alt="`店铺环境图 ${index + 1}`" class="carousel-image" />
</div>
</a-carousel>
2026-02-26 23:28:24 +08:00
</div>
</div>
<!-- 图片查看模态框 -->
<a-modal
v-model:open="imageModalVisible"
title="店铺环境图"
:width="800"
@cancel="handleCancel"
>
<img :src="selectedImage" alt="店铺环境图" class="modal-image" />
</a-modal>
<a-modal v-model:open="contactOpen" title="一键联系" :footer="null">
<div class="contact-box">
<p><strong>{{ contactInfo.contactName || contactInfo.roleLabel || '联系人' }}</strong></p>
<p>电话联系:{{ contactInfo.phoneAvailable ? contactInfo.phone : '暂无电话' }}</p>
<a-button v-if="contactInfo.phoneAvailable" type="primary" block :href="`tel:${contactInfo.phone}`">拨打电话</a-button>
<a-button block disabled>{{ contactInfo.platformContactText || '平台联系暂未接入' }}</a-button>
</div>
</a-modal>
2026-02-26 23:28:24 +08:00
</div>
</a-card>
</div>
</div>
</template>
<script setup lang="ts">
/**
* ShopDetailView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, ref, onMounted } from 'vue'
2026-02-26 23:28:24 +08:00
import { useRouter, useRoute } from 'vue-router'
import { LeftOutlined, ShopOutlined } from '@ant-design/icons-vue'
2026-03-05 16:28:05 +08:00
import { message } from 'ant-design-vue'
2026-02-26 23:28:24 +08:00
import { shopApi, type ShopVO } from '@/api/shop'
import { fileApi } from '@/api/file'
import { userApi, type ContactInfoVO } from '@/api/user'
2026-03-27 14:55:41 +08:00
import { toOptionalIdString } from '@/utils/id'
2026-02-26 23:28:24 +08:00
const router = useRouter()
const route = useRoute()
const shopInfo = ref<ShopVO>({
2026-03-27 14:55:41 +08:00
id: '',
2026-02-26 23:28:24 +08:00
shopName: '',
description: '',
address: '',
mapProvider: 'TENCENT',
longitude: '',
latitude: '',
2026-02-26 23:28:24 +08:00
businessHours: '',
2026-03-02 10:13:20 +08:00
imageFileIds: '',
createTime: '',
updateTime: ''
2026-02-26 23:28:24 +08:00
})
const shopImages = ref<string[]>([])
// 图片模态框
/** imageModalVisible is a reactive state variable used by the template and event handlers. */
const imageModalVisible = ref(false)
/** selectedImage is a reactive state variable used by the template and event handlers. */
const selectedImage = ref('')
/** contactOpen is a reactive state variable used by the template and event handlers. */
const contactOpen = ref(false)
const contactInfo = ref<ContactInfoVO>({})
const hasLocation = computed(() => Boolean(shopInfo.value.longitude && shopInfo.value.latitude))
const distanceText = ref('')
/** handleBackClick is a local helper used by this page script. */
2026-02-26 23:28:24 +08:00
const handleBackClick = () => {
router.back()
}
// 显示图片模态框
/** showImageModal is a local helper used by this page script. */
const showImageModal = (imageUrl: string) => {
selectedImage.value = imageUrl
imageModalVisible.value = true
}
// 关闭图片模态框
/** handleCancel is a local helper used by this page script. */
const handleCancel = () => {
imageModalVisible.value = false
selectedImage.value = ''
}
/** openManagerContact is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const openManagerContact = async () => {
try {
contactInfo.value = await userApi.getShopManagerContact(shopInfo.value.id)
contactOpen.value = true
} catch (error: any) {
message.error(error?.message || '获取联系方式失败')
}
}
const openMapPreview = () => {
const url = shopInfo.value.navigationUrls?.BROWSER || shopInfo.value.navigationUrls?.TENCENT
if (!url) {
message.warning('店铺暂未设置地图位置')
return
}
window.open(url, '_blank')
}
const openNavigation = (provider: 'TENCENT' | 'AMAP') => {
const url = shopInfo.value.navigationUrls?.[provider]
if (!url) {
message.warning('店铺暂未设置地图位置')
return
}
window.open(url, '_blank')
}
const calculateDistanceText = (currentLat: number, currentLng: number) => {
const shopLat = Number(shopInfo.value.latitude)
const shopLng = Number(shopInfo.value.longitude)
if (!Number.isFinite(currentLat) || !Number.isFinite(currentLng) || !Number.isFinite(shopLat) || !Number.isFinite(shopLng)) {
distanceText.value = ''
return
}
const toRad = (value: number) => value * Math.PI / 180
const earthRadius = 6371000
const dLat = toRad(shopLat - currentLat)
const dLng = toRad(shopLng - currentLng)
const a = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(currentLat)) * Math.cos(toRad(shopLat)) * Math.sin(dLng / 2) ** 2
const meters = 2 * earthRadius * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
distanceText.value = meters >= 1000 ? `距你约 ${(meters / 1000).toFixed(1)} km` : `距你约 ${Math.round(meters)} m`
}
const loadCurrentDistance = () => {
if (!hasLocation.value || !navigator.geolocation) {
return
}
navigator.geolocation.getCurrentPosition(
position => calculateDistanceText(position.coords.latitude, position.coords.longitude),
() => {
distanceText.value = ''
},
{ enableHighAccuracy: false, timeout: 8000, maximumAge: 300000 }
)
}
// 复制到剪贴板
/** copyToClipboard is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const copyToClipboard = async (text: string, type: string) => {
try {
await navigator.clipboard.writeText(text)
message.success(`${type}已复制到剪贴板`)
} catch (err) {
console.error('复制失败:', err)
message.error('复制失败,请手动复制')
}
}
/** loadShopImages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-26 23:28:24 +08:00
const loadShopImages = async () => {
try {
const imageFileIds = shopInfo.value.imageFileIds
if (imageFileIds) {
const fileIds = imageFileIds.split(',').filter(id => id.trim())
const fileIdPromises = fileIds.map(idStr => {
2026-03-27 14:55:41 +08:00
const fileId = idStr.trim()
if (!fileId) {
return null
}
2026-03-27 14:55:41 +08:00
return fileApi.getSignedUrl(fileId).catch(() => {
return null
})
})
const results = await Promise.all(fileIdPromises)
2026-03-05 16:28:05 +08:00
const filteredResults = results
.filter((url): url is any => url !== null)
.map(url => {
const urlStr = typeof url === 'string' ? url : String(url)
return urlStr.replace(/[`]/g, '').trim()
})
shopImages.value = filteredResults
}
} catch (error) {
}
2026-02-26 23:28:24 +08:00
}
/** fetchShopDetail is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-26 23:28:24 +08:00
const fetchShopDetail = async () => {
try {
// 从路由参数或本地存储获取店铺ID
2026-03-27 14:55:41 +08:00
const shopId = toOptionalIdString(route.params.id || localStorage.getItem('userShopId'))
2026-02-26 23:28:24 +08:00
if (!shopId) {
message.error('店铺ID不存在')
router.back()
return
}
2026-03-27 14:55:41 +08:00
const response = await shopApi.getShopById(shopId) as any
2026-03-02 10:13:20 +08:00
shopInfo.value = response || {}
2026-02-26 23:28:24 +08:00
// 加载店铺图片
await loadShopImages()
loadCurrentDistance()
2026-02-26 23:28:24 +08:00
} catch (error) {
message.error('获取店铺详情失败')
}
}
onMounted(() => {
fetchShopDetail()
})
</script>
<style scoped>
.shop-detail {
min-height: 100vh;
background: #f5f5f5;
position: relative;
}
.header-bg {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 120px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
z-index: 0;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 15px;
background: transparent;
color: white;
}
.back-btn {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.header h1 {
font-size: 18px;
font-weight: bold;
margin: 0;
}
.header-placeholder {
width: 40px;
height: 40px;
}
.shop-content {
padding: 100px 15px 20px;
position: relative;
z-index: 1;
}
.shop-card {
border-radius: 20px;
overflow: hidden;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}
.shop-card :deep(.ant-card-body) {
padding: 24px;
}
.shop-info {
display: flex;
flex-direction: column;
gap: 20px;
}
.shop-header {
display: flex;
align-items: center;
gap: 16px;
}
.shop-icon-wrapper {
width: 80px;
height: 80px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.shop-icon {
font-size: 36px;
color: white;
}
.shop-header-content {
flex: 1;
}
.shop-name {
font-size: 22px;
font-weight: 700;
margin: 0 0 8px 0;
color: #1a1a2e;
}
.shop-address {
font-size: 14px;
color: #8b8b9a;
margin: 0;
}
.shop-distance {
margin: 6px 0 0;
color: #7a5262;
font-size: 13px;
}
.copy-icon {
font-size: 12px;
margin-left: 6px;
opacity: 0.6;
transition: opacity 0.2s ease;
}
.shop-name:hover .copy-icon,
.shop-address:hover .copy-icon {
opacity: 1;
color: #667eea;
}
2026-02-26 23:28:24 +08:00
.shop-details {
display: flex;
flex-direction: column;
gap: 16px;
}
.contact-btn {
margin-top: 18px;
border-radius: 8px;
}
.map-actions {
display: grid;
gap: 10px;
margin-top: 12px;
}
.contact-box {
display: grid;
gap: 12px;
}
2026-02-26 23:28:24 +08:00
.detail-item {
display: flex;
flex-direction: column;
gap: 6px;
}
.detail-label {
font-size: 13px;
color: #8b8b9a;
font-weight: 500;
}
.detail-value {
font-size: 16px;
color: #1a1a2e;
line-height: 1.5;
}
.section-title {
font-size: 16px;
font-weight: 600;
color: #1a1a2e;
margin: 0 0 12px 0;
}
.image-carousel {
margin: 12px 0;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
width: 100%;
height: 200px;
}
.carousel-item {
width: 100%;
height: 200px;
cursor: pointer;
position: relative;
overflow: hidden;
2026-02-26 23:28:24 +08:00
display: flex;
align-items: center;
justify-content: center;
}
.carousel-image {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s ease;
}
.carousel-item:hover .carousel-image {
transform: scale(1.05);
}
/* 轮播指示器样式 */
.image-carousel :deep(.slick-dots) {
bottom: 10px;
}
.image-carousel :deep(.slick-dots li) {
margin: 0 4px;
}
.image-carousel :deep(.slick-dots li button) {
width: 8px;
height: 8px;
border-radius: 50%;
background: rgba(0, 0, 0, 0.4);
}
.image-carousel :deep(.slick-dots li.slick-active button) {
width: 20px;
border-radius: 4px;
background: #667eea;
}
.modal-image {
width: 100%;
max-height: 600px;
object-fit: contain;
border-radius: 8px;
2026-02-26 23:28:24 +08:00
}
2026-03-24 09:50:55 +08:00
@media (min-width: 992px) {
.shop-content {
max-width: 1040px;
margin: 0 auto;
padding: 100px 24px 24px;
2026-03-24 09:50:55 +08:00
}
}
</style>