<template>
	<view class="page">
        <view class="navtab">
        	<view class="toptab">
        		<!-- <view @click="btntabone(1)" :class="activeoneindex == 1 ? 'activeone' : ''">
        			
					<text></text>
        		</view> -->
        		<view @click="btntabone(3)" class="activeone">
        			兑换卡劵
        		</view>
        	</view>
        	<view class="twotab">
        		<view @click="btntabtwo(0)" :class="activetwoindex == 0 ? 'activetwo' : ''">
        			全部
        		</view>
				<view @click="btntabtwo(1)" :class="activetwoindex == 1 ? 'activetwo' : ''">
					储值卡
				</view>
        		<view @click="btntabtwo(2)" :class="activetwoindex == 2 ? 'activetwo' : ''">
        			小时卡
        		</view>
        		<view @click="btntabtwo(3)" :class="activetwoindex == 3 ? 'activetwo' : ''">
        			次卡
        		</view>
        	</view>
        </view>
		<scroll-view class="list" scroll-y style="height: 81vh;" @scrolltolower="onScrollToLower">
			<view class="list_item" v-for="(item,index) in listka" :key="index" @click="btnyhj(item.couponId,item.type)">
				<image src="https://api.ccttiot.com/smartmeter/img/static/u9yhfTszqRFL3zhHWyR7" mode=""></image>
				<view class="top">
					<view class="lt">
						<view class="time">
							{{item.name == undefined ? '--' : item.name}}
						</view>
						<view class="wz" v-if="item.type == 1">
							可用金额：{{item.storedAmount == undefined ? '--' : '￥' + item.storedAmount}}
						</view>
							<view class="wz" v-if="item.type == 2">
								可用时长：{{item.hours == undefined ? '--' : item.hours}}小时
							</view>
							<view class="wz" v-if="item.type == 3">
								
							</view>
							<view class="wz" v-if="item.type == 4">
								可用次数：{{item.limitNum == undefined ? '--' : item.limitNum}}次
							</view>
						<view class="wz" v-if="item.type != 3">
							有效期：{{item.validityValue == undefined ? '--' : item.validityValue + '天'}}
						</view>
					</view>
					<view class="leix" v-if="item.type == 1">
						储存卡
					</view>
						<view class="leix" v-if="item.type == 2">
							小时卡
						</view>
						<view class="leix" v-if="item.type == 3">
							团购劵
						</view>
						<view class="leix" v-if="item.type == 4">
							次卡
						</view>
					<view class="rt">
						￥{{item.retailPrice == undefined ? '--' : item.retailPrice}}
					</view>
				</view>
				<view class="bot">
					该卡券<text v-for="(val,index) in item.availableWeek">{{val == 1 ? '周一' : val == 2 ? '周二' : val == 3 ? '周三': val == 4 ? '周四': val == 5 ? '周五': val == 6 ? '周六': val == 7 ? '周日' : ''}}</text> 
						  <span style="margin-left:50rpx" v-if="item.availableTimeStart == '00:00' && item.availableTimeEnd == '00:00'">全时段可使用</span>
						  <span style="margin-left:50rpx" v-else>{{item.availableTimeStart}}-{{item.availableTimeEnd}}可使用</span>
					<view class="">
						描述：{{item.descr == null ? '--' : item.descr}}
					</view>
				</view>
			</view>
			<view style="width: 100%;text-align: center;color: #ccc;margin-top: 50rpx;">
				当前没有更多卡劵啦...
			</view>
		</scroll-view>
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
				bgc: { 
					backgroundColor: "",
				},
				activeoneindex:1,
				activetwoindex:0,
				listka:[],
				type:'',
				storeId:''
			}
		},
		onLoad() {

		},
		onShow() {
			this.storeId = uni.getStorageSync('storeId')
			this.getkajuanlist()
		},
		methods: {
			// 点击跳转到购买优惠劵
			btnyhj(couponId,type){
				if(type == 3){
					uni.showToast({
						title: '团购劵不支持小程序购买',
						icon: 'none',
						duration:2000
					})
				}else{
					uni.navigateTo({
					 	url:'/page_fenbaotwo/hexiao/youhuijuan?couponId=' + couponId
					 })
				}
			},
			// 用户获取可用卡劵
			getkajuanlist(){
				this.$u.get(`/app/card/list?type=${this.type}&storeId=${this.storeId}`).then(res => {
					if (res.code == 200) {
						this.listka = res.rows
					}
				})
			},
			// 滚动到底部触发
			onScrollToLower(){
				console.log(11);
			},
             // 点击第一个tab切换
			 btntabone(num){
				 if(num == 3){
					 uni.navigateTo({
					 	url:'/page_fenbaotwo/hexiao/index'
					 })
				 }else{
					 this.activeoneindex = num
				 }
			 },
			 // 点击第二个tab切换
			 btntabtwo(num){
				 this.activetwoindex = num
				 if(num == 0){
					 this.type = ''
					 this.getkajuanlist()
				 }else{
					 this.type = num
					 this.getkajuanlist()
				 }
			 }
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F6F6;
	}
	.list{
		margin-top: 300rpx;
		padding-bottom: 50rpx;
		box-sizing: border-box;
		.list_item{
			width: 698rpx;
			height: 288rpx;
			margin: auto;
			margin-bottom: 50rpx;
			position: relative;
			.top{
				height: 236rpx;
				width: 100%;
				display: flex;
				justify-content: space-between;
				padding: 0 44rpx;
				box-sizing: border-box;
				.lt{
					margin-top: 38rpx;
					.time{
						font-weight: 600;
						font-size: 52rpx;
						color: #48893B;
						margin-bottom: 18rpx;
					}
					.wz{
						font-size: 24rpx;
						color: #48893B;
						margin-bottom: 8rpx;
					}
				}
				.leix{
					width: 144rpx;
					height: 52rpx;
					line-height: 52rpx;
					background: #48893B;
					font-weight: 600;
					font-size: 32rpx;
					color: #FFFFFF;
					position: absolute;
					top: 0;
					right: 0;
					text-align: center;
					border-radius: 0 0 0 10rpx;
				}
				.rt{
					font-weight: 600;
					font-size: 70rpx;
					color: #FFFFFF;
					-webkit-text-stroke: 2px #48893B; /* 边框宽度和颜色 */
					text-stroke: 2px #48893B;
					margin-top: 90rpx;
				}
			}
			.bot{
				width: 698rpx;
				max-height: 252rpx;
				background: #ECFAE9;
				font-size: 24rpx;
				color: #48893B;
				flex-wrap: wrap;
				padding: 10rpx;
				box-sizing: border-box;
			}
			image{
				width: 100%;
				height: 100%;
				position: absolute;
				top: 0;
				left: 0;
				z-index: -1;
			}
		}
	}
	.activeone{
		font-weight: 600;
		font-size: 32rpx !important;
		color: #262B37 !important;
		text{
			display: block;
			width: 60rpx;
			height: 6rpx;
			background: #48893B;
			border-radius: 3rpx 3rpx 3rpx 3rpx;
			margin: auto;
			margin-top: 4rpx;
		}
	}
	.activetwo{
		background: #DEF1DA !important;
		font-weight: 600;
		font-size: 28rpx !important;
		color: #48893B !important;
	}
	.navtab{
		width: 750rpx;
		height: 274rpx;
		background: #FFFFFF;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		position: fixed;
		top: 0;
		padding-top: 108rpx;
		padding-left: 52rpx;
		box-sizing: border-box;
		z-index: 9;
		.toptab{
			display: flex; 
			view{
				font-size: 32rpx;
				color: #7C7C7C;
				width: 300rpx;
			}
		}
		.twotab{
			display: flex;
			margin-top: 44rpx;
			box-sizing: border-box;
			view{
				font-size: 28rpx;
				text-align: center;
				color: #7C7C7C;
				width: 126rpx;
				height: 50rpx;
				line-height: 50rpx;
				margin-right: 36rpx;
				border-radius: 30rpx;
			}
		}
	}

	
</style>