<template>
	<view class="pages">
		<u-navbar
			title="我的优惠券"
			:placeholder="true"
			:autoBack="false"
			 @leftClick="leftClick"
			 :safeAreaInsetTop="true"
		>
		</u-navbar>
		<view class="tabs-wrap">
			<view class="inner">
				<u-tabs
					:list="tabsArr"  
					@click="tabsClick"
					lineColor="#ED0000" 
					lineWidth="82rpx"
					:activeStyle="{color: '#2D2D2D',fontWeight: 'bold'}"
					itemStyle="width:33%; height: 46px;box-sizing:border-box"
				>
				</u-tabs>
			</view>
		</view>
		<view class="page-wrap">
			<mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
				<!-- :down="downOption" :up="upOption" -->
				<view class="list">
					<view v-for="(item,index) in dataList" class="list-item u-flex" :class="{hotel:index==1}" :key="item.id" :style="{backgroundImage:`url(${staticUrl}/img/coupon-bg.png)`}">
						<view class="left u-flex u-row-center u-col-top">
							<text class="icon">￥</text>
							<text class="num">30</text>
						</view>
						<view class="right u-flex u-row-between">
							<view class="text">
								<view class="name">演出购票折扣券</view>
								<view class="time">有限期：2023.10.22-2023.10.22</view>
								<view class="rule u-flex">
									使用规则
									<u-icon name="arrow-right" color="#D56442" size="30rpx"></u-icon>
								</view>
							</view>
							<view class="btn">去使用</view>
						</view>
					</view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	// 引入mescroll-mixins.js
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			
		},
		data() {
			return {
				staticUrl:this.$commonConfig.staticUrl,
				// // 下拉刷新的配置(可选, 绝大部分情况无需配置)
				// downOption: {
				// },
				// // 上拉加载的配置(可选, 绝大部分情况无需配置)
				// upOption: {
				// 	page: {
				// 		size: 10 // 每页数据的数量,默认10
				// 	},
				// 	noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
				// 	empty: {
				// 		tip: '暂无相关数据'
				// 	}
				// },
				params:{
				},
				dataList:[
					{name:'路线推荐',pic:`${this.$commonConfig.staticUrl}/img/indexnav-luxian.png`,id:1},
					{name:'路线推荐',pic:`${this.$commonConfig.staticUrl}/img/indexnav-luxian.png`,id:1},
				],
				tabsArr:[
					{name:'待使用',status:0},
					{name:'已使用',status:1},
					{name:'已过期',status:2}
				],
				status:0,
				
			}
		},
		onShow() {
		},
		onLoad() {

		},
		methods: {
			leftClick(e){
				let pages = getCurrentPages();
				if(pages.length==1){
					uni.$u.route('/pages/index/index')
				}else{
					uni.navigateBack()
				};
			},
			/*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
			downCallback(){
				this.mescroll.resetUpScroll();
			},
			/*上拉加载的回调*/
			upCallback(page) {
				// 此处可以继续请求其他接口
				// if(page.num == 1){
				// 	// 请求其他接口...
				// }
			
				// 如果希望先请求其他接口,再触发upCallback,可参考以下写法
				// if(!this.hasTypeId){
				// 	this.mescroll.endErr();//没有接口暂时不调用
				// 	return // 此处return,先获取xx
				// }
			
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
			
				let params = {
					pageNum : page.num,
					pageSize :  page.size,
					status:this.status
				}
				// console.log('this.params',params);
				this.$u.api.orderList(params).then(data => {
					this.hasfetch = true;
					console.log('data',JSON.parse(JSON.stringify(data)));
					// 接口返回的当前页数据列表 (数组)
					let curPageData = data.data.rows;
					// console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
					// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
					let curPageLen = curPageData.length; 
					// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
					// let totalPage =  data.data.data.totalPage; 
					// 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
					let totalSize = data.data.total; 
					// 接口返回的是否有下一页 (true/false)
					// let hasNext = data.xxx; 
					// console.log('totalPage',totalPage,'curPageLen',curPageLen);
					//设置列表数据
					if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
					this.dataList = this.dataList.concat(curPageData); //追加新数据
					// 请求成功,隐藏加载状态
					//方法一(推荐): 后台接口有返回列表的总页数 totalPage
					// this.mescroll.endByPage(curPageLen, totalPage); 
					//方法二(推荐): 后台接口有返回列表的总数据量 totalSize
					this.mescroll.endBySize(curPageLen, totalSize); 
				}).catch(err => {
					this.mescroll.endErr()
					console.log(err)
				});	
			
			},
			/*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
			reloadList() {
				this.mescroll.resetUpScroll();
			},
			search(e){
				this.reloadList();
			},
			tabsClick(e){
				console.log('tabsClick',e);
				this.status = e.status;
				this.reloadList();
				// this.tabsIndex = e.index;
			},
		}
	}
</script>

<style lang="scss" scoped>
.tabs-wrap{
	position: relative;
	margin-bottom: 24rpx;
	box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(226,226,226,0.5);
}
.list{
	.list-item{
		width: 100%;
		height: 158rpx;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		margin-bottom: 24rpx;
		.left{
			width: 190rpx;
			.icon{
				width: 26rpx;
				height: 26rpx;
				line-height: 26rpx;
				text-align: center;
				font-size: 10px;
				color: #fff;
				border-radius: 50%;
				background: linear-gradient(360deg, #ED0000 0%, #F27C7D 100%);
			}
			.num{
				font-size: 100rpx;
				font-family: Helvetica, Helvetica;
				font-weight: bold;
				color: #000000;
				background: linear-gradient(180deg, #F28082 0%, #ED0000 100%);
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
			}
		}
		.right{
			flex: 1;
			padding: 32rpx 20rpx;
			.text{
				padding-left: 10rpx;
				color: #D56442;
				font-size: 20rpx;
				font-weight: 400;
			}
			.name{
				font-size: 28rpx;
				font-weight: bold;
				color: #C5412B;
				margin-bottom: 16rpx;
			}
			.time{
				margin-bottom: 16rpx;
			}
			.btn{
				height: 50rpx;
				line-height: 50rpx;
				background: #ED0000;
				border-radius: 25rpx;
				font-size: 24rpx;
				font-weight: bold;
				color: #FFFFFF;
				padding: 0 24rpx;
			}
		}
		&.hotel{
			.num{
				background: linear-gradient(180deg, #F77941 0%, #E84816 100%);
				background: linear-gradient(180deg, #F77941 0%, #E84816 100%);
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
			}
			.icon{
				background: linear-gradient(360deg, #E84917 0%, #F97E45 100%);
			}
		}
	}
}
</style>