<template>
	<view class="page">
		<u-navbar title="卡劵管理" :border-bottom="false" :background="bgc" back-icon-color="#262B37" title-color='#262B37'
			title-size='36' height='44' id="navbar">
		</u-navbar>
       <view class="toptab">
       	<view @click="btntabone(0)" :class="activeoneindex == '' ? 'activeone' : ''">
       		全部
       		<text></text>
       	</view>
		<view @click="btntabone(1)" :class="activeoneindex == 1 ? 'activeone' : ''">
			储存卡
			<text></text>
		</view>
       	<view @click="btntabone(2)" :class="activeoneindex == 2 ? 'activeone' : ''">
       		小时卡
       		<text></text>
       	</view>
		<view @click="btntabone(3)" :class="activeoneindex == 3 ? 'activeone' : ''">
			团购劵
			<text></text>
		</view>
       	<view @click="btntabone(4)" :class="activeoneindex == 4 ? 'activeone' : ''">
       		次卡
       		<text></text>
       	</view>
       </view>
	   
	   <scroll-view class="list" scroll-y style="height: 77vh;" @scrolltolower="onScrollToLower">
	   	<view class="list_item" v-for="(item,index) in listka" :key="index" @click="btnxq(item.couponId)">
	   		<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>
	   	</view>
	   	<view style="width: 100%;text-align: center;color: #ccc;margin-top: 30rpx;">
	   		当前没有更多卡劵啦...
	   	</view>
	   </scroll-view>
	   
	   
	   <view class="anniu" @click="btnadd">
	   	   新建卡劵
	   </view>
	   
	</view>
</template>

<script>
	export default {
		data() {
			return {
                bgc: {
                	backgroundColor: "#fff",
                },
				activeoneindex:'',
				listka:[]
			}
		},
		onLoad() {

		},
		onShow() {
			this.getkajuanlist()
		},
		methods: {
			// 点击卡劵去编辑
			btnxq(couponId){
				uni.navigateTo({
					url:'/page_user/kabao/addka?couponId=' + couponId
				})
			},
			// 获取可用卡劵
			getkajuanlist(){
				this.$u.get(`/app/card/list?type=${this.activeoneindex}`).then(res => {
					if (res.code == 200) {
						this.listka = res.rows
					}
				})
			},
			// 点击新增卡卷
			btnadd(){
				uni.navigateTo({
					url:'/page_user/kabao/addka'
				})
			},
			// 滚动到底部触发
			onScrollToLower(){
				console.log(11);
			},
			btntabone(num){
				if(num == 0){
					this.activeoneindex = ''
					this.getkajuanlist()
				}else{
					this.activeoneindex = num
					this.getkajuanlist()
				}
			},
		}
	}
</script>

<style lang="scss">
	/deep/ .u-icon__icon,
	/deep/ .u-title{
		padding-bottom: 22rpx !important;
	}
	.anniu{
		width: 680rpx;
		height: 110rpx;
		line-height: 110rpx;
		text-align: center;
		color: #fff;
		font-weight: 600;
		border-radius: 20rpx;
		background-color: #48893B;
		position: fixed;
		bottom: 30rpx;
		left: 50%;
		transform: translateX(-50%);
		font-size: 40rpx;
	}
	.list{
		padding-bottom: 50rpx;
		box-sizing: border-box;
		.list_item{
			width: 698rpx;
			max-height: 588rpx;
			margin: auto;
			margin-top: 32rpx;
			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: 352rpx;
				background: #ECFAE9;
				font-size: 24rpx;
				color: #48893B;
				padding: 20rpx;
				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;
		}
	}
	page {
		background: #F6F6F6;
	}
	.toptab{
		display: flex; 
		width: 100%;
		background-color: #fff;
		padding-left: 34rpx;
		padding-bottom: 20rpx;
		box-sizing: border-box;
		view{
			margin-right: 20rpx;
			font-size: 32rpx;
			color: #7C7C7C;
			width: 120rpx;
			text-align: center;
		}
	}


</style>