<template>
	<view class="service-detail-page">
		<nav-bar title="服务详情"></nav-bar>
		<!-- 顶部主图区域 -->
		<view class="hero-section">
			<image :src="serviceData.heroImg" class="hero-img" mode="aspectFill"></image>
			<view class="hero-overlay"></view>
			<view class="hero-title-box">
				<text class="hero-main-title">{{ serviceData.heroTitle }}</text>
				<text class="hero-sub-title">{{ serviceData.heroSubTitle }}</text>
			</view>
		</view>

		<!-- 购买数据 -->
		<view class="info-section card">
			<view class="service-price-row">
				<view class="price-box">
					<text class="price-label">订单服务费:</text>
					<text class="price-symbol">￥</text>
					<text class="price-num">{{ serviceData.price }}</text>
					<text class="price-unit">{{ serviceData.unit }}</text>
				</view>
			</view>
			<text class="service-name-text">{{ serviceData.title }}</text>
		</view>

		<!-- 详情选项卡 -->
		<view class="tab-section card">
			<view class="tab-header">
				<view :class="['tab-btn', { active: activeTab === 'intro' }]" @click="activeTab = 'intro'">
					<text>服务介绍</text>
				</view>
				<view :class="['tab-btn', { active: activeTab === 'notice' }]" @click="activeTab = 'notice'">
					<text>下单须知</text>
				</view>
			</view>

			<view class="tab-content" v-if="activeTab === 'intro'">
				<text class="content-title">服务介绍</text>
				<rich-text :nodes="serviceData.intro" class="content-text"></rich-text>
				<view class="intro-images" v-if="serviceData.introImages && serviceData.introImages.length">
					<image v-for="(img, idx) in serviceData.introImages" :key="idx" :src="img" class="intro-img"
						mode="widthFix"></image>
				</view>
			</view>

			<view class="tab-content" v-if="activeTab === 'notice'">
				<text class="content-title">下单须知</text>
				<rich-text :nodes="serviceData.notice" class="content-text"></rich-text>
			</view>
		</view>

		<!-- 底部操作栏 -->
		<view class="footer-bar safe-bottom">
			<button class="buy-btn" @click="goToOrderApply">立即预约</button>
		</view>
	</view>
</template>

<script setup>
import { ref, computed } from 'vue'
import navBar from '@/components/nav-bar/index.vue'
import { onLoad } from '@dcloudio/uni-app'

const activeTab = ref('intro')
const serviceInfo = ref(null)

const defaultHeroImg = 'https://images.unsplash.com/photo-1544568100-847a948585b9?q=80&w=600&auto=format&fit=crop'

onLoad((options) => {
	const storedService = uni.getStorageSync('currentService')
	if (storedService) {
		serviceInfo.value = storedService
		console.log('获取到的服务数据:', storedService)
	}
})

const serviceData = computed(() => {
	if (!serviceInfo.value) {
		return {
			heroImg: defaultHeroImg,
			heroTitle: '服务详情',
			heroSubTitle: '加载中...',
			price: '0',
			unit: '',
			booked: '0 人已约',
			title: '服务名称',
			intro: '加载中...',
			notice: '加载中...',
			introImages: []
		}
	}

	const service = serviceInfo.value
	const priceInYuan = service.price ? (service.price / 100).toFixed(2) : '0.00'

	return {
		type: service.id,
		title: service.name,
		heroTitle: service.name,
		heroSubTitle: service.remark || '专业服务',
		heroImg: service.iconUrl || defaultHeroImg,
		price: priceInYuan,
		unit: '',
		booked: '0 人已约',
		intro: service.introduction || '暂无介绍',
		introImages: [],
		notice: service.orderInstruction || '暂无须知'
	}
})

const goToOrderApply = () => {
	uni.navigateTo({
		url: `/pages/order/apply/index?service=${serviceData.value.type}`
	})
}
</script>

<style lang="scss" scoped>
.service-detail-page {
	background-color: #f5f5f5;
	min-height: 100vh;
	padding-bottom: 160rpx;
}

.hero-section {
	position: relative;
	width: 100%;
	height: 640rpx;
	overflow: hidden;
}

.hero-img {
	width: 100%;
	height: 100%;
}

.hero-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0) 40%, rgba(0, 0, 0, 0.4) 80%, rgba(0, 0, 0, 0.7) 100%);
}

.hero-title-box {
	position: absolute;
	bottom: 48rpx;
	left: 40rpx;
	right: 40rpx;
	z-index: 2;
}

.hero-main-title {
	display: block;
	font-size: 52rpx;
	font-weight: 900;
	color: #fff;
	margin-bottom: 12rpx;
}

.hero-sub-title {
	display: block;
	font-size: 28rpx;
	color: rgba(255, 255, 255, 0.9);
	font-weight: 600;
}

.card {
	background-color: #fff;
	margin-bottom: 20rpx;
}

.info-section {
	padding: 32rpx 40rpx;
	position: relative;
	z-index: 3;
	border-radius: 24rpx 24rpx 0 0;
	margin-top: -24rpx;
}

.service-price-row {
	display: flex;
	justify-content: space-between;
	align-items: flex-end;
	margin-bottom: 20rpx;
}

.price-box {
	display: flex;
	align-items: baseline;
	color: #f44336;
}

.price-label {
	font-size: 26rpx;
	color: #333;
	font-weight: bold;
	margin-right: 12rpx;
}

.price-symbol {
	font-size: 28rpx;
	font-weight: bold;
}

.price-num {
	font-size: 56rpx;
	font-weight: 900;
	line-height: 1;
}

.price-unit {
	font-size: 24rpx;
	color: #999;
	margin-left: 4rpx;
}

.bought-count {
	font-size: 24rpx;
	color: #999;
	background: #f5f5f5;
	padding: 4rpx 16rpx;
	border-radius: 20rpx;
}

.service-name-text {
	font-size: 32rpx;
	color: #111;
	font-weight: bold;
}

.tab-section {
	padding: 0;
}

.tab-header {
	display: flex;
	border-bottom: 1rpx solid #f0f0f0;
}

.tab-btn {
	flex: 1;
	text-align: center;
	padding: 24rpx 0;
	font-size: 28rpx;
	color: #666;
	position: relative;
}

.tab-btn.active {
	color: #fcd53f;
	font-weight: bold;
}

.tab-btn.active::after {
	content: '';
	position: absolute;
	bottom: 0;
	left: 50%;
	transform: translateX(-50%);
	width: 60rpx;
	height: 6rpx;
	background: #fcd53f;
	border-radius: 6rpx;
}

.tab-content {
	padding: 40rpx 32rpx;
}

.content-title {
	display: block;
	font-size: 32rpx;
	color: #333;
	font-weight: 900;
	margin-bottom: 24rpx;
	padding-left: 20rpx;
	position: relative;
}

.content-title::before {
	content: '';
	position: absolute;
	left: 0;
	top: 4rpx;
	bottom: 4rpx;
	width: 8rpx;
	background: #fcd53f;
	border-radius: 4rpx;
}

.content-text {
	font-size: 28rpx;
	color: #555;
	line-height: 1.8;
}

.intro-images {
	margin-top: 32rpx;
	display: flex;
	flex-direction: column;
	gap: 24rpx;
}

.intro-img {
	width: 100%;
	border-radius: 20rpx;
}

.footer-bar {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	padding: 20rpx 32rpx 40rpx;
	background-color: #fff;
	z-index: 10;
	box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.05);
}

.buy-btn {
	width: 100%;
	height: 92rpx;
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	background: linear-gradient(90deg, #ffd53f, #ff9500);
	border: none;
	border-radius: 46rpx;
	line-height: 92rpx;
}
</style>
