uniapp 结合uview实现复选弹窗

uniapp yekong

uniapp开发的小程序需要一个可以复选的弹窗。 结合uview实现复选弹窗,记录一下后期遇到类似的可以直接复用。
uniapp 结合uview实现复选弹窗

第二版

uniapp 复选效果 限制最多3个 选择语言

代码

<template>
	<view>
		<view @click="show=true">
			<slot></slot>
		</view>
		<u-popup :show="show" mode="bottom" bgColor="transparent">
			<view class="popupwin">
				<div class="popTitle">
					选择语言
				</div>
				<div class="close" @click="getHide">
					<u-icon name="close"></u-icon>
				</div>
				<scroll-view class="searchbody" scroll-y>
					<div class="list">
						<div @click="getactive(item)" class="listitem" v-for="(item,index) in list" :key="index">
							<text>{{item.name}}</text>
							<div @click.stop="getactiveremove(item)" v-if="item.active" class="icon">
								<u-icon size="24" name="minus-circle-fill" color="#FFA41E"></u-icon>
							</div>
						</div>
					</div>
				</scroll-view>
				<div class="logout2">
					<div class="logout" @click="returnlist">
						确认
					</div>
				</div>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		labelGetList
	} from '@/config/api.js'
	export default {
		data() {
			return {
				show: false,
				keyword: '',
				list: [{
					name: '中文',
					active: false
				}, {
					name: '日文',
					active: false
				}, {
					name: '英语',
					active: false
				}, {
					name: '法语',
					active: false
				}, {
					name: '德语',
					active: false
				}, {
					name: '俄语',
					active: false
				}, ],
			}
		},
		props: {
			datastr: {
				type: String,
				default () {
					return '';
				}
			}
		},
		watch: {
			datastr() {
				if (this.datastr) {
					var data = this.datastr.split(",");
					this.list.forEach((type, index) => {
						data.forEach((type2) => {
							if (type2 == type.name) {
								this.list[index].active = true
							}
						});
					});
				}
			},
		},
		mounted() {},
		methods: {
			getHide() {
				this.show = false
			},
			returnlist() {
				var list = []
				this.list.forEach((type) => {
					if (type.active) {
						list.push(type.name)
					}
				});
				this.$emit('getdata', list.join(","))
				this.getHide()
			},
			getactive(item) {
				var that = this;
				console.log(item)
				this.list.forEach((type) => {
					if (item.name == type.name) {
						type.active = true
					}
				});
				// that.returnlist()
			},
			getactiveremove(item) {
				var that = this;
				that.list.forEach((type) => {
					if (item.name == type.name) {
						type.active = false
					}
				});
				// that.returnlist()
			},
		}
	}
</script>

<style scoped lang="scss">
	.popupwin {
		width: 750rpx;
		// height: 750rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 0px 0px;
		opacity: 1;
		position: relative;
		z-index: 1000;
	}

	.line {
		width: 100rpx;
		height: 4rpx;
		opacity: 1;
		background: #7D7D7D;
		margin: 25rpx auto;
	}

	.list {
		width: 686rpx;
		margin: 0 auto;

		.listitem {
			height: 96rpx;
			width: 100%;
			border-bottom: 1rpx solid rgba(#000000, 0.1);
			display: flex;
			justify-content: space-between;
			align-items: center;
			flex-wrap: nowrap;
			flex-direction: row;

			image {
				width: 34rpx;
				height: 34rpx;
				margin-right: 32rpx;
			}

			text {
				margin-left: 32rpx;
				font-size: 34rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #000000;
			}
		}
	}

	.nodata {
		font-size: 34rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #7D7D7D;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: nowrap;
		flex-direction: row;
		margin: 64rpx auto;
	}

	.searchbody {
		height: 550rpx;
	}
	.close {
		position: absolute;
		right: 30rpx;
		top: 30rpx;
		z-index: 10;
	}

	.logout {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: nowrap;
		flex-direction: row;
		margin: 64rpx auto;
		font-size: 34rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		width: 311rpx;
		height: 80rpx;
		background: #2563E9;
		border-radius: 20rpx;
		opacity: 1;
	}

	.logout2 {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: nowrap;
		flex-direction: row;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
	}

	.popTitle {
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: nowrap;
		flex-direction: row;
		font-size: 32rpx;
		color: #000;
	}
</style>

喜欢