<template>
	<view class="client-detail" :class="{ 'dark-mode': isDarkTheme }">
		<!-- 顶部导航栏 -->
		<view class="header">
			<view class="back-icon" @click="handleBack"></view>
			<text class="header-title">客户信息</text>
			<view class="header-right"></view>
		</view>

		<!-- 客户基本信息 -->
		<view class="client-basic-info">
			<image :src="clientInfo.avatar" class="client-avatar" mode="aspectFill"></image>
			<view class="basic-info">
				<text class="client-name">{{ clientInfo.gender }} · {{ clientInfo.name }}</text>
				<text class="client-status">{{ clientInfo.status }}</text>
				<view class="client-tags">
					<text class="tag" v-for="(tag, index) in clientInfo.tags" :key="index">{{ tag }}</text>
				</view>
			</view>
		</view>

		<!-- 择偶要求 -->
		<view class="requirement-section">
			<view class="section-title">
				<text class="title-icon">💑</text>
				<text class="title-text">择偶要求</text>
			</view>
			<text class="requirement-content">{{ clientInfo.requirement }}</text>
		</view>

		<!-- 联系方式 -->
		<view class="contact-section">
			<view class="contact-item">
				<text class="contact-label">联系方式</text>
				<view class="contact-value">
					<text class="contact-number">{{ clientInfo.contact }}</text>
					<text class="copy-btn" @click="handleCopy(clientInfo.contact)">复制</text>
				</view>
			</view>
			<view class="contact-item">
				<text class="contact-label">备用联系方式</text>
				<view class="contact-value">
					<text class="contact-number">{{ clientInfo.backupContact }}</text>
					<text class="copy-btn" @click="handleCopy(clientInfo.backupContact)">复制</text>
				</view>
			</view>
		</view>

		<!-- 跟进统计 -->
		<view class="stats-section">
			<text class="stats-title">跟进统计</text>
			<view class="stats-grid">
				<view class="stat-item">
					<text class="stat-value">{{ clientInfo.stats.followTimes }}</text>
					<text class="stat-label">跟进次数</text>
				</view>
				<view class="stat-item">
					<text class="stat-value">{{ clientInfo.stats.matchCount }}</text>
					<text class="stat-label">匹配对象</text>
				</view>
				<view class="stat-item">
					<text class="stat-value">{{ clientInfo.stats.phoneCalls }}</text>
					<text class="stat-label">电话沟通</text>
				</view>
				<view class="stat-item">
					<text class="stat-value">{{ clientInfo.stats.interviews }}</text>
					<text class="stat-label">面谈次数</text>
				</view>
			</view>
		</view>

		<!-- 标签切换 -->
		<view class="tabs-section">
			<text class="tab" :class="{ active: activeTab === 'details' }" @click="switchTab('details')">详细信息</text>
			<text class="tab" :class="{ active: activeTab === 'follow' }" @click="switchTab('follow')">跟进</text>
		</view>

		<!-- 详细信息 -->
		<scroll-view scroll-y class="details-section" v-if="activeTab === 'details'">
			<view class="edit-btn" @click="handleEdit">编辑</view>

			<!-- 基本信息 -->
			<view class="detail-item">
				<text class="detail-label">婚姻状况:</text>
				<text class="detail-value">{{ clientInfo.details.maritalStatus }}</text>
			</view>
			<view class="detail-item">
				<text class="detail-label">学历:</text>
				<text class="detail-value">{{ clientInfo.details.education }}</text>
			</view>
			<view class="detail-item">
				<text class="detail-label">职业:</text>
				<text class="detail-value">{{ clientInfo.details.occupation }}</text>
			</view>
			<view class="detail-item">
				<text class="detail-label">收入:</text>
				<text class="detail-value">{{ clientInfo.details.income }}</text>
			</view>
			<view class="detail-item">
				<text class="detail-label">购房情况:</text>
				<text class="detail-value">{{ clientInfo.details.housing }}</text>
			</view>

			<!-- 择偶要求详情 -->
			<view class="sub-section-title">择偶要求</view>
			<view class="detail-item">
				<text class="detail-label">年龄范围:</text>
				<text class="detail-value">{{ clientInfo.details.requirement.ageRange }}</text>
			</view>
			<view class="detail-item">
				<text class="detail-label">身高要求:</text>
				<text class="detail-value">{{ clientInfo.details.requirement.height }}</text>
			</view>
			<view class="detail-item">
				<text class="detail-label">婚姻状况:</text>
				<text class="detail-value">{{ clientInfo.details.requirement.maritalStatus }}</text>
			</view>
			<view class="detail-item">
				<text class="detail-label">学历要求:</text>
				<text class="detail-value">{{ clientInfo.details.requirement.education }}</text>
			</view>
			<view class="detail-item" v-if="clientInfo.details.requirement.other">
				<text class="detail-label">其他要求:</text>
				<text class="detail-value">{{ clientInfo.details.requirement.other }}</text>
			</view>

			<!-- 客户标签 -->
			<view class="sub-section-title">客户标签</view>
			<view class="client-tags">
				<text class="tag" v-for="(tag, index) in clientInfo.tags" :key="index">{{ tag }}</text>
			</view>
		</scroll-view>

		<!-- 跟进信息 -->
		<scroll-view scroll-y class="follow-section" v-else>
			<!-- 跟进方式 -->
			<view class="follow-group">
				<text class="group-label">跟进方式</text>
				<view class="follow-type-options">
					<view class="follow-type-item" :class="{ active: followForm.type === 'phone' }" @click="followForm.type = 'phone'">
						<text class="radio-circle"></text>
						<text class="option-text">电话</text>
					</view>
					<view class="follow-type-item" :class="{ active: followForm.type === 'meet' }" @click="followForm.type = 'meet'">
						<text class="radio-circle"></text>
						<text class="option-text">面谈</text>
					</view>
					<view class="follow-type-item" :class="{ active: followForm.type === 'other' }" @click="followForm.type = 'other'">
						<text class="radio-circle"></text>
						<text class="option-text">其他</text>
					</view>
				</view>
			</view>

			<!-- 跟进进度 -->
			<view class="follow-group">
				<text class="group-label">跟进进度</text>
				<view class="status-tags-row">
					<view class="status-tag" :class="{ active: followForm.progress === 'matched' }" @click="followForm.progress = 'matched'">已匹配</view>
					<view class="status-tag" :class="{ active: followForm.progress === 'notMet' }" @click="followForm.progress = 'notMet'">未见面</view>
					<view class="status-tag" :class="{ active: followForm.progress === 'communicating' }" @click="followForm.progress = 'communicating'">沟通中</view>
				</view>
			</view>

			<!-- 邀约状态 -->
			<view class="follow-group">
				<text class="group-label">邀约状态</text>
				<view class="input-like">{{ followForm.inviteStatus || '未邀约' }}</view>
			</view>

			<!-- 邀约时间 -->
			<view class="follow-group">
				<text class="group-label">邀约时间</text>
				<view class="input-like">
					<picker mode="date" :value="followForm.inviteDate" @change="onInviteDateChange">
						<view class="picker-inner">{{ followForm.inviteDate || '请选择日期' }}</view>
					</picker>
				</view>
			</view>

			<!-- 跟进备注 -->
			<view class="follow-group">
				<text class="group-label">跟进备注</text>
				<textarea class="textarea" v-model="followForm.remark" placeholder="请输入跟进备注详细信息..." placeholder-style="color:#C5A4D8" />
			</view>

			<!-- 提交按钮（预留） -->
			<view class="follow-submit-btn" @click="handleSubmitFollow">保存跟进</view>
		</scroll-view>
	</view>
</template>

<script>
export default {
	name: 'client-detail',
	data() {
		return {
			activeTab: 'details',
			followForm: {
				type: 'phone',
				progress: 'matched',
				inviteStatus: '未邀约',
				inviteDate: '',
				remark: ''
			},
			clientInfo: {
				id: 1,
				name: '小明',
				gender: '男',
				status: '已匹配',
				tags: ['气质男', '小清新'],
				avatar: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&auto=format&fit=crop&w=200&q=60',
				requirement: '165+ 本科 天津 本地户口 无婚姻经历',
				contact: '123****9912',
				backupContact: '155****4512',
				stats: {
					followTimes: 12,
					matchCount: 3,
					phoneCalls: 5,
					interviews: 7
				},
				details: {
					maritalStatus: '离异',
					education: '本科',
					occupation: '企业高管',
					income: '50万/年',
					housing: '已购房',
					requirement: {
						ageRange: '30-40岁',
						height: '175cm以上',
						maritalStatus: '离异无孩或未婚',
						education: '本科及以上',
						other: '外貌或者性格'
					}
				}
			},
			isDarkTheme: false
		}
	},
	onShow() {
		const stored = uni.getStorageSync('matchmakerDarkMode')
		if (stored === true || stored === false) {
			this.isDarkTheme = stored
		}
	},
	onLoad(options) {
		// 从URL参数获取客户ID
		if (options.id) {
			// 这里可以根据ID从API获取客户信息
			console.log('客户ID:', options.id)
			// this.loadClientInfo(options.id)
		}
	},
	methods: {
		// 返回上一页
		handleBack() {
			uni.navigateBack()
		},
		// 复制联系方式
		handleCopy(contact) {
			uni.setClipboardData({
				data: contact.replace(/\*+/g, ''),
				success: () => {
					uni.showToast({
						title: '复制成功',
						icon: 'success'
					})
				}
			})
		},
		// 切换标签
		switchTab(tab) {
			this.activeTab = tab
		},
		// 编辑客户信息
		handleEdit() {
			uni.showToast({
				title: '编辑功能正在开发中',
				icon: 'none'
			})
		},
		// 邀约日期变更
		onInviteDateChange(e) {
			this.followForm.inviteDate = e.detail.value
		},
		// 提交跟进（暂时仅提示）
		handleSubmitFollow() {
			uni.showToast({
				title: '跟进已保存',
				icon: 'success'
			})
		},
		// 从API加载客户信息
		async loadClientInfo(id) {
			try {
				// 这里调用API获取客户信息
				// const res = await api.matchmaker.getClientInfo(id)
				// this.clientInfo = res.data
			} catch (e) {
				console.error('加载客户信息失败:', e)
				uni.showToast({
					title: '加载失败',
					icon: 'none'
				})
			}
		}
	}
}
</script>

<style lang="scss" scoped>
.client-detail {
	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;
	}
}

/* 客户基本信息 */
.client-basic-info {
	display: flex;
	align-items: flex-start;
	padding: 30rpx;
	background-color: #FFFFFF;
	margin: 20rpx;
	border-radius: 20rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);

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

	.basic-info {
		flex: 1;

		.client-name {
			font-size: 36rpx;
			font-weight: bold;
			color: #333;
			margin-bottom: 10rpx;
		}

		.client-status {
			font-size: 28rpx;
			color: #FF6B8A;
			margin-bottom: 15rpx;
			display: inline-block;
		}

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

			.tag {
				padding: 8rpx 20rpx;
				background-color: #F3E5F5;
				color: #9C27B0;
				border-radius: 20rpx;
				font-size: 24rpx;
				font-weight: bold;
			}
		}
	}
}

/* 择偶要求 */
.requirement-section {
	padding: 30rpx;
	background-color: #FFFFFF;
	margin: 0 20rpx 20rpx;
	border-radius: 20rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);

	.section-title {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;

		.title-icon {
			font-size: 28rpx;
			margin-right: 10rpx;
		}

		.title-text {
			font-size: 28rpx;
			font-weight: bold;
			color: #333;
		}
	}

	.requirement-content {
		font-size: 28rpx;
		color: #666;
		line-height: 1.5;
	}
}

/* 联系方式 */
.contact-section {
	padding: 30rpx;
	background-color: #FFFFFF;
	margin: 0 20rpx 20rpx;
	border-radius: 20rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);

	.contact-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 25rpx;

		&:last-child {
			margin-bottom: 0;
		}

		.contact-label {
			font-size: 28rpx;
			color: #333;
		}

		.contact-value {
			display: flex;
			align-items: center;
			gap: 20rpx;

			.contact-number {
				font-size: 28rpx;
				color: #666;
			}

			.copy-btn {
				padding: 8rpx 20rpx;
				background-color: #F3E5F5;
				color: #9C27B0;
				border-radius: 20rpx;
				font-size: 24rpx;
				font-weight: bold;
			}
		}
	}
}

/* 跟进统计 */
.stats-section {
	padding: 30rpx;
	background-color: #FFFFFF;
	margin: 0 20rpx 20rpx;
	border-radius: 20rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);

	.stats-title {
		font-size: 28rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 25rpx;
	}

	.stats-grid {
		display: grid;
		grid-template-columns: repeat(4, 1fr);
		gap: 20rpx;

		.stat-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 20rpx;
			background-color: #FFF3F5;
			border-radius: 15rpx;

			.stat-value {
				font-size: 48rpx;
				font-weight: bold;
				color: #FF6B8A;
				margin-bottom: 10rpx;
			}

			.stat-label {
				font-size: 22rpx;
				color: #666;
			}
		}
	}
}

/* 标签切换 */
.tabs-section {
	display: flex;
	padding: 0 20rpx;
	background-color: #FFFFFF;
	margin: 0 20rpx 20rpx;
	border-radius: 20rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);

	.tab {
		flex: 1;
		text-align: center;
		padding: 20rpx 0;
		font-size: 28rpx;
		color: #666;
		font-weight: bold;
		transition: all 0.3s;

		&.active {
			color: #9C27B0;
			border-bottom: 4rpx solid #9C27B0;
		}
	}
}

/* 详细信息滚动区域 */
.details-section {
	padding: 30rpx 20rpx 100rpx;
	background-color: #FFFFFF;
	margin: 0 20rpx 20rpx;
	border-radius: 20rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
	box-sizing: border-box;

	.edit-btn {
		position: absolute;
		top: 20rpx;
		right: 30rpx;
		padding: 8rpx 25rpx;
		background-color: #F3E5F5;
		color: #9C27B0;
		border-radius: 20rpx;
		font-size: 24rpx;
		font-weight: bold;
	}

	.detail-item {
		display: flex;
		margin-bottom: 25rpx;

		.detail-label {
			width: 180rpx;
			font-size: 28rpx;
			color: #333;
			font-weight: bold;
		}

		.detail-value {
			flex: 1;
			font-size: 28rpx;
			color: #666;
		}
	}

	.sub-section-title {
		font-size: 30rpx;
		font-weight: bold;
		color: #333;
		margin: 30rpx 0 20rpx;
		padding-bottom: 10rpx;
		border-bottom: 2rpx solid #F0F0F0;
	}

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

		.tag {
			padding: 8rpx 20rpx;
			background-color: #F3E5F5;
			color: #9C27B0;
			border-radius: 20rpx;
			font-size: 24rpx;
			font-weight: bold;
		}
	}
}

/* 跟进信息 */
.follow-section {
	background-color: #FFFFFF;
	margin: 0 20rpx 20rpx;
	border-radius: 20rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
	padding: 30rpx 20rpx 40rpx;
	max-height: 700rpx;
	box-sizing: border-box;
}

.follow-group {
	margin-bottom: 30rpx;

	.group-label {
		font-size: 28rpx;
		color: #333;
		font-weight: bold;
		margin-bottom: 16rpx;
		display: block;
	}
}

/* 跟进方式单选 */
.follow-type-options {
	display: flex;
	align-items: center;
	gap: 30rpx;

	.follow-type-item {
		display: flex;
		align-items: center;
		gap: 10rpx;
		font-size: 26rpx;
		color: #666;

		.radio-circle {
			width: 26rpx;
			height: 26rpx;
			border-radius: 50%;
			border: 2rpx solid #C5A4D8;
			box-sizing: border-box;
		}

		&.active {
			color: #D81B60;

			.radio-circle {
				background-color: #D81B60;
				border-color: #D81B60;
			}
		}
	}
}

/* 跟进进度标签 */
.status-tags-row {
	display: flex;
	flex-wrap: wrap;
	gap: 16rpx;

	.status-tag {
		min-width: 140rpx;
		text-align: center;
		padding: 14rpx 20rpx;
		border-radius: 20rpx;
		border: 2rpx solid #E1BEE7;
		font-size: 26rpx;
		color: #9C27B0;
		background-color: #FAF5FF;
		box-sizing: border-box;

		&.active {
			background-color: #F8BBD0;
			border-color: #F06292;
			color: #FFFFFF;
		}
	}
}

/* 邀约状态/时间 等输入类展示 */
.input-like {
	width: 100%;
	padding: 18rpx 22rpx;
	border-radius: 16rpx;
	background-color: #FAF5FF;
	font-size: 26rpx;
	color: #666;
	box-sizing: border-box;
}

.picker-inner {
	font-size: 26rpx;
	color: #666;
}

/* 备注输入框 */
.textarea {
	width: 100%;
	min-height: 160rpx;
	padding: 18rpx 22rpx;
	border-radius: 16rpx;
	background-color: #FAF5FF;
	font-size: 26rpx;
	color: #333;
	box-sizing: border-box;
}

/* 保存按钮 */
.follow-submit-btn {
	margin-top: 10rpx;
	width: 100%;
	padding: 22rpx 0;
	text-align: center;
	border-radius: 26rpx;
	background: linear-gradient(135deg, #F48FB1 0%, #EC407A 100%);
	color: #FFFFFF;
	font-size: 30rpx;
	font-weight: bold;
}
</style>