<template>
	<view class="content">
		<view class="buy-list">
			<view class="label">
				<text>领取记录</text>
			</view>
			<view class="listcontainer">
				<view v-for="(item,index) in buy_list" :key="item.id">
					<couponitem :data="item"></couponitem>
				</view>
				<u-loadmore :status="status" />
			</view>
		</view>
	</view>
</template>

<script>
	import couponitem from '@/pages/simpleshop/components/couponitem.vue'
	import api from '@/api/api.js'
	export default {
		data() {
			return {
				userinfo: {
					url: require("@/static/images/avatar.png"),
					phone: "",
					integral: 0
				},
				buy_list: [
					{
						id: 1,
						price: 15,
						title: "15元微信立减金",
						expiration_time: "2024-5-27 12:00:00",
						status:1,
					},
					{
						id: 2,
						price: 15,
						title: "15元微信立减金",
						expiration_time: "2024-5-27 12:00:00",
						status:2,
					},
					{
						id: 3,
						price: 15,
						title: "15元微信立减金",
						expiration_time: "2024-1-27 12:00:00",
						status:3,
					},
				],
				status: 'loadmore',
				list: 15,
				page: 1,
				pagesize:8,
				total: 0,
			}
		},
		components: {
			couponitem
		},
		methods: { 
			getAccountInfo(){
				api.getAccountInfo().then((res)=>{
					if(res.data.code == 200){
						const userinfo = res.data.data
						// if(userinfo.flag == false){
						// 	uni.navigateTo({
						// 		url:"/pages/simpleshop/notinwl/notinwl"
						// 	})
						// }
					}else{
						uni.showToast({
							title: res.data.message,
							icon: "none"
						})
					}
				})
			},
			getorderlist(){
				api.getorderlist({
					page:this.page,
					pageSize:this.pagesize
				}).then((res)=>{
					if(res.data.code == 200){
						const orderlist = res.data.data.data
						this.total = res.data.data.total
						this.buy_list = this.buy_list.concat(orderlist)
					}else{
						uni.showToast({
							title: res.data.message,
							icon: "none"
						})
					}
				})
			},
		},
		onShow(){
			this.buy_list = []
			this.page = 1
			this.total = 0
			this.getAccountInfo()	
			this.getorderlist()
		},
		onReachBottom() {
			if (this.page * this.pagesize >= this.total) return;
			this.status = 'loading';
			this.page = ++this.page;
			this.getorderlist()
			if (this.page * this.pagesize >= this.total) this.status = 'nomore';
			else this.status = 'loadmore';
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: start;
		height: 100%;
		background: #FAFAFA;
		padding: 21rpx;
		gap: 22rpx;
	}

	.integral {
		font-weight: normal;
		font-size: 28rpx;
		color: #00A8EA;
		line-height: 28rpx;
		text-align: left;
		font-style: normal;
		text-transform: none;
		margin-top: 20rpx;
		font-weight: bold;
	}

	.label {
		font-weight: 500;
		font-size: 32rpx;
		color: #1A1A1A;
		line-height: 48rpx;
		text-align: left;
		font-style: normal;
		text-transform: none;
		width: 100%;
		margin-top: 56rpx;
		margin-left: 126rpx;
		margin-bottom: 20rpx;
		font-weight: 600;
	}

	.buy-list {
		width: 100%;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: center;
		padding-bottom: 64rpx;
		
		background: #FFFFFF;
		box-shadow: 0rpx 3 9rpx 0rpx rgba(0,0,0,0.06);
		border-radius: 28rpx;
	}

	.listcontainer {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		gap: 24rpx;
		padding-bottom: 128rpx;
	}
</style>