<template>
	<view class="center">
		<view class="bg"></view>
		<view class="zong flex">
			<view class="info">
				<view class="info-num">{{ USDL || '0' }}</view>
				<view class="info-font">USDL</view>
			</view>
			<view class="info">
				<view class="info-num">{{ lucky || '0' }}</view>
				<view class="info-font">幸运值</view>
			</view>
			<view class="info">
				<view class="info-num">{{ honor || '0' }}</view>
				<view class="info-font">荣誉值</view>
			</view>
		</view>
		<view class="rule">
			<view class="rule-title">福利兑换规则</view>
			<view class="rule-main">
				每{{ list.sp_exchange_origin_cost * 1 }}{{ list.sp_exchange_origin }}+{{ list.sp_exchange_bingo_time }}幸运值可兑换{{ list.sp_exchange_target_get * 1
				}}{{ list.sp_exchange_target }}+{{ list.sp_exchange_bingo_time }}荣誉值
			</view>
		</view>
		<view class="main-title">
			<view class="shu"></view>
			<view class="m-title">兑换记录</view>
		</view>
		<scroll-view scroll-y class="list-box" @scrolltolower="getList()">
			<!-- <view class="empty-box"><empty v-if="exchange.length === 0 || loadingType == 'nomore'"></empty></view> -->
			<view v-for="(item, index) in exchange" :key="index" class="list-item flex">
				<view class="list-left">
					<view class="list-title">福利兑换</view>
					<view class="time">{{ item.time }}</view>
				</view>
				<view class="list-right">已兑换</view>
			</view>
			<u-loadmore :status="loadingType" />
		</scroll-view>
		<view class="btn" @click="nav()">立即兑换</view>
	</view>
</template>

<script>
import { getSp } from '@/api/market.js';
import { lalaDetial } from '@/api/product.js';
import { wallet } from '@/api/finance.js';
import { getTime } from '@/utils/rocessor.js';
export default {
	data() {
		return {
			id: '',
			lucky: '',
			honor: '',
			list: '',
			USDL: '',
			exchange: [],
			page: 1,
			limit: 10,
			loadingType: 'loadmore'
		};
	},
	onLoad(option) {
		this.id = option.id;
		this.loadData();
		this.getList();
	},
	methods: {
		async loadData() {
			lalaDetial({}, this.id)
				.then(({ data }) => {
					console.log(data);
					this.honor = data.exchange_point;
					this.lucky = data.luck_point - data.exchange_point;
					this.list = data.data;
				})
				.catch(e => {
					console.log(e);
				});
			wallet({}).then(({ data }) => {
				this.USDL = data.back['USDL'].money.money * 1;
			});
		},
		getList() {
			if (this.loadingType == 'nomore' || this.loadingType == 'loading') {
				return;
			}
			this.loadingType = 'loading';
			getSp(
				{
					page: this.page,
					limit: this.limit
				},
				this.id
			).then(({ data }) => {
				if (data.count != 0) {
					data.data.forEach(e => {
						e.time = getTime(e.add_time);
					});
				}
				this.exchange = data.list;
				if (data.length != this.limit) {
					this.loadingType = 'nomore';
				} else {
					this.page++;
					this.loadingType = 'loadmore';
				}
			});
		},
		nav() {
			uni.navigateTo({
				url: '/pages/market/duihuan?id=' + this.id
			});
		}
	}
};
</script>

<style lang="scss">
.center,
page {
	height: 100%;
	background: #f7fbfe;
}
.bg {
	width: 750rpx;
	height: 248rpx;

	background: linear-gradient(30deg, #2e58ff, #33eeff);
	border-bottom-left-radius: 150rpx;
	border-bottom-right-radius: 150rpx;
}
.zong {
	width: 690rpx;
	height: 181rpx;
	background: #ffffff;
	box-shadow: 0px 0px 17rpx 0px rgba(0, 0, 0, 0.05);
	border-radius: 20rpx;
	margin: -150rpx auto 0;
	justify-content: space-between;
	padding: 0rpx 36rpx;
	.info {
		display: flex;
		flex-direction: column;
		align-items: center;
		.info-num {
			font-size: 50rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #0f253a;
		}
		.info-font {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #6d7c88;
		}
	}
}
.rule {
	width: 690rpx;
	background: #ffffff;
	box-shadow: 0px 0px 17rpx 0px rgba(0, 0, 0, 0.05);
	border-radius: 20rpx;
	margin: 16rpx auto 0;
	padding: 26rpx 36rpx;
	.rule-title {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #2e58ff;
	}
	.rule-main {
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #0f253a;
		margin-top: 10rpx;
	}
}
.main-title {
	margin-top: 36rpx;
	display: flex;
	justify-content: flex-start;
	align-items: center;
	.shu {
		margin-left: 30rpx;
		width: 5rpx;
		height: 29rpx;
		background: #0f253a;
		border-radius: 3rpx;
	}
	.m-title {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #0f253a;
		margin-left: 16rpx;
	}
}
.list-box {
	margin-top: 34rpx;
	height: calc(100% - 260px);
	background-color: #ffffff;
	.list-item {
		padding: 25rpx 50rpx;
		border-bottom: 1px solid #f0f4f8;
		.list-title {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #666666;
		}
		.time {
			margin-top: 10rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #aeaeae;
		}
		.list-right {
			font-size: 27rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
		}
	}
}
.btn {
	position: fixed;
	bottom: 28rpx;
	left: 0;
	right: 0;
	margin: 0 auto;
	width: 674rpx;
	height: 88rpx;
	background: linear-gradient(0deg, #2E58FF, #32C6FF);
	border-radius: 44rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #ffffff;
	text-align: center;
	line-height: 88rpx;
}
</style>
