<template>
	<view class="all-services-page">
		<!-- 顶部搜索栏 -->
		<view class="header-search">
			<view class="location-box">
				<text>昆明市</text>
				<uni-icons type="bottom" size="12" color="#333"></uni-icons>
			</view>
			<view class="search-input-wrap">
				<uni-icons type="search" size="14" color="#999"></uni-icons>
				<input class="search-input" v-model="searchValue" placeholder="搜索服务内容"
					placeholder-class="placeholder-style" />
			</view>
		</view>

		<!-- 主体分类区域 -->
		<view class="main-content">
			<!-- 左侧侧边栏 -->
			<scroll-view scroll-y class="sidebar">
				<view v-for="(item, index) in allData" :key="index"
					:class="['sidebar-item', { active: activeSidebar === index }]" @click="activeSidebar = index">
					<text>{{ item.title }}</text>
				</view>
			</scroll-view>

			<!-- 右侧服务列表 -->
			<scroll-view scroll-y class="content-view">
				<view class="category-section" v-for="(cat, index) in currentCategories" :key="index">
					<text class="cat-section-title">{{ cat.name }}</text>
					<view class="service-grid">
						<view class="service-cell" v-for="(service, sIndex) in cat.items" :key="sIndex"
							@click="onServiceClick(service)">
							<view class="icon-wrapper">
								<image :src="service.icon" class="service-icon" mode="aspectFit"></image>
							</view>
							<text class="service-name">{{ service.name }}</text>
						</view>
					</view>
				</view>

				<!-- 底部客服提示 -->
				<view class="contact-footer">
					<image src="https://img.icons8.com/?size=100&id=108639&format=png" class="kf-avatar"
						mode="aspectFit"></image>
					<text class="footer-msg">没有找到想要的服务？可以联系客服哟~</text>
					<button size="mini" class="kf-btn">联系客服 ></button>
				</view>
			</scroll-view>
		</view>

		<custom-tabbar></custom-tabbar>
	</view>
</template>

<script setup>
import { ref, computed } from 'vue'
import customTabbar from '@/components/custom-tabbar/index.vue'
import servicesMockData from '@/mock/services.json'

const searchValue = ref('')
const activeSidebar = ref(0)
const allData = servicesMockData
const currentCategories = computed(() => allData[activeSidebar.value].categories)

const onServiceClick = (service) => {
	if (service.type) {
		uni.navigateTo({ url: `/pages/service/detail/index?service=${service.type}` })
	} else {
		uni.showToast({ title: service.name + ' 功能即将上线', icon: 'none' })
	}
}
</script>

<style lang="scss" scoped>
.all-services-page { height: 100vh; display: flex; flex-direction: column; background-color: #fff; }
.header-search { display: flex; align-items: center; padding: 16rpx 32rpx; background-color: #fff; border-bottom: 1rpx solid #f2f2f2; }
.location-box { display: flex; align-items: center; gap: 8rpx; font-size: 28rpx; color: #333; margin-right: 24rpx; }
.search-input-wrap { flex: 1; display: flex; align-items: center; background: #f5f5f5; border-radius: 32rpx; padding: 12rpx 20rpx; gap: 12rpx; }
.search-input { flex: 1; font-size: 26rpx; }
.placeholder-style { color: #999; font-size: 26rpx; }
.main-content { flex: 1; display: flex; overflow: hidden; }
.sidebar { width: 200rpx; background-color: #f7f8fa; }
.sidebar-item { padding: 28rpx 0; text-align: center; font-size: 26rpx; color: #666; position: relative; }
.sidebar-item.active { background-color: #fff; color: #333; font-weight: bold; }
.sidebar-item.active::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 6rpx; height: 40rpx; background-color: #f7ca3e; border-radius: 0 6rpx 6rpx 0; }
.content-view { flex: 1; padding: 32rpx; }
.category-section { margin-bottom: 48rpx; }
.cat-section-title { font-size: 28rpx; font-weight: bold; color: #333; display: block; margin-bottom: 24rpx; background-color: #f9f9f9; padding: 8rpx 20rpx; border-radius: 8rpx; }
.service-grid { display: flex; flex-wrap: wrap; }
.service-cell { width: 33.33%; display: flex; flex-direction: column; align-items: center; margin-bottom: 32rpx; }
.icon-wrapper { width: 96rpx; height: 96rpx; background-color: #fff; border-radius: 24rpx; display: flex; align-items: center; justify-content: center; box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04); margin-bottom: 16rpx; }
.service-icon { width: 56rpx; height: 56rpx; }
.service-name { font-size: 24rpx; color: #666; text-align: center; }
.contact-footer { margin-top: 40rpx; background-color: #f0f7ff; border-radius: 24rpx; padding: 32rpx; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 20rpx; }
.kf-avatar { width: 80rpx; height: 80rpx; }
.footer-msg { font-size: 26rpx; color: #333; }
.kf-btn { font-size: 24rpx; color: #1989fa; background: transparent; border: 1rpx solid #1989fa; border-radius: 28rpx; padding: 8rpx 32rpx; line-height: 1.5; }
</style>
