<template>
	<view class="content">
		<view class="tabs">
			<u-tabs :list="tabs" :scrollable="true" lineWidth="0" @click="changetab" keyName="name" :current="current"
				:inactiveStyle="{color: '#999999',fontSize: '30rpx',}"
				:activeStyle="{color: '#222222',fontSize: '30rpx',}"></u-tabs>
		</view>
		<view class="list" v-if="list.length> 0">
			<view class="list-item hflex acenter jbetween" v-for="(item,index) in list" :key="index">
				<view class="item-left vflex acenter jcenter"
					:class="item.is_use == 1 || item.is_expire == 1 ? 'left-bg' : ''"
					v-if="item.coupon.type == 'integral_threshold' || item.coupon.type == 'integral_no_threshold'">
					<view class="left-price">￥{{Number(item.coupon.amount).toFixed(0)}}</view>
					<view class="left-text" v-if="item.coupon.type == 'integral_threshold'">
						满{{Number(item.coupon.threshold).toFixed(0)}}元可用</view>
				</view>
				<view class="item-left vflex acenter jcenter"
					:class="item.is_use == 1 || item.is_expire == 1 ? 'left-bg' : ''"
					v-if="item.coupon.type == 'shoot'">
					<view class="left-price">拍摄券</view>
				</view>
				<view class="item-left vflex acenter jcenter"
					:class="item.is_use == 1 || item.is_expire == 1 ? 'left-bg' : ''"
					v-if="item.coupon.type == 'lease'">
					<view class="left-price">租赁券</view>
				</view>
				<view class="item-center vflex">
					<text class="text_hide" style="width: 300rpx;">{{item.coupon.name}}</text>
					<text class="text_hide" style="width: 300rpx;">{{item.coupon.description}}</text>
					<text>到期时间：{{item.expired_at.slice(0,-9)}}</text>
				</view>
				<view class="item-right hflex acenter jcenter">
					<view class="btn" v-if="item.is_use == 0 && item.is_expire == 0">使用</view>
					<image src="static/yishiyong.png" mode="aspectFill" v-if="item.is_use == 1"></image><!-- 已使用 -->
					<image src="static/yishixiao.png" mode="aspectFill" v-if="item.is_expire == 1"></image><!-- 已失效 -->
				</view>
			</view>
		</view>
		<view class="hflex acenter jcenter " style="height: 100vh;" v-else>
			<u-empty mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	export default {
		data() {
			return {
				tabs: [{
						name: '全部'
					},
					{
						name: '待使用'
					},
					{
						name: '已使用'
					},
					{
						name: '已失效'
					},
				],
				current: 0,
				list: [],
				page: 1,
				last_page: 1
			}
		},
		onLoad() {
			this.getlist()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.getlist()
			} else {
				uni.$u.toast('已经到底了')
				return
			}
		},
		methods: {
			changetab(e) {
				console.log(e);
				this.current = e.index
				this.list = []
				this.page = 1
				this.getlist()
			},
			getlist() {
				var _this = this
				var is_expire = ''
				var is_use = ''
				if (_this.current == 1) {
					is_expire = 0
					is_use = 0
				} else if (_this.current == 2) {
					is_use = 1
				} else if (_this.current == 3) {
					is_expire = 1
				}
				$api.req({
					url: 'user/coupon',
					data: {
						is_page: 1,
						page: _this.page,
						limit: 10,
						is_expire: is_expire,
						is_use: is_use
					}
				}, function(res) {
					if (res.code == 10000) {
						_this.list = _this.list.concat(res.data.list)
						_this.last_page = res.data.last_page
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background: #F5F5F5;

		.list {
			width: 100%;
			box-sizing: border-box;
			padding: 0 28rpx;

			.list-item {
				margin: 20rpx 0 0;
				width: 694rpx;
				height: 160rpx;
				border-radius: 8rpx;
				background: #FFFFFF;

				.item-right {
					height: 100%;
					padding: 0 28rpx 0 0;

					.btn {
						width: 124rpx;
						height: 48rpx;
						border-radius: 28rpx;
						border: 1rpx solid #00B0B0;
						font-size: 22rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #00B0B0;
						line-height: 48rpx;
						text-align: center;
					}

					image {
						width: 108rpx;
						height: 108rpx;
					}
				}

				.item-center {
					padding: 16rpx 20rpx;
					width: 362rpx;

					text {
						font-size: 20rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #333333;
					}

					text:first-child {
						font-size: 28rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 500;
						color: #333333;
						padding: 0 0 8rpx;
					}

					text:last-child {
						font-size: 18rpx;
						font-family: SFPro, SFPro;
						font-weight: 400;
						color: #666666;
						padding: 24rpx 0 0;
						white-space: nowrap;
					}
				}

				.item-left {
					height: 100%;
					width: 196rpx;
					background: #00B0B0;

					.left-price {
						font-size: 32rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 600;
						color: #FFFFFF;
					}

					.left-text {
						font-size: 20rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						padding: 18rpx 0 0;
					}
				}

				.left-bg {
					background: #B2B2B2 !important;
				}
			}
		}

		.tabs {
			background: #FFFFFF;
		}
	}
</style>