<template> <div id="cardBox"> <div class="card_item" v-for="(item,index) in cardList" :key="index" @click="handleCard(index)"> <div class="left"> <div class="top"> <img v-if="item.img" :src="item.img" alt=""> <p class="title"><span>{{item.title}}</span></p> </div> <p class="end_time">可用商品:{{item.proName}}</p> </div> <div class="right"> <p class="discount"><span>¥</span>{{item.couponPrice}}</p> <img class="select" v-if="selectIndex==index" src="@/assets/service/true.png" alt=""> </div> </div> <van-empty v-if="cardList.length==0" description="暂无优惠券" /> <div class="Collection"> <div class="box box1"> <p>优惠:¥{{selectIndex>=0?cardList[selectIndex].couponPrice:'0'}}</p> </div> <div class="box box2"> <span @click="confirmCard()">确认</span> </div> </div> </div> </template> <script> export default { name: 'ServiceCardSelect', data () { return { cardList: [], selectIndex: -1, } }, mounted () { let cardList = localStorage.getItem('proCoupon') if (cardList) { this.cardList = JSON.parse(cardList) } }, methods: { // 点击优惠券 handleCard (index) { if (this.selectIndex == index) { this.selectIndex = -1 } else { this.selectIndex = index } }, // 确认使用优惠券 confirmCard () { if (this.selectIndex > -1) { localStorage.setItem('useCard', JSON.stringify(this.cardList[this.selectIndex])) } this.$router.back() } } } </script> <style lang="scss" scoped> #cardBox { width: 100%; min-height: 100%; background: rgb(246, 246, 250); overflow: hidden; .card_item { width: 726px; height: 216px; background: url("../../assets/service/card.png"); background-size: 100%; margin: 0 auto; margin-top: 20px; position: relative; p { width: 100%; margin: 0; } .left { display: inline-block; width: 68%; height: 100%; vertical-align: top; box-sizing: border-box; padding: 24px 40px; padding-right: 0; .top { display: flex; img { width: 66px; height: 66px; background: #d8d8d8; border-radius: 6px; } .title { font-size: 24px; font-weight: bold; margin-left: 10px; word-break: break-all; color: #333; span { color: #7f5316; } } } } .right { width: 32%; height: 100%; display: inline-flex; align-content: center; flex-wrap: wrap; } .title { font-size: 32px; color: #fff; } .end_time { font-size: 24px; color: #999; margin-top: 6px; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; } .des { font-size: 24px; color: #fff; margin-top: 58px; } .discount { text-align: center; font-size: 52px; font-weight: bold; span { font-size: 28px; } } .condition { text-align: center; font-size: 24px; color: #894b2f; margin-top: 16px; } .select { width: 28px; position: absolute; top: 22px; right: 22px; } } .Collection { background-color: white; position: fixed; bottom: 0; left: 0; width: 100%; padding: 28px 22px; box-sizing: border-box; padding-bottom: 50px; z-index: 500; box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.34); .box { display: inline-block; vertical-align: middle; color: #666666; .icon { display: inline-block; width: 45%; text-align: center; font-size: 24px; p { // margin: 0; color: #999999; margin-top: 8px; } i { font-size: 48px; color: rgb(45, 45, 45); font-weight: bold; } } span { display: inline-block; width: 100%; line-height: 92px; box-sizing: border-box; border-radius: 100px; color: white; font-size: 32px; background: #4092ff; text-align: center; box-shadow: 0px 10px 40px 0px #a0c9ff; b { display: inline-block; vertical-align: middle; margin-left: 20px; color: white; } i { vertical-align: middle; font-size: 44px; font-weight: bold; } } } .box1 { width: 40%; p { font-size: 28px; font-weight: bold; color: #333; } del { font-size: 20px; color: #999; } } .box2 { width: 60%; } } } </style>