image.png
<!--<template>
<view>
<uni-nav-bar left-icon="back" title="合并账号"></uni-nav-bar>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>-->
<template>
<view>
<uni-nav-bar left-icon="back" title="合并账号"></uni-nav-bar>
<!-- 单个复选框 -->
<!--<checkbox-group class="block" @change="checkboxChange">
<view class="cu-form-group">
<view class="title">复选选操作(checkbox)</view>
<checkbox :class="isChecked?'checked':''" :checked="isChecked?true:false" value="1"></checkbox>
</view>
</checkbox-group>-->
<!-- 多个复选框,带全选 -->
<view class="tl-section">
<checkbox-group class="block" @change="changeCheckbox">
<view v-for="item in checkboxData" :key="item.value" class="tl-row">
<view>
<image :src="defaultImg" class="tl-img-100"></image>
</view>
<view class="tl-center">
<view>张三三</view>
<view>187****1998 <text class="tl-font-green">商家</text></view>
</view>
<view>
<checkbox :value="String(item.value)" :checked="checkedArr.includes(String(item.value))" :class="{'checked':checkedArr.includes(String(item.value))}"></checkbox>
</view>
</view>
</checkbox-group>
</view>
<view>
<checkbox-group @change="allChoose">
<label>
全选 <checkbox value="all" :class="{'checked':allChecked}" :checked="allChecked?true:false"></checkbox>
</label>
</checkbox-group>
</view>
</view>
</template>
<script>
export default {
data() {
return {
isChecked:false,
defaultImg: 'https://wkfiles.weikepingtai.com/wks/20201112/images/20201112042458217.jpg',
checkboxData:[
{'value':0,'label':'选项一'},
{'value':1,'label':'选项二'},
{'value':2,'label':'选项三'},
{'value':3,'label':'选项四'},
{'value':4,'label':'选项五'},
{'value':5,'label':'选项六'},
{'value':6,'label':'选项七'},
{'value':7,'label':'选项八'},
{'value':8,'label':'选项九'},
{'value':9,'label':'选项十'}
],
checkedArr:[], //复选框选中的值
allChecked:false //是否全选
}
},
methods: {
// 单个复选框事件
checkboxChange(e) {
let values = e.detail.value;
if(values[0]==1){
this.isChecked=true;
}else{
this.isChecked=false;
}
},
// 多选复选框改变事件
changeCheckbox(e){
this.checkedArr = e.detail.value;
// 如果选择的数组中有值,并且长度等于列表的长度,就是全选
if(this.checkedArr.length>0 && this.checkedArr.length==this.checkboxData.length){
this.allChecked=true;
}else{
this.allChecked=false;
}
},
// 全选事件
allChoose(e){
let chooseItem = e.detail.value;
// 全选
if(chooseItem[0]=='all'){
this.allChecked=true;
for(let item of this.checkboxData){
let itemVal=String(item.value);
if(!this.checkedArr.includes(itemVal)){
this.checkedArr.push(itemVal);
}
}
}else{
// 取消全选
this.allChecked=false;
this.checkedArr=[];
}
}
}
}
</script>
<style>
.tl-section{
padding: 78rpx 60rpx 44rpx 60rpx;
}
.tl-row{
display: flex;
justify-content: flex-start;
align-items: center;
position: relative;
height: 172rpx;
border-bottom: 2rpx solid #E7E9EE;
}
.tl-img-100{
width: 100rpx;
height: 100rpx;
background: #C1BFBF;
border-radius: 50%;
}
.tl-center{
width: 420rpx;
margin: 0 20rpx;
}
.tl-font-green{
font-size: 28rpx;
font-family: PingFang SC;
font-weight: 500;
color: #4DB046;
margin-left: 16rpx;
}
</style>
网友评论