<template>
	<view class="precise-match">
		<!-- 顶部导航栏 -->
		<view class="header">
			<view class="back-icon" @click="handleBack"></view>
			<text class="header-title">精准匹配</text>
			<view class="header-right"></view>
		</view>

		<!-- 匹配客户列表 -->
		<scroll-view scroll-y class="match-list">
			<view class="match-client" v-for="(client, index) in matchClients" :key="index">
				<view class="client-info">
					<image :src="client.avatar" class="client-avatar" mode="aspectFill"></image>
					<view class="info-content">
						<view class="client-name">
							<text class="name-text">{{ client.name }}</text>
							<text class="client-gender">{{ client.gender }}</text>
							<text class="client-status">{{ client.status }}</text>
						</view>
						<view class="client-tags">
							<text class="tag" v-for="(tag, tagIndex) in client.tags" :key="tagIndex">{{ tag }}</text>
						</view>
						<view class="requirement">
							<text class="requirement-label">择偶要求:</text>
							<text class="requirement-content">{{ client.requirement }}</text>
						</view>
						<view class="contact-info">
							<text class="contact-label">联系方式:</text>
							<text class="contact-number">{{ client.contact }}</text>
							<text class="copy-btn" @click="handleCopy(client.contact)">复制</text>
						</view>
					</view>
				</view>
				<view class="action-btn" @click="handleChat(client)">牵线聊聊</view>
			</view>
		</scroll-view>

		<!-- 底部导航 -->
		<view class="tabbar">
			<view class="tabbar-item" @click="handleHome">
				<view class="tabbar-icon home"></view>
				<text class="tabbar-text">工作台</text>
			</view>
			<view class="tabbar-item active" @click="handleMyResources">
				<view class="tabbar-icon resources"></view>
				<text class="tabbar-text">我的资源</text>
			</view>
			<view class="tabbar-item" @click="handleRanking">
				<view class="tabbar-icon trophy"></view>
				<text class="tabbar-text">排行榜</text>
			</view>
			<view class="tabbar-item" @click="handleMessage">
				<view class="tabbar-icon message">
					<text class="badge">3</text>
				</view>
				<text class="tabbar-text">消息</text>
			</view>
			<view class="tabbar-item" @click="handleMine">
				<view class="tabbar-icon mine"></view>
				<text class="tabbar-text">我的</text>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'precise-match',
	data() {
		return {
			matchClients: [
				{
					id: 1,
					name: '小高',
					gender: '女',
					status: '未匹配',
					tags: ['气质男', '小清新'],
					avatar: 'https://images.unsplash.com/photo-1506744038136-46273834b3fb?ixlib=rb-1.2.1&auto=format&fit=crop&w=200&q=60',
					requirement: '165+ 本科',
					contact: '123****8912'
				},
				{
					id: 2,
					name: '小子',
					gender: '女',
					status: '未匹配',
					tags: ['周末有空'],
					avatar: 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixlib=rb-1.2.1&auto=format&fit=crop&w=200&q=60',
					requirement: '165+ 本科',
					contact: '123****8912'
				},
				{
					id: 3,
					name: '小博',
					gender: '女',
					status: '未匹配',
					tags: ['电话联系', '运动'],
					avatar: 'https://images.unsplash.com/photo-1516321318423-f06f85e504b3?ixlib=rb-1.2.1&auto=format&fit=crop&w=200&q=60',
					requirement: '180+ 本科',
					contact: '123****8912'
				}
			]
		}
	},
	onLoad(options) {
		// 从URL参数获取客户ID
		if (options.id) {
			// 这里可以根据ID从API获取匹配客户信息
			console.log('当前客户ID:', options.id)
			// this.loadMatchClients(options.id)
		}
	},
	methods: {
		// 返回上一页
		handleBack() {
			uni.navigateBack()
		},
		// 复制联系方式
		handleCopy(contact) {
			uni.setClipboardData({
				data: contact.replace(/\*+/g, ''),
				success: () => {
					uni.showToast({
						title: '复制成功',
						icon: 'success'
					})
				}
			})
		},
		// 牵线聊聊
		handleChat(client) {
			// 跳转到聊天页面或打开聊天弹窗
			uni.showToast({
				title: '牵线成功',
				icon: 'success'
			})
		},
		// 从API加载匹配客户信息
		async loadMatchClients(id) {
			try {
				// 这里调用API获取匹配客户信息
				// const res = await api.matchmaker.getPreciseMatch(id)
				// this.matchClients = res.data
			} catch (e) {
				console.error('加载匹配客户失败:', e)
				uni.showToast({
					title: '加载失败',
					icon: 'none'
				})
			}
		},
		// 底部导航 - 工作台
		handleHome() {
			uni.navigateTo({
				url: '/pages/matchmaker-workbench/index'
			})
		},
		// 底部导航 - 我的资源
		handleMyResources() {
			uni.navigateTo({
				url: '/pages/matchmaker-workbench/my-resources'
			})
		},
		// 底部导航 - 排行榜
		handleRanking() {
			uni.navigateTo({
				url: '/pages/matchmaker-workbench/ranking'
			})
		},
		// 底部导航 - 消息
		handleMessage() {
			uni.navigateTo({
				url: '/pages/matchmaker-workbench/message'
			})
		},
		// 底部导航 - 我的
		handleMine() {
			uni.navigateTo({
				url: '/pages/matchmaker-workbench/mine'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
	.precise-match {
		min-height: 100vh;
		background-color: #FFF9F9;
		padding-top: 90rpx;
	}

	/* 顶部导航栏 */
	.header {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		height: 90rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 20rpx;
		background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
		z-index: 999;

		.back-icon {
			width: 44rpx;
			height: 44rpx;
			background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333"><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></svg>');
			background-size: contain;
			background-repeat: no-repeat;
			background-position: center;
		}

		.header-title {
			font-size: 38rpx;
			font-weight: bold;
			color: #333;
		}

		.header-right {
			width: 44rpx;
		}
	}

	/* 匹配客户列表 */
	.match-list {
		padding: 20rpx;
		padding-bottom: 120rpx;

		.match-client {
			background-color: #FFFFFF;
			border-radius: 20rpx;
			margin-bottom: 20rpx;
			padding: 25rpx;
			box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);

			.client-info {
				display: flex;
				align-items: flex-start;
				margin-bottom: 20rpx;

				.client-avatar {
					width: 120rpx;
					height: 120rpx;
					border-radius: 50%;
					margin-right: 20rpx;
					background-color: #F5F5F5;
				}

				.info-content {
					flex: 1;

					.client-name {
						display: flex;
						align-items: center;
						gap: 15rpx;
						margin-bottom: 10rpx;

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

						.client-gender {
							font-size: 26rpx;
							color: #666;
						}

						.client-status {
							font-size: 24rpx;
							color: #FF6B8A;
							background-color: #FFF3F5;
							padding: 4rpx 12rpx;
							border-radius: 15rpx;
						}
					}

					.client-tags {
						display: flex;
						flex-wrap: wrap;
						gap: 10rpx;
						margin-bottom: 15rpx;

						.tag {
							padding: 6rpx 16rpx;
							background-color: #F3E5F5;
							color: #9C27B0;
							border-radius: 15rpx;
							font-size: 22rpx;
						}
					}

					.requirement {
						display: flex;
						margin-bottom: 15rpx;

						.requirement-label {
							font-size: 26rpx;
							color: #666;
							margin-right: 10rpx;
						}

						.requirement-content {
							font-size: 26rpx;
							color: #333;
						}
					}

					.contact-info {
						display: flex;
						align-items: center;

						.contact-label {
							font-size: 26rpx;
							color: #666;
							margin-right: 10rpx;
						}

						.contact-number {
							font-size: 26rpx;
							color: #333;
							margin-right: 15rpx;
						}

						.copy-btn {
							font-size: 24rpx;
							color: #9C27B0;
							padding: 6rpx 16rpx;
							background-color: #F3E5F5;
							border-radius: 15rpx;
						}
					}
				}
			}

			.action-btn {
				width: 200rpx;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background-color: #9C27B0;
				color: #FFFFFF;
				border-radius: 30rpx;
				font-size: 28rpx;
				font-weight: bold;
				margin-left: auto;
			}
		}
	}

	/* 底部导航 */
	.tabbar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 100rpx;
		background: #FFFFFF;
		border-top: 1rpx solid #F0F0F0;
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding-bottom: env(safe-area-inset-bottom);

		.tabbar-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			gap: 8rpx;
			padding: 10rpx 0;

			.tabbar-icon {
				width: 44rpx;
				height: 44rpx;
				background-size: contain;
				background-repeat: no-repeat;
				background-position: center;
				position: relative;

				.badge {
					position: absolute;
					top: -8rpx;
					right: -8rpx;
					width: 32rpx;
					height: 32rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					background-color: #FF4444;
					color: #FFFFFF;
					font-size: 20rpx;
					font-weight: bold;
					border-radius: 50%;
				}
			}

			.tabbar-text {
				font-size: 20rpx;
				color: #999;
			}

			&.active {
				.tabbar-text {
					color: #9C27B0;
					font-weight: bold;
				}
			}

			&.home .tabbar-icon {
				background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>');
			}

			&.resources .tabbar-icon {
				background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239C27B0"><path d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"/></svg>');
			}

			&.trophy .tabbar-icon {
				background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M18 6l-1.42 1.42-1.59-1.59L13 8.17l-1.42-1.42L9 8.17l-1.59-1.59L6 6l3 3V18c0 1.1.9 2 2 2h4c1.1 0 2-.9 2-2V9l3-3zm-4 12H8v-7.5l4-4 4 4V18z"/></svg>');
			}

			&.message .tabbar-icon {
				background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/></svg>');
			}

			&.mine .tabbar-icon {
				background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>');
			}
		}
	}
</style>