<template>
	<view>
		<view>
			<scroll-view scroll-x class="bg-white nav text-center" style="height: 100vh;">
				<view :class="index==TabCur?'cu-item text-blue cur':'cu-item'" v-for="(item,index) in list" :key="index" @click="tabSelect"
				 :data-id="index" style="">
					{{item.name}}
					<text v-if="index == 0">({{notUsedList.length}})</text>
					<text v-if="index == 1">({{usedList.length}})</text>
					<text v-if="index == 2">({{invalidList.length}})</text>
				</view>
				<view class="coupon-List" v-if="TabCur == 0">
					<view style="text-align: right;">
						<text>使用规则 ></text>
					</view>
					<view class="margin-top-sm">
						<view class="cu-list menu-avatar padding-tb-sm bg-white">
							<view class="cu-item" v-for="(item,index) in notUsedList" :key="index">
								<view class="cu-avatar round lg" :style="'background-image:url('+item.icon+');'">
								</view>
								<view class="content">
									<view class="text-grey">
										<text class="text-cut">{{item.name}}</text>
									</view>
									<view class="text-gray text-sm flex">
										<text class="text-cut">{{item.title}}</text>
									</view>
									<view class="text-gray text-sm flex">
										<text class="text-cut">有效期：{{item.start_time}}-{{item.end_time}}</text>
									</view>
								</view>
								<view class="action">
									<!-- <view class="text-grey text-xs">22:20</view>
									<view class="cuIcon-notice_forbid_fill text-gray"></view> -->
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-else-if="TabCur == 1">
					<view class="margin-top-sm">
						<view class="cu-list menu-avatar padding-tb-sm bg-white">
							<view class="cu-item" v-for="(item,index) in usedList" :key="index">
								<view class="cu-avatar round lg" :style="'background-image:url('+item.icon+');'">
								</view>
								<view class="content">
									<view class="text-grey">
										<text class="text-cut">{{item.name}}</text>
									</view>
									<view class="text-gray text-sm flex">
										<text class="text-cut">{{item.title}}</text>
									</view>
									<view class="text-gray text-sm flex">
										<text class="text-cut">有效期：{{item.start_time}}-{{item.end_time}}</text>
									</view>
								</view>
								<view class="action">
									<!-- <view class="text-grey text-xs">22:20</view>
									<view class="cuIcon-notice_forbid_fill text-gray"></view> -->
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-else="TabCur == 2">
					<view class="margin-top-sm">
						<view class="cu-list menu-avatar padding-tb-sm bg-white">
							<view class="cu-item" v-for="(item,index) in invalidList" :key="index">
								<view class="cu-avatar round lg" :style="'background-image:url('+item.icon+');'">
								</view>
								<view class="content">
									<view class="text-grey">
										<text class="text-cut">{{item.name}}</text>
									</view>
									<view class="text-gray text-sm flex">
										<text class="text-cut">{{item.title}}</text>
									</view>
									<view class="text-gray text-sm flex">
										<text class="text-cut">有效期：{{item.start_time}}-{{item.end_time}}</text>
									</view>
								</view>
								<view class="action">
									<!-- <view class="text-grey text-xs">22:20</view>
									<view class="cuIcon-notice_forbid_fill text-gray"></view> -->
								</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		mounted() {
			this.getCouponList()
		},
		data() {
			return {
				notUsed: 1, //未使用
				used: 2, //已使用
				invalid: 3, //过期

				TabCur: 0,
				list: [{
					name: '未使用',
				}, {
					name: '已使用',
				}, {
					name: '已过期',
				}],
				// 因为内部的滑动机制限制，请将tabs组件和swiper组件的current用不同变量赋值
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
				pageindex: 1,
				couponList: [],
				notUsedList: [],
				usedList: [],
				invalidList: [],
				show: false
			};
		},
		methods: {
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id
			},
			getCouponList: async function() {
				let res = await this.$request.post("/api/v1/coupon/couponList", {
					page: this.pageindex
				})
				if (res.status == 0) {
					this.notUsedList = res.data.data.filter(item => {
						if (item.status == 1) {
							return item
						}
					})
					this.usedList = res.data.data.filter(item => {
						if (item.status == 2) {
							return item
						}
					})
					this.invalidList = res.data.data.filter(item => {
						if (item.status == 3) {
							return item
						}
					})
				}
			}
		},
		onShow() {

		}
	};
</script>
<style>
	.coupon-List {
		height: 100%;
		width: 100%;
		/* background-color: #f9f9f9; */
		padding: 20rpx 20rpx 0 20rpx;
	}

	/*卡片*/
	.u-card-wrap {
		background-color: $u-bg-color;
		padding: 1px;
	}

	.u-body-item {
		font-size: 32rpx;
		color: #333;
		padding: 20rpx 10rpx;
	}

	.u-body-item image {
		width: 120rpx;
		flex: 0 0 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		margin-left: 12rpx;
	}
</style>
