selectcoupon.vue 6.4 KB
<template>
	<view class="page">
		<view class="nodata" v-if="couponlist.length==0">暂无优惠券</view>
		<view class="boxb" v-else>
			<view class="container">
				<view class="bitem flexone" @click="item.status!=1?'':selcoupon(item,index)" :class="item.status!=1?'borderactive':''"  v-for="(item,index) in couponlist" :key="index">
					<view class="couponleft" v-if="item.status!=1">
						<image src="../../static/cartnosel.png" mode="" v-if="item.sel==false"></image>
						<image src="../../static/cartsel.png" mode="" v-else></image>
					</view>
					
					<view class="couponleft" v-else >
						<image src="../../static/cartnosel.png" mode="" v-if="item.sel==false"></image>
						<image src="../../static/cartsel.png" mode="" v-else></image>
					</view>
					<view class="couponright">
						<view class="top">
							<view class="price" :class="item.status!=1?'wordacticve':''">¥{{item.price}}</view>
							<view class="right">
								<view class="bname">
									<text :class="item.status!=1?'wordacticve':''">抵用券</text>
									<!-- <text>待使用</text> -->
								</view>
								<view class="tips" :class="item.status!=1?'wordacticve':''">{{item.name}}</view>
							</view>
						</view>
						<view class="btime" :class="item.status!=1?'wordacticve':''">
							有效期至:{{item.pasttime}}
						</view>
					</view>
				</view>
				
			</view>
			
			<view class="add">
				<view class="addcount" @click="surecoupon">确认</view>
			</view>
		</view>
	</view>
</template>
<script>
	import app from "../../App.vue";
	export default {
		data() {
			return {
				page:1,
				couponlist:[],
				price:''
			}
		},
		
		onLoad() {
			this.getcoupon()
			
		},
		methods: {
			// 获取优惠券
			getcoupon() {
				let that = this;
				var url = 'user_ticket/get_user_ticket';
				var params = {
					price:that.price,
					is_get:1,
					type:'',
					page:that.page,
					pageNum:10,
				}
				console.log(params)
				app.post(url, params, "post").then((res) => {
					console.log(res);
					that.couponlist=that.couponlist.concat(res.data.data);
					that.couponlist.forEach(function(value,index,array){
						value.sel=false
					})
					that.couponlist=that.couponlist;
					let couponitem=uni.getStorageSync("couponitem");
					that.couponlist.forEach(function(value,index,array){
						if(value.id==couponitem.id){
							value.sel=true
						}
					})
					that.couponlist=that.couponlist;
					that.$forceUpdate()
					console.log(couponitem,'优惠券又回去ss')

				}).catch((err) => {
					console.log(err)

				})
			},
			//选择优惠券
			selcoupon(item,index){
				let that=this
				console.log(item);
				that.couponlist.forEach(function(value,index,array){
					if(value.id==item.id){
						that.couponlist[index].sel=!that.couponlist[index].sel;
					}else{
						that.couponlist[index].sel=false
					}
				})
				
				console.log(that.couponlist[index].sel)
				
				that.couponlist=that.couponlist;
				that.$forceUpdate()
				if(that.couponlist[index].sel==true){
					 uni.setStorageSync("couponitem",item);
				}else{
					 uni.setStorageSync("couponitem",'');
				}
				
			},
			surecoupon(){
				uni.navigateBack({
					checked:true
				})
			}
		},
		onReachBottom() {
			let newpage=this.page;
			newpage++;
			this.page=newpage;
			this.getcoupon()
			
		}
	}
</script>

<style>
	page {
		background: #F7F7F7;
	}

	.couponleft {
		width: 24rpx;
		height: 24rpx;
		font-size: 0;
		margin-right: 29rpx;
	}

	.navbox {
		height: 88rpx;
		background: #fff;
		display: flex;
	}

	.navitem {
		width: 50%;
		height: 100%;
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(35, 35, 35, 1);
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.boxa {
		margin-top: 16rpx;
		background: #fff;
		overflow: hidden;
		padding: 0 36rpx;
		box-sizing: border-box;
	}

	.aitem {
		height: 150rpx;
		border-bottom: 1px solid #FEFEFE;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.left {
		width: 340rpx;
	}

	.left .name {
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(35, 35, 35, 1);
	}

	.left .time {
		font-size: 24rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(91, 94, 100, 1);
		margin-top: 8rpx;
	}

	.btn {
		width: 160rpx;
		height: 64rpx;
		border-radius: 8rpx;
		border: 1px solid rgba(255, 148, 23, 1);
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(255, 148, 23, 1);
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.activeA {
		color: #BDC4CE;
		border-color: #BDC4CE;
	}

	.boxb {
		padding: 0 32rpx;
		box-sizing: border-box;
	}

	.xnavbox {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 16rpx;
	}

	.xnavitem {
		width: 212rpx;
		height: 62rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(61, 69, 76, 1);
		display: flex;
		align-items: center;
		justify-content: center;
		background: #fff;
	}

	.xactive {
		background: #C29445;
		color: #fff;
	}

	.container {
		margin-top: 12rpx;
		padding-bottom: 150rpx;
	}

	.bitem {
		margin-top: 16rpx;
		border-left: 8rpx solid #C29445;
		padding: 40rpx 32rpx 20rpx;
		box-sizing: border-box;
		background: #fff;
	}

	.top {
		height: 156rpx;
		border-bottom: 1px solid #EEEEEE;
		display: flex;
		align-items: center;
	}

	.price {
		font-size: 72rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(194, 148, 69, 1);
		margin-right: 32rpx;
	}

	.right {
		width: 100%;
	}

	.bname {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(91, 94, 100, 1);
	}

	.bname text:first-child {
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 600;
		color: rgba(6, 18, 32, 1);
	}

	.tips {
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(61, 68, 76, 1);
		margin-top: 16rpx;
	}

	.btime {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(61, 69, 76, 1);
		margin-top: 40rpx;
	}

	.borderactive {
		border-color: #BDC4CE;
	}

	.wordacticve {
		font-weight: 500 !important;
		color: rgba(189, 196, 206, 1) !important;
	}
</style>