
HTML:
<!--投票列表-->
<ul class="list f16"><li v-for="(list,index) in listData" :key="index" ><!--div @click="goAbout(list.orderid)">img :src="list.thumb"<span><i>编号:</i>{{list.orderid}}</span></div--><h6>姓名:{{list.tpname}}</h6><p>票数:{{list.num}}</p><label><input type="checkbox" :value="list.orderid" v-model="checkGroup" @click="getCheck($event,list.orderid)"><b>已选中</b></label></li>
</ul><!--投票按钮-->
<div class="endButton" @click="checkVote"><button>提交投票</button><div class="countNum" v-if="checkGroup.length > 0">请选择<b>3</b>个,已选择<b> {{checkGroup.length}} </b>个</div>
</div>
JS:
let checkGroup = ref([]) //选中数据//选中 限制选中数量上限在选中时校验
const getCheck =(event,orderid)=>{//设置最多选择三个if(checkGroup.value.length < 3 && event.target.checked) {checkGroup.value.push(orderid)}else if(!event.target.checked){checkGroup.value.splice(checkGroup.value.indexOf(orderid),1)}else{event.target.checked = false//提示使用vantUiproxy.$toast({message: '已超出投票人数!',icon: 'warning',});}
}//提交投票 限制选中数量下限在提交时校验
const checkVote=()=>{//设置至少选择三个if(checkGroup.value.length <3){proxy.$toast({message: '至少选择三个再投票',icon: 'warning',});return}//其他代码if ("提交成功") {//提示使用vantUiproxy.$toast({message: '投票成功!',icon: 'smile',});//清除checkGroup选中数据checkGroup.value = []} else {//提示使用vantUiproxy.$toast({message: response.data.info,icon: 'warning',});//清除checkGroup选中数据checkGroup.value = []}})//其他代码}
CSS:
/*列表样式*/
.list{display:flex;justify-content:space-between;flex-wrap:wrap;}
.list li{width:48%;background:#d71f18;border-radius:1vh;overflow:hidden;margin-top:2vh;color:#fff;text-align:center;padding-bottom:1vh;}
.list li div{position:relative;}
.list li span{display:block;position:absolute;left:1vh;bottom:1vh;background:rgba(0,0,0,0.6);padding:0 1.5vh 0 0;font-size:1.6vh;border-radius:1vh;overflow:hidden;color:#fff;}
.list li span i{display:inline-block;font-style:normal;background:#ac0006;padding:1vh 0 1vh 1vh;margin-right:1vh;}
.list li h6{padding:1.5vh 0 1vh 0;}
.list li p{padding:0 1vh;}
.list li label{display:block;background:#ffecd1;height:3.6vh;position:relative;border-radius:0.5vh;overflow:hidden;width:90%;margin:1.5vh auto 0 auto;}
.list li label:before{content:"\70b9\51fb\9009\4e2d";position:absolute;left:0;top:0;width:100%;text-align:center;color:#c0151b;line-height:3.8vh;}
.list li label input,.list li label input+b{display:none;}
.list li label input:checked+b{background:#ffcc00;display:block;position:absolute;left:0;top:0;width:100%;z-index:2;color:#c0151b;line-height:3.8vh;text-align:center;font-weight:normal;}/*底部按钮样式*/
.endButton{position:fixed;left:0;bottom:0;width:100%;background:#ac0006;z-index:5;padding:1vh 0 1.5vh 0;color:#fff;text-align:center;}
.countNum{padding-top:1vh;font-size:1.4vh;}
.endButton button{border:none;background:none;font-size:2.4vh;font-weight:bold;}