<template>
	<view class="record-home">
		<view class="title">
			红包领取记录
		</view>
		<view class="list-border" :style="{height:winHeight-150 + 'px'}" v-if="list.length>0">
			<scroll-view class="list" @scrolltolower='getMore' scroll-y='true' :style="{height:winHeight-155 + 'px'}">
				<view class="list-item" v-for="(item,index) in list">
					<view class="left">
						<image src="../static/images/hongbao.png" mode=""></image>
					</view>
					<view class="middle">
						<view class="text">
							{{item.type==1 ? item.spoil.name + "x1" :'领取红包'}}
						</view>
						<view class="time">
							{{item.created_at}}
						</view>
					</view>
					<view class="right" v-if="item.type==0">
						￥{{item.total_money}}
					</view>
					<view class="right1" v-if="item.type==1 && item.pay_status==0" @click="lookCode(item)">
						核销码
					</view>
					<view class="right" v-if="item.type==1 && item.pay_status==1">
						已兑换
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="empty" v-else>
			<image src="../static/images/empty.png"></image>
			<view class="text">
				暂无领取记录
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp()
	export default {
		data() {
			return {
				list: [],
				winHeight: app.globalData.winHeight,
				page: 1
			}
		},

		created() {

		},
		onLoad() {
			this.getOrderList()
		},
		onReachBottom() {
			this.getMore()
		},
		methods: {
			lookCode(item) {
				let that = this
				console.log('点击领取')
				if (uni.getStorageSync('is_auth') == false) {
					uni.navigateTo({
						url: './information'
					})
					return
				}
				uni.showModal({
					showCancel: false,
					title: '核销码',
					content: item.verification_code,
					success(res) {
						if (res.confirm) {
							that.getOrderList()
						}
					}

				})
			},
			getOrderList() {
				app.request('/orders', '', 'get').then(res => {
					console.log(res, '红包领取记录')
					this.list = res.data.data
				})
			},
			getMore: function() {
				console.log("pppppp")
				this.page++
				let params = {
					page: this.page
				}
				app.request('/orders', params, 'get').then(res => {
					let list = res.data.data
					if (list.length == 0) {
						uni.showToast({
							title: '到底了~',
							icon: 'none'
						})
					} else {
						this.list = this.list.concat(list)
					}

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #FEE4C7;
	}

	.record-home {
		.title {
			height: 60px;
			line-height: 60px;
			font-size: 24px;
			font-family: HelloFont WenYiHei;
			font-weight: 700;
			color: #AC5102;
			opacity: 1;
			text-align: center;

		}

		.list-border {
			margin: 0 15px;
			background: linear-gradient(137deg, #FFEFCD 100%, #FBF7E4 0%);
			padding: 10px;
			// height: 500px;
			border-radius: 16px;
			overflow: auto;

			.list {

				border: 1px solid #FED773;
				width: 100%;
				border-radius: 16px;

				.list-item {
					padding: 10px 15px;
					display: flex;
					// margin-bottom: 20px;

					.left {
						flex: 0 0 40px;
						height: 40px;
						line-height: 40px;
						border-radius: 50%;
						text-align: center;
						margin-right: 5px;
						background: linear-gradient(180deg, #FF973B 0%, rgba(255, 217, 175, 0.15) 100%);

						image {
							width: 19px;
							height: 23px;
							margin-top: 8px;
						}
					}

					.middle {
						flex: 1;

						.text {
							font-size: 14px;
							font-family: PingFang SC;
							font-weight: bold;
							line-height: 21px;
							color: #AC5102;
							opacity: 1;
						}

						.time {
							font-size: 12px;
							font-family: PingFang SC;
							font-weight: 400;
							line-height: 21px;
							color: #AC5102;
							opacity: 1;
						}
					}

					.right {
						flex: 1;
						font-size: 16px;
						font-family: PingFang SC;
						font-weight: bold;
						line-height: 21px;
						color: #F92B0B;
						opacity: 1;
						text-align: right;
						line-height: 40px;
					}

					.right1 {
						flex: 0 0 70px;
						font-size: 16px;
						text-align: center;
						font-family: PingFang SC;
						font-weight: bold;
						line-height: 30px;
						margin-top: 5px;
						height: 30px;
						color: #AC5102;
						background-color: #ffb472;
						opacity: 1;
						border-radius: 8px;
					}
				}
			}
		}

		.empty {
			margin-top: 25%;
			text-align: center;

			image {
				width: 250px;
				height:250px;

			}
			.text{
				margin-top: 10px;
				font-size: 14px;
				text-align: center;
				color: #AC5102;
			}
		}
	}
</style>
