<template>
	<view class="container">
		<!-- 顶部导航栏 -->
		<view class="header">
			<view class="back-btn" @click="goBack">
				<text class="back-icon">←</text>
			</view>
			<text class="header-title">笔记</text>
			<view class="header-right"></view>
		</view>
		
		<!-- 笔记列表 -->
		<scroll-view class="scroll-content" scroll-y>
			<view 
				class="note-item" 
				v-for="(item, index) in noteList" 
				:key="index"
				@click="goToBookNotes(item)"
			>
				<image class="book-cover" :src="item.cover" mode="aspectFill" :lazy-load="true"></image>
				<view class="book-info">
					<text class="book-title">{{ item.title }}</text>
					<text class="note-count">{{ item.noteCount }}个笔记</text>
				</view>
			</view>
			
			<!-- 空状态 -->
			<view class="empty-state" v-if="noteList.length === 0">
				<text class="empty-text">暂无笔记</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			const getRandomImage = (seed) => {
				return `https://picsum.photos/seed/${seed}/200/300`;
			};
			
			return {
				noteList: [
					{
						id: 1,
						title: '西游记',
						cover: getRandomImage('notes1'),
						noteCount: 3
					},
					{
						id: 2,
						title: '孝经 (中华经典诵读)',
						cover: getRandomImage('notes2'),
						noteCount: 10
					},
					{
						id: 3,
						title: '西游记',
						cover: getRandomImage('notes3'),
						noteCount: 4
					},
					{
						id: 4,
						title: '孝经 (中华经典诵读)',
						cover: getRandomImage('notes4'),
						noteCount: 10
					},
					{
						id: 5,
						title: '红楼梦',
						cover: getRandomImage('notes5'),
						noteCount: 5
					},
					{
						id: 6,
						title: '三国演义',
						cover: getRandomImage('notes6'),
						noteCount: 8
					}
				]
			}
		},
		onLoad() {
			// 可以在这里加载用户的笔记列表
			this.loadNotes()
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			goToBookNotes(item) {
				// 跳转到该书籍的笔记详情页
				uni.navigateTo({
					url: `/pages/book-notes/book-notes?bookId=${item.id}&title=${encodeURIComponent(item.title)}&cover=${encodeURIComponent(item.cover)}`
				})
			},
			loadNotes() {
				// 这里可以调用API获取用户的笔记列表
				// uni.request({
				// 	url: '/api/notes/list',
				// 	success: (res) => {
				// 		this.noteList = res.data
				// 	}
				// })
			}
		}
	}
</script>

<style scoped>
	.container {
		width: 100%;
		height: 100vh;
		min-height: 100vh;
		background-color: #FFFFFF;
		display: flex;
		padding-top: 30px;
		box-sizing: border-box;
		flex-direction: column;
		box-sizing: border-box;
		overflow: hidden;
	}
	
	.header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 30rpx;
		padding-top: calc(20rpx + env(safe-area-inset-top));
		background-color: #FFFFFF;
		border-bottom: 1rpx solid #F0F0F0;
		position: relative;
		flex-shrink: 0;
		box-sizing: border-box;
	}
	
	.back-btn {
		width: 60rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 10;
	}
	
	.back-icon {
		font-size: 40rpx;
		color: #333333;
		font-weight: bold;
	}
	
	.header-title {
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		font-size: 36rpx;
		font-weight: bold;
		color: #333333;
	}
	
	.header-right {
		width: 60rpx;
	}
	
	.scroll-content {
		flex: 1;
		width: 100%;
		height: 0;
		overflow: hidden;
		padding-bottom: calc(env(safe-area-inset-bottom));
		background-color: #FFFFFF;
		box-sizing: border-box;
	}
	
	.note-item {
		display: flex;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #F0F0F0;
		background-color: #FFFFFF;
		width: 100%;
		box-sizing: border-box;
	}
	
	.note-item:last-child {
		border-bottom: none;
	}
	
	.book-cover {
		width: 120rpx;
		height: 160rpx;
		border-radius: 8rpx;
		margin-right: 30rpx;
		flex-shrink: 0;
		box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.1);
		background-color: #F5F5F5;
	}
	
	.book-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		min-width: 0;
	}
	
	.book-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
		margin-bottom: 15rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
	
	.note-count {
		font-size: 26rpx;
		color: #999999;
	}
	
	.empty-state {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 200rpx 0;
	}
	
	.empty-text {
		font-size: 28rpx;
		color: #999999;
	}
</style>


