uniapp写微信小程序——多标签选择和删除

<template>
	<view class="contianer">
	    <view  @click="open">请选择</view>
		    <view class="time_contain" v-else>
				<view class="time_box">
					<view class="time_item" v-for="(item,index) in foodAttrIds" :key="index">{{item.name}}
					<view class="icon" @click="cancleLable(item)"> >>> <uv-icon name="close-circle-fill" color="rgba(58, 98, 255, 1)"></uv-icon></view>
				</view>
			</view>
		</view>
		<!--客户标签 弹窗 -->
		<uv-popup ref="popup" mode="bottom"  :close-on-click-overlay="false">
			<view class="label_box">
				<view class="title">选择标签</view>
				<view class="cancle" @click="close">取消</view>
			</view>
			<view class="label_detail">
				<view v-for="(item,index) in listType"  :key="index" class="label_gray" @click="onReplace(item)" 
				:class="{label_blue:foodAttrIds.indexOf(item)>=0}">
					{{item.name}}
				</view>
			</view>
			<view class="determine">
				<uv-button :custom-style="customStyle"  text="确定" @click="close"></uv-button>
			</view>
		</uv-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 选择标签
				listType:[{id:1,name:'标签1'},{id:2,name:'标签2'},{id:3,name:'标签3'}],
				// 选中的标签数组  起始没有标签选中
				foodAttrIds : [],
			};
		},
		methods:{
			// 打开标签抽屉
			open(){
				this.$refs.popup.open();
			},
			// 关闭标签抽屉
			close(){
				this.$refs.popup.close();
				// 如果时间便签组为空,则显示"请选择",否则显示标签
				if(this.foodAttrIds.length>0){
					this.select = false;
				}else{
					this.select = true;
				}
			},
			//选中标签则加入foodAttrIds[]
			//取消选中则从foodAttrIds[]删除
			onReplace(foodAttrId){
				
				var i = this.foodAttrIds.indexOf(foodAttrId);
                //在数组中,删除
				if(i>=0){
					this.foodAttrIds.splice(i,1);
				}else{
				//添加
					this.foodAttrIds.push(foodAttrId);
				}
			},
			// 标签的删除
			cancleLable(item){
				console.log(item);
				var i = this.foodAttrIds.indexOf(item);
				if(i>=0){
					this.foodAttrIds.splice(i,1);
				}
				if(this.foodAttrIds.length==0){
					this.select=true
				}
			},
		
		},
	}
</script>

<style lang="scss">
	.contianer{
		
		// 标签组 抽屉
		.label_box{
			padding: 0 30rpx;
			box-sizing: border-box;
			text-align: center;
			color: #333333FF;
			font-size: 33rpx;
			line-height: 70rpx;
			position: relative;
			.cancle{
				width: 20%;
				position: absolute;
				right: 0;
				top: 0;
			}
			
		}
		.determine{
			width: 90%;
			margin: 0 5%;
		}
		.label_detail{
			padding: 0px 30rpx;
			box-sizing: border-box;
			display: flex;
			flex-wrap: wrap;
			margin-top: 30rpx;
			margin-bottom: 46rpx;
			overflow: scroll;
			flex-flow: row;
			flex-wrap: wrap;
			font-size: 28rpx;
			.label_gray{
				padding: 15rpx 10rpx;
				box-sizing: border-box;
				border: 1px solid gray;
				text-align: center;
				border-radius: 10rpx;
				color: #707070;
				height: 74rpx;
				margin: 10rpx;
			}
			.label_blue{
				padding:15rpx 10rpx;
				box-sizing: border-box;
				border: 1px solid #3D6DFFFF;
				text-align: center;
				border-radius: 10rpx;
				color: #3D6DFFFF;
				height: 74rpx;
				margin: 10rpx;
			}
		}
		// 标签多选
		.time_contain{
			width: 396rpx;
			overflow-x: scroll;	
			.time_box{
				white-space:nowrap;
				height: 61rpx;
				.time_item{
					display: inline-block;
					padding: 0px 28rpx;
					background-color: #e7eefb;
					border-radius: 17rpx;
					margin-right: 10rpx;
					font-size: 25rpx;
					height: 50rpx;
					line-height: 50rpx;
					position: relative;
					margin-top: 10rpx;
					.icon{
					    position: absolute;
					    right: -6rpx;
					    top: -4rpx;
					}
				}
			}
		}
	}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值