<template>
	<view class="page">

		<!-- 收藏列表 -->
		<view class="content">
			<view v-if="favoritesList.length > 0" class="list">
				<view v-for="item in favoritesList" :key="item.id" class="record-item" @click="viewGoodsDetail(item)">
					<image class="record-image" :src="item.image" mode="aspectFit"></image>
					<view class="record-content">
						<view class="record-info">
							<view class="title-row">
								<text class="record-title">{{ item.title }}</text>
							</view>
							<view class="record-points">
								<uv-icon name="integral" size="16" color="#218cdd"></uv-icon>
								<text class="points-text">{{ item.points }}积分</text>
							</view>
							<view class="record-time">
								<uv-icon name="heart-fill" size="14" color="#ff6b6b"></uv-icon>
								<text class="time-text">收藏时间：{{ item.favoriteTime }}</text>
							</view>
						</view>
						<view class="record-action">
							<uv-button 
								type="primary" 
								size="small" 
								text="查看详情"
								shape="circle"
								@click.stop="viewGoodsDetail(item)"
							></uv-button>
						</view>
					</view>
				</view>
			</view>
			<view v-else class="empty">
				<uv-empty mode="data" text="暂无收藏商品"></uv-empty>
			</view>
		</view>

		<!-- 操作菜单 -->
		<uv-action-sheet :show="showActionSheet" :actions="actions" @close="showActionSheet = false" @select="onActionSelect"></uv-action-sheet>
	</view>
</template>

<script>
export default {
	data() {
		return {
			showActionSheet: false,
			actions: [
				{ name: '清空收藏', color: '#ff4757' }
			],
			favoritesList: [
				{
					id: 1,
					title: '咖吧之夜童话海新款教育咖吧放内艺术手办树脂伴学生小礼品',
					image: '/static/商城_商品1.png',
					points: 100,
					favoriteTime: '2025-06-12 14:30:12'
				},
				{
					id: 2,
					title: '创意文具套装学生用品办公用品礼盒装',
					image: '/static/商城_商品2.png',
					points: 150,
					favoriteTime: '2025-06-11 10:20:30'
				},
				{
					id: 3,
					title: '精美笔记本套装商务办公记事本礼品',
					image: '/static/商城_商品1.png',
					points: 80,
					favoriteTime: '2025-06-10 16:45:22'
				},
				{
					id: 4,
					title: '环保购物袋帆布袋手提袋学生用品',
					image: '/static/商城_商品2.png',
					points: 50,
					favoriteTime: '2025-06-09 09:15:18'
				}
			]
		}
	},
	methods: {
		// 查看商品详情
		viewGoodsDetail(item) {
			uni.navigateTo({
				url: `/subPages/shop/goodsDetail?id=${item.id}`
			})
		},
		// 操作菜单选择
		onActionSelect(item) {
			if (item.name === '清空收藏') {
				uni.showModal({
					title: '提示',
					content: '确定要清空所有收藏商品吗？',
					success: (res) => {
						if (res.confirm) {
							this.favoritesList = []
							uni.showToast({
								title: '已清空收藏',
								icon: 'success'
							})
						}
					}
				})
			}
			this.showActionSheet = false
		}
	}
}
</script>

<style lang="scss" scoped>
.page {
	background-color: #f5f5f5;
	min-height: 100vh;
}

.content {
	padding: 0;
}

.list {
	padding: 20rpx;
}

.record-item {
	display: flex;
	align-items: flex-start;
	margin-bottom: 30rpx;
	background: #fff;
	border-radius: 12rpx;
	padding: 20rpx;
}

.record-image {
	width: 215rpx;
	height: 215rpx;
	border-radius: 8rpx;
	margin-right: 20rpx;
	flex-shrink: 0;
}

.record-content {
	flex: 1;
	display: flex;
	flex-direction: column;
}

.record-info {
	display: flex;
	flex-direction: column;
	margin-bottom: 20rpx;
}

.title-row {
	margin-bottom: 10rpx;
}

.record-title {
	font-size: 22rpx;
	color: #000;
	line-height: 1.4;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
}

.record-points {
	display: flex;
	align-items: center;
	margin-bottom: 8rpx;
}

.points-text {
	font-size: 26rpx;
	color: #218cdd;
	font-weight: bold;
	margin-left: 6rpx;
}

.record-time {
	display: flex;
	align-items: center;
}

.time-text {
	font-size: 22rpx;
	color: #999;
	margin-left: 6rpx;
}

.record-action {
	display: flex;
	justify-content: flex-end;
	border-top: 1rpx solid #f0f0f0;
}

.empty {
	margin-top: 200rpx;
}
</style>