<template>
	<u-popup v-model="visible" mode="bottom" border-radius="24" :safe-area-inset-bottom="true" :mask-close-able="true"
		@close="close">
		<view class="history-popup">
			<view class="header">
				<text class="title">宝贝售后详情</text>
				<image src="/pages-sell/static/select-good/icon-close.png" class="close-icon" @click="close"></image>
			</view>
			<view class="list" v-if="list.length > 0">
				<view class="item" v-for="(item, index) in list" :key="index" @click="handleView(item)">
					<image class="cover" :src="item.cover" mode="aspectFill"></image>
					<view class="content">
						<view class="name u-line-2">{{ item.bookName }}</view>
						<view class="meta">
							<text class="meta-text">数量：{{ item.refundNum }}</text>
							<text class="meta-text">¥ {{ formatMoney(item.refundMoney) }}</text>
						</view>
					</view>
					<view class="right">
						<text class="link-text">查看</text>
						<u-icon name="arrow-right" color="#C9C9C9" size="24"></u-icon>
					</view>
				</view>
			</view>
			<view class="empty" v-else>
				<u-empty text="暂无历史退款记录" mode="history"></u-empty>
			</view>
		</view>
	</u-popup>
</template>

<script>
	export default {
		data() {
			return {
				visible: false,
				list: []
			};
		},
		methods: {
			open(list) {
				this.list = Array.isArray(list) ? list : [];
				this.visible = true;
			},
			close() {
				this.visible = false;
			},
			handleView(item) {
				this.$emit('view', item);
				this.close();
			},
			formatMoney(money) {
				const num = Number(money || 0);
				if (Number.isNaN(num)) return '0.00';
				return num.toFixed(2);
			}
		}
	};
</script>

<style lang="scss" scoped>
	.history-popup {
		background-color: #fff;
		padding: 30rpx;
		min-height: 420rpx;
		max-height: 900rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}

	.header {
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;
		margin-bottom: 20rpx;
		padding-bottom: 20rpx;
		border-bottom: 2rpx dashed #eee;
		flex-shrink: 0;
	}

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

	.close-icon {
		position: absolute;
		right: 0;
		top: 0;
		width: 24rpx;
		height: 24rpx;
		padding: 10rpx;
		box-sizing: content-box;
	}

	.list {
		flex: 1;
		overflow: auto;
	}

	.item {
		display: flex;
		align-items: center;
		padding: 24rpx 0;
		border-bottom: 1rpx solid #F0F0F0;
	}

	.cover {
		width: 120rpx;
		height: 140rpx;
		border-radius: 8rpx;
		margin-right: 20rpx;
		flex-shrink: 0;
		background-color: #f5f5f5;
	}

	.content {
		flex: 1;
		min-width: 0;
	}

	.name {
		font-size: 28rpx;
		color: #333;
		line-height: 1.4;
		margin-bottom: 10rpx;
	}

	.meta {
		display: flex;
		align-items: center;
		gap: 16rpx;
	}

	.meta-text {
		font-size: 24rpx;
		color: #666;
	}

	.right {
		display: flex;
		align-items: center;
		margin-left: 16rpx;
		flex-shrink: 0;
	}

	.link-text {
		font-size: 26rpx;
		color: #38C148;
		margin-right: 6rpx;
	}

	.empty {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>

