<template>
	<view class="content">
		<!-- 顶部导航栏 -->
		<uni-nav-bar
			left-icon="left"
			title="患者消息"
			@clickLeft="goBack"
			fixed
			color="#8B2316"
			height="140rpx"
			:border="false"
			backgroundColor="#ffffff"
		>
			<template #right>
				<view class="nav-right">
					<uni-icons type="search" size="24" color="#8B2316" @click="searchPatients"></uni-icons>
					<uni-icons type="staff" size="24" color="#8B2316" @click="managePatients" style="margin-left: 30rpx;"></uni-icons>
				</view>
			</template>
		</uni-nav-bar>
		
		<!-- 消息列表区域 -->
		<view class="message-list">
			<!-- 消息项 -->
			<view class="message-item" @click="openMessage">
				<view class="message-avatar">
					<view class="avatar-placeholder">
						<uni-icons type="person" size="32" color="#ffffff"></uni-icons>
					</view>
				</view>
				<view class="message-content">
					<view class="message-header">
						<text class="patient-name">测试</text>
						<text class="message-time">2025-08-11</text>
					</view>
					<view class="message-preview">
						<text class="preview-text">[图片]</text>
					</view>
				</view>
			</view>
			
			<!-- 空状态提示 -->
			<view class="empty-state" v-if="messageList.length === 0">
				<uni-icons type="chat" size="80" color="#cccccc"></uni-icons>
				<text class="empty-text">暂无患者消息</text>
			</view>
		</view>
		
		<!-- 底部标签栏 -->
		<view class="tab-bar">
			<view class="tab-item active" @click="switchTab('message')">
				<text class="tab-text">患者消息</text>
				<view class="tab-line"></view>
			</view>
			<view class="tab-item" @click="switchTab('list')">
				<text class="tab-text">患者列表</text>
			</view>
			<view class="tab-item" @click="switchTab('plan')">
				<text class="tab-text">随访计划</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { onShow } from "@dcloudio/uni-app";
	
	// 消息列表数据
	const messageList = ref([
		{
			id: 1,
			patientName: '测试',
			messagePreview: '[图片]',
			time: '2025-08-11',
			avatar: ''
		}
	]);
	
	// 当前激活的标签
	const activeTab = ref('message');
	
	// 返回上一页
	const goBack = () => {
		uni.navigateBack();
	};
	
	// 搜索患者
	const searchPatients = () => {
		uni.showToast({
			title: '搜索患者',
			icon: 'none'
		});
	};
	
	// 管理患者
	const managePatients = () => {
		uni.showToast({
			title: '患者管理',
			icon: 'none'
		});
	};
	
	// 打开消息
	const openMessage = () => {
		uni.showToast({
			title: '打开消息',
			icon: 'none'
		});
	};
	
	// 切换标签
	const switchTab = (tab) => {
		activeTab.value = tab;
		
		switch(tab) {
			case 'message':
				// 患者消息页面逻辑
				break;
			case 'list':
				// 跳转到患者列表页面
				uni.navigateTo({
					url: '/pages_app/myPatient/myPatient'
				});
				break;
			case 'plan':
				// 跳转到随访计划页面
				uni.showToast({
					title: '随访计划',
					icon: 'none'
				});
				break;
		}
	};
	
	// 页面显示时加载数据
	onShow(() => {
		loadMessageList();
	});
	
	// 加载消息列表
	const loadMessageList = () => {
		// 这里可以调用API获取消息列表
		console.log('加载患者消息列表');
	};
</script>

<style lang="scss" scoped>
	.content {
		background-color: #f5f5f5;
		min-height: 100vh;
	}
	
	// 导航栏右侧按钮样式
	.nav-right {
		display: flex;
		align-items: center;
	}
	
	// 消息列表样式
	.message-list {
		background-color: #ffffff;
		margin-top: 20rpx;
		
		.message-item {
			display: flex;
			align-items: center;
			padding: 30rpx;
			border-bottom: 1rpx solid #f0f0f0;
			background-color: #ffffff;
			
			&:last-child {
				border-bottom: none;
			}
			
			.message-avatar {
				margin-right: 20rpx;
				
				.avatar-placeholder {
					width: 80rpx;
					height: 80rpx;
					background-color: #ff6b6b;
					border-radius: 10rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
			
			.message-content {
				flex: 1;
				
				.message-header {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 10rpx;
				}
				
				.patient-name {
					font-size: 32rpx;
					color: #333333;
					font-weight: 500;
				}
				
				.message-time {
					font-size: 24rpx;
					color: #999999;
				}
				
				.message-preview {
					margin-top: 5rpx;
					
					.preview-text {
						font-size: 28rpx;
						color: #666666;
					}
				}
			}
		}
		
		// 空状态样式
		.empty-state {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 100rpx 0;
			
			.empty-text {
				margin-top: 20rpx;
				font-size: 28rpx;
				color: #999999;
			}
		}
	}
	
	// 底部标签栏样式
	.tab-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 100rpx;
		background-color: #f8f8f8;
		display: flex;
		align-items: center;
		border-top: 1rpx solid #e0e0e0;
		z-index: 999;
		
		.tab-item {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			position: relative;
			height: 100%;
			
			&:nth-child(2) {
				border: 2rpx solid #ccc;
				border-top: none;
				border-bottom: none;
			}
			
			.tab-text {
				font-size: 28rpx;
				color: #999999;
				transition: color 0.3s;
			}
			
			&.active {
				.tab-text {
					color: #8B2316;
					font-weight: 500;
				}
				
				.tab-line {
					position: absolute;
					bottom: 0;
					width: 60rpx;
					height: 4rpx;
					background-color: #8B2316;
					border-radius: 2rpx;
				}
			}
		}
	}
</style>
