自写选择框,全选框

16 篇文章 0 订阅

技术:uniapp+uview

<view @click="isManagement = true">操作</view>

<view class="list-item" v-for="(item,index) in list" :key="index">
	<u-image width="100%" height="274rpx" :src=""></u-image>
	<view class="checkbox" :class="{checked:checkedIndex.indexOf(item.Id) >= 0}"
		@click.stop="check(item.Id)" v-if="isManagement">
		<u-icon v-if="checkedIndex.indexOf(item.Id) >= 0" name="checkbox-mark"></u-icon>
	</view>
	<view class="item-content">
     ...
	</view>
</view>
<view class="action-section" v-if="isManagement">
	<view class="checkbox u-margin-right-16" :class="{checked:checkall}" @click.stop="checkAll()">
		<u-icon v-if="checkall" name="checkbox-mark"></u-icon>
	</view>
	<view class="checkall-text">全选</view>
	<view class="deletebutton" @click="deleteChecked">删除</view>
</view>
check(index) {
	let _index = this.checkedIndex.indexOf(index)
	if (_index > -1) {
		// checkedIndex 数组里有这个项,取消选中
		this.checkedIndex.splice(_index, 1)
	} else {
		// 没有这个项,选中
		this.checkedIndex.push(index);
	}
	if (this.checkedIndex.length == this.list.length) {
		//选中数组的长度等于全部数组的长度,全选成立
		this.checkall = true;
	} else {
		this.checkall = false;
	}
},
checkAll() {
	this.checkall = !this.checkall;
	this.checkedIndex = [];
	if (this.checkall) {
		// 全选
		this.list.forEach((e, index) => {
			this.checkedIndex.push(e.Id);
		})
	} else {
		// 取消全选
		return;
	}
}
.list-item {
	width: 350rpx;
	margin-bottom: 16rpx;
	background: #FFFFFF;
	position: relative;

	.checkbox {
		position: absolute;
		width: 34rpx;
		height: 34rpx;
		border-radius: 50%;
		background: #FFFFFF;
		top: 16rpx;
		right: 16rpx;
		border: 1px solid #777777;
	}

	.checked {
		font-size: 18rpx;
		text-align: center;
		line-height: 34rpx;
		background: #CE0032;
		color: #FFFFFF;
	}

	.item-content {
		//...
	}
}
.action-section {
	position: fixed;
	z-index: 95;
	display: flex;
	align-items: center;
	padding: 30rpx 26rpx;
	bottom: 0;
	left: 0;
	right: 0;
	background-color: #FFFFFF;

	.checkbox {
		width: 34rpx;
		height: 34rpx;
		border-radius: 50%;
		background: #FFFFFF;
		border: 1px solid #777777;
	}

	.checked {
		font-size: 18rpx;
		text-align: center;
		line-height: 34rpx;
		background: #CE0032;
		color: #FFFFFF;
	}

	.checkall-text {
		font-size: 30rpx;
		color: #777777;
	}

	.deletebutton {
		width: 150rpx;
		height: 66rpx;
		background: #FFFFFF;
		border-radius: 34rpx;
		border: 2rpx solid #CE0032;
		font-size: 30rpx;
		color: #CE0032;
		line-height: 66rpx;
		text-align: center;
		margin-left: auto;
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值