<template>
	<view class="page">
		<u-navbar title="我的骑行卡" :border-bottom="false" :background="bgc" title-color='#000' title-size='36'
			height='45'></u-navbar>

		<view class="cont">
			<view class="card1">
				<view class="card_txt">
					不使用骑行卡
				</view>
				<image src="https://lxnapi.ccttiot.com/bike/img/static/u2RancJg66W4KNy3NVOW" mode="" v-if="chooseIdx!=999"></image>
				<image src="https://lxnapi.ccttiot.com/bike/img/static/u534UfvcSJmYAoPtTP4V" mode=""  v-if="chooseIdx==999"></image>
			</view>
			<view class="tips">
				可用骑行卡
			</view>
			<view class="card2" v-for="(item,index) in CouponLists" :key="index" v-if="(item.couponType==3||item.couponType==4)&&item.status==1">
				<view class="txt1">
					{{item.couponName}} | 剩余{{item.limitNum}}次
				</view>
				<view class="txt2">
					有效期至{{formatDate(item.expirationTime) }}
				</view>
				<!-- <view class="btn1">
					满5.00元可使用
				</view> -->
				<view class="imgs">
					<!-- <image src="https://lxnapi.ccttiot.com/bike/img/static/u2RancJg66W4KNy3NVOW" mode=""></image> -->
					<image src="https://lxnapi.ccttiot.com/bike/img/static/u534UfvcSJmYAoPtTP4V" mode=""></image>
				</view>
			</view>
			<view class="card3" v-for="(item,index) in CouponLists" :key="index" v-if="item.couponType==1&&item.status==1" @click="choose(item,index)">
				<view class="txt4">
					有效期至{{formatDate(item.expirationTime)}}
				</view>
				<view class="imgs">
					<image src="https://lxnapi.ccttiot.com/bike/img/static/ug8PuJqm4gM8NTod9QhV" mode="" v-if="chooseIdx!=index"></image>
					<image src="https://lxnapi.ccttiot.com/bike/img/static/udiSbHYWZQYLoapdWOyc" mode=""  v-if="chooseIdx==index"></image>
				</view>
			</view> 
			<view class="sub_btn" @click="sub()">
				确定
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: '#fff'
				},
				sn: '',
				istrue: false,
				orderId:'',
				chooseIdx:-1,
				CouponLists:[],
				chooseInfo:{}
			}
		},
		onShow() {
			this.getinfo()
		},
		onLoad(e) {
			this.orderId=e.orderId
			console.log(e,);
		},
		methods: {
			choose(item,index){
				this.chooseIdx=index
				this.chooseInfo=item
			},
			sub(){
				if(this.chooseIdx==999){
				uni.navigateBack({
					delta: 1 // delta值为1时表示返回的页面层数
				});
				}else{
					this.$u.post("/appVerify/useCoupon?orderNo="+this.orderId+'&logId='+this.chooseInfo.logId).then((res) => {
								
						if (res.code == 200) {
							uni.navigateBack({
								delta: 1 // delta值为1时表示返回的页面层数
							});
							
						} else {
						
						}
					});
				}
				
			
			},
			getinfo() {
				// uni.showLoading({
				// 	title:'加载中'
				// })
				this.$u.get("/getAppInfo").then((res) => {
			
					if (res.code == 200) {
					
						this.$store.commit('SET_USERID', res.user.userId);
						this.userinfo = res.user
						this.getcard()
					} else {
					
					}
				});
			},
			 formatDate(dateString) {
			    if (!dateString) return '';
			    const date = new Date(dateString);
			    const year = date.getFullYear();
			    const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始,需要加1
			    const day = date.getDate().toString().padStart(2, '0');
			    return `${year}-${month}-${day}`;
			  },
			getcard(){
				let data={
					userId:this.userinfo.userId
				}
				this.$u.get("/appVerify/getCouponListByUserId?",data ).then((res) => {
							
					if (res.code == 200) {
						this.CouponLists = res.data
						
					} else { 
						// uni.showToast({
						// 	title: res.msg,
						// 	icon: 'none',
						// 	duration: 2000
						// });
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.page {
		width: 750rpx;

		.cont {
			display: flex;
			justify-content: center;
			flex-wrap: wrap;
			.sub_btn{
				position: fixed;
				bottom: 48rpx;
				left: 34rpx;
				width: 680rpx;
				height: 90rpx;
				background: #64B6A7;
				border-radius: 54rpx 54rpx 54rpx 54rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-weight: 500;
				font-size: 40rpx;
				color: #FFFFFF;
			}
			.tips {
				margin-left: 36rpx;
				margin-top: 60rpx;
				width: 100%;
				font-weight: 500;
				font-size: 36rpx;
				color: #808080;
			}
			.card3 {
				position: relative;
				margin-top: 18rpx;
				width: 680rpx;
				height: 410rpx;
				background-image: url('https://lxnapi.ccttiot.com/bike/img/static/uZCTchd4XbAwsmNDuGun');
				background-size: cover;
				/* 背景图片等比缩放以覆盖整个容器 */
				background-position: center;
				/* 背景图片居中显示 */
				background-repeat: no-repeat;
				/* 防止背景图片重复 */
				.txt4{
					position: absolute;
					top: 72rpx;
					right: 78rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #F5C164;
				}
				.imgs{
					position: absolute;
					top: 192rpx;
					right: 54rpx;
					width: 66rpx;
					height: 66rpx;
					image{
						width: 66rpx;
						height: 66rpx;
					}
				}
				
			}
			.card2 {
				// display: flex;
				// flex-wrap: wrap;
				position: relative;
				padding: 22rpx 46rpx;
				margin-top: 44rpx;
				width: 680rpx;
				height: 226rpx;
				background-image: url('https://lxnapi.ccttiot.com/bike/img/static/uc3Hj4vMSljiPB1JCYZH');
				background-size: cover;
				/* 背景图片等比缩放以覆盖整个容器 */
				background-position: center;
				/* 背景图片居中显示 */
				background-repeat: no-repeat;
				.imgs{
					position: absolute;
					top: 80rpx;
					right: 54rpx;
					width: 66rpx;
					height: 66rpx;
					image{
						width: 66rpx;
						height: 66rpx;
					}
				}
				.txt1 {
					width: 100%;
					font-weight: 500;
					font-size: 32rpx;
					color: #FFFFFF;
				}

				.txt2 {
					width: 100%;
					margin-top: 10rpx;
					font-weight: 500;
					font-size: 24rpx;
					color: #FFFFFF;
				}

				.btn1 {
					margin-top: 34rpx;
					display: inline-flex;
					font-weight: 500;
					font-size: 24rpx;
					color: #FFFFFF;
					padding: 12rpx 18rpx;
					border-radius: 10rpx 10rpx 10rpx 10rpx;
					border: 2rpx solid #FFFFFF;
				}
			}

			.card1 {
				display: flex;
				flex-wrap: nowrap;
				justify-content: space-between;
				padding: 44rpx 48rpx;
				width: 680rpx;
				height: 142rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 10rpx 64rpx 0rpx rgba(0, 0, 0, 0.08);

				.card_txt {
					font-weight: 500;
					font-size: 40rpx;
					color: #808080;
				}

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

		}


	}
</style>