<template>
	<view class="container" v-if="fetch">
		<use-tabbar :tabbar="false"></use-tabbar>
		<view class="w-full navbar-area bg-main">
			<view class="state-area dflex-a">
				<view v-for="(item, index) in navList" :key="index" :class="{ active: status === index }" class="nav-item dflex-c pos-r fs padding-lr-lg h-full"
				 @click="tabClick(index)">
					{{ item.state }}
					<text v-if="item.cnt > 0">({{ item.cnt }})</text>
				</view>
			</view>
		</view>

		<scroll-view class="list-scroll-content h-full" scroll-y >
			<!-- 空白页 -->
			<u-empty v-if="fetch.list && fetch.list.length == 0" marginTop="200" mode="coupon" text="暂无礼品卡"></u-empty>
			<view v-else class="padding-lr" v-for="(item, index) in fetch.list" :key="index">
				<view class="coupon_box border-radius margin-top-sm bg-main" :class="[{ 'disabled': status != 0 }]" @click="showModal(item.scope.title, item.scope.tip)">
					<view class="dflex-b">
						<view class="left pos-a h-full dflex-c dflex-flow-c">
							
							<view>
								<text class="price fs-big">{{ item.yue }}</text>
							</view>
							<view class="fs-sm">余额</view>
						</view>
						<view class="right padding left_t flex1">
							<view class="dflex-b padding-bottom-xs">
								<view class="fwb fs">{{ item.name }}</view>
								<text class="arrow" v-if="item.scope.tip">›</text>
							</view>
							<view v-if="status == 1" class="ft-dark iconfont iconyishiyong"></view>
							<view v-if="status == 2" class="ft-dark iconfont iconyiguoqi"></view>
							<view class="dflex-b ft-dark fs-xs padding-bottom border-line">
								<view class="">{{ item.date_name }}</view>
							</view>
							<view class="fs-xs ft-dark padding-top-xs">
								{{ item.title }}
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<u-modal @close="closeModal" @confirm="closeModal" :show="show.state" :title="show.title" :closeOnClickOverlay="true">
			<view class="slot-content">
				<u-parse :content="show.content"></u-parse>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				fetch: {},
				status: 0,
				show : {
					state : false,
					title : '',
					content : '',
				},
				navList: [{
						id: 0,
						state: '已领取',
						cnt: 0,
					},
					{
						id: 1,
						state: '已过期',
						cnt: 0,
					}
				],
			};
		},
		onLoad(options) {
			this.loadData(1);
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.loadData(1);
		},
		// 上拉加载更多
		onReachBottom() {
			this.loadData(2);
		},
		methods: {
			loadData(page) {
				this.DeverApi.page([page, 'list'], this, 'gift.my', {status:this.status});
			},
			// 顶部tab点击
			tabClick(index) {
				this.status = index;
				this.fetch.list = {}
				this.loadData(1);
			},
			showModal(title, content) {
				if (content) {
					this.show.title = title;
					this.show.content = content;
					this.show.state = true;
				}
			},
			closeModal() {
				this.show.state = false;
			},
		}
	};
</script>

<style lang="scss">
	page,
	.container {
		min-height: 100%;
		background: $page-color-base;
	}

	/* 优惠券状态区 */
	.navbar-area {
		white-space: nowrap;

		.state-area {
			height: 7vh;
			box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
			z-index: 10;
		}

		.nav-item {
			flex: 1;

			&.active {
				&:after {
					content: '';
					position: absolute;
					left: 50%;
					transform: translate(-50%);
					bottom: 0;
					width: 44px;
					height: 0;
					border-bottom: 2px solid $base-color;
				}
			}
		}
	}

	/* 优惠券轮播区 */
	.swiper-area {
		height: 93vh;
	}

	.coupon_box {
		position: relative;
		&:last-child {
			margin-bottom: 20rpx;
		}
		.left {
			background-color: #ff8b6a;
			color: #fff;
			width: 30%;

			.price {
				color: #fff !important;
			}
		}

		.right {
			margin-left: 30%;
		}

		.discount {
			font-weight: 580;
		}

		.discount::after {
			content: '折';
			font-size: 24rpx;
			margin-left: 6rpx;
		}

		.border-line {
			border-bottom: 1px dotted #ededed;
		}
	}

	.disabled {
		.left {
			background-color: #d9d9d9;
			color: #b2b2b2 !important;

			.price {
				color: #b2b2b2 !important;
			}
		}

		.iconfont {
			position: absolute;
			/*top: 0rpx;*/
			right: 30rpx;
			font-size: 110rpx;
		}
	}
	
	.btn-container {
	    left: 9px;
	    right: 9px;
	    bottom: 0;
	}
</style>
