<template>
	<view>
		<mNavbar title="我的优惠劵"
		:leftClick="toLeft"
		/>
		
		<view style="position: sticky;top: 45px;z-index: 99;">
			<van-tabs v-model:active="active"
			title-active-color="#6e3009"
			@change="clickTabs"
			>
				<van-tab :title="item.name"
				v-for="(item, index) in tabs"
				:key="index"></van-tab>
			</van-tabs>
		</view>
		
		<van-list
		  v-model:loading="loading"
		  :finished="finished"
		  @load="onLoad"
		>
			<couponList :list="couponList" @select="toHome"/>
		</van-list>
	</view>
</template>

<script>
	import couponList from '/components/couponList.vue'
	import mNavbar from '@/components/base/m-navbar.vue'
	export default {
		components : {
			couponList,
			mNavbar
		},
		data() {
			return {
				value : '',
				tabs : [
					{
						name: '待使用优惠劵',
					}, {
						name: '已使用优惠劵',
					}, {
						name: '已过期优惠劵'
					}
				],
				active : 0,
				queryParams : {
					pageNo : 1,
					pageSize : 10,
				},
				couponList : [],
				loading : false,
				finished : false,
			}
		},
		onShow(){
			this.getCouponList()
		},
		methods: {
			onLoad(){
				this.queryParams.pageSize += 10
				this.getCouponList()
			},
			//获取优惠券列表
			getCouponList(){
				this.$api('getCouponList' , {
					...this.queryParams,
					state : this.active
				} , res => {
					if(res.code == 200){
						this.couponList = res.result.records;
						if(this.queryParams.pageSize > res.result.total){
							this.finished = true
						}
					}
					this.loading = false
				})
			},
			toLeft(){
				uni.switchTab({
					url: '/pages/index/center'
				})
			},
			clickTabs(e){
				this.getCouponList()
			},
			onClickButton(){
				
			},
			toHome(){		//跳转首页
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.btn{
	padding: 0px 30rpx;
	background: linear-gradient(178deg, #ffe6ed, #ecb978);
	color: #6e3009;
	font-size: 22rpx;
	margin-left: 20rpx;
	font-size: 20rpx;
	border-radius: 30rpx;
}
</style>
