<template>
	<view class="container">
		<view class="towcontent">
			<view class="towcontentlistxitem flex-start">
				<view class="towcontentlistxitembox flex-colum"
					:class="towcontentclickindex == index?'towcontentlistxitemboxopacity':''"
					v-for="(item,index) in listbox" :key="index" @click="towcontentclick(index,item)">
					<text>{{item.name}}</text>
					<image v-if="towcontentclickindex == index"
						src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/index/today/dg.png" mode="widthFix">
					</image>
				</view>
			</view>
		</view>
		<view class="containertop">
			<view class="containertopbox">
				<view class="containertopboxitem flex-start" v-for="(item,index) in list" :key="index">
					<view class="containertopboxitemleft flex-colum"
						:class="item.status == 0?'':'containertopboxitemlefts'">
						<view class="containertopboxitemleft_one"
							:class="item.status == 0?'':'containertopboxitemleft_ones'">
							<text style="font-size: 28rpx;">￥</text>
							<text>{{item.couponsAmount || 0}}</text>
						</view>
						<view class="containertopboxitemleft_tow"
							:class="item.status == 0?'':'containertopboxitemleft_tows'">
							优惠券(元)
						</view>
					</view>
					<view class="containertopboxitemright">
						<view class="containertopboxitemright_one">
							无门槛使用
						</view>
						<view class="containertopboxitemright_tow">
							通用红包券
						</view>
						<view class="containertopboxitemright_there">
							有效期至：{{$u.timeFormat(item.endTime, 'yyyy/mm/dd') || '0'}}
						</view>
						<view
							:class="item.status == 0?'containertopboxitemright_four':'containertopboxitemright_fours'">
							{{item.status == 0 ? '兑换积分':'已过期'}}
						</view>
					</view>
				</view>
				<image style="margin:32rpx auto;" src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/nomore.png"
					v-if="is_end" mode="aspectFill"></image>
				<u-loadmore :status="form.status" iconSize='24' fontSize='24' height='40' />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listbox: [{
						name: '全部',
						type: ''
					},
					{
						name: '未使用',
						type: '0'
					},
					{
						name: '已过期',
						type: '1'
					}
				],
				towcontentclickindex: 0,
				list: [],
				is_end:false,
				form: {
					page: 1, //页数
					size: 10, //页容量
					status: 'loadmore',
					statuses: ''
				},
			};
		},
		onLoad() {
			this.ordermineCouponsthis()
		},
		onReachBottom() {
			this.ordermineCouponsthis()
		},
		methods: {
			init_fn(e) {
				this.list = []
				this.form = {
					page: 1, //页数
					size: 10, //页容量
					status: 'loadmore',
					statuses: ''
				}
				try {
					if (e) {
						this.form.statuses = e
					}
				} catch (e) {
					//TODO handle the exception
				}
				this.ordermineCouponsthis()
			},
			async ordermineCouponsthis() {
				try {
					let res = await this.api.ordermineCoupons({
						userId: uni.cache.get('userInfo').id,
						status: this.form.statuses,
						page: this.form.page,
						size: this.form.size,
						orderId:""
					})
					if (res.data.pages < this.form.page) {
						this.form.status = 'nomore'
						if (this.form.page == 1 && res.data.list == 0) {
							this.is_end = true
						}
						return false;
					} else {
						this.form.status = 'loading';
						this.form.page = ++this.form.page;
						setTimeout(() => {
							this.list = [...this.list, ...res.data.list];
							this.form.status = 'loading';
							if (res.data.pageNum == res.data.pages) {
								this.form.status = 'nomore';
							} else {
								this.form.status = 'loading';
							}
						}, 500)
					}
				} catch (e) {
					//TODO handle the exception
				}
			},
			towcontentclick(index, item) {
				this.towcontentclickindex = index
				this.form.statuses = item.type
				this.init_fn(item.type)
			}
		}
	};
</script>

<style scoped lang="scss">
	page {
		background: #fff;
	}

	.container {
		.towcontent {
			padding: 0 28rpx;
			border-top: 16rpx solid #F9F9F9;

			.towcontentlistxitem {
				width: 100%;
				margin-top: 32rpx;

				.towcontentlistxitembox {
					width: 33%;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #333333;

					image {
						margin-top: 6rpx;
						width: 38.83rpx;
						height: 8.62rpx;
					}
				}

				.towcontentlistxitemboxopacity {
					width: 33%;
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;

					image {
						width: 38.83rpx;
						height: 8.62rpx;
					}
				}


			}
		}

		.containertop {
			padding: 40rpx 32rpx;

			.containertopbox {
				.containertopboxitem::after {
					position: absolute;
					bottom: 14rpx;
					left: 14rpx;
					content: '';
					display: inline-block;
					background: url(https://czg-qr-order.oss-cn-beijing.aliyuncs.com/coupontop.png) no-repeat;
					width: 72.83rpx;
					height: 77.14rpx;
					background-size: cover;
				}

				.containertopboxitem {
					margin-top: 20rpx;
					width: 100%;
					position: relative;

					.containertopboxitemleft {
						position: relative;
						width: 182rpx;
						height: 192rpx;
						background: #F1CB66;
						border-radius: 18rpx 0rpx 0rpx 18rpx;
						box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);

						::after {
							content: '';
							position: absolute;
							top: 0rpx;
							left: 166rpx;
							background: #f9f9f9;
							display: inline-block;
							width: 32rpx;
							height: 16rpx;
							border-radius: 0 0 32rpx 32rpx;
							z-index: 999;
						}

						::before {
							content: '';
							position: absolute;
							bottom: 0rpx;
							left: 166rpx;
							background: #f9f9f9;
							display: inline-block;
							width: 32rpx;
							height: 16rpx;
							line-height: 32rpx;
							border-radius: 32rpx 32rpx 0 0;
							box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
							z-index: 999;

						}

						.containertopboxitemleft_one {
							text {
								font-family: Source Han Sans CN, Source Han Sans CN;
								font-weight: 500;
								font-size: 60rpx;
								color: #FFFFFF;
							}
						}

						.containertopboxitemleft_ones {
							text {
								color: #999999;
							}
						}

						.containertopboxitemleft_tow {
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: 500;
							font-size: 24rpx;
							color: #FFFFFF;
						}

						.containertopboxitemleft_tows {
							color: #999999;
						}
					}

					.containertopboxitemlefts {
						background: #F7F7F7;
					}

					.containertopboxitemright {
						position: relative;
						padding: 0 32rpx;
						flex: auto;
						height: 192rpx;
						background: #FFFFFF;
						box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);
						border-radius: 0rpx 18rpx 18rpx 0rpx;

						.containertopboxitemright_one {
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: 500;
							font-size: 24rpx;
							color: #666666;
							padding: 12rpx 0;
							border-bottom: 1rpx dotted #707070;
						}

						.containertopboxitemright_tow {
							margin-top: 14rpx;
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: 500;
							font-size: 32rpx;
							color: #333333;
						}

						.containertopboxitemright_there {
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: 500;
							font-size: 24rpx;
							color: #999999;
						}

						.containertopboxitemright_four {
							position: absolute;
							right: 32rpx;
							top: 50%;
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: 500;
							font-size: 24rpx;
							color: #FFFFFF;
							padding: 0 14rpx;
							height: 48rpx;
							line-height: 48rpx;
							text-align: center;
							background: #FE665E;
							border-radius: 24rpx 24rpx 24rpx 24rpx;
						}

						.containertopboxitemright_fours {
							position: absolute;
							right: 32rpx;
							top: 50%;
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 24rpx;
							color: #999999;
							padding: 0 14rpx;
							height: 48rpx;
							line-height: 48rpx;
							text-align: center;
							background: #F7F7F7;
							border-radius: 24rpx 24rpx 24rpx 24rpx;
						}
					}
				}

			}
		}


	}
</style>