<template>
	<view class="intro-page common">
		<view class="top-class"></view>
		<view class="title">
			扫码记录
		</view>
		<view class="head">
			<u-row class="row-class">
				<u-col span="4">
					<image class="logo-img"
						src="https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/cjx/logo.png"
						mode="aspectFit" />
				</u-col>
				<u-col span="4">
					<image class="commodity-img"
						src="https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/cjx/commodity.png"
						mode="aspectFit" />
				</u-col>
				<u-col span="4">
					<image class="logo-rules"
						src="https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/cjx/rules.png" />
				</u-col>
			</u-row>
		</view>
		<view class="topImg">
			<image class="img_1" src="https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/cjx/topImg.png"
				mode="heightFix" />
		</view>
		<!-- 公司简介内容卡片 -->
		<view class="content">

			<view class="cardTop">

			</view>
			<view class="content_text">
				<view class="filter-btn-group">
					<view class="row-text">发放状态：</view>
					<view v-for="(item, idx) in filterOptions" :key="idx"
						:class="['filter-btn', filterStatus === item.value ? 'active' : '']"
						@click="onFilterChange(item.value)">
						{{ item.label }}
					</view>
				</view>
				<view class="filter-btn-group list-title">
					<view class="son">
						奖品名称
					</view>
					<view class="son">
						中奖时间
					</view>
					<view class="son">
						兑换状态
					</view>

					<view class="son">
						活动名称
					</view>
					<view>
						操作
					</view>
				</view>
				<view class="content-list">
					<image v-if="list == null || list.length == 0 "
						src="https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/noData.png"
						mode="aspectFit"></image>
					<template v-for="(item, index) in list">
						<view class="row-one" :key="index">
							<view class="filter-btn-group">
								<view class="son">
									{{ item.prize_name }}
								</view>
								<view class="son">
									{{ item.zhongjiang_time }}
								</view>
								<view class="son">
									{{ item.duijiang_status }}
								</view>
								<view class="son">
									{{item.rule_name == null ? '--' : item.rule_name}}
								</view>
								<view class="detail-btn" @click="toggleDetail(index)">
									详情
								</view>
							</view>

							<!-- 只有当 detailVisible 为 true 时才显示 detail 部分 -->
							<view class="detail" v-if="item.detailVisible">
								<view class="text-one">
									盲盒名称：{{item.prize_detail}}
								</view>
								<view class="text-two">
									发放时间：{{ item.send_time != undefined ? item.send_time : '--'  }} <!-- 这里可以填入合适的数据 -->
								</view>
							</view>
						</view>
					</template>

				</view>
			</view>


			<view class="return_view">
				<view class="return-button" >返回</view>
			</view>	
		</view>

	</view>
</template>

<script>
	import {
		scanQuery
	} from '@/api/scan'
	export default {
		data() {
			return {
				scanCode: '',
				filterStatus: '0',
				list: [],
				filterOptions: [{
						label: '全部',
						value: '0'
					},
					{
						label: '未发放',
						value: '2'
					},
					{
						label: '已发放',
						value: '1'
					}
				]
			}
		},
		onLoad() {
			this.scanCode = uni.getStorageSync('scanCode');
			this.initGetlist();
		},
		methods: {
			toggleDetail(index) {
				// 切换点击项的详情显示状态
				if (this.list[index].detailVisible == undefined) {
					this.list[index].detailVisible = false
				}
				this.list[index].detailVisible = !this.list[index].detailVisible;
				this.$forceUpdate();
			},
			goBack() {
				uni.navigateBack();
			},
			onFilterChange(val) {
				if (this.filterStatus !== val) {
					this.filterStatus = val;
				}
				this.initGetlist();
			},
			initGetlist() {
				scanQuery(this.scanCode, this.filterStatus).then(res => {
					if (res.code == 0) {
						this.list = res.data
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import url('../../../static/scss/common_cjx.css');

	.row-class {
		height: 80rpx;
	}


	.theme-text {
		height: 10vh;
		text-align: center;
		line-height: 11vh;

		.textImage {
			height: 80rpx;
			width: 400rpx;
		}
	}

	.content {
		height: 68vh;
		border-radius: 10rpx;
		margin: 0rpx 20rpx;
		padding: 10rpx 24rpx;
		overflow: auto;
		align-items: center;
		justify-content: center;
		background-image:
			url("https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/cjx/cardBgi.png");
		background-size: cover;
		background-position: center;
		background-repeat: no-repeat;
		
	}

	.filter-btn-group {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		gap: 24rpx;
		margin: 10rpx 0 10rpx 0;
	}

	.filter-btn {
		padding: 4rpx 20rpx;
		border: 2rpx solid #fff;
		color: #fff;
		font-size: 28rpx;
		transition: all 0.2s;
	}

	.filter-btn.active {
		background: #DE00FF;
		color: #fff;
		border: 2rpx solid #DE00FF;
	}

	.row-text {
		font-weight: bold;
		font-size: 14px;
		color: #FFFFFF;
	}

	.list-title {
		font-weight: bold;
		font-size: 28rpx;
		color: #FFFFFF;
	}

	.son {
		width: 120rpx;
	}

	.row-one {
		font-weight: 400;
		font-size: 28rpx;
		color: #FFFFFF;
	}

	.detail {
		background-image: url("https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/detailImg.png");
		background-size: cover;
		/* 确保背景图片自适应填充整个容器 */
		background-position: inherit;
		/* 背景图片居中显示 */
		background-repeat: no-repeat;
		/* 防止背景图重复 */
		height: 134rpx;

		.text-one {
			height: 70rpx;
			line-height: 90rpx;
			text-align: left;
			margin-left: 20rpx;
		}

		.text-two {
			text-align: left;
			height: 60rpx;
			line-height: 60rpx;
			margin-left: 20rpx;

		}

	}



	.detail-btn {
		color: #DE00FF;
	}

	.content-list {
		overflow: auto;
		text-align: center;
		height: calc(100% - 160rpx);
	}
</style>